blob: 5c7e7d83d394269d533f34a89e4dcc3d726c5df9 [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Don Skidmore94971822012-01-06 03:24:16 +00004 Copyright(c) 1999 - 2012 Intel Corporation.
Auke Kok9a799d72007-09-15 14:07:45 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
Auke Kok9a799d72007-09-15 14:07:45 -070023 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26*******************************************************************************/
27
28#include <linux/types.h>
29#include <linux/module.h>
30#include <linux/pci.h>
31#include <linux/netdevice.h>
32#include <linux/vmalloc.h>
33#include <linux/string.h>
34#include <linux/in.h>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000035#include <linux/interrupt.h>
Auke Kok9a799d72007-09-15 14:07:45 -070036#include <linux/ip.h>
37#include <linux/tcp.h>
Alexander Duyck897ab152011-05-27 05:31:47 +000038#include <linux/sctp.h>
Lucy Liu60127862009-07-22 14:07:33 +000039#include <linux/pkt_sched.h>
Auke Kok9a799d72007-09-15 14:07:45 -070040#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090041#include <linux/slab.h>
Auke Kok9a799d72007-09-15 14:07:45 -070042#include <net/checksum.h>
43#include <net/ip6_checksum.h>
44#include <linux/ethtool.h>
Jiri Pirko01789342011-08-16 06:29:00 +000045#include <linux/if.h>
Auke Kok9a799d72007-09-15 14:07:45 -070046#include <linux/if_vlan.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040047#include <linux/prefetch.h>
Yi Zoueacd73f2009-05-13 13:11:06 +000048#include <scsi/fc/fc_fcoe.h>
Auke Kok9a799d72007-09-15 14:07:45 -070049
50#include "ixgbe.h"
51#include "ixgbe_common.h"
Don Skidmoreee5f7842009-11-06 12:56:20 +000052#include "ixgbe_dcb_82599.h"
Greg Rose1cdd1ec2010-01-09 02:26:46 +000053#include "ixgbe_sriov.h"
Auke Kok9a799d72007-09-15 14:07:45 -070054
55char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070056static const char ixgbe_driver_string[] =
Joe Perchese8e9f692010-09-07 21:34:53 +000057 "Intel(R) 10 Gigabit PCI Express Network Driver";
Neerav Parikhea818752012-01-04 20:23:40 +000058char ixgbe_default_device_descr[] =
59 "Intel(R) 10 Gigabit Network Connection";
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000060#define MAJ 3
Don Skidmore19d478b2011-10-07 03:53:51 +000061#define MIN 6
62#define BUILD 7
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000063#define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
Don Skidmorea38a1042011-05-20 03:05:14 +000064 __stringify(BUILD) "-k"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070065const char ixgbe_driver_version[] = DRV_VERSION;
Don Skidmorea52055e2011-02-23 09:58:39 +000066static const char ixgbe_copyright[] =
Don Skidmore94971822012-01-06 03:24:16 +000067 "Copyright (c) 1999-2012 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070068
69static const struct ixgbe_info *ixgbe_info_tbl[] = {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070070 [board_82598] = &ixgbe_82598_info,
PJ Waskiewicze8e26352009-02-27 15:45:05 +000071 [board_82599] = &ixgbe_82599_info,
Don Skidmorefe15e8e2010-11-16 19:27:16 -080072 [board_X540] = &ixgbe_X540_info,
Auke Kok9a799d72007-09-15 14:07:45 -070073};
74
75/* ixgbe_pci_tbl - PCI Device ID Table
76 *
77 * Wildcard entries (PCI_ANY_ID) should come last
78 * Last entry must be all 0s
79 *
80 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
81 * Class, Class Mask, private data (not used) }
82 */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000083static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
Alexander Duyck54239c62011-07-15 03:06:06 +000084 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
85 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
86 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
87 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
88 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
89 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
90 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
91 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
92 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
93 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
94 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
95 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
96 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
97 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
98 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
99 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
100 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
102 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
Emil Tantilov7d145282011-09-08 08:30:14 +0000110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
Emil Tantilov9e791e42011-11-04 06:43:29 +0000111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
Auke Kok9a799d72007-09-15 14:07:45 -0700112 /* required last entry */
113 {0, }
114};
115MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
116
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400117#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800118static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000119 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800120static struct notifier_block dca_notifier = {
121 .notifier_call = ixgbe_notify_dca,
122 .next = NULL,
123 .priority = 0
124};
125#endif
126
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000127#ifdef CONFIG_PCI_IOV
128static unsigned int max_vfs;
129module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000130MODULE_PARM_DESC(max_vfs,
131 "Maximum number of virtual functions to allocate per physical function");
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000132#endif /* CONFIG_PCI_IOV */
133
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +0000134static unsigned int allow_unsupported_sfp;
135module_param(allow_unsupported_sfp, uint, 0);
136MODULE_PARM_DESC(allow_unsupported_sfp,
137 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
138
Auke Kok9a799d72007-09-15 14:07:45 -0700139MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
140MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
141MODULE_LICENSE("GPL");
142MODULE_VERSION(DRV_VERSION);
143
144#define DEFAULT_DEBUG_LEVEL_SHIFT 3
145
Alexander Duyck70864002011-04-27 09:13:56 +0000146static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
147{
148 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
149 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
150 schedule_work(&adapter->service_task);
151}
152
153static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
154{
155 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
156
Stephen Hemminger52f33af2011-12-22 16:34:52 +0000157 /* flush memory to make sure state is correct before next watchdog */
Alexander Duyck70864002011-04-27 09:13:56 +0000158 smp_mb__before_clear_bit();
159 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
160}
161
Taku Izumidcd79ae2010-04-27 14:39:53 +0000162struct ixgbe_reg_info {
163 u32 ofs;
164 char *name;
165};
166
167static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
168
169 /* General Registers */
170 {IXGBE_CTRL, "CTRL"},
171 {IXGBE_STATUS, "STATUS"},
172 {IXGBE_CTRL_EXT, "CTRL_EXT"},
173
174 /* Interrupt Registers */
175 {IXGBE_EICR, "EICR"},
176
177 /* RX Registers */
178 {IXGBE_SRRCTL(0), "SRRCTL"},
179 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
180 {IXGBE_RDLEN(0), "RDLEN"},
181 {IXGBE_RDH(0), "RDH"},
182 {IXGBE_RDT(0), "RDT"},
183 {IXGBE_RXDCTL(0), "RXDCTL"},
184 {IXGBE_RDBAL(0), "RDBAL"},
185 {IXGBE_RDBAH(0), "RDBAH"},
186
187 /* TX Registers */
188 {IXGBE_TDBAL(0), "TDBAL"},
189 {IXGBE_TDBAH(0), "TDBAH"},
190 {IXGBE_TDLEN(0), "TDLEN"},
191 {IXGBE_TDH(0), "TDH"},
192 {IXGBE_TDT(0), "TDT"},
193 {IXGBE_TXDCTL(0), "TXDCTL"},
194
195 /* List Terminator */
196 {}
197};
198
199
200/*
201 * ixgbe_regdump - register printout routine
202 */
203static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
204{
205 int i = 0, j = 0;
206 char rname[16];
207 u32 regs[64];
208
209 switch (reginfo->ofs) {
210 case IXGBE_SRRCTL(0):
211 for (i = 0; i < 64; i++)
212 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
213 break;
214 case IXGBE_DCA_RXCTRL(0):
215 for (i = 0; i < 64; i++)
216 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
217 break;
218 case IXGBE_RDLEN(0):
219 for (i = 0; i < 64; i++)
220 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
221 break;
222 case IXGBE_RDH(0):
223 for (i = 0; i < 64; i++)
224 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
225 break;
226 case IXGBE_RDT(0):
227 for (i = 0; i < 64; i++)
228 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
229 break;
230 case IXGBE_RXDCTL(0):
231 for (i = 0; i < 64; i++)
232 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
233 break;
234 case IXGBE_RDBAL(0):
235 for (i = 0; i < 64; i++)
236 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
237 break;
238 case IXGBE_RDBAH(0):
239 for (i = 0; i < 64; i++)
240 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
241 break;
242 case IXGBE_TDBAL(0):
243 for (i = 0; i < 64; i++)
244 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
245 break;
246 case IXGBE_TDBAH(0):
247 for (i = 0; i < 64; i++)
248 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
249 break;
250 case IXGBE_TDLEN(0):
251 for (i = 0; i < 64; i++)
252 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
253 break;
254 case IXGBE_TDH(0):
255 for (i = 0; i < 64; i++)
256 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
257 break;
258 case IXGBE_TDT(0):
259 for (i = 0; i < 64; i++)
260 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
261 break;
262 case IXGBE_TXDCTL(0):
263 for (i = 0; i < 64; i++)
264 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
265 break;
266 default:
Joe Perchesc7689572010-09-07 21:35:17 +0000267 pr_info("%-15s %08x\n", reginfo->name,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000268 IXGBE_READ_REG(hw, reginfo->ofs));
269 return;
270 }
271
272 for (i = 0; i < 8; i++) {
273 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
Joe Perchesc7689572010-09-07 21:35:17 +0000274 pr_err("%-15s", rname);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000275 for (j = 0; j < 8; j++)
Joe Perchesc7689572010-09-07 21:35:17 +0000276 pr_cont(" %08x", regs[i*8+j]);
277 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000278 }
279
280}
281
282/*
283 * ixgbe_dump - Print registers, tx-rings and rx-rings
284 */
285static void ixgbe_dump(struct ixgbe_adapter *adapter)
286{
287 struct net_device *netdev = adapter->netdev;
288 struct ixgbe_hw *hw = &adapter->hw;
289 struct ixgbe_reg_info *reginfo;
290 int n = 0;
291 struct ixgbe_ring *tx_ring;
Alexander Duyck729739b2012-02-08 07:51:06 +0000292 struct ixgbe_tx_buffer *tx_buffer;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000293 union ixgbe_adv_tx_desc *tx_desc;
294 struct my_u0 { u64 a; u64 b; } *u0;
295 struct ixgbe_ring *rx_ring;
296 union ixgbe_adv_rx_desc *rx_desc;
297 struct ixgbe_rx_buffer *rx_buffer_info;
298 u32 staterr;
299 int i = 0;
300
301 if (!netif_msg_hw(adapter))
302 return;
303
304 /* Print netdevice Info */
305 if (netdev) {
306 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000307 pr_info("Device Name state "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000308 "trans_start last_rx\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000309 pr_info("%-15s %016lX %016lX %016lX\n",
310 netdev->name,
311 netdev->state,
312 netdev->trans_start,
313 netdev->last_rx);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000314 }
315
316 /* Print Registers */
317 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000318 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000319 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
320 reginfo->name; reginfo++) {
321 ixgbe_regdump(hw, reginfo);
322 }
323
324 /* Print TX Ring Summary */
325 if (!netdev || !netif_running(netdev))
326 goto exit;
327
328 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000329 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000330 for (n = 0; n < adapter->num_tx_queues; n++) {
331 tx_ring = adapter->tx_ring[n];
Alexander Duyck729739b2012-02-08 07:51:06 +0000332 tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Alexander Duyckd3d00232011-07-15 02:31:25 +0000333 pr_info(" %5d %5X %5X %016llX %04X %p %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000334 n, tx_ring->next_to_use, tx_ring->next_to_clean,
Alexander Duyck729739b2012-02-08 07:51:06 +0000335 (u64)dma_unmap_addr(tx_buffer, dma),
336 dma_unmap_len(tx_buffer, len),
337 tx_buffer->next_to_watch,
338 (u64)tx_buffer->time_stamp);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000339 }
340
341 /* Print TX Rings */
342 if (!netif_msg_tx_done(adapter))
343 goto rx_ring_summary;
344
345 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
346
347 /* Transmit Descriptor Formats
348 *
349 * Advanced Transmit Descriptor
350 * +--------------------------------------------------------------+
351 * 0 | Buffer Address [63:0] |
352 * +--------------------------------------------------------------+
353 * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
354 * +--------------------------------------------------------------+
355 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
356 */
357
358 for (n = 0; n < adapter->num_tx_queues; n++) {
359 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000360 pr_info("------------------------------------\n");
361 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
362 pr_info("------------------------------------\n");
363 pr_info("T [desc] [address 63:0 ] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000364 "[PlPOIdStDDt Ln] [bi->dma ] "
365 "leng ntw timestamp bi->skb\n");
366
367 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duycke4f74022012-01-31 02:59:44 +0000368 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +0000369 tx_buffer = &tx_ring->tx_buffer_info[i];
Taku Izumidcd79ae2010-04-27 14:39:53 +0000370 u0 = (struct my_u0 *)tx_desc;
Joe Perchesc7689572010-09-07 21:35:17 +0000371 pr_info("T [0x%03X] %016llX %016llX %016llX"
Alexander Duyckd3d00232011-07-15 02:31:25 +0000372 " %04X %p %016llX %p", i,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000373 le64_to_cpu(u0->a),
374 le64_to_cpu(u0->b),
Alexander Duyck729739b2012-02-08 07:51:06 +0000375 (u64)dma_unmap_addr(tx_buffer, dma),
376 dma_unmap_len(tx_buffer, len),
377 tx_buffer->next_to_watch,
378 (u64)tx_buffer->time_stamp,
379 tx_buffer->skb);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000380 if (i == tx_ring->next_to_use &&
381 i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000382 pr_cont(" NTC/U\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000383 else if (i == tx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000384 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000385 else if (i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000386 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000387 else
Joe Perchesc7689572010-09-07 21:35:17 +0000388 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000389
390 if (netif_msg_pktdata(adapter) &&
Alexander Duyck729739b2012-02-08 07:51:06 +0000391 dma_unmap_len(tx_buffer, len) != 0)
Taku Izumidcd79ae2010-04-27 14:39:53 +0000392 print_hex_dump(KERN_INFO, "",
393 DUMP_PREFIX_ADDRESS, 16, 1,
Alexander Duyck729739b2012-02-08 07:51:06 +0000394 phys_to_virt(dma_unmap_addr(tx_buffer,
395 dma)),
396 dma_unmap_len(tx_buffer, len),
397 true);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000398 }
399 }
400
401 /* Print RX Rings Summary */
402rx_ring_summary:
403 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000404 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000405 for (n = 0; n < adapter->num_rx_queues; n++) {
406 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000407 pr_info("%5d %5X %5X\n",
408 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000409 }
410
411 /* Print RX Rings */
412 if (!netif_msg_rx_status(adapter))
413 goto exit;
414
415 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
416
417 /* Advanced Receive Descriptor (Read) Format
418 * 63 1 0
419 * +-----------------------------------------------------+
420 * 0 | Packet Buffer Address [63:1] |A0/NSE|
421 * +----------------------------------------------+------+
422 * 8 | Header Buffer Address [63:1] | DD |
423 * +-----------------------------------------------------+
424 *
425 *
426 * Advanced Receive Descriptor (Write-Back) Format
427 *
428 * 63 48 47 32 31 30 21 20 16 15 4 3 0
429 * +------------------------------------------------------+
430 * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
431 * | Checksum Ident | | | | Type | Type |
432 * +------------------------------------------------------+
433 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
434 * +------------------------------------------------------+
435 * 63 48 47 32 31 20 19 0
436 */
437 for (n = 0; n < adapter->num_rx_queues; n++) {
438 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000439 pr_info("------------------------------------\n");
440 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
441 pr_info("------------------------------------\n");
442 pr_info("R [desc] [ PktBuf A0] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000443 "[ HeadBuf DD] [bi->dma ] [bi->skb] "
444 "<-- Adv Rx Read format\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000445 pr_info("RWB[desc] [PcsmIpSHl PtRs] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000446 "[vl er S cks ln] ---------------- [bi->skb] "
447 "<-- Adv Rx Write-Back format\n");
448
449 for (i = 0; i < rx_ring->count; i++) {
450 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000451 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000452 u0 = (struct my_u0 *)rx_desc;
453 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
454 if (staterr & IXGBE_RXD_STAT_DD) {
455 /* Descriptor Done */
Joe Perchesc7689572010-09-07 21:35:17 +0000456 pr_info("RWB[0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000457 "%016llX ---------------- %p", i,
458 le64_to_cpu(u0->a),
459 le64_to_cpu(u0->b),
460 rx_buffer_info->skb);
461 } else {
Joe Perchesc7689572010-09-07 21:35:17 +0000462 pr_info("R [0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000463 "%016llX %016llX %p", i,
464 le64_to_cpu(u0->a),
465 le64_to_cpu(u0->b),
466 (u64)rx_buffer_info->dma,
467 rx_buffer_info->skb);
468
469 if (netif_msg_pktdata(adapter)) {
470 print_hex_dump(KERN_INFO, "",
471 DUMP_PREFIX_ADDRESS, 16, 1,
472 phys_to_virt(rx_buffer_info->dma),
Alexander Duyckf8003262012-03-03 02:35:52 +0000473 ixgbe_rx_bufsz(rx_ring), true);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000474 }
475 }
476
477 if (i == rx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000478 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000479 else if (i == rx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000480 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000481 else
Joe Perchesc7689572010-09-07 21:35:17 +0000482 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000483
484 }
485 }
486
487exit:
488 return;
489}
490
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800491static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
492{
493 u32 ctrl_ext;
494
495 /* Let firmware take over control of h/w */
496 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
497 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000498 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800499}
500
501static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
502{
503 u32 ctrl_ext;
504
505 /* Let firmware know the driver has taken over */
506 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
507 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000508 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800509}
Auke Kok9a799d72007-09-15 14:07:45 -0700510
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000511/*
512 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
513 * @adapter: pointer to adapter struct
514 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
515 * @queue: queue to map the corresponding interrupt to
516 * @msix_vector: the vector to map to the corresponding queue
517 *
518 */
519static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000520 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700521{
522 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000523 struct ixgbe_hw *hw = &adapter->hw;
524 switch (hw->mac.type) {
525 case ixgbe_mac_82598EB:
526 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
527 if (direction == -1)
528 direction = 0;
529 index = (((direction * 64) + queue) >> 2) & 0x1F;
530 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
531 ivar &= ~(0xFF << (8 * (queue & 0x3)));
532 ivar |= (msix_vector << (8 * (queue & 0x3)));
533 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
534 break;
535 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800536 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000537 if (direction == -1) {
538 /* other causes */
539 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
540 index = ((queue & 1) * 8);
541 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
542 ivar &= ~(0xFF << index);
543 ivar |= (msix_vector << index);
544 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
545 break;
546 } else {
547 /* tx or rx causes */
548 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
549 index = ((16 * (queue & 1)) + (8 * direction));
550 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
551 ivar &= ~(0xFF << index);
552 ivar |= (msix_vector << index);
553 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
554 break;
555 }
556 default:
557 break;
558 }
Auke Kok9a799d72007-09-15 14:07:45 -0700559}
560
Alexander Duyckfe49f042009-06-04 16:00:09 +0000561static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000562 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000563{
564 u32 mask;
565
Alexander Duyckbd508172010-11-16 19:27:03 -0800566 switch (adapter->hw.mac.type) {
567 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000568 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
569 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800570 break;
571 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800572 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000573 mask = (qmask & 0xFFFFFFFF);
574 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
575 mask = (qmask >> 32);
576 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800577 break;
578 default:
579 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000580 }
581}
582
Alexander Duyck729739b2012-02-08 07:51:06 +0000583void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *ring,
584 struct ixgbe_tx_buffer *tx_buffer)
Alexander Duyckd3d00232011-07-15 02:31:25 +0000585{
Alexander Duyck729739b2012-02-08 07:51:06 +0000586 if (tx_buffer->skb) {
587 dev_kfree_skb_any(tx_buffer->skb);
588 if (dma_unmap_len(tx_buffer, len))
Alexander Duyckd3d00232011-07-15 02:31:25 +0000589 dma_unmap_single(ring->dev,
Alexander Duyck729739b2012-02-08 07:51:06 +0000590 dma_unmap_addr(tx_buffer, dma),
591 dma_unmap_len(tx_buffer, len),
592 DMA_TO_DEVICE);
593 } else if (dma_unmap_len(tx_buffer, len)) {
594 dma_unmap_page(ring->dev,
595 dma_unmap_addr(tx_buffer, dma),
596 dma_unmap_len(tx_buffer, len),
597 DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000598 }
Alexander Duyck729739b2012-02-08 07:51:06 +0000599 tx_buffer->next_to_watch = NULL;
600 tx_buffer->skb = NULL;
601 dma_unmap_len_set(tx_buffer, len, 0);
602 /* tx_buffer must be completely set up in the transmit path */
Auke Kok9a799d72007-09-15 14:07:45 -0700603}
604
John Fastabendc84d3242010-11-16 19:27:12 -0800605static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700606{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700607 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800608 struct ixgbe_hw_stats *hwstats = &adapter->stats;
609 u32 data = 0;
610 u32 xoff[8] = {0};
611 int i;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700612
John Fastabendc84d3242010-11-16 19:27:12 -0800613 if ((hw->fc.current_mode == ixgbe_fc_full) ||
614 (hw->fc.current_mode == ixgbe_fc_rx_pause)) {
615 switch (hw->mac.type) {
616 case ixgbe_mac_82598EB:
617 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
618 break;
619 default:
620 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
621 }
622 hwstats->lxoffrxc += data;
623
624 /* refill credits (no tx hang) if we received xoff */
625 if (!data)
626 return;
627
628 for (i = 0; i < adapter->num_tx_queues; i++)
629 clear_bit(__IXGBE_HANG_CHECK_ARMED,
630 &adapter->tx_ring[i]->state);
631 return;
632 } else if (!(adapter->dcb_cfg.pfc_mode_enable))
633 return;
634
635 /* update stats for each tc, only valid with PFC enabled */
636 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
637 switch (hw->mac.type) {
638 case ixgbe_mac_82598EB:
639 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
640 break;
641 default:
642 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
643 }
644 hwstats->pxoffrxc[i] += xoff[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700645 }
646
John Fastabendc84d3242010-11-16 19:27:12 -0800647 /* disarm tx queues that have received xoff frames */
648 for (i = 0; i < adapter->num_tx_queues; i++) {
649 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendfb5475f2011-04-26 07:26:36 +0000650 u8 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800651
652 if (xoff[tc])
653 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
654 }
655}
656
657static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
658{
Alexander Duyck7d7ce682012-02-08 07:50:51 +0000659 return ring->stats.packets;
John Fastabendc84d3242010-11-16 19:27:12 -0800660}
661
662static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
663{
664 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
665 struct ixgbe_hw *hw = &adapter->hw;
666
667 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
668 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
669
670 if (head != tail)
671 return (head < tail) ?
672 tail - head : (tail + ring->count - head);
673
674 return 0;
675}
676
677static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
678{
679 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
680 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
681 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
682 bool ret = false;
683
684 clear_check_for_tx_hang(tx_ring);
685
686 /*
687 * Check for a hung queue, but be thorough. This verifies
688 * that a transmit has been completed since the previous
689 * check AND there is at least one packet pending. The
690 * ARMED bit is set to indicate a potential hang. The
691 * bit is cleared if a pause frame is received to remove
692 * false hang detection due to PFC or 802.3x frames. By
693 * requiring this to fail twice we avoid races with
694 * pfc clearing the ARMED bit and conditions where we
695 * run the check_tx_hang logic with a transmit completion
696 * pending but without time to complete it yet.
697 */
698 if ((tx_done_old == tx_done) && tx_pending) {
699 /* make sure it is true for two checks in a row */
700 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
701 &tx_ring->state);
702 } else {
703 /* update completed stats and continue */
704 tx_ring->tx_stats.tx_done_old = tx_done;
705 /* reset the countdown */
706 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
707 }
708
709 return ret;
Auke Kok9a799d72007-09-15 14:07:45 -0700710}
711
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000712/**
713 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
714 * @adapter: driver private struct
715 **/
716static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
717{
718
719 /* Do the reset outside of interrupt context */
720 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
721 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
722 ixgbe_service_event_schedule(adapter);
723 }
724}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700725
Auke Kok9a799d72007-09-15 14:07:45 -0700726/**
727 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000728 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700729 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700730 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000731static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +0000732 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700733{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000734 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000735 struct ixgbe_tx_buffer *tx_buffer;
736 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700737 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +0000738 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyck729739b2012-02-08 07:51:06 +0000739 unsigned int i = tx_ring->next_to_clean;
740
741 if (test_bit(__IXGBE_DOWN, &adapter->state))
742 return true;
Auke Kok9a799d72007-09-15 14:07:45 -0700743
Alexander Duyckd3d00232011-07-15 02:31:25 +0000744 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000745 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +0000746 i -= tx_ring->count;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800747
Alexander Duyck729739b2012-02-08 07:51:06 +0000748 do {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000749 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -0700750
Alexander Duyckd3d00232011-07-15 02:31:25 +0000751 /* if next_to_watch is not set then there is no work pending */
752 if (!eop_desc)
753 break;
754
Alexander Duyck7f83a9e2012-02-08 07:49:23 +0000755 /* prevent any other reads prior to eop_desc */
756 rmb();
757
Alexander Duyckd3d00232011-07-15 02:31:25 +0000758 /* if DD is not set pending work has not been completed */
759 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
760 break;
761
Alexander Duyckd3d00232011-07-15 02:31:25 +0000762 /* clear next_to_watch to prevent false hangs */
763 tx_buffer->next_to_watch = NULL;
764
Alexander Duyck091a6242012-02-08 07:51:01 +0000765 /* update the statistics for this packet */
766 total_bytes += tx_buffer->bytecount;
767 total_packets += tx_buffer->gso_segs;
768
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000769 /* free the skb */
770 dev_kfree_skb_any(tx_buffer->skb);
771
Alexander Duyck729739b2012-02-08 07:51:06 +0000772 /* unmap skb header data */
773 dma_unmap_single(tx_ring->dev,
774 dma_unmap_addr(tx_buffer, dma),
775 dma_unmap_len(tx_buffer, len),
776 DMA_TO_DEVICE);
777
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000778 /* clear tx_buffer data */
779 tx_buffer->skb = NULL;
Alexander Duyck729739b2012-02-08 07:51:06 +0000780 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000781
Alexander Duyck729739b2012-02-08 07:51:06 +0000782 /* unmap remaining buffers */
783 while (tx_desc != eop_desc) {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000784 tx_buffer++;
785 tx_desc++;
786 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +0000787 if (unlikely(!i)) {
788 i -= tx_ring->count;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000789 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duycke4f74022012-01-31 02:59:44 +0000790 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000791 }
792
Alexander Duyck729739b2012-02-08 07:51:06 +0000793 /* unmap any remaining paged data */
794 if (dma_unmap_len(tx_buffer, len)) {
795 dma_unmap_page(tx_ring->dev,
796 dma_unmap_addr(tx_buffer, dma),
797 dma_unmap_len(tx_buffer, len),
798 DMA_TO_DEVICE);
799 dma_unmap_len_set(tx_buffer, len, 0);
800 }
801 }
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800802
Alexander Duyck729739b2012-02-08 07:51:06 +0000803 /* move us one more past the eop_desc for start of next pkt */
804 tx_buffer++;
805 tx_desc++;
806 i++;
807 if (unlikely(!i)) {
808 i -= tx_ring->count;
809 tx_buffer = tx_ring->tx_buffer_info;
810 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
811 }
812
813 /* issue prefetch for next Tx descriptor */
814 prefetch(tx_desc);
815
816 /* update budget accounting */
817 budget--;
818 } while (likely(budget));
819
820 i += tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -0700821 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000822 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -0800823 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +0000824 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000825 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +0000826 q_vector->tx.total_bytes += total_bytes;
827 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -0800828
John Fastabendc84d3242010-11-16 19:27:12 -0800829 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -0800830 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -0800831 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800832 e_err(drv, "Detected Tx Unit Hang\n"
833 " Tx Queue <%d>\n"
834 " TDH, TDT <%x>, <%x>\n"
835 " next_to_use <%x>\n"
836 " next_to_clean <%x>\n"
837 "tx_buffer_info[next_to_clean]\n"
838 " time_stamp <%lx>\n"
839 " jiffies <%lx>\n",
840 tx_ring->queue_index,
841 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
842 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +0000843 tx_ring->next_to_use, i,
844 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -0800845
846 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
847
848 e_info(probe,
849 "tx hang %d detected on queue %d, resetting adapter\n",
850 adapter->tx_timeout_count + 1, tx_ring->queue_index);
851
852 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000853 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -0800854
855 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +0000856 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -0800857 }
Auke Kok9a799d72007-09-15 14:07:45 -0700858
Alexander Duyckb2d96e02012-02-07 08:14:33 +0000859 netdev_tx_completed_queue(txring_txq(tx_ring),
860 total_packets, total_bytes);
861
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800862#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +0000863 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +0000864 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800865 /* Make sure that anybody stopping the queue after this
866 * sees the new next_to_clean.
867 */
868 smp_mb();
Alexander Duyck729739b2012-02-08 07:51:06 +0000869 if (__netif_subqueue_stopped(tx_ring->netdev,
870 tx_ring->queue_index)
871 && !test_bit(__IXGBE_DOWN, &adapter->state)) {
872 netif_wake_subqueue(tx_ring->netdev,
873 tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -0800874 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800875 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800876 }
Auke Kok9a799d72007-09-15 14:07:45 -0700877
Alexander Duyck59224552011-08-31 00:01:06 +0000878 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -0700879}
880
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400881#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800882static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800883 struct ixgbe_ring *tx_ring,
884 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800885{
Don Skidmoreee5f7842009-11-06 12:56:20 +0000886 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000887 u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
888 u16 reg_offset;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800889
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800890 switch (hw->mac.type) {
891 case ixgbe_mac_82598EB:
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000892 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800893 break;
894 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800895 case ixgbe_mac_X540:
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000896 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
897 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
898 break;
899 default:
900 /* for unknown hardware do not write register */
901 return;
902 }
903
904 /*
905 * We can enable relaxed ordering for reads, but not writes when
906 * DCA is enabled. This is due to a known issue in some chipsets
907 * which will cause the DCA tag to be cleared.
908 */
909 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
910 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
911 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
912
913 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
914}
915
916static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
917 struct ixgbe_ring *rx_ring,
918 int cpu)
919{
920 struct ixgbe_hw *hw = &adapter->hw;
921 u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
922 u8 reg_idx = rx_ring->reg_idx;
923
924
925 switch (hw->mac.type) {
926 case ixgbe_mac_82599EB:
927 case ixgbe_mac_X540:
928 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800929 break;
930 default:
931 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800932 }
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000933
934 /*
935 * We can enable relaxed ordering for reads, but not writes when
936 * DCA is enabled. This is due to a known issue in some chipsets
937 * which will cause the DCA tag to be cleared.
938 */
939 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
940 IXGBE_DCA_RXCTRL_DATA_DCA_EN |
941 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
942
943 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800944}
945
946static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
947{
948 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000949 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800950 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800951
952 if (q_vector->cpu == cpu)
953 goto out_no_update;
954
Alexander Duycka5579282012-02-08 07:50:04 +0000955 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000956 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800957
Alexander Duycka5579282012-02-08 07:50:04 +0000958 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000959 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800960
961 q_vector->cpu = cpu;
962out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800963 put_cpu();
964}
965
966static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
967{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800968 int num_q_vectors;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800969 int i;
970
971 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
972 return;
973
Alexander Duycke35ec122009-05-21 13:07:12 +0000974 /* always use CB2 mode, difference is masked in the CB driver */
975 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
976
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800977 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
978 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
979 else
980 num_q_vectors = 1;
981
982 for (i = 0; i < num_q_vectors; i++) {
983 adapter->q_vector[i]->cpu = -1;
984 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800985 }
986}
987
988static int __ixgbe_notify_dca(struct device *dev, void *data)
989{
Alexander Duyckc60fbb02010-11-16 19:26:54 -0800990 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800991 unsigned long event = *(unsigned long *)data;
992
Don Skidmore2a72c312011-07-20 02:27:05 +0000993 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800994 return 0;
995
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800996 switch (event) {
997 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700998 /* if we're already enabled, don't do it again */
999 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1000 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001001 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001002 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001003 ixgbe_setup_dca(adapter);
1004 break;
1005 }
1006 /* Fall Through since DCA is disabled. */
1007 case DCA_PROVIDER_REMOVE:
1008 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1009 dca_remove_requester(dev);
1010 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1011 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1012 }
1013 break;
1014 }
1015
Denis V. Lunev652f0932008-03-27 14:39:17 +03001016 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001017}
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001018
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001019#endif /* CONFIG_IXGBE_DCA */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001020static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1021 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001022 struct sk_buff *skb)
1023{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001024 if (ring->netdev->features & NETIF_F_RXHASH)
1025 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001026}
1027
Alexander Duyckf8003262012-03-03 02:35:52 +00001028#ifdef IXGBE_FCOE
Auke Kok9a799d72007-09-15 14:07:45 -07001029/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001030 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
1031 * @adapter: address of board private structure
1032 * @rx_desc: advanced rx descriptor
1033 *
1034 * Returns : true if it is FCoE pkt
1035 */
1036static inline bool ixgbe_rx_is_fcoe(struct ixgbe_adapter *adapter,
1037 union ixgbe_adv_rx_desc *rx_desc)
1038{
1039 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1040
1041 return (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
1042 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1043 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1044 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1045}
1046
Alexander Duyckf8003262012-03-03 02:35:52 +00001047#endif /* IXGBE_FCOE */
Alexander Duyckff886df2011-06-11 01:45:13 +00001048/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001049 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001050 * @ring: structure containing ring specific data
1051 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001052 * @skb: skb currently being received and modified
1053 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001054static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001055 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001056 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001057{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001058 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001059
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001060 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001061 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001062 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001063
1064 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001065 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1066 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001067 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001068 return;
1069 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001070
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001071 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001072 return;
1073
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001074 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00001075 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
Don Skidmore8bae1b22009-07-23 18:00:39 +00001076
1077 /*
1078 * 82599 errata, UDP frames with a 0 checksum can be marked as
1079 * checksum errors.
1080 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001081 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1082 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001083 return;
1084
Alexander Duyck8a0da212012-01-31 02:59:49 +00001085 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001086 return;
1087 }
1088
Auke Kok9a799d72007-09-15 14:07:45 -07001089 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001090 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001091}
1092
Alexander Duyck84ea2592010-11-16 19:26:49 -08001093static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001094{
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001095 rx_ring->next_to_use = val;
Alexander Duyckf8003262012-03-03 02:35:52 +00001096
1097 /* update next to alloc since we have filled the ring */
1098 rx_ring->next_to_alloc = val;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001099 /*
1100 * Force memory writes to complete before letting h/w
1101 * know there are new descriptors to fetch. (Only
1102 * applicable for weak-ordered memory model archs,
1103 * such as IA-64).
1104 */
1105 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001106 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001107}
1108
Alexander Duyckf990b792012-01-31 02:59:34 +00001109static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1110 struct ixgbe_rx_buffer *bi)
1111{
1112 struct page *page = bi->page;
Alexander Duyckf8003262012-03-03 02:35:52 +00001113 dma_addr_t dma = bi->dma;
Alexander Duyckf990b792012-01-31 02:59:34 +00001114
Alexander Duyckf8003262012-03-03 02:35:52 +00001115 /* since we are recycling buffers we should seldom need to alloc */
1116 if (likely(dma))
Alexander Duyckf990b792012-01-31 02:59:34 +00001117 return true;
1118
Alexander Duyckf8003262012-03-03 02:35:52 +00001119 /* alloc new page for storage */
1120 if (likely(!page)) {
1121 page = alloc_pages(GFP_ATOMIC | __GFP_COLD,
1122 ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf990b792012-01-31 02:59:34 +00001123 if (unlikely(!page)) {
1124 rx_ring->rx_stats.alloc_rx_page_failed++;
1125 return false;
1126 }
Alexander Duyckf8003262012-03-03 02:35:52 +00001127 bi->page = page;
Alexander Duyckf990b792012-01-31 02:59:34 +00001128 }
1129
Alexander Duyckf8003262012-03-03 02:35:52 +00001130 /* map page for use */
1131 dma = dma_map_page(rx_ring->dev, page, 0,
1132 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
Alexander Duyckf990b792012-01-31 02:59:34 +00001133
Alexander Duyckf8003262012-03-03 02:35:52 +00001134 /*
1135 * if mapping failed free memory back to system since
1136 * there isn't much point in holding memory we can't use
1137 */
1138 if (dma_mapping_error(rx_ring->dev, dma)) {
1139 put_page(page);
1140 bi->page = NULL;
1141
Alexander Duyckf990b792012-01-31 02:59:34 +00001142 rx_ring->rx_stats.alloc_rx_page_failed++;
1143 return false;
1144 }
1145
Alexander Duyckf8003262012-03-03 02:35:52 +00001146 bi->dma = dma;
1147 bi->page_offset ^= ixgbe_rx_bufsz(rx_ring);
1148
Alexander Duyckf990b792012-01-31 02:59:34 +00001149 return true;
1150}
1151
Auke Kok9a799d72007-09-15 14:07:45 -07001152/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001153 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001154 * @rx_ring: ring to place buffers on
1155 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001156 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001157void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001158{
Auke Kok9a799d72007-09-15 14:07:45 -07001159 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001160 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001161 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001162
Alexander Duyckf8003262012-03-03 02:35:52 +00001163 /* nothing to do */
1164 if (!cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001165 return;
1166
Alexander Duycke4f74022012-01-31 02:59:44 +00001167 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001168 bi = &rx_ring->rx_buffer_info[i];
1169 i -= rx_ring->count;
1170
Alexander Duyckf8003262012-03-03 02:35:52 +00001171 do {
1172 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
Alexander Duyckf990b792012-01-31 02:59:34 +00001173 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001174
Alexander Duyckf8003262012-03-03 02:35:52 +00001175 /*
1176 * Refresh the desc even if buffer_addrs didn't change
1177 * because each write-back erases this info.
1178 */
1179 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
Auke Kok9a799d72007-09-15 14:07:45 -07001180
Alexander Duyckf990b792012-01-31 02:59:34 +00001181 rx_desc++;
1182 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001183 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001184 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001185 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001186 bi = rx_ring->rx_buffer_info;
1187 i -= rx_ring->count;
1188 }
1189
1190 /* clear the hdr_addr for the next_to_use descriptor */
1191 rx_desc->read.hdr_addr = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001192
1193 cleaned_count--;
1194 } while (cleaned_count);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001195
Alexander Duyckf990b792012-01-31 02:59:34 +00001196 i += rx_ring->count;
1197
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001198 if (rx_ring->next_to_use != i)
Alexander Duyck84ea2592010-11-16 19:26:49 -08001199 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001200}
1201
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001202/**
1203 * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE
1204 * @data: pointer to the start of the headers
1205 * @max_len: total length of section to find headers in
1206 *
1207 * This function is meant to determine the length of headers that will
1208 * be recognized by hardware for LRO, GRO, and RSC offloads. The main
1209 * motivation of doing this is to only perform one pull for IPv4 TCP
1210 * packets so that we can do basic things like calculating the gso_size
1211 * based on the average data per packet.
1212 **/
1213static unsigned int ixgbe_get_headlen(unsigned char *data,
1214 unsigned int max_len)
1215{
1216 union {
1217 unsigned char *network;
1218 /* l2 headers */
1219 struct ethhdr *eth;
1220 struct vlan_hdr *vlan;
1221 /* l3 headers */
1222 struct iphdr *ipv4;
1223 } hdr;
1224 __be16 protocol;
1225 u8 nexthdr = 0; /* default to not TCP */
1226 u8 hlen;
1227
1228 /* this should never happen, but better safe than sorry */
1229 if (max_len < ETH_HLEN)
1230 return max_len;
1231
1232 /* initialize network frame pointer */
1233 hdr.network = data;
1234
1235 /* set first protocol and move network header forward */
1236 protocol = hdr.eth->h_proto;
1237 hdr.network += ETH_HLEN;
1238
1239 /* handle any vlan tag if present */
1240 if (protocol == __constant_htons(ETH_P_8021Q)) {
1241 if ((hdr.network - data) > (max_len - VLAN_HLEN))
1242 return max_len;
1243
1244 protocol = hdr.vlan->h_vlan_encapsulated_proto;
1245 hdr.network += VLAN_HLEN;
1246 }
1247
1248 /* handle L3 protocols */
1249 if (protocol == __constant_htons(ETH_P_IP)) {
1250 if ((hdr.network - data) > (max_len - sizeof(struct iphdr)))
1251 return max_len;
1252
1253 /* access ihl as a u8 to avoid unaligned access on ia64 */
1254 hlen = (hdr.network[0] & 0x0F) << 2;
1255
1256 /* verify hlen meets minimum size requirements */
1257 if (hlen < sizeof(struct iphdr))
1258 return hdr.network - data;
1259
1260 /* record next protocol */
1261 nexthdr = hdr.ipv4->protocol;
1262 hdr.network += hlen;
Alexander Duyckf8003262012-03-03 02:35:52 +00001263#ifdef IXGBE_FCOE
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001264 } else if (protocol == __constant_htons(ETH_P_FCOE)) {
1265 if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN))
1266 return max_len;
1267 hdr.network += FCOE_HEADER_LEN;
1268#endif
1269 } else {
1270 return hdr.network - data;
1271 }
1272
1273 /* finally sort out TCP */
1274 if (nexthdr == IPPROTO_TCP) {
1275 if ((hdr.network - data) > (max_len - sizeof(struct tcphdr)))
1276 return max_len;
1277
1278 /* access doff as a u8 to avoid unaligned access on ia64 */
1279 hlen = (hdr.network[12] & 0xF0) >> 2;
1280
1281 /* verify hlen meets minimum size requirements */
1282 if (hlen < sizeof(struct tcphdr))
1283 return hdr.network - data;
1284
1285 hdr.network += hlen;
1286 }
1287
1288 /*
1289 * If everything has gone correctly hdr.network should be the
1290 * data section of the packet and will be the end of the header.
1291 * If not then it probably represents the end of the last recognized
1292 * header.
1293 */
1294 if ((hdr.network - data) < max_len)
1295 return hdr.network - data;
1296 else
1297 return max_len;
1298}
1299
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001300static void ixgbe_get_rsc_cnt(struct ixgbe_ring *rx_ring,
1301 union ixgbe_adv_rx_desc *rx_desc,
1302 struct sk_buff *skb)
1303{
1304 __le32 rsc_enabled;
1305 u32 rsc_cnt;
1306
1307 if (!ring_is_rsc_enabled(rx_ring))
1308 return;
1309
1310 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1311 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1312
1313 /* If this is an RSC frame rsc_cnt should be non-zero */
1314 if (!rsc_enabled)
1315 return;
1316
1317 rsc_cnt = le32_to_cpu(rsc_enabled);
1318 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1319
1320 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
Alexander Duyckaa801752010-11-16 19:27:02 -08001321}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001322
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001323static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1324 struct sk_buff *skb)
1325{
Alexander Duyckf8003262012-03-03 02:35:52 +00001326 u16 hdr_len = skb_headlen(skb);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001327
1328 /* set gso_size to avoid messing up TCP MSS */
1329 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1330 IXGBE_CB(skb)->append_cnt);
1331}
1332
1333static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1334 struct sk_buff *skb)
1335{
1336 /* if append_cnt is 0 then frame is not RSC */
1337 if (!IXGBE_CB(skb)->append_cnt)
1338 return;
1339
1340 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1341 rx_ring->rx_stats.rsc_flush++;
1342
1343 ixgbe_set_rsc_gso_size(rx_ring, skb);
1344
1345 /* gso_size is computed using append_cnt so always clear it last */
1346 IXGBE_CB(skb)->append_cnt = 0;
1347}
1348
Alexander Duyck8a0da212012-01-31 02:59:49 +00001349/**
1350 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1351 * @rx_ring: rx descriptor ring packet is being transacted on
1352 * @rx_desc: pointer to the EOP Rx descriptor
1353 * @skb: pointer to current skb being populated
1354 *
1355 * This function checks the ring, descriptor, and packet information in
1356 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1357 * other fields within the skb.
1358 **/
1359static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1360 union ixgbe_adv_rx_desc *rx_desc,
1361 struct sk_buff *skb)
1362{
1363 ixgbe_update_rsc_stats(rx_ring, skb);
1364
1365 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1366
1367 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1368
1369 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
1370 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
1371 __vlan_hwaccel_put_tag(skb, vid);
1372 }
1373
1374 skb_record_rx_queue(skb, rx_ring->queue_index);
1375
1376 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
1377}
1378
1379static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1380 struct sk_buff *skb)
1381{
1382 struct ixgbe_adapter *adapter = q_vector->adapter;
1383
1384 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1385 napi_gro_receive(&q_vector->napi, skb);
1386 else
1387 netif_rx(skb);
Alexander Duyckf8212f92009-04-27 22:42:37 +00001388}
1389
Alexander Duyckf8003262012-03-03 02:35:52 +00001390/**
1391 * ixgbe_is_non_eop - process handling of non-EOP buffers
1392 * @rx_ring: Rx ring being processed
1393 * @rx_desc: Rx descriptor for current buffer
1394 * @skb: Current socket buffer containing buffer in progress
1395 *
1396 * This function updates next to clean. If the buffer is an EOP buffer
1397 * this function exits returning false, otherwise it will place the
1398 * sk_buff in the next buffer to be chained and return true indicating
1399 * that this is in fact a non-EOP buffer.
1400 **/
1401static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1402 union ixgbe_adv_rx_desc *rx_desc,
1403 struct sk_buff *skb)
1404{
1405 u32 ntc = rx_ring->next_to_clean + 1;
1406
1407 /* fetch, update, and store next to clean */
1408 ntc = (ntc < rx_ring->count) ? ntc : 0;
1409 rx_ring->next_to_clean = ntc;
1410
1411 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1412
1413 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1414 return false;
1415
1416 /* append_cnt indicates packet is RSC, if so fetch nextp */
1417 if (IXGBE_CB(skb)->append_cnt) {
1418 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1419 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1420 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1421 }
1422
1423 /* place skb in next buffer to be received */
1424 rx_ring->rx_buffer_info[ntc].skb = skb;
1425 rx_ring->rx_stats.non_eop_descs++;
1426
1427 return true;
1428}
1429
1430/**
1431 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1432 * @rx_ring: rx descriptor ring packet is being transacted on
1433 * @rx_desc: pointer to the EOP Rx descriptor
1434 * @skb: pointer to current skb being fixed
1435 *
1436 * Check for corrupted packet headers caused by senders on the local L2
1437 * embedded NIC switch not setting up their Tx Descriptors right. These
1438 * should be very rare.
1439 *
1440 * Also address the case where we are pulling data in on pages only
1441 * and as such no data is present in the skb header.
1442 *
1443 * In addition if skb is not at least 60 bytes we need to pad it so that
1444 * it is large enough to qualify as a valid Ethernet frame.
1445 *
1446 * Returns true if an error was encountered and skb was freed.
1447 **/
1448static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1449 union ixgbe_adv_rx_desc *rx_desc,
1450 struct sk_buff *skb)
1451{
1452 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1453 struct net_device *netdev = rx_ring->netdev;
1454 unsigned char *va;
1455 unsigned int pull_len;
1456
1457 /* if the page was released unmap it, else just sync our portion */
1458 if (unlikely(IXGBE_CB(skb)->page_released)) {
1459 dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma,
1460 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
1461 IXGBE_CB(skb)->page_released = false;
1462 } else {
1463 dma_sync_single_range_for_cpu(rx_ring->dev,
1464 IXGBE_CB(skb)->dma,
1465 frag->page_offset,
1466 ixgbe_rx_bufsz(rx_ring),
1467 DMA_FROM_DEVICE);
1468 }
1469 IXGBE_CB(skb)->dma = 0;
1470
1471 /* verify that the packet does not have any known errors */
1472 if (unlikely(ixgbe_test_staterr(rx_desc,
1473 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1474 !(netdev->features & NETIF_F_RXALL))) {
1475 dev_kfree_skb_any(skb);
1476 return true;
1477 }
1478
1479 /*
1480 * it is valid to use page_address instead of kmap since we are
1481 * working with pages allocated out of the lomem pool per
1482 * alloc_page(GFP_ATOMIC)
1483 */
1484 va = skb_frag_address(frag);
1485
1486 /*
1487 * we need the header to contain the greater of either ETH_HLEN or
1488 * 60 bytes if the skb->len is less than 60 for skb_pad.
1489 */
1490 pull_len = skb_frag_size(frag);
1491 if (pull_len > 256)
1492 pull_len = ixgbe_get_headlen(va, pull_len);
1493
1494 /* align pull length to size of long to optimize memcpy performance */
1495 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1496
1497 /* update all of the pointers */
1498 skb_frag_size_sub(frag, pull_len);
1499 frag->page_offset += pull_len;
1500 skb->data_len -= pull_len;
1501 skb->tail += pull_len;
1502
1503 /*
1504 * if we sucked the frag empty then we should free it,
1505 * if there are other frags here something is screwed up in hardware
1506 */
1507 if (skb_frag_size(frag) == 0) {
1508 BUG_ON(skb_shinfo(skb)->nr_frags != 1);
1509 skb_shinfo(skb)->nr_frags = 0;
1510 __skb_frag_unref(frag);
1511 skb->truesize -= ixgbe_rx_bufsz(rx_ring);
1512 }
1513
1514 /* if skb_pad returns an error the skb was freed */
1515 if (unlikely(skb->len < 60)) {
1516 int pad_len = 60 - skb->len;
1517
1518 if (skb_pad(skb, pad_len))
1519 return true;
1520 __skb_put(skb, pad_len);
1521 }
1522
1523 return false;
1524}
1525
1526/**
1527 * ixgbe_can_reuse_page - determine if we can reuse a page
1528 * @rx_buffer: pointer to rx_buffer containing the page we want to reuse
1529 *
1530 * Returns true if page can be reused in another Rx buffer
1531 **/
1532static inline bool ixgbe_can_reuse_page(struct ixgbe_rx_buffer *rx_buffer)
1533{
1534 struct page *page = rx_buffer->page;
1535
1536 /* if we are only owner of page and it is local we can reuse it */
1537 return likely(page_count(page) == 1) &&
1538 likely(page_to_nid(page) == numa_node_id());
1539}
1540
1541/**
1542 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1543 * @rx_ring: rx descriptor ring to store buffers on
1544 * @old_buff: donor buffer to have page reused
1545 *
1546 * Syncronizes page for reuse by the adapter
1547 **/
1548static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1549 struct ixgbe_rx_buffer *old_buff)
1550{
1551 struct ixgbe_rx_buffer *new_buff;
1552 u16 nta = rx_ring->next_to_alloc;
1553 u16 bufsz = ixgbe_rx_bufsz(rx_ring);
1554
1555 new_buff = &rx_ring->rx_buffer_info[nta];
1556
1557 /* update, and store next to alloc */
1558 nta++;
1559 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1560
1561 /* transfer page from old buffer to new buffer */
1562 new_buff->page = old_buff->page;
1563 new_buff->dma = old_buff->dma;
1564
1565 /* flip page offset to other buffer and store to new_buff */
1566 new_buff->page_offset = old_buff->page_offset ^ bufsz;
1567
1568 /* sync the buffer for use by the device */
1569 dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma,
1570 new_buff->page_offset, bufsz,
1571 DMA_FROM_DEVICE);
1572
1573 /* bump ref count on page before it is given to the stack */
1574 get_page(new_buff->page);
1575}
1576
1577/**
1578 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1579 * @rx_ring: rx descriptor ring to transact packets on
1580 * @rx_buffer: buffer containing page to add
1581 * @rx_desc: descriptor containing length of buffer written by hardware
1582 * @skb: sk_buff to place the data into
1583 *
1584 * This function is based on skb_add_rx_frag. I would have used that
1585 * function however it doesn't handle the truesize case correctly since we
1586 * are allocating more memory than might be used for a single receive.
1587 **/
1588static void ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
1589 struct ixgbe_rx_buffer *rx_buffer,
1590 struct sk_buff *skb, int size)
1591{
1592 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
1593 rx_buffer->page, rx_buffer->page_offset,
1594 size);
1595 skb->len += size;
1596 skb->data_len += size;
1597 skb->truesize += ixgbe_rx_bufsz(rx_ring);
1598}
1599
1600/**
1601 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
1602 * @q_vector: structure containing interrupt and ring information
1603 * @rx_ring: rx descriptor ring to transact packets on
1604 * @budget: Total limit on number of packets to process
1605 *
1606 * This function provides a "bounce buffer" approach to Rx interrupt
1607 * processing. The advantage to this is that on systems that have
1608 * expensive overhead for IOMMU access this provides a means of avoiding
1609 * it by maintaining the mapping of the page to the syste.
1610 *
1611 * Returns true if all work is completed without reaching budget
1612 **/
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001613static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001614 struct ixgbe_ring *rx_ring,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001615 int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001616{
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001617 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Ben Greear3f2d1c02012-03-08 08:28:41 +00001618#ifdef IXGBE_FCOE
Alexander Duyckf8003262012-03-03 02:35:52 +00001619 struct ixgbe_adapter *adapter = q_vector->adapter;
Yi Zou3d8fd382009-06-08 14:38:44 +00001620 int ddp_bytes = 0;
1621#endif /* IXGBE_FCOE */
Alexander Duyckf8003262012-03-03 02:35:52 +00001622 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07001623
Alexander Duyckf8003262012-03-03 02:35:52 +00001624 do {
1625 struct ixgbe_rx_buffer *rx_buffer;
1626 union ixgbe_adv_rx_desc *rx_desc;
1627 struct sk_buff *skb;
1628 struct page *page;
1629 u16 ntc;
Auke Kok9a799d72007-09-15 14:07:45 -07001630
Alexander Duyckf8003262012-03-03 02:35:52 +00001631 /* return some buffers to hardware, one at a time is too slow */
1632 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
1633 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1634 cleaned_count = 0;
1635 }
Auke Kok9a799d72007-09-15 14:07:45 -07001636
Alexander Duyckf8003262012-03-03 02:35:52 +00001637 ntc = rx_ring->next_to_clean;
1638 rx_desc = IXGBE_RX_DESC(rx_ring, ntc);
1639 rx_buffer = &rx_ring->rx_buffer_info[ntc];
Auke Kok9a799d72007-09-15 14:07:45 -07001640
Alexander Duyckf8003262012-03-03 02:35:52 +00001641 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD))
1642 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001643
Alexander Duyckf8003262012-03-03 02:35:52 +00001644 /*
1645 * This memory barrier is needed to keep us from reading
1646 * any other fields out of the rx_desc until we know the
1647 * RXD_STAT_DD bit is set
1648 */
1649 rmb();
Auke Kok9a799d72007-09-15 14:07:45 -07001650
Alexander Duyckf8003262012-03-03 02:35:52 +00001651 page = rx_buffer->page;
1652 prefetchw(page);
1653
1654 skb = rx_buffer->skb;
1655
1656 if (likely(!skb)) {
1657 void *page_addr = page_address(page) +
1658 rx_buffer->page_offset;
1659
1660 /* prefetch first cache line of first page */
1661 prefetch(page_addr);
1662#if L1_CACHE_BYTES < 128
1663 prefetch(page_addr + L1_CACHE_BYTES);
1664#endif
1665
1666 /* allocate a skb to store the frags */
1667 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
1668 IXGBE_RX_HDR_SIZE);
1669 if (unlikely(!skb)) {
1670 rx_ring->rx_stats.alloc_rx_buff_failed++;
1671 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001672 }
1673
Alexander Duyckf8003262012-03-03 02:35:52 +00001674 /*
1675 * we will be copying header into skb->data in
1676 * pskb_may_pull so it is in our interest to prefetch
1677 * it now to avoid a possible cache miss
1678 */
1679 prefetchw(skb->data);
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001680
1681 /*
1682 * Delay unmapping of the first packet. It carries the
1683 * header information, HW may still access the header
Alexander Duyckf8003262012-03-03 02:35:52 +00001684 * after the writeback. Only unmap it when EOP is
1685 * reached
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001686 */
Alexander Duyckf8003262012-03-03 02:35:52 +00001687 IXGBE_CB(skb)->dma = rx_buffer->dma;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001688 } else {
Alexander Duyckf8003262012-03-03 02:35:52 +00001689 /* we are reusing so sync this buffer for CPU use */
1690 dma_sync_single_range_for_cpu(rx_ring->dev,
1691 rx_buffer->dma,
1692 rx_buffer->page_offset,
1693 ixgbe_rx_bufsz(rx_ring),
1694 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001695 }
1696
Alexander Duyckf8003262012-03-03 02:35:52 +00001697 /* pull page into skb */
1698 ixgbe_add_rx_frag(rx_ring, rx_buffer, skb,
1699 le16_to_cpu(rx_desc->wb.upper.length));
1700
1701 if (ixgbe_can_reuse_page(rx_buffer)) {
1702 /* hand second half of page back to the ring */
1703 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
1704 } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
1705 /* the page has been released from the ring */
1706 IXGBE_CB(skb)->page_released = true;
1707 } else {
1708 /* we are not reusing the buffer so unmap it */
1709 dma_unmap_page(rx_ring->dev, rx_buffer->dma,
1710 ixgbe_rx_pg_size(rx_ring),
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001711 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001712 }
1713
Alexander Duyckf8003262012-03-03 02:35:52 +00001714 /* clear contents of buffer_info */
1715 rx_buffer->skb = NULL;
1716 rx_buffer->dma = 0;
1717 rx_buffer->page = NULL;
1718
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001719 ixgbe_get_rsc_cnt(rx_ring, rx_desc, skb);
1720
Auke Kok9a799d72007-09-15 14:07:45 -07001721 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001722
Alexander Duyckf8003262012-03-03 02:35:52 +00001723 /* place incomplete frames back on ring for completion */
1724 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
1725 continue;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001726
Alexander Duyckf8003262012-03-03 02:35:52 +00001727 /* verify the packet layout is correct */
1728 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
1729 continue;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001730
1731 /* probably a little skewed due to removing CRC */
1732 total_rx_bytes += skb->len;
1733 total_rx_packets++;
1734
Alexander Duyck8a0da212012-01-31 02:59:49 +00001735 /* populate checksum, timestamp, VLAN, and protocol */
1736 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
1737
Yi Zou332d4a72009-05-13 13:11:53 +00001738#ifdef IXGBE_FCOE
1739 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyckff886df2011-06-11 01:45:13 +00001740 if (ixgbe_rx_is_fcoe(adapter, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001741 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
David S. Miller823dcd22011-08-20 10:39:12 -07001742 if (!ddp_bytes) {
1743 dev_kfree_skb_any(skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001744 continue;
David S. Miller823dcd22011-08-20 10:39:12 -07001745 }
Yi Zou3d8fd382009-06-08 14:38:44 +00001746 }
Alexander Duyckf8003262012-03-03 02:35:52 +00001747
Yi Zou332d4a72009-05-13 13:11:53 +00001748#endif /* IXGBE_FCOE */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001749 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001750
Alexander Duyckf8003262012-03-03 02:35:52 +00001751 /* update budget accounting */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001752 budget--;
Alexander Duyckf8003262012-03-03 02:35:52 +00001753 } while (likely(budget));
Auke Kok9a799d72007-09-15 14:07:45 -07001754
Yi Zou3d8fd382009-06-08 14:38:44 +00001755#ifdef IXGBE_FCOE
1756 /* include DDPed FCoE data */
1757 if (ddp_bytes > 0) {
1758 unsigned int mss;
1759
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001760 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
Yi Zou3d8fd382009-06-08 14:38:44 +00001761 sizeof(struct fc_frame_header) -
1762 sizeof(struct fcoe_crc_eof);
1763 if (mss > 512)
1764 mss &= ~511;
1765 total_rx_bytes += ddp_bytes;
1766 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1767 }
Yi Zou3d8fd382009-06-08 14:38:44 +00001768
Alexander Duyckf8003262012-03-03 02:35:52 +00001769#endif /* IXGBE_FCOE */
Alexander Duyckc267fc12010-11-16 19:27:00 -08001770 u64_stats_update_begin(&rx_ring->syncp);
1771 rx_ring->stats.packets += total_rx_packets;
1772 rx_ring->stats.bytes += total_rx_bytes;
1773 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001774 q_vector->rx.total_packets += total_rx_packets;
1775 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001776
Alexander Duyckf8003262012-03-03 02:35:52 +00001777 if (cleaned_count)
1778 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1779
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001780 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001781}
1782
Auke Kok9a799d72007-09-15 14:07:45 -07001783/**
1784 * ixgbe_configure_msix - Configure MSI-X hardware
1785 * @adapter: board private structure
1786 *
1787 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1788 * interrupts.
1789 **/
1790static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1791{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001792 struct ixgbe_q_vector *q_vector;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001793 int q_vectors, v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001794 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001795
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001796 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1797
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00001798 /* Populate MSIX to EITR Select */
1799 if (adapter->num_vfs > 32) {
1800 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
1801 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
1802 }
1803
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001804 /*
1805 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001806 * corresponding register.
1807 */
1808 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001809 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00001810 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001811
Alexander Duycka5579282012-02-08 07:50:04 +00001812 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001813 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001814
Alexander Duycka5579282012-02-08 07:50:04 +00001815 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001816 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001817
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001818 if (q_vector->tx.ring && !q_vector->rx.ring) {
1819 /* tx only vector */
1820 if (adapter->tx_itr_setting == 1)
1821 q_vector->itr = IXGBE_10K_ITR;
1822 else
1823 q_vector->itr = adapter->tx_itr_setting;
1824 } else {
1825 /* rx or rx/tx vector */
1826 if (adapter->rx_itr_setting == 1)
1827 q_vector->itr = IXGBE_20K_ITR;
1828 else
1829 q_vector->itr = adapter->rx_itr_setting;
1830 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001831
Alexander Duyckfe49f042009-06-04 16:00:09 +00001832 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001833 }
1834
Alexander Duyckbd508172010-11-16 19:27:03 -08001835 switch (adapter->hw.mac.type) {
1836 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001837 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001838 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001839 break;
1840 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001841 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001842 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001843 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08001844 default:
1845 break;
1846 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001847 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001848
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001849 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001850 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001851 mask &= ~(IXGBE_EIMS_OTHER |
1852 IXGBE_EIMS_MAILBOX |
1853 IXGBE_EIMS_LSC);
1854
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001855 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001856}
1857
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001858enum latency_range {
1859 lowest_latency = 0,
1860 low_latency = 1,
1861 bulk_latency = 2,
1862 latency_invalid = 255
1863};
1864
1865/**
1866 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00001867 * @q_vector: structure containing interrupt and ring information
1868 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001869 *
1870 * Stores a new ITR value based on packets and byte
1871 * counts during the last interrupt. The advantage of per interrupt
1872 * computation is faster updates and more accurate ITR for the current
1873 * traffic pattern. Constants in this function were computed
1874 * based on theoretical maximum wire speed and thresholds were set based
1875 * on testing data as well as attempting to minimize response time
1876 * while increasing bulk throughput.
1877 * this functionality is controlled by the InterruptThrottleRate module
1878 * parameter (see ixgbe_param.c)
1879 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00001880static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
1881 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001882{
Alexander Duyckbd198052011-06-11 01:45:08 +00001883 int bytes = ring_container->total_bytes;
1884 int packets = ring_container->total_packets;
1885 u32 timepassed_us;
Alexander Duyck621bd702012-02-08 07:50:20 +00001886 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00001887 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001888
1889 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00001890 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001891
1892 /* simple throttlerate management
Alexander Duyck621bd702012-02-08 07:50:20 +00001893 * 0-10MB/s lowest (100000 ints/s)
1894 * 10-20MB/s low (20000 ints/s)
1895 * 20-1249MB/s bulk (8000 ints/s)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001896 */
1897 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001898 timepassed_us = q_vector->itr >> 2;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001899 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1900
1901 switch (itr_setting) {
1902 case lowest_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00001903 if (bytes_perint > 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00001904 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001905 break;
1906 case low_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00001907 if (bytes_perint > 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00001908 itr_setting = bulk_latency;
Alexander Duyck621bd702012-02-08 07:50:20 +00001909 else if (bytes_perint <= 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00001910 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001911 break;
1912 case bulk_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00001913 if (bytes_perint <= 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00001914 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001915 break;
1916 }
1917
Alexander Duyckbd198052011-06-11 01:45:08 +00001918 /* clear work counters since we have the values we need */
1919 ring_container->total_bytes = 0;
1920 ring_container->total_packets = 0;
1921
1922 /* write updated itr to ring container */
1923 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001924}
1925
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001926/**
1927 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001928 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001929 *
1930 * This function is made to be called by ethtool and by the driver
1931 * when it needs to update EITR registers at runtime. Hardware
1932 * specific quirks/differences are taken care of here.
1933 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001934void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001935{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001936 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001937 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001938 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00001939 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001940
Alexander Duyckbd508172010-11-16 19:27:03 -08001941 switch (adapter->hw.mac.type) {
1942 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001943 /* must write high and low 16 bits to reset counter */
1944 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08001945 break;
1946 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001947 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001948 /*
1949 * set the WDIS bit to not clear the timer bits and cause an
1950 * immediate assertion of the interrupt
1951 */
1952 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08001953 break;
1954 default:
1955 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001956 }
1957 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1958}
1959
Alexander Duyckbd198052011-06-11 01:45:08 +00001960static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001961{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001962 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00001963 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001964
Alexander Duyckbd198052011-06-11 01:45:08 +00001965 ixgbe_update_itr(q_vector, &q_vector->tx);
1966 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001967
Alexander Duyck08c88332011-06-11 01:45:03 +00001968 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001969
1970 switch (current_itr) {
1971 /* counts and packets in update_itr are dependent on these numbers */
1972 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001973 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001974 break;
1975 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001976 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001977 break;
1978 case bulk_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001979 new_itr = IXGBE_8K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001980 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00001981 default:
1982 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001983 }
1984
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001985 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001986 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001987 new_itr = (10 * new_itr * q_vector->itr) /
1988 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001989
Alexander Duyckbd198052011-06-11 01:45:08 +00001990 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00001991 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001992
1993 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001994 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001995}
1996
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001997/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00001998 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00001999 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002000 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00002001static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002002{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002003 struct ixgbe_hw *hw = &adapter->hw;
2004 u32 eicr = adapter->interrupt_event;
2005
Alexander Duyckf0f97782011-04-22 04:08:09 +00002006 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00002007 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002008
Alexander Duyckf0f97782011-04-22 04:08:09 +00002009 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2010 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
2011 return;
2012
2013 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2014
Joe Perches7ca647b2010-09-07 21:35:40 +00002015 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002016 case IXGBE_DEV_ID_82599_T3_LOM:
2017 /*
2018 * Since the warning interrupt is for both ports
2019 * we don't have to check if:
2020 * - This interrupt wasn't for our port.
2021 * - We may have missed the interrupt so always have to
2022 * check if we got a LSC
2023 */
2024 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
2025 !(eicr & IXGBE_EICR_LSC))
2026 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002027
Alexander Duyckf0f97782011-04-22 04:08:09 +00002028 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
2029 u32 autoneg;
2030 bool link_up = false;
2031
Joe Perches7ca647b2010-09-07 21:35:40 +00002032 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
2033
Alexander Duyckf0f97782011-04-22 04:08:09 +00002034 if (link_up)
2035 return;
2036 }
2037
2038 /* Check if this is not due to overtemp */
2039 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2040 return;
2041
2042 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00002043 default:
2044 if (!(eicr & IXGBE_EICR_GPI_SDP0))
2045 return;
2046 break;
2047 }
2048 e_crit(drv,
2049 "Network adapter has been stopped because it has over heated. "
2050 "Restart the computer. If the problem persists, "
2051 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00002052
2053 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002054}
2055
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002056static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2057{
2058 struct ixgbe_hw *hw = &adapter->hw;
2059
2060 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
2061 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002062 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002063 /* write to clear the interrupt */
2064 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
2065 }
2066}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002067
Jacob Keller4f51bf72011-08-20 04:49:45 +00002068static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2069{
2070 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2071 return;
2072
2073 switch (adapter->hw.mac.type) {
2074 case ixgbe_mac_82599EB:
2075 /*
2076 * Need to check link state so complete overtemp check
2077 * on service task
2078 */
2079 if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) &&
2080 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2081 adapter->interrupt_event = eicr;
2082 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2083 ixgbe_service_event_schedule(adapter);
2084 return;
2085 }
2086 return;
2087 case ixgbe_mac_X540:
2088 if (!(eicr & IXGBE_EICR_TS))
2089 return;
2090 break;
2091 default:
2092 return;
2093 }
2094
2095 e_crit(drv,
2096 "Network adapter has been stopped because it has over heated. "
2097 "Restart the computer. If the problem persists, "
2098 "power off the system and replace the adapter\n");
2099}
2100
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002101static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2102{
2103 struct ixgbe_hw *hw = &adapter->hw;
2104
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002105 if (eicr & IXGBE_EICR_GPI_SDP2) {
2106 /* Clear the interrupt */
2107 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00002108 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2109 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
2110 ixgbe_service_event_schedule(adapter);
2111 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002112 }
2113
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002114 if (eicr & IXGBE_EICR_GPI_SDP1) {
2115 /* Clear the interrupt */
2116 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00002117 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2118 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2119 ixgbe_service_event_schedule(adapter);
2120 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002121 }
2122}
2123
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002124static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2125{
2126 struct ixgbe_hw *hw = &adapter->hw;
2127
2128 adapter->lsc_int++;
2129 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2130 adapter->link_check_timeout = jiffies;
2131 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2132 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002133 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002134 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002135 }
2136}
2137
Alexander Duyckfe49f042009-06-04 16:00:09 +00002138static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2139 u64 qmask)
2140{
2141 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002142 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002143
Alexander Duyckbd508172010-11-16 19:27:03 -08002144 switch (hw->mac.type) {
2145 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002146 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002147 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2148 break;
2149 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002150 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002151 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002152 if (mask)
2153 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002154 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002155 if (mask)
2156 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2157 break;
2158 default:
2159 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002160 }
2161 /* skip the flush */
2162}
2163
2164static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002165 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002166{
2167 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002168 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002169
Alexander Duyckbd508172010-11-16 19:27:03 -08002170 switch (hw->mac.type) {
2171 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002172 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002173 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2174 break;
2175 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002176 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002177 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002178 if (mask)
2179 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002180 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002181 if (mask)
2182 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2183 break;
2184 default:
2185 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002186 }
2187 /* skip the flush */
2188}
2189
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002190/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002191 * ixgbe_irq_enable - Enable default interrupt generation settings
2192 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002193 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002194static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2195 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002196{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002197 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002198
Alexander Duyck2c4af692011-07-15 07:29:55 +00002199 /* don't reenable LSC while waiting for link */
2200 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2201 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002202
Alexander Duyck2c4af692011-07-15 07:29:55 +00002203 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002204 switch (adapter->hw.mac.type) {
2205 case ixgbe_mac_82599EB:
2206 mask |= IXGBE_EIMS_GPI_SDP0;
2207 break;
2208 case ixgbe_mac_X540:
2209 mask |= IXGBE_EIMS_TS;
2210 break;
2211 default:
2212 break;
2213 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002214 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2215 mask |= IXGBE_EIMS_GPI_SDP1;
2216 switch (adapter->hw.mac.type) {
2217 case ixgbe_mac_82599EB:
Alexander Duyck2c4af692011-07-15 07:29:55 +00002218 mask |= IXGBE_EIMS_GPI_SDP1;
2219 mask |= IXGBE_EIMS_GPI_SDP2;
Don Skidmore858bc082011-08-04 09:28:30 +00002220 case ixgbe_mac_X540:
2221 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002222 mask |= IXGBE_EIMS_MAILBOX;
2223 break;
2224 default:
2225 break;
2226 }
2227 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2228 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2229 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002230
Alexander Duyck2c4af692011-07-15 07:29:55 +00002231 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2232 if (queues)
2233 ixgbe_irq_enable_queues(adapter, ~0);
2234 if (flush)
2235 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002236}
2237
Alexander Duyck2c4af692011-07-15 07:29:55 +00002238static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002239{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002240 struct ixgbe_adapter *adapter = data;
2241 struct ixgbe_hw *hw = &adapter->hw;
2242 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002243
Alexander Duyck2c4af692011-07-15 07:29:55 +00002244 /*
2245 * Workaround for Silicon errata. Use clear-by-write instead
2246 * of clear-by-read. Reading with EICS will return the
2247 * interrupt causes without clearing, which later be done
2248 * with the write to EICR.
2249 */
2250 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
2251 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002252
Alexander Duyck2c4af692011-07-15 07:29:55 +00002253 if (eicr & IXGBE_EICR_LSC)
2254 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002255
Alexander Duyck2c4af692011-07-15 07:29:55 +00002256 if (eicr & IXGBE_EICR_MAILBOX)
2257 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002258
Alexander Duyck2c4af692011-07-15 07:29:55 +00002259 switch (hw->mac.type) {
2260 case ixgbe_mac_82599EB:
2261 case ixgbe_mac_X540:
2262 if (eicr & IXGBE_EICR_ECC)
2263 e_info(link, "Received unrecoverable ECC Err, please "
2264 "reboot\n");
2265 /* Handle Flow Director Full threshold interrupt */
2266 if (eicr & IXGBE_EICR_FLOW_DIR) {
2267 int reinit_count = 0;
2268 int i;
2269 for (i = 0; i < adapter->num_tx_queues; i++) {
2270 struct ixgbe_ring *ring = adapter->tx_ring[i];
2271 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2272 &ring->state))
2273 reinit_count++;
2274 }
2275 if (reinit_count) {
2276 /* no more flow director interrupts until after init */
2277 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2278 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2279 ixgbe_service_event_schedule(adapter);
2280 }
2281 }
2282 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002283 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002284 break;
2285 default:
2286 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002287 }
2288
Alexander Duyck2c4af692011-07-15 07:29:55 +00002289 ixgbe_check_fan_failure(adapter, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07002290
Alexander Duyck2c4af692011-07-15 07:29:55 +00002291 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002292 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00002293 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002294
Alexander Duyck2c4af692011-07-15 07:29:55 +00002295 return IRQ_HANDLED;
2296}
2297
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002298static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07002299{
2300 struct ixgbe_q_vector *q_vector = data;
2301
Auke Kok9a799d72007-09-15 14:07:45 -07002302 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002303
2304 if (q_vector->rx.ring || q_vector->tx.ring)
2305 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002306
2307 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002308}
2309
Auke Kok9a799d72007-09-15 14:07:45 -07002310/**
Alexander Duyckeb01b972012-02-08 07:51:27 +00002311 * ixgbe_poll - NAPI Rx polling callback
2312 * @napi: structure for representing this polling device
2313 * @budget: how many packets driver is allowed to clean
2314 *
2315 * This function is used for legacy and MSI, NAPI mode
2316 **/
2317static int ixgbe_poll(struct napi_struct *napi, int budget)
2318{
2319 struct ixgbe_q_vector *q_vector =
2320 container_of(napi, struct ixgbe_q_vector, napi);
2321 struct ixgbe_adapter *adapter = q_vector->adapter;
2322 struct ixgbe_ring *ring;
2323 int per_ring_budget;
2324 bool clean_complete = true;
2325
2326#ifdef CONFIG_IXGBE_DCA
2327 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2328 ixgbe_update_dca(q_vector);
2329#endif
2330
2331 ixgbe_for_each_ring(ring, q_vector->tx)
2332 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
2333
2334 /* attempt to distribute budget to each queue fairly, but don't allow
2335 * the budget to go below 1 because we'll exit polling */
2336 if (q_vector->rx.count > 1)
2337 per_ring_budget = max(budget/q_vector->rx.count, 1);
2338 else
2339 per_ring_budget = budget;
2340
2341 ixgbe_for_each_ring(ring, q_vector->rx)
2342 clean_complete &= ixgbe_clean_rx_irq(q_vector, ring,
2343 per_ring_budget);
2344
2345 /* If all work not completed, return budget and keep polling */
2346 if (!clean_complete)
2347 return budget;
2348
2349 /* all work done, exit the polling mode */
2350 napi_complete(napi);
2351 if (adapter->rx_itr_setting & 1)
2352 ixgbe_set_itr(q_vector);
2353 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2354 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
2355
2356 return 0;
2357}
2358
2359/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002360 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2361 * @adapter: board private structure
2362 *
2363 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2364 * interrupts from the kernel.
2365 **/
2366static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2367{
2368 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002369 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2370 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002371 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002372
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002373 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002374 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002375 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002376
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002377 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002378 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002379 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002380 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002381 } else if (q_vector->rx.ring) {
2382 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2383 "%s-%s-%d", netdev->name, "rx", ri++);
2384 } else if (q_vector->tx.ring) {
2385 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2386 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002387 } else {
2388 /* skip this unused q_vector */
2389 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002390 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002391 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2392 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002393 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002394 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002395 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002396 goto free_queue_irqs;
2397 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002398 /* If Flow Director is enabled, set interrupt affinity */
2399 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2400 /* assign the mask for this irq */
2401 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00002402 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00002403 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002404 }
2405
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002406 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00002407 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002408 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00002409 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002410 goto free_queue_irqs;
2411 }
2412
2413 return 0;
2414
2415free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00002416 while (vector) {
2417 vector--;
2418 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2419 NULL);
2420 free_irq(adapter->msix_entries[vector].vector,
2421 adapter->q_vector[vector]);
2422 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002423 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2424 pci_disable_msix(adapter->pdev);
2425 kfree(adapter->msix_entries);
2426 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002427 return err;
2428}
2429
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002430/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002431 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002432 * @irq: interrupt number
2433 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002434 **/
2435static irqreturn_t ixgbe_intr(int irq, void *data)
2436{
Alexander Duycka65151b2011-05-27 05:31:32 +00002437 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002438 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002439 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002440 u32 eicr;
2441
Don Skidmore54037502009-02-21 15:42:56 -08002442 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00002443 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08002444 * before the read of EICR.
2445 */
2446 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2447
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002448 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00002449 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002450 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002451 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002452 /*
2453 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002454 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002455 * have disabled interrupts due to EIAM
2456 * finish the workaround of silicon errata on 82598. Unmask
2457 * the interrupt that we masked before the EICR read.
2458 */
2459 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2460 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002461 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002462 }
Auke Kok9a799d72007-09-15 14:07:45 -07002463
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002464 if (eicr & IXGBE_EICR_LSC)
2465 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002466
Alexander Duyckbd508172010-11-16 19:27:03 -08002467 switch (hw->mac.type) {
2468 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002469 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00002470 /* Fall through */
2471 case ixgbe_mac_X540:
2472 if (eicr & IXGBE_EICR_ECC)
2473 e_info(link, "Received unrecoverable ECC err, please "
2474 "reboot\n");
Jacob Keller4f51bf72011-08-20 04:49:45 +00002475 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002476 break;
2477 default:
2478 break;
2479 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002480
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002481 ixgbe_check_fan_failure(adapter, eicr);
2482
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00002483 /* would disable interrupts here but EIAM disabled it */
2484 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002485
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002486 /*
2487 * re-enable link(maybe) and non-queue interrupts, no flush.
2488 * ixgbe_poll will re-enable the queue interrupts
2489 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002490 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2491 ixgbe_irq_enable(adapter, false, false);
2492
Auke Kok9a799d72007-09-15 14:07:45 -07002493 return IRQ_HANDLED;
2494}
2495
2496/**
2497 * ixgbe_request_irq - initialize interrupts
2498 * @adapter: board private structure
2499 *
2500 * Attempts to configure interrupts using the best available
2501 * capabilities of the hardware and kernel.
2502 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002503static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002504{
2505 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002506 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002507
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002508 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002509 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002510 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08002511 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151b2011-05-27 05:31:32 +00002512 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002513 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08002514 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151b2011-05-27 05:31:32 +00002515 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002516
Alexander Duyckde88eee2012-02-08 07:49:59 +00002517 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002518 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002519
Auke Kok9a799d72007-09-15 14:07:45 -07002520 return err;
2521}
2522
2523static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2524{
Auke Kok9a799d72007-09-15 14:07:45 -07002525 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002526 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07002527
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002528 q_vectors = adapter->num_msix_vectors;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002529 i = q_vectors - 1;
Alexander Duycka65151b2011-05-27 05:31:32 +00002530 free_irq(adapter->msix_entries[i].vector, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002531 i--;
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002532
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002533 for (; i >= 0; i--) {
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002534 /* free only the irqs that were actually requested */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002535 if (!adapter->q_vector[i]->rx.ring &&
2536 !adapter->q_vector[i]->tx.ring)
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002537 continue;
2538
Alexander Duyck207867f2011-07-15 03:05:37 +00002539 /* clear the affinity_mask in the IRQ descriptor */
2540 irq_set_affinity_hint(adapter->msix_entries[i].vector,
2541 NULL);
2542
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002543 free_irq(adapter->msix_entries[i].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002544 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002545 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002546 } else {
Alexander Duycka65151b2011-05-27 05:31:32 +00002547 free_irq(adapter->pdev->irq, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002548 }
2549}
2550
2551/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002552 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2553 * @adapter: board private structure
2554 **/
2555static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2556{
Alexander Duyckbd508172010-11-16 19:27:03 -08002557 switch (adapter->hw.mac.type) {
2558 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002559 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002560 break;
2561 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002562 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002563 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2564 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002565 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002566 break;
2567 default:
2568 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002569 }
2570 IXGBE_WRITE_FLUSH(&adapter->hw);
2571 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2572 int i;
2573 for (i = 0; i < adapter->num_msix_vectors; i++)
2574 synchronize_irq(adapter->msix_entries[i].vector);
2575 } else {
2576 synchronize_irq(adapter->pdev->irq);
2577 }
2578}
2579
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002580/**
Auke Kok9a799d72007-09-15 14:07:45 -07002581 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2582 *
2583 **/
2584static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2585{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002586 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002587
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002588 /* rx/tx vector */
2589 if (adapter->rx_itr_setting == 1)
2590 q_vector->itr = IXGBE_20K_ITR;
2591 else
2592 q_vector->itr = adapter->rx_itr_setting;
2593
2594 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002595
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002596 ixgbe_set_ivar(adapter, 0, 0, 0);
2597 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002598
Emil Tantilov396e7992010-07-01 20:05:12 +00002599 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002600}
2601
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002602/**
2603 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2604 * @adapter: board private structure
2605 * @ring: structure containing ring specific data
2606 *
2607 * Configure the Tx descriptor ring after a reset.
2608 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002609void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2610 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002611{
2612 struct ixgbe_hw *hw = &adapter->hw;
2613 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002614 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002615 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002616 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002617
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002618 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002619 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002620 IXGBE_WRITE_FLUSH(hw);
2621
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002622 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002623 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002624 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2625 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2626 ring->count * sizeof(union ixgbe_adv_tx_desc));
2627 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2628 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002629 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002630
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002631 /*
2632 * set WTHRESH to encourage burst writeback, it should not be set
2633 * higher than 1 when ITR is 0 as it could cause false TX hangs
2634 *
2635 * In order to avoid issues WTHRESH + PTHRESH should always be equal
2636 * to or less than the number of on chip descriptors, which is
2637 * currently 40.
2638 */
Alexander Duycke954b372012-02-08 07:49:38 +00002639 if (!ring->q_vector || (ring->q_vector->itr < 8))
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002640 txdctl |= (1 << 16); /* WTHRESH = 1 */
2641 else
2642 txdctl |= (8 << 16); /* WTHRESH = 8 */
2643
Alexander Duycke954b372012-02-08 07:49:38 +00002644 /*
2645 * Setting PTHRESH to 32 both improves performance
2646 * and avoids a TX hang with DFP enabled
2647 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002648 txdctl |= (1 << 8) | /* HTHRESH = 1 */
2649 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002650
2651 /* reinitialize flowdirector state */
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002652 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2653 adapter->atr_sample_rate) {
2654 ring->atr_sample_rate = adapter->atr_sample_rate;
2655 ring->atr_count = 0;
2656 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2657 } else {
2658 ring->atr_sample_rate = 0;
2659 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002660
John Fastabendc84d3242010-11-16 19:27:12 -08002661 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2662
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002663 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002664 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2665
Alexander Duyckb2d96e02012-02-07 08:14:33 +00002666 netdev_tx_reset_queue(txring_txq(ring));
2667
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002668 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2669 if (hw->mac.type == ixgbe_mac_82598EB &&
2670 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2671 return;
2672
2673 /* poll to verify queue is enabled */
2674 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002675 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002676 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2677 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2678 if (!wait_loop)
2679 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002680}
2681
Alexander Duyck120ff942010-08-19 13:34:50 +00002682static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2683{
2684 struct ixgbe_hw *hw = &adapter->hw;
2685 u32 rttdcs;
John Fastabend72a32f12011-04-26 07:25:58 +00002686 u32 reg;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002687 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00002688
2689 if (hw->mac.type == ixgbe_mac_82598EB)
2690 return;
2691
2692 /* disable the arbiter while setting MTQC */
2693 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2694 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2695 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2696
2697 /* set transmit pool layout */
John Fastabend8b1c0b22011-05-03 02:26:48 +00002698 switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Alexander Duyck120ff942010-08-19 13:34:50 +00002699 case (IXGBE_FLAG_SRIOV_ENABLED):
2700 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2701 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2702 break;
Alexander Duyck120ff942010-08-19 13:34:50 +00002703 default:
John Fastabend8b1c0b22011-05-03 02:26:48 +00002704 if (!tcs)
2705 reg = IXGBE_MTQC_64Q_1PB;
2706 else if (tcs <= 4)
2707 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2708 else
2709 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2710
2711 IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
2712
2713 /* Enable Security TX Buffer IFG for multiple pb */
2714 if (tcs) {
2715 reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2716 reg |= IXGBE_SECTX_DCB;
2717 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
2718 }
Alexander Duyck120ff942010-08-19 13:34:50 +00002719 break;
2720 }
2721
2722 /* re-enable the arbiter */
2723 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2724 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2725}
2726
Auke Kok9a799d72007-09-15 14:07:45 -07002727/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002728 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002729 * @adapter: board private structure
2730 *
2731 * Configure the Tx unit of the MAC after a reset.
2732 **/
2733static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2734{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002735 struct ixgbe_hw *hw = &adapter->hw;
2736 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002737 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002738
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002739 ixgbe_setup_mtqc(adapter);
2740
2741 if (hw->mac.type != ixgbe_mac_82598EB) {
2742 /* DMATXCTL.EN must be before Tx queues are enabled */
2743 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2744 dmatxctl |= IXGBE_DMATXCTL_TE;
2745 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2746 }
2747
Auke Kok9a799d72007-09-15 14:07:45 -07002748 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002749 for (i = 0; i < adapter->num_tx_queues; i++)
2750 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002751}
2752
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002753#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002754
Yi Zoua6616b42009-08-06 13:05:23 +00002755static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002756 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002757{
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002758 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002759 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002760
Alexander Duyckbd508172010-11-16 19:27:03 -08002761 switch (adapter->hw.mac.type) {
2762 case ixgbe_mac_82598EB: {
2763 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2764 const int mask = feature[RING_F_RSS].mask;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002765 reg_idx = reg_idx & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002766 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002767 break;
2768 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002769 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08002770 default:
2771 break;
2772 }
2773
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002774 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002775
2776 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2777 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002778 if (adapter->num_vfs)
2779 srrctl |= IXGBE_SRRCTL_DROP_EN;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002780
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002781 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2782 IXGBE_SRRCTL_BSIZEHDR_MASK;
2783
Alexander Duyckf8003262012-03-03 02:35:52 +00002784#if PAGE_SIZE > IXGBE_MAX_RXBUFFER
2785 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002786#else
Alexander Duyckf8003262012-03-03 02:35:52 +00002787 srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002788#endif
Alexander Duyckf8003262012-03-03 02:35:52 +00002789 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002790
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002791 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002792}
2793
Alexander Duyck05abb122010-08-19 13:35:41 +00002794static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002795{
Alexander Duyck05abb122010-08-19 13:35:41 +00002796 struct ixgbe_hw *hw = &adapter->hw;
2797 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00002798 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2799 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00002800 u32 mrqc = 0, reta = 0;
2801 u32 rxcsum;
2802 int i, j;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002803 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend86b4db32011-04-26 07:26:19 +00002804 int maxq = adapter->ring_feature[RING_F_RSS].indices;
2805
2806 if (tcs)
2807 maxq = min(maxq, adapter->num_tx_queues / tcs);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002808
Alexander Duyck05abb122010-08-19 13:35:41 +00002809 /* Fill out hash function seeds */
2810 for (i = 0; i < 10; i++)
2811 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002812
Alexander Duyck05abb122010-08-19 13:35:41 +00002813 /* Fill out redirection table */
2814 for (i = 0, j = 0; i < 128; i++, j++) {
John Fastabend86b4db32011-04-26 07:26:19 +00002815 if (j == maxq)
Alexander Duyck05abb122010-08-19 13:35:41 +00002816 j = 0;
2817 /* reta = 4-byte sliding window of
2818 * 0x00..(indices-1)(indices-1)00..etc. */
2819 reta = (reta << 8) | (j * 0x11);
2820 if ((i & 3) == 3)
2821 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2822 }
2823
2824 /* Disable indicating checksum in descriptor, enables RSS hash */
2825 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2826 rxcsum |= IXGBE_RXCSUM_PCSD;
2827 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2828
John Fastabend8b1c0b22011-05-03 02:26:48 +00002829 if (adapter->hw.mac.type == ixgbe_mac_82598EB &&
2830 (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002831 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002832 } else {
2833 int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
2834 | IXGBE_FLAG_SRIOV_ENABLED);
2835
2836 switch (mask) {
2837 case (IXGBE_FLAG_RSS_ENABLED):
2838 if (!tcs)
2839 mrqc = IXGBE_MRQC_RSSEN;
2840 else if (tcs <= 4)
2841 mrqc = IXGBE_MRQC_RTRSS4TCEN;
2842 else
2843 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2844 break;
2845 case (IXGBE_FLAG_SRIOV_ENABLED):
2846 mrqc = IXGBE_MRQC_VMDQEN;
2847 break;
2848 default:
2849 break;
2850 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002851 }
2852
Alexander Duyck05abb122010-08-19 13:35:41 +00002853 /* Perform hash on these packet types */
2854 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2855 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2856 | IXGBE_MRQC_RSS_FIELD_IPV6
2857 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2858
Alexander Duyckef6afc02012-02-08 07:51:53 +00002859 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
2860 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
2861 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
2862 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
2863
Alexander Duyck05abb122010-08-19 13:35:41 +00002864 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002865}
2866
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002867/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002868 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2869 * @adapter: address of board private structure
2870 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002871 **/
Don Skidmore082757a2011-07-21 05:55:00 +00002872static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00002873 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002874{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002875 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002876 u32 rscctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002877 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002878
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002879 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00002880 return;
2881
Alexander Duyck73670962010-08-19 13:38:34 +00002882 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002883 rscctrl |= IXGBE_RSCCTL_RSCEN;
2884 /*
2885 * we must limit the number of descriptors so that the
2886 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00002887 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002888 */
Alexander Duyckf8003262012-03-03 02:35:52 +00002889#if (PAGE_SIZE <= 8192)
2890 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2891#elif (PAGE_SIZE <= 16384)
2892 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002893#else
Alexander Duyckf8003262012-03-03 02:35:52 +00002894 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002895#endif
Alexander Duyck73670962010-08-19 13:38:34 +00002896 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002897}
2898
Alexander Duyck9e10e042010-08-19 13:40:06 +00002899/**
2900 * ixgbe_set_uta - Set unicast filter table address
2901 * @adapter: board private structure
2902 *
2903 * The unicast table address is a register array of 32-bit registers.
2904 * The table is meant to be used in a way similar to how the MTA is used
2905 * however due to certain limitations in the hardware it is necessary to
2906 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
2907 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
2908 **/
2909static void ixgbe_set_uta(struct ixgbe_adapter *adapter)
2910{
2911 struct ixgbe_hw *hw = &adapter->hw;
2912 int i;
2913
2914 /* The UTA table only exists on 82599 hardware and newer */
2915 if (hw->mac.type < ixgbe_mac_82599EB)
2916 return;
2917
2918 /* we only need to do this if VMDq is enabled */
2919 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
2920 return;
2921
2922 for (i = 0; i < 128; i++)
2923 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
2924}
2925
2926#define IXGBE_MAX_RX_DESC_POLL 10
2927static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2928 struct ixgbe_ring *ring)
2929{
2930 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002931 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2932 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002933 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002934
2935 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2936 if (hw->mac.type == ixgbe_mac_82598EB &&
2937 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2938 return;
2939
2940 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002941 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002942 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2943 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
2944
2945 if (!wait_loop) {
2946 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
2947 "the polling period\n", reg_idx);
2948 }
2949}
2950
Yi Zou2d39d572011-01-06 14:29:56 +00002951void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
2952 struct ixgbe_ring *ring)
2953{
2954 struct ixgbe_hw *hw = &adapter->hw;
2955 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2956 u32 rxdctl;
2957 u8 reg_idx = ring->reg_idx;
2958
2959 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2960 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
2961
2962 /* write value back with RXDCTL.ENABLE bit cleared */
2963 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2964
2965 if (hw->mac.type == ixgbe_mac_82598EB &&
2966 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2967 return;
2968
2969 /* the hardware may take up to 100us to really disable the rx queue */
2970 do {
2971 udelay(10);
2972 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2973 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
2974
2975 if (!wait_loop) {
2976 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
2977 "the polling period\n", reg_idx);
2978 }
2979}
2980
Alexander Duyck84418e32010-08-19 13:40:54 +00002981void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
2982 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00002983{
2984 struct ixgbe_hw *hw = &adapter->hw;
2985 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002986 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002987 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00002988
Alexander Duyck9e10e042010-08-19 13:40:06 +00002989 /* disable queue to avoid issues while updating state */
2990 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00002991 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002992
Alexander Duyckacd37172010-08-19 13:36:05 +00002993 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
2994 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
2995 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
2996 ring->count * sizeof(union ixgbe_adv_rx_desc));
2997 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
2998 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002999 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003000
3001 ixgbe_configure_srrctl(adapter, ring);
3002 ixgbe_configure_rscctl(adapter, ring);
3003
Greg Rosee9f98072011-01-26 01:06:07 +00003004 /* If operating in IOV mode set RLPML for X540 */
3005 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
3006 hw->mac.type == ixgbe_mac_X540) {
3007 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
3008 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
3009 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
3010 }
3011
Alexander Duyck9e10e042010-08-19 13:40:06 +00003012 if (hw->mac.type == ixgbe_mac_82598EB) {
3013 /*
3014 * enable cache line friendly hardware writes:
3015 * PTHRESH=32 descriptors (half the internal cache),
3016 * this also removes ugly rx_no_buffer_count increment
3017 * HTHRESH=4 descriptors (to minimize latency on fetch)
3018 * WTHRESH=8 burst writeback up to two cache lines
3019 */
3020 rxdctl &= ~0x3FFFFF;
3021 rxdctl |= 0x080420;
3022 }
3023
3024 /* enable receive descriptor ring */
3025 rxdctl |= IXGBE_RXDCTL_ENABLE;
3026 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3027
3028 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003029 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003030}
3031
Alexander Duyck48654522010-08-19 13:36:27 +00003032static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3033{
3034 struct ixgbe_hw *hw = &adapter->hw;
3035 int p;
3036
3037 /* PSRTYPE must be initialized in non 82598 adapters */
3038 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003039 IXGBE_PSRTYPE_UDPHDR |
3040 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003041 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003042 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003043
3044 if (hw->mac.type == ixgbe_mac_82598EB)
3045 return;
3046
3047 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
3048 psrtype |= (adapter->num_rx_queues_per_pool << 29);
3049
3050 for (p = 0; p < adapter->num_rx_pools; p++)
3051 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
3052 psrtype);
3053}
3054
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003055static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3056{
3057 struct ixgbe_hw *hw = &adapter->hw;
3058 u32 gcr_ext;
3059 u32 vt_reg_bits;
3060 u32 reg_offset, vf_shift;
3061 u32 vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00003062 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003063
3064 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3065 return;
3066
3067 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
3068 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
3069 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
3070 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
3071
3072 vf_shift = adapter->num_vfs % 32;
Greg Rose4cd69232012-01-25 07:59:37 +00003073 reg_offset = (adapter->num_vfs >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003074
3075 /* Enable only the PF's pool for Tx/Rx */
3076 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
3077 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
3078 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
3079 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
3080 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
3081
3082 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3083 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
3084
3085 /*
3086 * Set up VF register offsets for selected VT Mode,
3087 * i.e. 32 or 64 VFs for SR-IOV
3088 */
3089 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
3090 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
3091 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
3092 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3093
3094 /* enable Tx loopback for VF/PF communication */
3095 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Greg Rosea985b6c32010-11-18 03:02:52 +00003096 /* Enable MAC Anti-Spoofing */
Greg Rosea1cbb152011-05-13 01:33:48 +00003097 hw->mac.ops.set_mac_anti_spoofing(hw,
Greg Rosede4c7f62011-09-29 05:57:33 +00003098 (adapter->num_vfs != 0),
Greg Rosea985b6c32010-11-18 03:02:52 +00003099 adapter->num_vfs);
Greg Rosede4c7f62011-09-29 05:57:33 +00003100 /* For VFs that have spoof checking turned off */
3101 for (i = 0; i < adapter->num_vfs; i++) {
3102 if (!adapter->vfinfo[i].spoofchk_enabled)
3103 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
3104 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003105}
3106
Alexander Duyck477de6e2010-08-19 13:38:11 +00003107static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003108{
Auke Kok9a799d72007-09-15 14:07:45 -07003109 struct ixgbe_hw *hw = &adapter->hw;
3110 struct net_device *netdev = adapter->netdev;
3111 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003112 struct ixgbe_ring *rx_ring;
3113 int i;
3114 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003115
Alexander Duyck477de6e2010-08-19 13:38:11 +00003116#ifdef IXGBE_FCOE
3117 /* adjust max frame to be able to do baby jumbo for FCoE */
3118 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3119 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3120 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3121
3122#endif /* IXGBE_FCOE */
3123 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3124 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3125 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3126 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3127
3128 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003129 }
3130
Alexander Duyck919e78a2011-08-26 09:52:38 +00003131 /* MHADD will allow an extra 4 bytes past for vlan tagged frames */
3132 max_frame += VLAN_HLEN;
3133
Auke Kok9a799d72007-09-15 14:07:45 -07003134 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003135 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3136 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003137 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3138
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003139 /*
3140 * Setup the HW Rx Head and Tail Descriptor Pointers and
3141 * the Base and Length of the Rx Descriptor Ring
3142 */
Auke Kok9a799d72007-09-15 14:07:45 -07003143 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003144 rx_ring = adapter->rx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003145 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3146 set_ring_rsc_enabled(rx_ring);
3147 else
3148 clear_ring_rsc_enabled(rx_ring);
Yi Zou63f39bd2009-05-17 12:34:35 +00003149#ifdef IXGBE_FCOE
Joe Perchese8e9f692010-09-07 21:34:53 +00003150 if (netdev->features & NETIF_F_FCOE_MTU) {
Yi Zou63f39bd2009-05-17 12:34:35 +00003151 struct ixgbe_ring_feature *f;
3152 f = &adapter->ring_feature[RING_F_FCOE];
Alexander Duyckf8003262012-03-03 02:35:52 +00003153 if ((i >= f->mask) && (i < f->mask + f->indices))
3154 set_bit(__IXGBE_RX_FCOE_BUFSZ, &rx_ring->state);
Yi Zou63f39bd2009-05-17 12:34:35 +00003155 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003156#endif /* IXGBE_FCOE */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003157 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003158}
3159
Alexander Duyck73670962010-08-19 13:38:34 +00003160static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3161{
3162 struct ixgbe_hw *hw = &adapter->hw;
3163 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3164
3165 switch (hw->mac.type) {
3166 case ixgbe_mac_82598EB:
3167 /*
3168 * For VMDq support of different descriptor types or
3169 * buffer sizes through the use of multiple SRRCTL
3170 * registers, RDRXCTL.MVMEN must be set to 1
3171 *
3172 * also, the manual doesn't mention it clearly but DCA hints
3173 * will only use queue 0's tags unless this bit is set. Side
3174 * effects of setting this bit are only that SRRCTL must be
3175 * fully programmed [0..15]
3176 */
3177 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3178 break;
3179 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003180 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003181 /* Disable RSC for ACK packets */
3182 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3183 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3184 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3185 /* hardware requires some bits to be set by default */
3186 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3187 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3188 break;
3189 default:
3190 /* We should do nothing since we don't know this hardware */
3191 return;
3192 }
3193
3194 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3195}
3196
Alexander Duyck477de6e2010-08-19 13:38:11 +00003197/**
3198 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3199 * @adapter: board private structure
3200 *
3201 * Configure the Rx unit of the MAC after a reset.
3202 **/
3203static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3204{
3205 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003206 int i;
3207 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003208
3209 /* disable receives while setting up the descriptors */
3210 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3211 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3212
3213 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003214 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003215
Alexander Duyck9e10e042010-08-19 13:40:06 +00003216 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003217 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003218
Alexander Duyck9e10e042010-08-19 13:40:06 +00003219 ixgbe_set_uta(adapter);
3220
Alexander Duyck477de6e2010-08-19 13:38:11 +00003221 /* set_rx_buffer_len must be called before ring initialization */
3222 ixgbe_set_rx_buffer_len(adapter);
3223
3224 /*
3225 * Setup the HW Rx Head and Tail Descriptor Pointers and
3226 * the Base and Length of the Rx Descriptor Ring
3227 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003228 for (i = 0; i < adapter->num_rx_queues; i++)
3229 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003230
Alexander Duyck9e10e042010-08-19 13:40:06 +00003231 /* disable drop enable for 82598 parts */
3232 if (hw->mac.type == ixgbe_mac_82598EB)
3233 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3234
3235 /* enable all receives */
3236 rxctrl |= IXGBE_RXCTRL_RXEN;
3237 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003238}
3239
Jiri Pirko8e586132011-12-08 19:52:37 -05003240static int ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003241{
3242 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003243 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003244 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003245
3246 /* add VID to filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003247 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003248 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003249
3250 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003251}
3252
Jiri Pirko8e586132011-12-08 19:52:37 -05003253static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003254{
3255 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003256 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003257 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003258
Auke Kok9a799d72007-09-15 14:07:45 -07003259 /* remove VID from filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003260 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003261 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003262
3263 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003264}
3265
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003266/**
3267 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3268 * @adapter: driver data
3269 */
3270static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3271{
3272 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003273 u32 vlnctrl;
3274
3275 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3276 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3277 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3278}
3279
3280/**
3281 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3282 * @adapter: driver data
3283 */
3284static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3285{
3286 struct ixgbe_hw *hw = &adapter->hw;
3287 u32 vlnctrl;
3288
3289 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3290 vlnctrl |= IXGBE_VLNCTRL_VFE;
3291 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3292 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3293}
3294
3295/**
3296 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3297 * @adapter: driver data
3298 */
3299static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3300{
3301 struct ixgbe_hw *hw = &adapter->hw;
3302 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003303 int i, j;
3304
3305 switch (hw->mac.type) {
3306 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003307 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3308 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003309 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3310 break;
3311 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003312 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003313 for (i = 0; i < adapter->num_rx_queues; i++) {
3314 j = adapter->rx_ring[i]->reg_idx;
3315 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3316 vlnctrl &= ~IXGBE_RXDCTL_VME;
3317 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3318 }
3319 break;
3320 default:
3321 break;
3322 }
3323}
3324
3325/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003326 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003327 * @adapter: driver data
3328 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003329static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003330{
3331 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003332 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003333 int i, j;
3334
3335 switch (hw->mac.type) {
3336 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003337 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3338 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003339 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3340 break;
3341 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003342 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003343 for (i = 0; i < adapter->num_rx_queues; i++) {
3344 j = adapter->rx_ring[i]->reg_idx;
3345 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3346 vlnctrl |= IXGBE_RXDCTL_VME;
3347 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3348 }
3349 break;
3350 default:
3351 break;
3352 }
3353}
3354
Auke Kok9a799d72007-09-15 14:07:45 -07003355static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3356{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003357 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003358
Jesse Grossf62bbb52010-10-20 13:56:10 +00003359 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3360
3361 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3362 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003363}
3364
3365/**
Alexander Duyck28500622010-06-15 09:25:48 +00003366 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3367 * @netdev: network interface device structure
3368 *
3369 * Writes unicast address list to the RAR table.
3370 * Returns: -ENOMEM on failure/insufficient address space
3371 * 0 on no addresses written
3372 * X on writing X addresses to the RAR table
3373 **/
3374static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3375{
3376 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3377 struct ixgbe_hw *hw = &adapter->hw;
3378 unsigned int vfn = adapter->num_vfs;
Greg Rosea1cbb152011-05-13 01:33:48 +00003379 unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS;
Alexander Duyck28500622010-06-15 09:25:48 +00003380 int count = 0;
3381
3382 /* return ENOMEM indicating insufficient memory for addresses */
3383 if (netdev_uc_count(netdev) > rar_entries)
3384 return -ENOMEM;
3385
3386 if (!netdev_uc_empty(netdev) && rar_entries) {
3387 struct netdev_hw_addr *ha;
3388 /* return error if we do not support writing to RAR table */
3389 if (!hw->mac.ops.set_rar)
3390 return -ENOMEM;
3391
3392 netdev_for_each_uc_addr(ha, netdev) {
3393 if (!rar_entries)
3394 break;
3395 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3396 vfn, IXGBE_RAH_AV);
3397 count++;
3398 }
3399 }
3400 /* write the addresses in reverse order to avoid write combining */
3401 for (; rar_entries > 0 ; rar_entries--)
3402 hw->mac.ops.clear_rar(hw, rar_entries);
3403
3404 return count;
3405}
3406
3407/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003408 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003409 * @netdev: network interface device structure
3410 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003411 * The set_rx_method entry point is called whenever the unicast/multicast
3412 * address list or the network interface flags are updated. This routine is
3413 * responsible for configuring the hardware for proper unicast, multicast and
3414 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003415 **/
Greg Rose7f870472010-01-09 02:25:29 +00003416void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003417{
3418 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3419 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003420 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3421 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003422
3423 /* Check for Promiscuous and All Multicast modes */
3424
3425 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3426
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003427 /* set all bits that we expect to always be set */
Ben Greear3f2d1c02012-03-08 08:28:41 +00003428 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003429 fctrl |= IXGBE_FCTRL_BAM;
3430 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3431 fctrl |= IXGBE_FCTRL_PMCF;
3432
Alexander Duyck28500622010-06-15 09:25:48 +00003433 /* clear the bits we are changing the status of */
3434 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3435
Auke Kok9a799d72007-09-15 14:07:45 -07003436 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003437 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003438 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003439 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003440 /* don't hardware filter vlans in promisc mode */
3441 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003442 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003443 if (netdev->flags & IFF_ALLMULTI) {
3444 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003445 vmolr |= IXGBE_VMOLR_MPE;
3446 } else {
3447 /*
3448 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003449 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003450 * that we can at least receive multicast traffic
3451 */
3452 hw->mac.ops.update_mc_addr_list(hw, netdev);
3453 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003454 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003455 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003456 hw->addr_ctrl.user_set_promisc = false;
Alexander Duyck28500622010-06-15 09:25:48 +00003457 /*
3458 * Write addresses to available RAR registers, if there is not
3459 * sufficient space to store all the addresses then enable
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003460 * unicast promiscuous mode
Alexander Duyck28500622010-06-15 09:25:48 +00003461 */
3462 count = ixgbe_write_uc_addr_list(netdev);
3463 if (count < 0) {
3464 fctrl |= IXGBE_FCTRL_UPE;
3465 vmolr |= IXGBE_VMOLR_ROPE;
3466 }
3467 }
3468
3469 if (adapter->num_vfs) {
3470 ixgbe_restore_vf_multicasts(adapter);
3471 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3472 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3473 IXGBE_VMOLR_ROPE);
3474 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003475 }
3476
Ben Greear3f2d1c02012-03-08 08:28:41 +00003477 /* This is useful for sniffing bad packets. */
3478 if (adapter->netdev->features & NETIF_F_RXALL) {
3479 /* UPE and MPE will be handled by normal PROMISC logic
3480 * in e1000e_set_rx_mode */
3481 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
3482 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
3483 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
3484
3485 fctrl &= ~(IXGBE_FCTRL_DPF);
3486 /* NOTE: VLAN filtering is disabled by setting PROMISC */
3487 }
3488
Auke Kok9a799d72007-09-15 14:07:45 -07003489 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003490
3491 if (netdev->features & NETIF_F_HW_VLAN_RX)
3492 ixgbe_vlan_strip_enable(adapter);
3493 else
3494 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003495}
3496
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003497static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3498{
3499 int q_idx;
3500 struct ixgbe_q_vector *q_vector;
3501 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3502
3503 /* legacy and MSI only use one vector */
3504 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3505 q_vectors = 1;
3506
3507 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003508 q_vector = adapter->q_vector[q_idx];
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003509 napi_enable(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003510 }
3511}
3512
3513static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3514{
3515 int q_idx;
3516 struct ixgbe_q_vector *q_vector;
3517 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3518
3519 /* legacy and MSI only use one vector */
3520 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3521 q_vectors = 1;
3522
3523 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003524 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003525 napi_disable(&q_vector->napi);
3526 }
3527}
3528
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003529#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003530/*
3531 * ixgbe_configure_dcb - Configure DCB hardware
3532 * @adapter: ixgbe adapter struct
3533 *
3534 * This is called by the driver on open to configure the DCB hardware.
3535 * This is also called by the gennetlink interface when reconfiguring
3536 * the DCB state.
3537 */
3538static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3539{
3540 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend98063072010-10-28 00:59:57 +00003541 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003542
Alexander Duyck67ebd792010-08-19 13:34:04 +00003543 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3544 if (hw->mac.type == ixgbe_mac_82598EB)
3545 netif_set_gso_max_size(adapter->netdev, 65536);
3546 return;
3547 }
3548
3549 if (hw->mac.type == ixgbe_mac_82598EB)
3550 netif_set_gso_max_size(adapter->netdev, 32768);
3551
Alexander Duyck2f90b862008-11-20 20:52:10 -08003552
Alexander Duyck2f90b862008-11-20 20:52:10 -08003553 /* Enable VLAN tag insert/strip */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003554 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003555
Alexander Duyck2f90b862008-11-20 20:52:10 -08003556 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003557
John Fastabendb1208182011-10-15 05:00:10 +00003558#ifdef IXGBE_FCOE
3559 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3560 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3561#endif
3562
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003563 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00003564 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00003565 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3566 DCB_TX_CONFIG);
3567 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3568 DCB_RX_CONFIG);
3569 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00003570 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
3571 ixgbe_dcb_hw_ets(&adapter->hw,
3572 adapter->ixgbe_ieee_ets,
3573 max_frame);
3574 ixgbe_dcb_hw_pfc_config(&adapter->hw,
3575 adapter->ixgbe_ieee_pfc->pfc_en,
3576 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00003577 }
John Fastabend8187cd42011-02-23 05:58:08 +00003578
3579 /* Enable RSS Hash per TC */
3580 if (hw->mac.type != ixgbe_mac_82598EB) {
3581 int i;
3582 u32 reg = 0;
3583
3584 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3585 u8 msb = 0;
3586 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3587
3588 while (cnt >>= 1)
3589 msb++;
3590
3591 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3592 }
3593 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3594 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003595}
John Fastabend9da712d2011-08-23 03:14:22 +00003596#endif
3597
3598/* Additional bittime to account for IXGBE framing */
3599#define IXGBE_ETH_FRAMING 20
3600
3601/*
3602 * ixgbe_hpbthresh - calculate high water mark for flow control
3603 *
3604 * @adapter: board private structure to calculate for
3605 * @pb - packet buffer to calculate
3606 */
3607static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
3608{
3609 struct ixgbe_hw *hw = &adapter->hw;
3610 struct net_device *dev = adapter->netdev;
3611 int link, tc, kb, marker;
3612 u32 dv_id, rx_pba;
3613
3614 /* Calculate max LAN frame size */
3615 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
3616
3617#ifdef IXGBE_FCOE
3618 /* FCoE traffic class uses FCOE jumbo frames */
3619 if (dev->features & NETIF_F_FCOE_MTU) {
3620 int fcoe_pb = 0;
3621
3622#ifdef CONFIG_IXGBE_DCB
3623 fcoe_pb = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003624
3625#endif
John Fastabend9da712d2011-08-23 03:14:22 +00003626 if (fcoe_pb == pb && tc < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3627 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3628 }
3629#endif
3630
3631 /* Calculate delay value for device */
3632 switch (hw->mac.type) {
3633 case ixgbe_mac_X540:
3634 dv_id = IXGBE_DV_X540(link, tc);
3635 break;
3636 default:
3637 dv_id = IXGBE_DV(link, tc);
3638 break;
3639 }
3640
3641 /* Loopback switch introduces additional latency */
3642 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3643 dv_id += IXGBE_B2BT(tc);
3644
3645 /* Delay value is calculated in bit times convert to KB */
3646 kb = IXGBE_BT2KB(dv_id);
3647 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
3648
3649 marker = rx_pba - kb;
3650
3651 /* It is possible that the packet buffer is not large enough
3652 * to provide required headroom. In this case throw an error
3653 * to user and a do the best we can.
3654 */
3655 if (marker < 0) {
3656 e_warn(drv, "Packet Buffer(%i) can not provide enough"
3657 "headroom to support flow control."
3658 "Decrease MTU or number of traffic classes\n", pb);
3659 marker = tc + 1;
3660 }
3661
3662 return marker;
3663}
3664
3665/*
3666 * ixgbe_lpbthresh - calculate low water mark for for flow control
3667 *
3668 * @adapter: board private structure to calculate for
3669 * @pb - packet buffer to calculate
3670 */
3671static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter)
3672{
3673 struct ixgbe_hw *hw = &adapter->hw;
3674 struct net_device *dev = adapter->netdev;
3675 int tc;
3676 u32 dv_id;
3677
3678 /* Calculate max LAN frame size */
3679 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
3680
3681 /* Calculate delay value for device */
3682 switch (hw->mac.type) {
3683 case ixgbe_mac_X540:
3684 dv_id = IXGBE_LOW_DV_X540(tc);
3685 break;
3686 default:
3687 dv_id = IXGBE_LOW_DV(tc);
3688 break;
3689 }
3690
3691 /* Delay value is calculated in bit times convert to KB */
3692 return IXGBE_BT2KB(dv_id);
3693}
3694
3695/*
3696 * ixgbe_pbthresh_setup - calculate and setup high low water marks
3697 */
3698static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
3699{
3700 struct ixgbe_hw *hw = &adapter->hw;
3701 int num_tc = netdev_get_num_tc(adapter->netdev);
3702 int i;
3703
3704 if (!num_tc)
3705 num_tc = 1;
3706
3707 hw->fc.low_water = ixgbe_lpbthresh(adapter);
3708
3709 for (i = 0; i < num_tc; i++) {
3710 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
3711
3712 /* Low water marks must not be larger than high water marks */
3713 if (hw->fc.low_water > hw->fc.high_water[i])
3714 hw->fc.low_water = 0;
3715 }
3716}
John Fastabend80605c652011-05-02 12:34:10 +00003717
3718static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3719{
John Fastabend80605c652011-05-02 12:34:10 +00003720 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00003721 int hdrm;
3722 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00003723
3724 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3725 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00003726 hdrm = 32 << adapter->fdir_pballoc;
3727 else
3728 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00003729
Alexander Duyckf7e10272011-07-21 00:40:35 +00003730 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00003731 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00003732}
3733
Alexander Duycke4911d52011-05-11 07:18:52 +00003734static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3735{
3736 struct ixgbe_hw *hw = &adapter->hw;
3737 struct hlist_node *node, *node2;
3738 struct ixgbe_fdir_filter *filter;
3739
3740 spin_lock(&adapter->fdir_perfect_lock);
3741
3742 if (!hlist_empty(&adapter->fdir_filter_list))
3743 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3744
3745 hlist_for_each_entry_safe(filter, node, node2,
3746 &adapter->fdir_filter_list, fdir_node) {
3747 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00003748 &filter->filter,
3749 filter->sw_idx,
3750 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3751 IXGBE_FDIR_DROP_QUEUE :
3752 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00003753 }
3754
3755 spin_unlock(&adapter->fdir_perfect_lock);
3756}
3757
Auke Kok9a799d72007-09-15 14:07:45 -07003758static void ixgbe_configure(struct ixgbe_adapter *adapter)
3759{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003760 struct ixgbe_hw *hw = &adapter->hw;
3761
John Fastabend80605c652011-05-02 12:34:10 +00003762 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003763#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003764 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003765#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003766
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003767 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003768 ixgbe_restore_vlan(adapter);
3769
Yi Zoueacd73f2009-05-13 13:11:06 +00003770#ifdef IXGBE_FCOE
3771 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3772 ixgbe_configure_fcoe(adapter);
3773
3774#endif /* IXGBE_FCOE */
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003775
3776 switch (hw->mac.type) {
3777 case ixgbe_mac_82599EB:
3778 case ixgbe_mac_X540:
3779 hw->mac.ops.disable_rx_buff(hw);
3780 break;
3781 default:
3782 break;
3783 }
3784
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003785 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003786 ixgbe_init_fdir_signature_82599(&adapter->hw,
3787 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00003788 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3789 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3790 adapter->fdir_pballoc);
3791 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003792 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003793
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003794 switch (hw->mac.type) {
3795 case ixgbe_mac_82599EB:
3796 case ixgbe_mac_X540:
3797 hw->mac.ops.enable_rx_buff(hw);
3798 break;
3799 default:
3800 break;
3801 }
3802
Alexander Duyck933d41f2010-09-07 21:34:29 +00003803 ixgbe_configure_virtualization(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003804
Auke Kok9a799d72007-09-15 14:07:45 -07003805 ixgbe_configure_tx(adapter);
3806 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003807}
3808
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003809static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3810{
3811 switch (hw->phy.type) {
3812 case ixgbe_phy_sfp_avago:
3813 case ixgbe_phy_sfp_ftl:
3814 case ixgbe_phy_sfp_intel:
3815 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003816 case ixgbe_phy_sfp_passive_tyco:
3817 case ixgbe_phy_sfp_passive_unknown:
3818 case ixgbe_phy_sfp_active_unknown:
3819 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003820 return true;
Alexander Duyck8917b442011-07-21 00:40:51 +00003821 case ixgbe_phy_nl:
3822 if (hw->mac.type == ixgbe_mac_82598EB)
3823 return true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003824 default:
3825 return false;
3826 }
3827}
3828
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003829/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003830 * ixgbe_sfp_link_config - set up SFP+ link
3831 * @adapter: pointer to private adapter struct
3832 **/
3833static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3834{
Alexander Duyck70864002011-04-27 09:13:56 +00003835 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00003836 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00003837 * is that an SFP was inserted/removed after the reset
3838 * but before SFP detection was enabled. As such the best
3839 * solution is to just start searching as soon as we start
3840 */
3841 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3842 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003843
Alexander Duyck70864002011-04-27 09:13:56 +00003844 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003845}
3846
3847/**
3848 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003849 * @hw: pointer to private hardware struct
3850 *
3851 * Returns 0 on success, negative on failure
3852 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003853static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003854{
3855 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003856 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003857 u32 ret = IXGBE_ERR_LINK_SETUP;
3858
3859 if (hw->mac.ops.check_link)
3860 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3861
3862 if (ret)
3863 goto link_cfg_out;
3864
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00003865 autoneg = hw->phy.autoneg_advertised;
3866 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00003867 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3868 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003869 if (ret)
3870 goto link_cfg_out;
3871
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003872 if (hw->mac.ops.setup_link)
3873 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003874link_cfg_out:
3875 return ret;
3876}
3877
Alexander Duycka34bcff2010-08-19 13:39:20 +00003878static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003879{
Auke Kok9a799d72007-09-15 14:07:45 -07003880 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003881 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003882
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003883 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00003884 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3885 IXGBE_GPIE_OCD;
3886 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003887 /*
3888 * use EIAM to auto-mask when MSI-X interrupt is asserted
3889 * this saves a register write for every interrupt
3890 */
3891 switch (hw->mac.type) {
3892 case ixgbe_mac_82598EB:
3893 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3894 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003895 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003896 case ixgbe_mac_X540:
3897 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003898 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3899 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3900 break;
3901 }
3902 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003903 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3904 * specifically only auto mask tx and rx interrupts */
3905 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003906 }
3907
Alexander Duycka34bcff2010-08-19 13:39:20 +00003908 /* XXX: to interrupt immediately for EICS writes, enable this */
3909 /* gpie |= IXGBE_GPIE_EIMEN; */
3910
3911 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3912 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3913 gpie |= IXGBE_GPIE_VTMODE_64;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07003914 }
3915
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00003916 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00003917 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
3918 switch (adapter->hw.mac.type) {
3919 case ixgbe_mac_82599EB:
3920 gpie |= IXGBE_SDP0_GPIEN;
3921 break;
3922 case ixgbe_mac_X540:
3923 gpie |= IXGBE_EIMS_TS;
3924 break;
3925 default:
3926 break;
3927 }
3928 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00003929
Alexander Duycka34bcff2010-08-19 13:39:20 +00003930 /* Enable fan failure interrupt */
3931 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003932 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003933
Don Skidmore2698b202011-04-13 07:01:52 +00003934 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003935 gpie |= IXGBE_SDP1_GPIEN;
3936 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00003937 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00003938
3939 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3940}
3941
Alexander Duyckc7ccde02011-07-21 00:40:40 +00003942static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00003943{
3944 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003945 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003946 u32 ctrl_ext;
3947
3948 ixgbe_get_hw_control(adapter);
3949 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003950
Auke Kok9a799d72007-09-15 14:07:45 -07003951 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3952 ixgbe_configure_msix(adapter);
3953 else
3954 ixgbe_configure_msi_and_legacy(adapter);
3955
Don Skidmorec6ecf392010-12-03 03:31:51 +00003956 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3957 if (hw->mac.ops.enable_tx_laser &&
3958 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00003959 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00003960 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00003961 hw->mac.ops.enable_tx_laser(hw);
3962
Auke Kok9a799d72007-09-15 14:07:45 -07003963 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003964 ixgbe_napi_enable_all(adapter);
3965
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08003966 if (ixgbe_is_sfp(hw)) {
3967 ixgbe_sfp_link_config(adapter);
3968 } else {
3969 err = ixgbe_non_sfp_link_config(hw);
3970 if (err)
3971 e_err(probe, "link_config FAILED %d\n", err);
3972 }
3973
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003974 /* clear any pending interrupts, may auto mask */
3975 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003976 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003977
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003978 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00003979 * If this adapter has a fan, check to see if we had a failure
3980 * before we enabled the interrupt.
3981 */
3982 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
3983 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3984 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00003985 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00003986 }
3987
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003988 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003989 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003990
Auke Kok9a799d72007-09-15 14:07:45 -07003991 /* bring the link up in the watchdog, this could race with our first
3992 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003993 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3994 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00003995 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00003996
3997 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3998 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
3999 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
4000 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07004001}
4002
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004003void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
4004{
4005 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00004006 /* put off any impending NetWatchDogTimeout */
4007 adapter->netdev->trans_start = jiffies;
4008
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004009 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00004010 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004011 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00004012 /*
4013 * If SR-IOV enabled then wait a bit before bringing the adapter
4014 * back up to give the VFs time to respond to the reset. The
4015 * two second wait is based upon the watchdog timer cycle in
4016 * the VF driver.
4017 */
4018 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4019 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004020 ixgbe_up(adapter);
4021 clear_bit(__IXGBE_RESETTING, &adapter->state);
4022}
4023
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004024void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004025{
4026 /* hardware has been reset, we need to reload some things */
4027 ixgbe_configure(adapter);
4028
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004029 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004030}
4031
4032void ixgbe_reset(struct ixgbe_adapter *adapter)
4033{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004034 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07004035 int err;
4036
Alexander Duyck70864002011-04-27 09:13:56 +00004037 /* lock SFP init bit to prevent race conditions with the watchdog */
4038 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
4039 usleep_range(1000, 2000);
4040
4041 /* clear all SFP and link config related flags while holding SFP_INIT */
4042 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
4043 IXGBE_FLAG2_SFP_NEEDS_RESET);
4044 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
4045
Don Skidmore8ca783a2009-05-26 20:40:47 -07004046 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004047 switch (err) {
4048 case 0:
4049 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00004050 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004051 break;
4052 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00004053 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004054 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004055 case IXGBE_ERR_EEPROM_VERSION:
4056 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00004057 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00004058 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00004059 "your hardware. If you are experiencing problems "
4060 "please contact your Intel or hardware "
4061 "representative who provided you with this "
4062 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004063 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004064 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00004065 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004066 }
Auke Kok9a799d72007-09-15 14:07:45 -07004067
Alexander Duyck70864002011-04-27 09:13:56 +00004068 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
4069
Auke Kok9a799d72007-09-15 14:07:45 -07004070 /* reprogram the RAR[0] in case user changed it. */
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004071 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
4072 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07004073}
4074
Auke Kok9a799d72007-09-15 14:07:45 -07004075/**
Alexander Duyckf8003262012-03-03 02:35:52 +00004076 * ixgbe_init_rx_page_offset - initialize page offset values for Rx buffers
4077 * @rx_ring: ring to setup
4078 *
4079 * On many IA platforms the L1 cache has a critical stride of 4K, this
4080 * results in each receive buffer starting in the same cache set. To help
4081 * reduce the pressure on this cache set we can interleave the offsets so
4082 * that only every other buffer will be in the same cache set.
4083 **/
4084static void ixgbe_init_rx_page_offset(struct ixgbe_ring *rx_ring)
4085{
4086 struct ixgbe_rx_buffer *rx_buffer = rx_ring->rx_buffer_info;
4087 u16 i;
4088
4089 for (i = 0; i < rx_ring->count; i += 2) {
4090 rx_buffer[0].page_offset = 0;
4091 rx_buffer[1].page_offset = ixgbe_rx_bufsz(rx_ring);
4092 rx_buffer = &rx_buffer[2];
4093 }
4094}
4095
4096/**
Auke Kok9a799d72007-09-15 14:07:45 -07004097 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004098 * @rx_ring: ring to free buffers from
4099 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004100static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004101{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004102 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07004103 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004104 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004105
Alexander Duyck84418e32010-08-19 13:40:54 +00004106 /* ring already cleared, nothing to do */
4107 if (!rx_ring->rx_buffer_info)
4108 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004109
Alexander Duyck84418e32010-08-19 13:40:54 +00004110 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004111 for (i = 0; i < rx_ring->count; i++) {
Alexander Duyckf8003262012-03-03 02:35:52 +00004112 struct ixgbe_rx_buffer *rx_buffer;
Auke Kok9a799d72007-09-15 14:07:45 -07004113
Alexander Duyckf8003262012-03-03 02:35:52 +00004114 rx_buffer = &rx_ring->rx_buffer_info[i];
4115 if (rx_buffer->skb) {
4116 struct sk_buff *skb = rx_buffer->skb;
4117 if (IXGBE_CB(skb)->page_released) {
4118 dma_unmap_page(dev,
4119 IXGBE_CB(skb)->dma,
4120 ixgbe_rx_bufsz(rx_ring),
4121 DMA_FROM_DEVICE);
4122 IXGBE_CB(skb)->page_released = false;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00004123 }
4124 dev_kfree_skb(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004125 }
Alexander Duyckf8003262012-03-03 02:35:52 +00004126 rx_buffer->skb = NULL;
4127 if (rx_buffer->dma)
4128 dma_unmap_page(dev, rx_buffer->dma,
4129 ixgbe_rx_pg_size(rx_ring),
4130 DMA_FROM_DEVICE);
4131 rx_buffer->dma = 0;
4132 if (rx_buffer->page)
4133 put_page(rx_buffer->page);
4134 rx_buffer->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07004135 }
4136
4137 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4138 memset(rx_ring->rx_buffer_info, 0, size);
4139
Alexander Duyckf8003262012-03-03 02:35:52 +00004140 ixgbe_init_rx_page_offset(rx_ring);
4141
Auke Kok9a799d72007-09-15 14:07:45 -07004142 /* Zero out the descriptor ring */
4143 memset(rx_ring->desc, 0, rx_ring->size);
4144
Alexander Duyckf8003262012-03-03 02:35:52 +00004145 rx_ring->next_to_alloc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004146 rx_ring->next_to_clean = 0;
4147 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004148}
4149
4150/**
4151 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004152 * @tx_ring: ring to be cleaned
4153 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004154static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004155{
4156 struct ixgbe_tx_buffer *tx_buffer_info;
4157 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004158 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004159
Alexander Duyck84418e32010-08-19 13:40:54 +00004160 /* ring already cleared, nothing to do */
4161 if (!tx_ring->tx_buffer_info)
4162 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004163
Alexander Duyck84418e32010-08-19 13:40:54 +00004164 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004165 for (i = 0; i < tx_ring->count; i++) {
4166 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004167 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004168 }
4169
4170 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4171 memset(tx_ring->tx_buffer_info, 0, size);
4172
4173 /* Zero out the descriptor ring */
4174 memset(tx_ring->desc, 0, tx_ring->size);
4175
4176 tx_ring->next_to_use = 0;
4177 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004178}
4179
4180/**
Auke Kok9a799d72007-09-15 14:07:45 -07004181 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4182 * @adapter: board private structure
4183 **/
4184static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4185{
4186 int i;
4187
4188 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004189 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004190}
4191
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004192/**
4193 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4194 * @adapter: board private structure
4195 **/
4196static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4197{
4198 int i;
4199
4200 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004201 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004202}
4203
Alexander Duycke4911d52011-05-11 07:18:52 +00004204static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4205{
4206 struct hlist_node *node, *node2;
4207 struct ixgbe_fdir_filter *filter;
4208
4209 spin_lock(&adapter->fdir_perfect_lock);
4210
4211 hlist_for_each_entry_safe(filter, node, node2,
4212 &adapter->fdir_filter_list, fdir_node) {
4213 hlist_del(&filter->fdir_node);
4214 kfree(filter);
4215 }
4216 adapter->fdir_filter_count = 0;
4217
4218 spin_unlock(&adapter->fdir_perfect_lock);
4219}
4220
Auke Kok9a799d72007-09-15 14:07:45 -07004221void ixgbe_down(struct ixgbe_adapter *adapter)
4222{
4223 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004224 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004225 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004226 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07004227
4228 /* signal that we are down to the interrupt handler */
4229 set_bit(__IXGBE_DOWN, &adapter->state);
4230
4231 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004232 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4233 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004234
Yi Zou2d39d572011-01-06 14:29:56 +00004235 /* disable all enabled rx queues */
4236 for (i = 0; i < adapter->num_rx_queues; i++)
4237 /* this call also flushes the previous write */
4238 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4239
Don Skidmore032b4322011-03-18 09:32:53 +00004240 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004241
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004242 netif_tx_stop_all_queues(netdev);
4243
Alexander Duyck70864002011-04-27 09:13:56 +00004244 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004245 netif_carrier_off(netdev);
4246 netif_tx_disable(netdev);
4247
4248 ixgbe_irq_disable(adapter);
4249
4250 ixgbe_napi_disable_all(adapter);
4251
Alexander Duyckd034acf2011-04-27 09:25:34 +00004252 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4253 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004254 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4255
4256 del_timer_sync(&adapter->service_timer);
4257
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004258 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004259 /* Clear EITR Select mapping */
4260 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
4261
4262 /* Mark all the VFs as inactive */
4263 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00004264 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004265
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004266 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004267 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004268
Auke Kok9a799d72007-09-15 14:07:45 -07004269 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004270 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004271 }
4272
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004273 /* disable transmits in the hardware now that interrupts are off */
4274 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004275 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004276 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004277 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004278
4279 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004280 switch (hw->mac.type) {
4281 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004282 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004283 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004284 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4285 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004286 break;
4287 default:
4288 break;
4289 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004290
Paul Larson6f4a0e42008-06-24 17:00:56 -07004291 if (!pci_channel_offline(adapter->pdev))
4292 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004293
4294 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4295 if (hw->mac.ops.disable_tx_laser &&
4296 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004297 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004298 (hw->mac.type == ixgbe_mac_82599EB))))
4299 hw->mac.ops.disable_tx_laser(hw);
4300
Auke Kok9a799d72007-09-15 14:07:45 -07004301 ixgbe_clean_all_tx_rings(adapter);
4302 ixgbe_clean_all_rx_rings(adapter);
4303
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004304#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004305 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004306 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004307#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004308}
4309
Auke Kok9a799d72007-09-15 14:07:45 -07004310/**
Auke Kok9a799d72007-09-15 14:07:45 -07004311 * ixgbe_tx_timeout - Respond to a Tx Hang
4312 * @netdev: network interface device structure
4313 **/
4314static void ixgbe_tx_timeout(struct net_device *netdev)
4315{
4316 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4317
4318 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004319 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004320}
4321
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004322/**
4323 * ixgbe_set_rss_queues: Allocate queues for RSS
4324 * @adapter: board private structure to initialize
4325 *
4326 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
4327 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
4328 *
4329 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004330static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
4331{
4332 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004333 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004334
4335 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004336 f->mask = 0xF;
4337 adapter->num_rx_queues = f->indices;
4338 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004339 ret = true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004340 }
4341
4342 return ret;
4343}
4344
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004345/**
4346 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
4347 * @adapter: board private structure to initialize
4348 *
4349 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
4350 * to the original CPU that initiated the Tx session. This runs in addition
4351 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
4352 * Rx load across CPUs using RSS.
4353 *
4354 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004355static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004356{
4357 bool ret = false;
4358 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
4359
Alexander Duyck6ca43502012-02-08 07:51:42 +00004360 f_fdir->indices = min_t(int, num_online_cpus(), f_fdir->indices);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004361 f_fdir->mask = 0;
4362
Alexander Duyck24ddd962012-02-10 02:08:32 +00004363 /*
4364 * Use RSS in addition to Flow Director to ensure the best
4365 * distribution of flows across cores, even when an FDIR flow
4366 * isn't matched.
4367 */
Alexander Duyck03ecf912011-05-20 07:36:17 +00004368 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4369 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004370 adapter->num_tx_queues = f_fdir->indices;
4371 adapter->num_rx_queues = f_fdir->indices;
4372 ret = true;
4373 } else {
4374 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004375 }
4376 return ret;
4377}
4378
Yi Zou0331a832009-05-17 12:33:52 +00004379#ifdef IXGBE_FCOE
4380/**
4381 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
4382 * @adapter: board private structure to initialize
4383 *
4384 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
4385 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
4386 * rx queues out of the max number of rx queues, instead, it is used as the
4387 * index of the first rx queue used by FCoE.
4388 *
4389 **/
4390static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
4391{
Yi Zou0331a832009-05-17 12:33:52 +00004392 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4393
John Fastabende5b64632011-03-08 03:44:52 +00004394 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4395 return false;
4396
Jesse Brandeburg3ed69d72012-02-10 10:20:02 +00004397 f->indices = min_t(int, num_online_cpus(), f->indices);
John Fastabende5b64632011-03-08 03:44:52 +00004398
John Fastabende901acd2011-04-26 07:26:08 +00004399 adapter->num_rx_queues = 1;
4400 adapter->num_tx_queues = 1;
John Fastabende5b64632011-03-08 03:44:52 +00004401
John Fastabende901acd2011-04-26 07:26:08 +00004402 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4403 e_info(probe, "FCoE enabled with RSS\n");
Alexander Duyck03ecf912011-05-20 07:36:17 +00004404 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
John Fastabende901acd2011-04-26 07:26:08 +00004405 ixgbe_set_fdir_queues(adapter);
4406 else
4407 ixgbe_set_rss_queues(adapter);
Yi Zou0331a832009-05-17 12:33:52 +00004408 }
Alexander Duyck03ecf912011-05-20 07:36:17 +00004409
John Fastabende901acd2011-04-26 07:26:08 +00004410 /* adding FCoE rx rings to the end */
4411 f->mask = adapter->num_rx_queues;
4412 adapter->num_rx_queues += f->indices;
4413 adapter->num_tx_queues += f->indices;
Yi Zou0331a832009-05-17 12:33:52 +00004414
John Fastabende5b64632011-03-08 03:44:52 +00004415 return true;
4416}
4417#endif /* IXGBE_FCOE */
4418
John Fastabende901acd2011-04-26 07:26:08 +00004419/* Artificial max queue cap per traffic class in DCB mode */
4420#define DCB_QUEUE_CAP 8
4421
John Fastabende5b64632011-03-08 03:44:52 +00004422#ifdef CONFIG_IXGBE_DCB
4423static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
4424{
John Fastabende901acd2011-04-26 07:26:08 +00004425 int per_tc_q, q, i, offset = 0;
4426 struct net_device *dev = adapter->netdev;
4427 int tcs = netdev_get_num_tc(dev);
John Fastabende5b64632011-03-08 03:44:52 +00004428
John Fastabende901acd2011-04-26 07:26:08 +00004429 if (!tcs)
4430 return false;
John Fastabende5b64632011-03-08 03:44:52 +00004431
John Fastabende901acd2011-04-26 07:26:08 +00004432 /* Map queue offset and counts onto allocated tx queues */
Jesse Brandeburg3ed69d72012-02-10 10:20:02 +00004433 per_tc_q = min_t(unsigned int, dev->num_tx_queues / tcs, DCB_QUEUE_CAP);
4434 q = min_t(int, num_online_cpus(), per_tc_q);
John Fastabend8b1c0b22011-05-03 02:26:48 +00004435
John Fastabend8b1c0b22011-05-03 02:26:48 +00004436 for (i = 0; i < tcs; i++) {
John Fastabende901acd2011-04-26 07:26:08 +00004437 netdev_set_tc_queue(dev, i, q, offset);
4438 offset += q;
John Fastabende5b64632011-03-08 03:44:52 +00004439 }
4440
John Fastabende901acd2011-04-26 07:26:08 +00004441 adapter->num_tx_queues = q * tcs;
4442 adapter->num_rx_queues = q * tcs;
John Fastabende5b64632011-03-08 03:44:52 +00004443
4444#ifdef IXGBE_FCOE
John Fastabende901acd2011-04-26 07:26:08 +00004445 /* FCoE enabled queues require special configuration indexed
4446 * by feature specific indices and mask. Here we map FCoE
4447 * indices onto the DCB queue pairs allowing FCoE to own
4448 * configuration later.
John Fastabende5b64632011-03-08 03:44:52 +00004449 */
John Fastabende901acd2011-04-26 07:26:08 +00004450 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
John Fastabendcdf485b2012-02-11 06:26:00 +00004451 u8 prio_tc[MAX_USER_PRIORITY] = {0};
John Fastabende901acd2011-04-26 07:26:08 +00004452 int tc;
4453 struct ixgbe_ring_feature *f =
4454 &adapter->ring_feature[RING_F_FCOE];
4455
John Fastabendcdf485b2012-02-11 06:26:00 +00004456 ixgbe_dcb_unpack_map(&adapter->dcb_cfg, DCB_TX_CONFIG, prio_tc);
4457 tc = prio_tc[adapter->fcoe.up];
John Fastabende901acd2011-04-26 07:26:08 +00004458 f->indices = dev->tc_to_txq[tc].count;
4459 f->mask = dev->tc_to_txq[tc].offset;
4460 }
John Fastabende5b64632011-03-08 03:44:52 +00004461#endif
4462
John Fastabende901acd2011-04-26 07:26:08 +00004463 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004464}
John Fastabende5b64632011-03-08 03:44:52 +00004465#endif
Yi Zou0331a832009-05-17 12:33:52 +00004466
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004467/**
4468 * ixgbe_set_sriov_queues: Allocate queues for IOV use
4469 * @adapter: board private structure to initialize
4470 *
4471 * IOV doesn't actually use anything, so just NAK the
4472 * request for now and let the other queue routines
4473 * figure out what to do.
4474 */
4475static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
4476{
4477 return false;
4478}
4479
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004480/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004481 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004482 * @adapter: board private structure to initialize
4483 *
4484 * This is the top level queue allocation routine. The order here is very
4485 * important, starting with the "most" number of features turned on at once,
4486 * and ending with the smallest set of features. This way large combinations
4487 * can be allocated if they're turned on, and smaller combinations are the
4488 * fallthrough conditions.
4489 *
4490 **/
Ben Hutchings847f53f2010-09-27 08:28:56 +00004491static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004492{
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004493 /* Start with base case */
4494 adapter->num_rx_queues = 1;
4495 adapter->num_tx_queues = 1;
4496 adapter->num_rx_pools = adapter->num_rx_queues;
4497 adapter->num_rx_queues_per_pool = 1;
4498
4499 if (ixgbe_set_sriov_queues(adapter))
Ben Hutchings847f53f2010-09-27 08:28:56 +00004500 goto done;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004501
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004502#ifdef CONFIG_IXGBE_DCB
4503 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004504 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004505
4506#endif
John Fastabende5b64632011-03-08 03:44:52 +00004507#ifdef IXGBE_FCOE
4508 if (ixgbe_set_fcoe_queues(adapter))
4509 goto done;
4510
4511#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004512 if (ixgbe_set_fdir_queues(adapter))
4513 goto done;
4514
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004515 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004516 goto done;
4517
4518 /* fallback to base case */
4519 adapter->num_rx_queues = 1;
4520 adapter->num_tx_queues = 1;
4521
4522done:
Yi Zou9d837ea2012-01-07 08:39:50 +00004523 if ((adapter->netdev->reg_state == NETREG_UNREGISTERED) ||
4524 (adapter->netdev->reg_state == NETREG_UNREGISTERING))
4525 return 0;
4526
Ben Hutchings847f53f2010-09-27 08:28:56 +00004527 /* Notify the stack of the (possibly) reduced queue counts. */
John Fastabendf0796d52010-07-01 13:21:57 +00004528 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
Ben Hutchings847f53f2010-09-27 08:28:56 +00004529 return netif_set_real_num_rx_queues(adapter->netdev,
4530 adapter->num_rx_queues);
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004531}
4532
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004533static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00004534 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004535{
4536 int err, vector_threshold;
4537
Alexander Duyck8f154862012-02-10 02:08:37 +00004538 /* We'll want at least 2 (vector_threshold):
4539 * 1) TxQ[0] + RxQ[0] handler
4540 * 2) Other (Link Status Change, etc.)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004541 */
4542 vector_threshold = MIN_MSIX_COUNT;
4543
Alexander Duyck24ddd962012-02-10 02:08:32 +00004544 /*
4545 * The more we get, the more we will assign to Tx/Rx Cleanup
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004546 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
4547 * Right now, we simply care about how many we'll get; we'll
4548 * set them up later while requesting irq's.
4549 */
4550 while (vectors >= vector_threshold) {
4551 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Joe Perchese8e9f692010-09-07 21:34:53 +00004552 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004553 if (!err) /* Success in acquiring all requested vectors. */
4554 break;
4555 else if (err < 0)
4556 vectors = 0; /* Nasty failure, quit now */
4557 else /* err == number of vectors we should try again with */
4558 vectors = err;
4559 }
4560
4561 if (vectors < vector_threshold) {
4562 /* Can't allocate enough MSI-X interrupts? Oh well.
4563 * This just means we'll go with either a single MSI
4564 * vector or fall back to legacy interrupts.
4565 */
Emil Tantilov849c4542010-06-03 16:53:41 +00004566 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4567 "Unable to allocate MSI-X interrupts\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004568 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4569 kfree(adapter->msix_entries);
4570 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004571 } else {
4572 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08004573 /*
4574 * Adjust for only the vectors we'll use, which is minimum
4575 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
4576 * vectors we were allocated.
4577 */
4578 adapter->num_msix_vectors = min(vectors,
Joe Perchese8e9f692010-09-07 21:34:53 +00004579 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004580 }
4581}
4582
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004583/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004584 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004585 * @adapter: board private structure to initialize
4586 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004587 * Cache the descriptor ring offsets for RSS to the assigned rings.
4588 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004589 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004590static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004591{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004592 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004593
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004594 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
4595 return false;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004596
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004597 for (i = 0; i < adapter->num_rx_queues; i++)
4598 adapter->rx_ring[i]->reg_idx = i;
4599 for (i = 0; i < adapter->num_tx_queues; i++)
4600 adapter->tx_ring[i]->reg_idx = i;
4601
4602 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004603}
4604
4605#ifdef CONFIG_IXGBE_DCB
John Fastabende5b64632011-03-08 03:44:52 +00004606
4607/* ixgbe_get_first_reg_idx - Return first register index associated with ring */
John Fastabendb32c8dc2011-04-12 02:44:55 +00004608static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc,
4609 unsigned int *tx, unsigned int *rx)
John Fastabende5b64632011-03-08 03:44:52 +00004610{
4611 struct net_device *dev = adapter->netdev;
4612 struct ixgbe_hw *hw = &adapter->hw;
4613 u8 num_tcs = netdev_get_num_tc(dev);
4614
4615 *tx = 0;
4616 *rx = 0;
4617
4618 switch (hw->mac.type) {
4619 case ixgbe_mac_82598EB:
John Fastabendaba70d52011-04-26 07:26:14 +00004620 *tx = tc << 2;
4621 *rx = tc << 3;
John Fastabende5b64632011-03-08 03:44:52 +00004622 break;
4623 case ixgbe_mac_82599EB:
4624 case ixgbe_mac_X540:
John Fastabend4fa2e0e2011-07-18 22:38:25 +00004625 if (num_tcs > 4) {
John Fastabende5b64632011-03-08 03:44:52 +00004626 if (tc < 3) {
4627 *tx = tc << 5;
4628 *rx = tc << 4;
4629 } else if (tc < 5) {
4630 *tx = ((tc + 2) << 4);
4631 *rx = tc << 4;
4632 } else if (tc < num_tcs) {
4633 *tx = ((tc + 8) << 3);
4634 *rx = tc << 4;
4635 }
John Fastabend4fa2e0e2011-07-18 22:38:25 +00004636 } else {
John Fastabende5b64632011-03-08 03:44:52 +00004637 *rx = tc << 5;
4638 switch (tc) {
4639 case 0:
4640 *tx = 0;
4641 break;
4642 case 1:
4643 *tx = 64;
4644 break;
4645 case 2:
4646 *tx = 96;
4647 break;
4648 case 3:
4649 *tx = 112;
4650 break;
4651 default:
4652 break;
4653 }
4654 }
4655 break;
4656 default:
4657 break;
4658 }
4659}
4660
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004661/**
4662 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
4663 * @adapter: board private structure to initialize
4664 *
4665 * Cache the descriptor ring offsets for DCB to the assigned rings.
4666 *
4667 **/
4668static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
4669{
John Fastabende5b64632011-03-08 03:44:52 +00004670 struct net_device *dev = adapter->netdev;
4671 int i, j, k;
4672 u8 num_tcs = netdev_get_num_tc(dev);
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004673
John Fastabend8b1c0b22011-05-03 02:26:48 +00004674 if (!num_tcs)
Alexander Duyckbd508172010-11-16 19:27:03 -08004675 return false;
4676
John Fastabende5b64632011-03-08 03:44:52 +00004677 for (i = 0, k = 0; i < num_tcs; i++) {
4678 unsigned int tx_s, rx_s;
4679 u16 count = dev->tc_to_txq[i].count;
4680
4681 ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s);
4682 for (j = 0; j < count; j++, k++) {
4683 adapter->tx_ring[k]->reg_idx = tx_s + j;
4684 adapter->rx_ring[k]->reg_idx = rx_s + j;
4685 adapter->tx_ring[k]->dcb_tc = i;
4686 adapter->rx_ring[k]->dcb_tc = i;
Alexander Duyckbd508172010-11-16 19:27:03 -08004687 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004688 }
John Fastabende5b64632011-03-08 03:44:52 +00004689
4690 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004691}
4692#endif
4693
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004694/**
4695 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
4696 * @adapter: board private structure to initialize
4697 *
4698 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
4699 *
4700 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004701static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004702{
4703 int i;
4704 bool ret = false;
4705
Alexander Duyck03ecf912011-05-20 07:36:17 +00004706 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4707 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004708 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004709 adapter->rx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004710 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004711 adapter->tx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004712 ret = true;
4713 }
4714
4715 return ret;
4716}
4717
Yi Zou0331a832009-05-17 12:33:52 +00004718#ifdef IXGBE_FCOE
4719/**
4720 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
4721 * @adapter: board private structure to initialize
4722 *
4723 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
4724 *
4725 */
4726static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
4727{
Yi Zou0331a832009-05-17 12:33:52 +00004728 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004729 int i;
4730 u8 fcoe_rx_i = 0, fcoe_tx_i = 0;
Yi Zou0331a832009-05-17 12:33:52 +00004731
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004732 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4733 return false;
4734
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004735 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Alexander Duyck03ecf912011-05-20 07:36:17 +00004736 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004737 ixgbe_cache_ring_fdir(adapter);
4738 else
4739 ixgbe_cache_ring_rss(adapter);
4740
4741 fcoe_rx_i = f->mask;
4742 fcoe_tx_i = f->mask;
4743 }
4744 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
4745 adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
4746 adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
4747 }
4748 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004749}
4750
4751#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004752/**
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004753 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
4754 * @adapter: board private structure to initialize
4755 *
4756 * SR-IOV doesn't use any descriptor rings but changes the default if
4757 * no other mapping is used.
4758 *
4759 */
4760static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
4761{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004762 adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
4763 adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004764 if (adapter->num_vfs)
4765 return true;
4766 else
4767 return false;
4768}
4769
4770/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004771 * ixgbe_cache_ring_register - Descriptor ring to register mapping
4772 * @adapter: board private structure to initialize
4773 *
4774 * Once we know the feature-set enabled for the device, we'll cache
4775 * the register offset the descriptor ring is assigned to.
4776 *
4777 * Note, the order the various feature calls is important. It must start with
4778 * the "most" features enabled at the same time, then trickle down to the
4779 * least amount of features turned on at once.
4780 **/
4781static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
4782{
4783 /* start with default case */
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004784 adapter->rx_ring[0]->reg_idx = 0;
4785 adapter->tx_ring[0]->reg_idx = 0;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004786
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004787 if (ixgbe_cache_ring_sriov(adapter))
4788 return;
4789
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004790#ifdef CONFIG_IXGBE_DCB
4791 if (ixgbe_cache_ring_dcb(adapter))
4792 return;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004793#endif
John Fastabende5b64632011-03-08 03:44:52 +00004794
4795#ifdef IXGBE_FCOE
4796 if (ixgbe_cache_ring_fcoe(adapter))
4797 return;
4798#endif /* IXGBE_FCOE */
4799
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004800 if (ixgbe_cache_ring_fdir(adapter))
4801 return;
4802
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004803 if (ixgbe_cache_ring_rss(adapter))
4804 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004805}
4806
Auke Kok9a799d72007-09-15 14:07:45 -07004807/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004808 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
4809 * @adapter: board private structure to initialize
4810 *
4811 * Attempt to configure the interrupts using the best available
4812 * capabilities of the hardware and the kernel.
4813 **/
Al Virofeea6a52008-11-27 15:34:07 -08004814static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004815{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004816 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004817 int err = 0;
4818 int vector, v_budget;
4819
4820 /*
4821 * It's easy to be greedy for MSI-X vectors, but it really
4822 * doesn't do us much good if we have a lot more vectors
4823 * than CPU's. So let's be conservative and only ask for
PJ Waskiewicz342bde12009-11-12 23:50:43 +00004824 * (roughly) the same number of vectors as there are CPU's.
Alexander Duyck8f154862012-02-10 02:08:37 +00004825 * The default is to use pairs of vectors.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004826 */
Alexander Duyck8f154862012-02-10 02:08:37 +00004827 v_budget = max(adapter->num_rx_queues, adapter->num_tx_queues);
4828 v_budget = min_t(int, v_budget, num_online_cpus());
4829 v_budget += NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004830
4831 /*
4832 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004833 * hw.mac->max_msix_vectors vectors. With features
4834 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
4835 * descriptor queues supported by our device. Thus, we cap it off in
4836 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004837 */
Alexander Duyckde88eee2012-02-08 07:49:59 +00004838 v_budget = min_t(int, v_budget, hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004839
4840 /* A failure in MSI-X entry allocation isn't fatal, but it does
4841 * mean we disable MSI-X capabilities of the adapter. */
4842 adapter->msix_entries = kcalloc(v_budget,
Joe Perchese8e9f692010-09-07 21:34:53 +00004843 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004844 if (adapter->msix_entries) {
4845 for (vector = 0; vector < v_budget; vector++)
4846 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004847
Alexander Duyck7a921c92009-05-06 10:43:28 +00004848 ixgbe_acquire_msix_vectors(adapter, v_budget);
4849
4850 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4851 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004852 }
David S. Miller26d27842010-05-03 15:18:22 -07004853
Alexander Duyck7a921c92009-05-06 10:43:28 +00004854 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
4855 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck03ecf912011-05-20 07:36:17 +00004856 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck45b9f502011-01-06 14:29:59 +00004857 e_err(probe,
Alexander Duyck03ecf912011-05-20 07:36:17 +00004858 "ATR is not supported while multiple "
Alexander Duyck45b9f502011-01-06 14:29:59 +00004859 "queues are disabled. Disabling Flow Director\n");
4860 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004861 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004862 adapter->atr_sample_rate = 0;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004863 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4864 ixgbe_disable_sriov(adapter);
4865
Ben Hutchings847f53f2010-09-27 08:28:56 +00004866 err = ixgbe_set_num_queues(adapter);
4867 if (err)
4868 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004869
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004870 err = pci_enable_msi(adapter->pdev);
4871 if (!err) {
4872 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
4873 } else {
Emil Tantilov849c4542010-06-03 16:53:41 +00004874 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4875 "Unable to allocate MSI interrupt, "
4876 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004877 /* reset err */
4878 err = 0;
4879 }
4880
4881out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004882 return err;
4883}
4884
Alexander Duyckde88eee2012-02-08 07:49:59 +00004885static void ixgbe_add_ring(struct ixgbe_ring *ring,
4886 struct ixgbe_ring_container *head)
4887{
4888 ring->next = head->ring;
4889 head->ring = ring;
4890 head->count++;
4891}
4892
4893/**
4894 * ixgbe_alloc_q_vector - Allocate memory for a single interrupt vector
4895 * @adapter: board private structure to initialize
4896 * @v_idx: index of vector in adapter struct
4897 *
4898 * We allocate one q_vector. If allocation fails we return -ENOMEM.
4899 **/
4900static int ixgbe_alloc_q_vector(struct ixgbe_adapter *adapter, int v_idx,
4901 int txr_count, int txr_idx,
4902 int rxr_count, int rxr_idx)
4903{
4904 struct ixgbe_q_vector *q_vector;
4905 struct ixgbe_ring *ring;
4906 int node = -1;
4907 int cpu = -1;
4908 int ring_count, size;
4909
4910 ring_count = txr_count + rxr_count;
4911 size = sizeof(struct ixgbe_q_vector) +
4912 (sizeof(struct ixgbe_ring) * ring_count);
4913
4914 /* customize cpu for Flow Director mapping */
4915 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
4916 if (cpu_online(v_idx)) {
4917 cpu = v_idx;
4918 node = cpu_to_node(cpu);
4919 }
4920 }
4921
4922 /* allocate q_vector and rings */
4923 q_vector = kzalloc_node(size, GFP_KERNEL, node);
4924 if (!q_vector)
4925 q_vector = kzalloc(size, GFP_KERNEL);
4926 if (!q_vector)
4927 return -ENOMEM;
4928
4929 /* setup affinity mask and node */
4930 if (cpu != -1)
4931 cpumask_set_cpu(cpu, &q_vector->affinity_mask);
4932 else
4933 cpumask_copy(&q_vector->affinity_mask, cpu_online_mask);
4934 q_vector->numa_node = node;
4935
4936 /* initialize NAPI */
4937 netif_napi_add(adapter->netdev, &q_vector->napi,
4938 ixgbe_poll, 64);
4939
4940 /* tie q_vector and adapter together */
4941 adapter->q_vector[v_idx] = q_vector;
4942 q_vector->adapter = adapter;
4943 q_vector->v_idx = v_idx;
4944
4945 /* initialize work limits */
4946 q_vector->tx.work_limit = adapter->tx_work_limit;
4947
4948 /* initialize pointer to rings */
4949 ring = q_vector->ring;
4950
4951 while (txr_count) {
4952 /* assign generic ring traits */
4953 ring->dev = &adapter->pdev->dev;
4954 ring->netdev = adapter->netdev;
4955
4956 /* configure backlink on ring */
4957 ring->q_vector = q_vector;
4958
4959 /* update q_vector Tx values */
4960 ixgbe_add_ring(ring, &q_vector->tx);
4961
4962 /* apply Tx specific ring traits */
4963 ring->count = adapter->tx_ring_count;
4964 ring->queue_index = txr_idx;
4965
4966 /* assign ring to adapter */
4967 adapter->tx_ring[txr_idx] = ring;
4968
4969 /* update count and index */
4970 txr_count--;
4971 txr_idx++;
4972
4973 /* push pointer to next ring */
4974 ring++;
4975 }
4976
4977 while (rxr_count) {
4978 /* assign generic ring traits */
4979 ring->dev = &adapter->pdev->dev;
4980 ring->netdev = adapter->netdev;
4981
4982 /* configure backlink on ring */
4983 ring->q_vector = q_vector;
4984
4985 /* update q_vector Rx values */
4986 ixgbe_add_ring(ring, &q_vector->rx);
4987
4988 /*
4989 * 82599 errata, UDP frames with a 0 checksum
4990 * can be marked as checksum errors.
4991 */
4992 if (adapter->hw.mac.type == ixgbe_mac_82599EB)
4993 set_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state);
4994
4995 /* apply Rx specific ring traits */
4996 ring->count = adapter->rx_ring_count;
4997 ring->queue_index = rxr_idx;
4998
4999 /* assign ring to adapter */
5000 adapter->rx_ring[rxr_idx] = ring;
5001
5002 /* update count and index */
5003 rxr_count--;
5004 rxr_idx++;
5005
5006 /* push pointer to next ring */
5007 ring++;
5008 }
5009
5010 return 0;
5011}
5012
5013/**
5014 * ixgbe_free_q_vector - Free memory allocated for specific interrupt vector
5015 * @adapter: board private structure to initialize
5016 * @v_idx: Index of vector to be freed
5017 *
5018 * This function frees the memory allocated to the q_vector. In addition if
5019 * NAPI is enabled it will delete any references to the NAPI struct prior
5020 * to freeing the q_vector.
5021 **/
5022static void ixgbe_free_q_vector(struct ixgbe_adapter *adapter, int v_idx)
5023{
5024 struct ixgbe_q_vector *q_vector = adapter->q_vector[v_idx];
5025 struct ixgbe_ring *ring;
5026
Alexander Duycka5579282012-02-08 07:50:04 +00005027 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckde88eee2012-02-08 07:49:59 +00005028 adapter->tx_ring[ring->queue_index] = NULL;
5029
Alexander Duycka5579282012-02-08 07:50:04 +00005030 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckde88eee2012-02-08 07:49:59 +00005031 adapter->rx_ring[ring->queue_index] = NULL;
5032
5033 adapter->q_vector[v_idx] = NULL;
5034 netif_napi_del(&q_vector->napi);
5035
5036 /*
5037 * ixgbe_get_stats64() might access the rings on this vector,
5038 * we must wait a grace period before freeing it.
5039 */
5040 kfree_rcu(q_vector, rcu);
5041}
5042
Alexander Duyck7a921c92009-05-06 10:43:28 +00005043/**
5044 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
5045 * @adapter: board private structure to initialize
5046 *
5047 * We allocate one q_vector per queue interrupt. If allocation fails we
5048 * return -ENOMEM.
5049 **/
5050static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
5051{
Alexander Duyckde88eee2012-02-08 07:49:59 +00005052 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
5053 int rxr_remaining = adapter->num_rx_queues;
5054 int txr_remaining = adapter->num_tx_queues;
5055 int rxr_idx = 0, txr_idx = 0, v_idx = 0;
5056 int err;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005057
Alexander Duyckde88eee2012-02-08 07:49:59 +00005058 /* only one q_vector if MSI-X is disabled. */
5059 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
5060 q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005061
Alexander Duyckde88eee2012-02-08 07:49:59 +00005062 if (q_vectors >= (rxr_remaining + txr_remaining)) {
5063 for (; rxr_remaining; v_idx++, q_vectors--) {
5064 int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors);
5065 err = ixgbe_alloc_q_vector(adapter, v_idx,
5066 0, 0, rqpv, rxr_idx);
5067
5068 if (err)
5069 goto err_out;
5070
5071 /* update counts and index */
5072 rxr_remaining -= rqpv;
5073 rxr_idx += rqpv;
5074 }
5075 }
5076
5077 for (; q_vectors; v_idx++, q_vectors--) {
5078 int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors);
5079 int tqpv = DIV_ROUND_UP(txr_remaining, q_vectors);
5080 err = ixgbe_alloc_q_vector(adapter, v_idx,
5081 tqpv, txr_idx,
5082 rqpv, rxr_idx);
5083
5084 if (err)
Alexander Duyck7a921c92009-05-06 10:43:28 +00005085 goto err_out;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00005086
Alexander Duyckde88eee2012-02-08 07:49:59 +00005087 /* update counts and index */
5088 rxr_remaining -= rqpv;
5089 rxr_idx += rqpv;
5090 txr_remaining -= tqpv;
5091 txr_idx += tqpv;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005092 }
5093
5094 return 0;
5095
5096err_out:
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00005097 while (v_idx) {
5098 v_idx--;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005099 ixgbe_free_q_vector(adapter, v_idx);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005100 }
Alexander Duyckde88eee2012-02-08 07:49:59 +00005101
Alexander Duyck7a921c92009-05-06 10:43:28 +00005102 return -ENOMEM;
5103}
5104
5105/**
5106 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
5107 * @adapter: board private structure to initialize
5108 *
5109 * This function frees the memory allocated to the q_vectors. In addition if
5110 * NAPI is enabled it will delete any references to the NAPI struct prior
5111 * to freeing the q_vector.
5112 **/
5113static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
5114{
Alexander Duyckde88eee2012-02-08 07:49:59 +00005115 int v_idx, q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005116
Alexander Duyck91281fd2009-06-04 16:00:27 +00005117 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyckde88eee2012-02-08 07:49:59 +00005118 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005119 else
Alexander Duyckde88eee2012-02-08 07:49:59 +00005120 q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005121
Alexander Duyckde88eee2012-02-08 07:49:59 +00005122 for (v_idx = 0; v_idx < q_vectors; v_idx++)
5123 ixgbe_free_q_vector(adapter, v_idx);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005124}
5125
Don Skidmore7b25cdb2009-08-25 04:47:32 +00005126static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005127{
5128 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
5129 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
5130 pci_disable_msix(adapter->pdev);
5131 kfree(adapter->msix_entries);
5132 adapter->msix_entries = NULL;
5133 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
5134 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
5135 pci_disable_msi(adapter->pdev);
5136 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005137}
5138
5139/**
5140 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
5141 * @adapter: board private structure to initialize
5142 *
5143 * We determine which interrupt scheme to use based on...
5144 * - Kernel support (MSI, MSI-X)
5145 * - which can be user-defined (via MODULE_PARAM)
5146 * - Hardware queue count (num_*_queues)
5147 * - defined by miscellaneous hardware support/features (RSS, etc.)
5148 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08005149int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005150{
5151 int err;
5152
5153 /* Number of supported queues */
Ben Hutchings847f53f2010-09-27 08:28:56 +00005154 err = ixgbe_set_num_queues(adapter);
5155 if (err)
5156 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005157
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005158 err = ixgbe_set_interrupt_capability(adapter);
5159 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005160 e_dev_err("Unable to setup interrupt capabilities\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005161 goto err_set_interrupt;
5162 }
5163
Alexander Duyck7a921c92009-05-06 10:43:28 +00005164 err = ixgbe_alloc_q_vectors(adapter);
5165 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005166 e_dev_err("Unable to allocate memory for queue vectors\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005167 goto err_alloc_q_vectors;
5168 }
5169
Alexander Duyckde88eee2012-02-08 07:49:59 +00005170 ixgbe_cache_ring_register(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005171
Emil Tantilov849c4542010-06-03 16:53:41 +00005172 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
Emil Tantilov396e7992010-07-01 20:05:12 +00005173 (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
5174 adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005175
5176 set_bit(__IXGBE_DOWN, &adapter->state);
5177
5178 return 0;
5179
Alexander Duyck7a921c92009-05-06 10:43:28 +00005180err_alloc_q_vectors:
5181 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005182err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00005183 return err;
5184}
5185
5186/**
5187 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
5188 * @adapter: board private structure to clear interrupt scheme on
5189 *
5190 * We go through and clear interrupt specific resources and reset the structure
5191 * to pre-load conditions
5192 **/
5193void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
5194{
Don Skidmoreb8eb3a12010-12-01 20:54:53 +00005195 adapter->num_tx_queues = 0;
5196 adapter->num_rx_queues = 0;
5197
Alexander Duyck7a921c92009-05-06 10:43:28 +00005198 ixgbe_free_q_vectors(adapter);
5199 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005200}
5201
5202/**
5203 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5204 * @adapter: board private structure to initialize
5205 *
5206 * ixgbe_sw_init initializes the Adapter private data structure.
5207 * Fields are initialized based on PCI device information and
5208 * OS network device settings (MTU size).
5209 **/
5210static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
5211{
5212 struct ixgbe_hw *hw = &adapter->hw;
5213 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005214 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005215#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005216 int j;
5217 struct tc_configuration *tc;
5218#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005219
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005220 /* PCI config space info */
5221
5222 hw->vendor_id = pdev->vendor;
5223 hw->device_id = pdev->device;
5224 hw->revision_id = pdev->revision;
5225 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5226 hw->subsystem_device_id = pdev->subsystem_device;
5227
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005228 /* Set capability flags */
Jesse Brandeburg3ed69d72012-02-10 10:20:02 +00005229 rss = min_t(int, IXGBE_MAX_RSS_INDICES, num_online_cpus());
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005230 adapter->ring_feature[RING_F_RSS].indices = rss;
5231 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
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;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005238 case ixgbe_mac_X540:
Jacob Keller4f51bf72011-08-20 04:49:45 +00005239 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
5240 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005241 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00005242 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
5243 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005244 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5245 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00005246 /* Flow Director hash filters enabled */
5247 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
5248 adapter->atr_sample_rate = 20;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005249 adapter->ring_feature[RING_F_FDIR].indices =
Joe Perchese8e9f692010-09-07 21:34:53 +00005250 IXGBE_MAX_FDIR_INDICES;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00005251 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
Yi Zoueacd73f2009-05-13 13:11:06 +00005252#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00005253 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5254 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5255 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou61a0f422009-12-03 11:32:22 +00005256#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00005257 /* Default traffic class to use for FCoE */
John Fastabend56075a92010-07-26 20:41:31 +00005258 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00005259#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00005260#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005261 break;
5262 default:
5263 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005264 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005265
Alexander Duyck1fc5f032011-06-02 04:28:39 +00005266 /* n-tuple support exists, always init our spinlock */
5267 spin_lock_init(&adapter->fdir_perfect_lock);
5268
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005269#ifdef CONFIG_IXGBE_DCB
John Fastabend4de2a022011-09-27 03:52:01 +00005270 switch (hw->mac.type) {
5271 case ixgbe_mac_X540:
5272 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
5273 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
5274 break;
5275 default:
5276 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
5277 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
5278 break;
5279 }
5280
Alexander Duyck2f90b862008-11-20 20:52:10 -08005281 /* Configure DCB traffic classes */
5282 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5283 tc = &adapter->dcb_cfg.tc_config[j];
5284 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5285 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5286 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5287 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5288 tc->dcb_pfc = pfc_disabled;
5289 }
John Fastabend4de2a022011-09-27 03:52:01 +00005290
5291 /* Initialize default user to priority mapping, UPx->TC0 */
5292 tc = &adapter->dcb_cfg.tc_config[0];
5293 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
5294 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
5295
Alexander Duyck2f90b862008-11-20 20:52:10 -08005296 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5297 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005298 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005299 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00005300 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005301 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
John Fastabende5b64632011-03-08 03:44:52 +00005302 MAX_TRAFFIC_CLASS);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005303
5304#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005305
5306 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005307 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005308 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005309#ifdef CONFIG_DCB
5310 adapter->last_lfc_mode = hw->fc.current_mode;
5311#endif
John Fastabend9da712d2011-08-23 03:14:22 +00005312 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005313 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5314 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00005315 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07005316
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005317 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005318 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005319 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005320
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005321 /* set default ring sizes */
5322 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5323 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5324
Alexander Duyckbd198052011-06-11 01:45:08 +00005325 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00005326 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00005327
Auke Kok9a799d72007-09-15 14:07:45 -07005328 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005329 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005330 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005331 return -EIO;
5332 }
5333
Auke Kok9a799d72007-09-15 14:07:45 -07005334 set_bit(__IXGBE_DOWN, &adapter->state);
5335
5336 return 0;
5337}
5338
5339/**
5340 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005341 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005342 *
5343 * Return 0 on success, negative on failure
5344 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005345int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005346{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005347 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005348 int orig_node = dev_to_node(dev);
5349 int numa_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07005350 int size;
5351
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005352 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005353
5354 if (tx_ring->q_vector)
5355 numa_node = tx_ring->q_vector->numa_node;
5356
5357 tx_ring->tx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005358 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005359 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005360 if (!tx_ring->tx_buffer_info)
5361 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005362
5363 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005364 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005365 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005366
Alexander Duyckde88eee2012-02-08 07:49:59 +00005367 set_dev_node(dev, numa_node);
5368 tx_ring->desc = dma_alloc_coherent(dev,
5369 tx_ring->size,
5370 &tx_ring->dma,
5371 GFP_KERNEL);
5372 set_dev_node(dev, orig_node);
5373 if (!tx_ring->desc)
5374 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
5375 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005376 if (!tx_ring->desc)
5377 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005378
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005379 tx_ring->next_to_use = 0;
5380 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005381 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005382
5383err:
5384 vfree(tx_ring->tx_buffer_info);
5385 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005386 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005387 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005388}
5389
5390/**
Alexander Duyck69888672008-09-11 20:05:39 -07005391 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5392 * @adapter: board private structure
5393 *
5394 * If this function returns with an error, then it's possible one or
5395 * more of the rings is populated (while the rest are not). It is the
5396 * callers duty to clean those orphaned rings.
5397 *
5398 * Return 0 on success, negative on failure
5399 **/
5400static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5401{
5402 int i, err = 0;
5403
5404 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005405 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005406 if (!err)
5407 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005408 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005409 break;
5410 }
5411
5412 return err;
5413}
5414
5415/**
Auke Kok9a799d72007-09-15 14:07:45 -07005416 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005417 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005418 *
5419 * Returns 0 on success, negative on failure
5420 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005421int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005422{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005423 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005424 int orig_node = dev_to_node(dev);
5425 int numa_node = -1;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005426 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005427
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005428 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005429
5430 if (rx_ring->q_vector)
5431 numa_node = rx_ring->q_vector->numa_node;
5432
5433 rx_ring->rx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005434 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005435 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005436 if (!rx_ring->rx_buffer_info)
5437 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005438
Auke Kok9a799d72007-09-15 14:07:45 -07005439 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005440 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5441 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005442
Alexander Duyckde88eee2012-02-08 07:49:59 +00005443 set_dev_node(dev, numa_node);
5444 rx_ring->desc = dma_alloc_coherent(dev,
5445 rx_ring->size,
5446 &rx_ring->dma,
5447 GFP_KERNEL);
5448 set_dev_node(dev, orig_node);
5449 if (!rx_ring->desc)
5450 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
5451 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005452 if (!rx_ring->desc)
5453 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005454
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005455 rx_ring->next_to_clean = 0;
5456 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005457
Alexander Duyckf8003262012-03-03 02:35:52 +00005458 ixgbe_init_rx_page_offset(rx_ring);
5459
Auke Kok9a799d72007-09-15 14:07:45 -07005460 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005461err:
5462 vfree(rx_ring->rx_buffer_info);
5463 rx_ring->rx_buffer_info = NULL;
5464 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005465 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005466}
5467
5468/**
Alexander Duyck69888672008-09-11 20:05:39 -07005469 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5470 * @adapter: board private structure
5471 *
5472 * If this function returns with an error, then it's possible one or
5473 * more of the rings is populated (while the rest are not). It is the
5474 * callers duty to clean those orphaned rings.
5475 *
5476 * Return 0 on success, negative on failure
5477 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005478static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5479{
5480 int i, err = 0;
5481
5482 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005483 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005484 if (!err)
5485 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005486 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005487 break;
5488 }
5489
5490 return err;
5491}
5492
5493/**
Auke Kok9a799d72007-09-15 14:07:45 -07005494 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005495 * @tx_ring: Tx descriptor ring for a specific queue
5496 *
5497 * Free all transmit software resources
5498 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005499void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005500{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005501 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005502
5503 vfree(tx_ring->tx_buffer_info);
5504 tx_ring->tx_buffer_info = NULL;
5505
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005506 /* if not set, then don't free */
5507 if (!tx_ring->desc)
5508 return;
5509
5510 dma_free_coherent(tx_ring->dev, tx_ring->size,
5511 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005512
5513 tx_ring->desc = NULL;
5514}
5515
5516/**
5517 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5518 * @adapter: board private structure
5519 *
5520 * Free all transmit software resources
5521 **/
5522static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5523{
5524 int i;
5525
5526 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005527 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005528 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005529}
5530
5531/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005532 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005533 * @rx_ring: ring to clean the resources from
5534 *
5535 * Free all receive software resources
5536 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005537void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005538{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005539 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005540
5541 vfree(rx_ring->rx_buffer_info);
5542 rx_ring->rx_buffer_info = NULL;
5543
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005544 /* if not set, then don't free */
5545 if (!rx_ring->desc)
5546 return;
5547
5548 dma_free_coherent(rx_ring->dev, rx_ring->size,
5549 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005550
5551 rx_ring->desc = NULL;
5552}
5553
5554/**
5555 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5556 * @adapter: board private structure
5557 *
5558 * Free all receive software resources
5559 **/
5560static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5561{
5562 int i;
5563
5564 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005565 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005566 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005567}
5568
5569/**
Auke Kok9a799d72007-09-15 14:07:45 -07005570 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5571 * @netdev: network interface device structure
5572 * @new_mtu: new value for maximum frame size
5573 *
5574 * Returns 0 on success, negative on failure
5575 **/
5576static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5577{
5578 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5579 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5580
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07005581 /* MTU < 68 is an error and causes problems on some kernels */
Alexander Duyck655309e2012-02-08 07:50:35 +00005582 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5583 return -EINVAL;
5584
5585 /*
5586 * For 82599EB we cannot allow PF to change MTU greater than 1500
5587 * in SR-IOV mode as it may cause buffer overruns in guest VFs that
5588 * don't allocate and chain buffers correctly.
5589 */
5590 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
5591 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
5592 (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
Greg Rosee9f98072011-01-26 01:06:07 +00005593 return -EINVAL;
Auke Kok9a799d72007-09-15 14:07:45 -07005594
Emil Tantilov396e7992010-07-01 20:05:12 +00005595 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Alexander Duyck655309e2012-02-08 07:50:35 +00005596
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005597 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07005598 netdev->mtu = new_mtu;
5599
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005600 if (netif_running(netdev))
5601 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005602
5603 return 0;
5604}
5605
5606/**
5607 * ixgbe_open - Called when a network interface is made active
5608 * @netdev: network interface device structure
5609 *
5610 * Returns 0 on success, negative value on failure
5611 *
5612 * The open entry point is called when a network interface is made
5613 * active by the system (IFF_UP). At this point all resources needed
5614 * for transmit and receive operations are allocated, the interrupt
5615 * handler is registered with the OS, the watchdog timer is started,
5616 * and the stack is notified that the interface is ready.
5617 **/
5618static int ixgbe_open(struct net_device *netdev)
5619{
5620 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5621 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005622
Auke Kok4bebfaa2008-02-11 09:26:01 -08005623 /* disallow open during test */
5624 if (test_bit(__IXGBE_TESTING, &adapter->state))
5625 return -EBUSY;
5626
Jesse Brandeburg54386462009-04-17 20:44:27 +00005627 netif_carrier_off(netdev);
5628
Auke Kok9a799d72007-09-15 14:07:45 -07005629 /* allocate transmit descriptors */
5630 err = ixgbe_setup_all_tx_resources(adapter);
5631 if (err)
5632 goto err_setup_tx;
5633
Auke Kok9a799d72007-09-15 14:07:45 -07005634 /* allocate receive descriptors */
5635 err = ixgbe_setup_all_rx_resources(adapter);
5636 if (err)
5637 goto err_setup_rx;
5638
5639 ixgbe_configure(adapter);
5640
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005641 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005642 if (err)
5643 goto err_req_irq;
5644
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005645 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005646
5647 return 0;
5648
Auke Kok9a799d72007-09-15 14:07:45 -07005649err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07005650err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005651 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005652err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005653 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005654 ixgbe_reset(adapter);
5655
5656 return err;
5657}
5658
5659/**
5660 * ixgbe_close - Disables a network interface
5661 * @netdev: network interface device structure
5662 *
5663 * Returns 0, this is not allowed to fail
5664 *
5665 * The close entry point is called when an interface is de-activated
5666 * by the OS. The hardware is still under the drivers control, but
5667 * needs to be disabled. A global MAC reset is issued to stop the
5668 * hardware, and all transmit and receive resources are freed.
5669 **/
5670static int ixgbe_close(struct net_device *netdev)
5671{
5672 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005673
5674 ixgbe_down(adapter);
5675 ixgbe_free_irq(adapter);
5676
Alexander Duycke4911d52011-05-11 07:18:52 +00005677 ixgbe_fdir_filter_exit(adapter);
5678
Auke Kok9a799d72007-09-15 14:07:45 -07005679 ixgbe_free_all_tx_resources(adapter);
5680 ixgbe_free_all_rx_resources(adapter);
5681
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005682 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005683
5684 return 0;
5685}
5686
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005687#ifdef CONFIG_PM
5688static int ixgbe_resume(struct pci_dev *pdev)
5689{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005690 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5691 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005692 u32 err;
5693
5694 pci_set_power_state(pdev, PCI_D0);
5695 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005696 /*
5697 * pci_restore_state clears dev->state_saved so call
5698 * pci_save_state to restore it.
5699 */
5700 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005701
5702 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005703 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005704 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005705 return err;
5706 }
5707 pci_set_master(pdev);
5708
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005709 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005710
5711 err = ixgbe_init_interrupt_scheme(adapter);
5712 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005713 e_dev_err("Cannot initialize interrupts for device\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005714 return err;
5715 }
5716
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005717 ixgbe_reset(adapter);
5718
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005719 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5720
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005721 if (netif_running(netdev)) {
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005722 err = ixgbe_open(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005723 if (err)
5724 return err;
5725 }
5726
5727 netif_device_attach(netdev);
5728
5729 return 0;
5730}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005731#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005732
5733static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005734{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005735 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5736 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005737 struct ixgbe_hw *hw = &adapter->hw;
5738 u32 ctrl, fctrl;
5739 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005740#ifdef CONFIG_PM
5741 int retval = 0;
5742#endif
5743
5744 netif_device_detach(netdev);
5745
5746 if (netif_running(netdev)) {
5747 ixgbe_down(adapter);
5748 ixgbe_free_irq(adapter);
5749 ixgbe_free_all_tx_resources(adapter);
5750 ixgbe_free_all_rx_resources(adapter);
5751 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005752
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005753 ixgbe_clear_interrupt_scheme(adapter);
John Fastabendd033d522011-02-10 14:40:01 +00005754#ifdef CONFIG_DCB
5755 kfree(adapter->ixgbe_ieee_pfc);
5756 kfree(adapter->ixgbe_ieee_ets);
5757#endif
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005758
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005759#ifdef CONFIG_PM
5760 retval = pci_save_state(pdev);
5761 if (retval)
5762 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005763
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005764#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005765 if (wufc) {
5766 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005767
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005768 /* turn on all-multi mode if wake on multicast is enabled */
5769 if (wufc & IXGBE_WUFC_MC) {
5770 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5771 fctrl |= IXGBE_FCTRL_MPE;
5772 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5773 }
5774
5775 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5776 ctrl |= IXGBE_CTRL_GIO_DIS;
5777 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5778
5779 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5780 } else {
5781 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5782 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5783 }
5784
Alexander Duyckbd508172010-11-16 19:27:03 -08005785 switch (hw->mac.type) {
5786 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005787 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005788 break;
5789 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005790 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005791 pci_wake_from_d3(pdev, !!wufc);
5792 break;
5793 default:
5794 break;
5795 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005796
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005797 *enable_wake = !!wufc;
5798
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005799 ixgbe_release_hw_control(adapter);
5800
5801 pci_disable_device(pdev);
5802
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005803 return 0;
5804}
5805
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005806#ifdef CONFIG_PM
5807static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5808{
5809 int retval;
5810 bool wake;
5811
5812 retval = __ixgbe_shutdown(pdev, &wake);
5813 if (retval)
5814 return retval;
5815
5816 if (wake) {
5817 pci_prepare_to_sleep(pdev);
5818 } else {
5819 pci_wake_from_d3(pdev, false);
5820 pci_set_power_state(pdev, PCI_D3hot);
5821 }
5822
5823 return 0;
5824}
5825#endif /* CONFIG_PM */
5826
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005827static void ixgbe_shutdown(struct pci_dev *pdev)
5828{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005829 bool wake;
5830
5831 __ixgbe_shutdown(pdev, &wake);
5832
5833 if (system_state == SYSTEM_POWER_OFF) {
5834 pci_wake_from_d3(pdev, wake);
5835 pci_set_power_state(pdev, PCI_D3hot);
5836 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005837}
5838
5839/**
Auke Kok9a799d72007-09-15 14:07:45 -07005840 * ixgbe_update_stats - Update the board statistics counters.
5841 * @adapter: board private structure
5842 **/
5843void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5844{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005845 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005846 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005847 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005848 u64 total_mpc = 0;
5849 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005850 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5851 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005852 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005853#ifdef IXGBE_FCOE
5854 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
5855 unsigned int cpu;
5856 u64 fcoe_noddp_counts_sum = 0, fcoe_noddp_ext_buff_counts_sum = 0;
5857#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07005858
Don Skidmored08935c2010-06-11 13:20:29 +00005859 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5860 test_bit(__IXGBE_RESETTING, &adapter->state))
5861 return;
5862
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005863 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005864 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005865 u64 rsc_flush = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005866 for (i = 0; i < 16; i++)
5867 adapter->hw_rx_no_dma_resources +=
Joe Perches7ca647b2010-09-07 21:35:40 +00005868 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005869 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005870 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5871 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005872 }
5873 adapter->rsc_total_count = rsc_count;
5874 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005875 }
5876
Alexander Duyck5b7da512010-11-16 19:26:50 -08005877 for (i = 0; i < adapter->num_rx_queues; i++) {
5878 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5879 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5880 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5881 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005882 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005883 bytes += rx_ring->stats.bytes;
5884 packets += rx_ring->stats.packets;
5885 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005886 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005887 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5888 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005889 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005890 netdev->stats.rx_bytes = bytes;
5891 netdev->stats.rx_packets = packets;
5892
5893 bytes = 0;
5894 packets = 0;
5895 /* gather some stats to the adapter struct that are per queue */
5896 for (i = 0; i < adapter->num_tx_queues; i++) {
5897 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5898 restart_queue += tx_ring->tx_stats.restart_queue;
5899 tx_busy += tx_ring->tx_stats.tx_busy;
5900 bytes += tx_ring->stats.bytes;
5901 packets += tx_ring->stats.packets;
5902 }
5903 adapter->restart_queue = restart_queue;
5904 adapter->tx_busy = tx_busy;
5905 netdev->stats.tx_bytes = bytes;
5906 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005907
Joe Perches7ca647b2010-09-07 21:35:40 +00005908 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005909
5910 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005911 for (i = 0; i < 8; i++) {
5912 /* for packet buffers not used, the register should read 0 */
5913 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5914 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005915 hwstats->mpc[i] += mpc;
5916 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005917 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5918 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005919 switch (hw->mac.type) {
5920 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005921 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5922 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5923 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005924 hwstats->pxonrxc[i] +=
5925 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005926 break;
5927 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005928 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005929 hwstats->pxonrxc[i] +=
5930 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005931 break;
5932 default:
5933 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005934 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005935 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005936
5937 /*16 register reads */
5938 for (i = 0; i < 16; i++) {
5939 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5940 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5941 if ((hw->mac.type == ixgbe_mac_82599EB) ||
5942 (hw->mac.type == ixgbe_mac_X540)) {
5943 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
5944 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
5945 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
5946 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
5947 }
5948 }
5949
Joe Perches7ca647b2010-09-07 21:35:40 +00005950 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005951 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005952 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005953
John Fastabendc84d3242010-11-16 19:27:12 -08005954 ixgbe_update_xoff_received(adapter);
5955
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005956 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005957 switch (hw->mac.type) {
5958 case ixgbe_mac_82598EB:
5959 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005960 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5961 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5962 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5963 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005964 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005965 /* OS2BMC stats are X540 only*/
5966 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5967 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5968 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5969 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5970 case ixgbe_mac_82599EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005971 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005972 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005973 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005974 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005975 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005976 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005977 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005978 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5979 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005980#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005981 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5982 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5983 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5984 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5985 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5986 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00005987 /* Add up per cpu counters for total ddp aloc fail */
5988 if (fcoe->pcpu_noddp && fcoe->pcpu_noddp_ext_buff) {
5989 for_each_possible_cpu(cpu) {
5990 fcoe_noddp_counts_sum +=
5991 *per_cpu_ptr(fcoe->pcpu_noddp, cpu);
5992 fcoe_noddp_ext_buff_counts_sum +=
5993 *per_cpu_ptr(fcoe->
5994 pcpu_noddp_ext_buff, cpu);
5995 }
5996 }
5997 hwstats->fcoe_noddp = fcoe_noddp_counts_sum;
5998 hwstats->fcoe_noddp_ext_buff = fcoe_noddp_ext_buff_counts_sum;
Yi Zou6d455222009-05-13 13:12:16 +00005999#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08006000 break;
6001 default:
6002 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006003 }
Auke Kok9a799d72007-09-15 14:07:45 -07006004 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006005 hwstats->bprc += bprc;
6006 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006007 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00006008 hwstats->mprc -= bprc;
6009 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
6010 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
6011 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
6012 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
6013 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
6014 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
6015 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
6016 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006017 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006018 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006019 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006020 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00006021 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
6022 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006023 /*
6024 * 82598 errata - tx of flow control packets is included in tx counters
6025 */
6026 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00006027 hwstats->gptc -= xon_off_tot;
6028 hwstats->mptc -= xon_off_tot;
6029 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
6030 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
6031 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
6032 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
6033 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
6034 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
6035 hwstats->ptc64 -= xon_off_tot;
6036 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
6037 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
6038 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
6039 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
6040 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
6041 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07006042
6043 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00006044 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07006045
6046 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00006047 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006048 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00006049 netdev->stats.rx_length_errors = hwstats->rlec;
6050 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006051 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07006052}
6053
6054/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00006055 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
6056 * @adapter - pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07006057 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00006058static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07006059{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006060 struct ixgbe_hw *hw = &adapter->hw;
6061 int i;
6062
Alexander Duyckd034acf2011-04-27 09:25:34 +00006063 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
6064 return;
6065
6066 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
6067
6068 /* if interface is down do nothing */
6069 if (test_bit(__IXGBE_DOWN, &adapter->state))
6070 return;
6071
6072 /* do nothing if we are not using signature filters */
6073 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
6074 return;
6075
6076 adapter->fdir_overflow++;
6077
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006078 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
6079 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08006080 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00006081 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00006082 /* re-enable flow director interrupts */
6083 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006084 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00006085 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00006086 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006087 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006088}
6089
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006090/**
6091 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
6092 * @adapter - pointer to the device adapter structure
6093 *
6094 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006095 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006096 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006097 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006098 */
6099static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
6100{
Auke Kok9a799d72007-09-15 14:07:45 -07006101 struct ixgbe_hw *hw = &adapter->hw;
6102 u64 eics = 0;
6103 int i;
6104
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006105 /* If we're down or resetting, just bail */
6106 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6107 test_bit(__IXGBE_RESETTING, &adapter->state))
6108 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00006109
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006110 /* Force detection of hung controller */
6111 if (netif_carrier_ok(adapter->netdev)) {
6112 for (i = 0; i < adapter->num_tx_queues; i++)
6113 set_check_for_tx_hang(adapter->tx_ring[i]);
6114 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006115
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006116 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00006117 /*
6118 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006119 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00006120 * would set *both* EIMS and EICS for any bit in EIAM
6121 */
6122 IXGBE_WRITE_REG(hw, IXGBE_EICS,
6123 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006124 } else {
6125 /* get one bit for every active tx/rx interrupt vector */
6126 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
6127 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00006128 if (qv->rx.ring || qv->tx.ring)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006129 eics |= ((u64)1 << i);
6130 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006131 }
6132
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006133 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00006134 ixgbe_irq_rearm_queues(adapter, eics);
6135
Alexander Duyckfe49f042009-06-04 16:00:09 +00006136}
6137
6138/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006139 * ixgbe_watchdog_update_link - update the link status
6140 * @adapter - pointer to the device adapter structure
6141 * @link_speed - pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006142 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006143static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006144{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006145 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006146 u32 link_speed = adapter->link_speed;
6147 bool link_up = adapter->link_up;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006148 int i;
6149
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006150 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
6151 return;
6152
6153 if (hw->mac.ops.check_link) {
6154 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006155 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006156 /* always assume link is up, if no check link function */
6157 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
6158 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006159 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006160 if (link_up) {
6161 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6162 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
6163 hw->mac.ops.fc_enable(hw, i);
6164 } else {
6165 hw->mac.ops.fc_enable(hw, 0);
6166 }
6167 }
6168
6169 if (link_up ||
6170 time_after(jiffies, (adapter->link_check_timeout +
6171 IXGBE_TRY_LINK_TIMEOUT))) {
6172 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
6173 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
6174 IXGBE_WRITE_FLUSH(hw);
6175 }
6176
6177 adapter->link_up = link_up;
6178 adapter->link_speed = link_speed;
6179}
6180
6181/**
6182 * ixgbe_watchdog_link_is_up - update netif_carrier status and
6183 * print link up message
6184 * @adapter - pointer to the device adapter structure
6185 **/
6186static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
6187{
6188 struct net_device *netdev = adapter->netdev;
6189 struct ixgbe_hw *hw = &adapter->hw;
6190 u32 link_speed = adapter->link_speed;
6191 bool flow_rx, flow_tx;
6192
6193 /* only continue if link was previously down */
6194 if (netif_carrier_ok(netdev))
6195 return;
6196
6197 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
6198
6199 switch (hw->mac.type) {
6200 case ixgbe_mac_82598EB: {
6201 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6202 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
6203 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6204 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
6205 }
6206 break;
6207 case ixgbe_mac_X540:
6208 case ixgbe_mac_82599EB: {
6209 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6210 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6211 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6212 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6213 }
6214 break;
6215 default:
6216 flow_tx = false;
6217 flow_rx = false;
6218 break;
6219 }
6220 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
6221 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
6222 "10 Gbps" :
6223 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
6224 "1 Gbps" :
6225 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
6226 "100 Mbps" :
6227 "unknown speed"))),
6228 ((flow_rx && flow_tx) ? "RX/TX" :
6229 (flow_rx ? "RX" :
6230 (flow_tx ? "TX" : "None"))));
6231
6232 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006233 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006234}
6235
6236/**
6237 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6238 * print link down message
6239 * @adapter - pointer to the adapter structure
6240 **/
Alexander Duyck581330b2012-02-08 07:51:47 +00006241static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006242{
6243 struct net_device *netdev = adapter->netdev;
6244 struct ixgbe_hw *hw = &adapter->hw;
6245
6246 adapter->link_up = false;
6247 adapter->link_speed = 0;
6248
6249 /* only continue if link was up previously */
6250 if (!netif_carrier_ok(netdev))
6251 return;
6252
6253 /* poll for SFP+ cable when link is down */
6254 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
6255 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
6256
6257 e_info(drv, "NIC Link is Down\n");
6258 netif_carrier_off(netdev);
6259}
6260
6261/**
6262 * ixgbe_watchdog_flush_tx - flush queues on link down
6263 * @adapter - pointer to the device adapter structure
6264 **/
6265static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
6266{
6267 int i;
6268 int some_tx_pending = 0;
6269
6270 if (!netif_carrier_ok(adapter->netdev)) {
6271 for (i = 0; i < adapter->num_tx_queues; i++) {
6272 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6273 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
6274 some_tx_pending = 1;
6275 break;
6276 }
6277 }
6278
6279 if (some_tx_pending) {
6280 /* We've lost link, so the controller stops DMA,
6281 * but we've got queued Tx work that's never going
6282 * to get done, so reset controller to flush Tx.
6283 * (Do the reset outside of interrupt context).
6284 */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006285 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006286 }
6287 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006288}
6289
Greg Rosea985b6c32010-11-18 03:02:52 +00006290static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6291{
6292 u32 ssvpc;
6293
6294 /* Do not perform spoof check for 82598 */
6295 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6296 return;
6297
6298 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6299
6300 /*
6301 * ssvpc register is cleared on read, if zero then no
6302 * spoofed packets in the last interval.
6303 */
6304 if (!ssvpc)
6305 return;
6306
6307 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
6308}
6309
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006310/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006311 * ixgbe_watchdog_subtask - check and bring link up
6312 * @adapter - pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006313 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006314static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006315{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006316 /* if interface is down do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00006317 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6318 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006319 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006320
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006321 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00006322
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006323 if (adapter->link_up)
6324 ixgbe_watchdog_link_is_up(adapter);
6325 else
6326 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006327
Greg Rosea985b6c32010-11-18 03:02:52 +00006328 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006329 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006330
6331 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006332}
6333
Alexander Duyck70864002011-04-27 09:13:56 +00006334/**
6335 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
6336 * @adapter - the ixgbe adapter structure
6337 **/
6338static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
6339{
6340 struct ixgbe_hw *hw = &adapter->hw;
6341 s32 err;
6342
6343 /* not searching for SFP so there is nothing to do here */
6344 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
6345 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6346 return;
6347
6348 /* someone else is in init, wait until next service event */
6349 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6350 return;
6351
6352 err = hw->phy.ops.identify_sfp(hw);
6353 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6354 goto sfp_out;
6355
6356 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6357 /* If no cable is present, then we need to reset
6358 * the next time we find a good cable. */
6359 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6360 }
6361
6362 /* exit on error */
6363 if (err)
6364 goto sfp_out;
6365
6366 /* exit if reset not needed */
6367 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6368 goto sfp_out;
6369
6370 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6371
6372 /*
6373 * A module may be identified correctly, but the EEPROM may not have
6374 * support for that module. setup_sfp() will fail in that case, so
6375 * we should not allow that module to load.
6376 */
6377 if (hw->mac.type == ixgbe_mac_82598EB)
6378 err = hw->phy.ops.reset(hw);
6379 else
6380 err = hw->mac.ops.setup_sfp(hw);
6381
6382 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6383 goto sfp_out;
6384
6385 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6386 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6387
6388sfp_out:
6389 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6390
6391 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6392 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6393 e_dev_err("failed to initialize because an unsupported "
6394 "SFP+ module type was detected.\n");
6395 e_dev_err("Reload the driver after installing a "
6396 "supported module.\n");
6397 unregister_netdev(adapter->netdev);
6398 }
6399}
6400
6401/**
6402 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
6403 * @adapter - the ixgbe adapter structure
6404 **/
6405static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6406{
6407 struct ixgbe_hw *hw = &adapter->hw;
6408 u32 autoneg;
6409 bool negotiation;
6410
6411 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6412 return;
6413
6414 /* someone else is in init, wait until next service event */
6415 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6416 return;
6417
6418 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6419
6420 autoneg = hw->phy.autoneg_advertised;
6421 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
6422 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
Alexander Duyck70864002011-04-27 09:13:56 +00006423 if (hw->mac.ops.setup_link)
6424 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
6425
6426 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6427 adapter->link_check_timeout = jiffies;
6428 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6429}
6430
Greg Rose83c61fa2011-09-07 05:59:35 +00006431#ifdef CONFIG_PCI_IOV
6432static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
6433{
6434 int vf;
6435 struct ixgbe_hw *hw = &adapter->hw;
6436 struct net_device *netdev = adapter->netdev;
6437 u32 gpc;
6438 u32 ciaa, ciad;
6439
6440 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
6441 if (gpc) /* If incrementing then no need for the check below */
6442 return;
6443 /*
6444 * Check to see if a bad DMA write target from an errant or
6445 * malicious VF has caused a PCIe error. If so then we can
6446 * issue a VFLR to the offending VF(s) and then resume without
6447 * requesting a full slot reset.
6448 */
6449
6450 for (vf = 0; vf < adapter->num_vfs; vf++) {
6451 ciaa = (vf << 16) | 0x80000000;
6452 /* 32 bit read so align, we really want status at offset 6 */
6453 ciaa |= PCI_COMMAND;
6454 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6455 ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599);
6456 ciaa &= 0x7FFFFFFF;
6457 /* disable debug mode asap after reading data */
6458 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6459 /* Get the upper 16 bits which will be the PCI status reg */
6460 ciad >>= 16;
6461 if (ciad & PCI_STATUS_REC_MASTER_ABORT) {
6462 netdev_err(netdev, "VF %d Hung DMA\n", vf);
6463 /* Issue VFLR */
6464 ciaa = (vf << 16) | 0x80000000;
6465 ciaa |= 0xA8;
6466 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6467 ciad = 0x00008000; /* VFLR */
6468 IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad);
6469 ciaa &= 0x7FFFFFFF;
6470 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6471 }
6472 }
6473}
6474
6475#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006476/**
6477 * ixgbe_service_timer - Timer Call-back
6478 * @data: pointer to adapter cast into an unsigned long
6479 **/
6480static void ixgbe_service_timer(unsigned long data)
6481{
6482 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6483 unsigned long next_event_offset;
Greg Rose83c61fa2011-09-07 05:59:35 +00006484 bool ready = true;
Alexander Duyck70864002011-04-27 09:13:56 +00006485
6486 /* poll faster when waiting for link */
6487 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6488 next_event_offset = HZ / 10;
6489 else
6490 next_event_offset = HZ * 2;
6491
Greg Rose83c61fa2011-09-07 05:59:35 +00006492#ifdef CONFIG_PCI_IOV
Alexander Duyck6bb78cf2012-02-08 07:51:22 +00006493 /*
6494 * don't bother with SR-IOV VF DMA hang check if there are
6495 * no VFs or the link is down
6496 */
6497 if (!adapter->num_vfs ||
6498 (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
6499 goto normal_timer_service;
6500
6501 /* If we have VFs allocated then we must check for DMA hangs */
6502 ixgbe_check_for_bad_vf(adapter);
6503 next_event_offset = HZ / 50;
6504 adapter->timer_event_accumulator++;
6505
6506 if (adapter->timer_event_accumulator >= 100)
6507 adapter->timer_event_accumulator = 0;
6508 else
6509 ready = false;
6510
6511normal_timer_service:
Greg Rose83c61fa2011-09-07 05:59:35 +00006512#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006513 /* Reset the timer */
6514 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6515
Greg Rose83c61fa2011-09-07 05:59:35 +00006516 if (ready)
6517 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006518}
6519
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006520static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6521{
6522 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6523 return;
6524
6525 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6526
6527 /* If we're already down or resetting, just bail */
6528 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6529 test_bit(__IXGBE_RESETTING, &adapter->state))
6530 return;
6531
6532 ixgbe_dump(adapter);
6533 netdev_err(adapter->netdev, "Reset adapter\n");
6534 adapter->tx_timeout_count++;
6535
6536 ixgbe_reinit_locked(adapter);
6537}
6538
Alexander Duyck70864002011-04-27 09:13:56 +00006539/**
6540 * ixgbe_service_task - manages and runs subtasks
6541 * @work: pointer to work_struct containing our data
6542 **/
6543static void ixgbe_service_task(struct work_struct *work)
6544{
6545 struct ixgbe_adapter *adapter = container_of(work,
6546 struct ixgbe_adapter,
6547 service_task);
6548
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006549 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006550 ixgbe_sfp_detection_subtask(adapter);
6551 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00006552 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006553 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00006554 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006555 ixgbe_check_hang_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006556
6557 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006558}
6559
Alexander Duyck897ab152011-05-27 05:31:47 +00006560void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens,
6561 u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07006562{
6563 struct ixgbe_adv_tx_context_desc *context_desc;
Alexander Duyck897ab152011-05-27 05:31:47 +00006564 u16 i = tx_ring->next_to_use;
6565
Alexander Duycke4f74022012-01-31 02:59:44 +00006566 context_desc = IXGBE_TX_CTXTDESC(tx_ring, i);
Alexander Duyck897ab152011-05-27 05:31:47 +00006567
6568 i++;
6569 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
6570
6571 /* set bits to identify this as an advanced context descriptor */
6572 type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
6573
6574 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6575 context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof);
6576 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
6577 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
6578}
6579
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006580static int ixgbe_tso(struct ixgbe_ring *tx_ring,
6581 struct ixgbe_tx_buffer *first,
Alexander Duyck244e27a2012-02-08 07:51:11 +00006582 u8 *hdr_len)
Alexander Duyck897ab152011-05-27 05:31:47 +00006583{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006584 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00006585 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006586 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07006587
Alexander Duyck897ab152011-05-27 05:31:47 +00006588 if (!skb_is_gso(skb))
6589 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006590
Alexander Duyck897ab152011-05-27 05:31:47 +00006591 if (skb_header_cloned(skb)) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00006592 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
Alexander Duyck897ab152011-05-27 05:31:47 +00006593 if (err)
6594 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00006595 }
6596
Alexander Duyck897ab152011-05-27 05:31:47 +00006597 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
6598 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
6599
Alexander Duyck244e27a2012-02-08 07:51:11 +00006600 if (first->protocol == __constant_htons(ETH_P_IP)) {
Alexander Duyck897ab152011-05-27 05:31:47 +00006601 struct iphdr *iph = ip_hdr(skb);
6602 iph->tot_len = 0;
6603 iph->check = 0;
6604 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
6605 iph->daddr, 0,
6606 IPPROTO_TCP,
6607 0);
6608 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006609 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
6610 IXGBE_TX_FLAGS_CSUM |
6611 IXGBE_TX_FLAGS_IPV4;
Alexander Duyck897ab152011-05-27 05:31:47 +00006612 } else if (skb_is_gso_v6(skb)) {
6613 ipv6_hdr(skb)->payload_len = 0;
6614 tcp_hdr(skb)->check =
6615 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
6616 &ipv6_hdr(skb)->daddr,
6617 0, IPPROTO_TCP, 0);
Alexander Duyck244e27a2012-02-08 07:51:11 +00006618 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
6619 IXGBE_TX_FLAGS_CSUM;
Alexander Duyck897ab152011-05-27 05:31:47 +00006620 }
6621
Alexander Duyck091a6242012-02-08 07:51:01 +00006622 /* compute header lengths */
Alexander Duyck897ab152011-05-27 05:31:47 +00006623 l4len = tcp_hdrlen(skb);
6624 *hdr_len = skb_transport_offset(skb) + l4len;
6625
Alexander Duyck091a6242012-02-08 07:51:01 +00006626 /* update gso size and bytecount with header size */
6627 first->gso_segs = skb_shinfo(skb)->gso_segs;
6628 first->bytecount += (first->gso_segs - 1) * *hdr_len;
6629
Alexander Duyck897ab152011-05-27 05:31:47 +00006630 /* mss_l4len_id: use 1 as index for TSO */
6631 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
6632 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
6633 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
6634
6635 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
6636 vlan_macip_lens = skb_network_header_len(skb);
6637 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006638 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006639
6640 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
Alexander Duyck244e27a2012-02-08 07:51:11 +00006641 mss_l4len_idx);
Alexander Duyck897ab152011-05-27 05:31:47 +00006642
6643 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00006644}
6645
Alexander Duyck244e27a2012-02-08 07:51:11 +00006646static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
6647 struct ixgbe_tx_buffer *first)
Auke Kok9a799d72007-09-15 14:07:45 -07006648{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006649 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00006650 u32 vlan_macip_lens = 0;
6651 u32 mss_l4len_idx = 0;
6652 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006653
Alexander Duyck897ab152011-05-27 05:31:47 +00006654 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00006655 if (!(first->tx_flags & IXGBE_TX_FLAGS_HW_VLAN) &&
6656 !(first->tx_flags & IXGBE_TX_FLAGS_TXSW))
6657 return;
Alexander Duyck897ab152011-05-27 05:31:47 +00006658 } else {
6659 u8 l4_hdr = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006660 switch (first->protocol) {
Alexander Duyck897ab152011-05-27 05:31:47 +00006661 case __constant_htons(ETH_P_IP):
6662 vlan_macip_lens |= skb_network_header_len(skb);
6663 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6664 l4_hdr = ip_hdr(skb)->protocol;
6665 break;
6666 case __constant_htons(ETH_P_IPV6):
6667 vlan_macip_lens |= skb_network_header_len(skb);
6668 l4_hdr = ipv6_hdr(skb)->nexthdr;
6669 break;
6670 default:
6671 if (unlikely(net_ratelimit())) {
6672 dev_warn(tx_ring->dev,
6673 "partial checksum but proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00006674 first->protocol);
Alexander Duyck897ab152011-05-27 05:31:47 +00006675 }
6676 break;
6677 }
Auke Kok9a799d72007-09-15 14:07:45 -07006678
Alexander Duyck897ab152011-05-27 05:31:47 +00006679 switch (l4_hdr) {
6680 case IPPROTO_TCP:
6681 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6682 mss_l4len_idx = tcp_hdrlen(skb) <<
6683 IXGBE_ADVTXD_L4LEN_SHIFT;
6684 break;
6685 case IPPROTO_SCTP:
6686 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6687 mss_l4len_idx = sizeof(struct sctphdr) <<
6688 IXGBE_ADVTXD_L4LEN_SHIFT;
6689 break;
6690 case IPPROTO_UDP:
6691 mss_l4len_idx = sizeof(struct udphdr) <<
6692 IXGBE_ADVTXD_L4LEN_SHIFT;
6693 break;
6694 default:
6695 if (unlikely(net_ratelimit())) {
6696 dev_warn(tx_ring->dev,
6697 "partial checksum but l4 proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00006698 l4_hdr);
Alexander Duyck897ab152011-05-27 05:31:47 +00006699 }
6700 break;
6701 }
Alexander Duyck244e27a2012-02-08 07:51:11 +00006702
6703 /* update TX checksum flag */
6704 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07006705 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006706
Alexander Duyck244e27a2012-02-08 07:51:11 +00006707 /* vlan_macip_lens: MACLEN, VLAN tag */
Alexander Duyck897ab152011-05-27 05:31:47 +00006708 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006709 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006710
6711 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6712 type_tucmd, mss_l4len_idx);
Auke Kok9a799d72007-09-15 14:07:45 -07006713}
6714
Alexander Duyckd3d00232011-07-15 02:31:25 +00006715static __le32 ixgbe_tx_cmd_type(u32 tx_flags)
6716{
6717 /* set type for advanced descriptor with frame checksum insertion */
6718 __le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA |
6719 IXGBE_ADVTXD_DCMD_IFCS |
6720 IXGBE_ADVTXD_DCMD_DEXT);
6721
6722 /* set HW vlan bit if vlan is present */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006723 if (tx_flags & IXGBE_TX_FLAGS_HW_VLAN)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006724 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE);
6725
6726 /* set segmentation enable bits for TSO/FSO */
6727#ifdef IXGBE_FCOE
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006728 if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FSO))
Alexander Duyckd3d00232011-07-15 02:31:25 +00006729#else
6730 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6731#endif
6732 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE);
6733
6734 return cmd_type;
6735}
6736
Alexander Duyck729739b2012-02-08 07:51:06 +00006737static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
6738 u32 tx_flags, unsigned int paylen)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006739{
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006740 __le32 olinfo_status = cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006741
6742 /* enable L4 checksum for TSO and TX checksum offload */
6743 if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6744 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM);
6745
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006746 /* enble IPv4 checksum for TSO */
6747 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6748 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006749
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006750 /* use index 1 context for TSO/FSO/FCOE */
6751#ifdef IXGBE_FCOE
6752 if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FCOE))
6753#else
6754 if (tx_flags & IXGBE_TX_FLAGS_TSO)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006755#endif
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006756 olinfo_status |= cpu_to_le32(1 << IXGBE_ADVTXD_IDX_SHIFT);
6757
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006758 /*
6759 * Check Context must be set if Tx switch is enabled, which it
6760 * always is for case where virtual functions are running
6761 */
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006762#ifdef IXGBE_FCOE
6763 if (tx_flags & (IXGBE_TX_FLAGS_TXSW | IXGBE_TX_FLAGS_FCOE))
6764#else
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006765 if (tx_flags & IXGBE_TX_FLAGS_TXSW)
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006766#endif
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006767 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC);
6768
Alexander Duyck729739b2012-02-08 07:51:06 +00006769 tx_desc->read.olinfo_status = olinfo_status;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006770}
6771
6772#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
6773 IXGBE_TXD_CMD_RS)
6774
6775static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
Alexander Duyckd3d00232011-07-15 02:31:25 +00006776 struct ixgbe_tx_buffer *first,
Alexander Duyckd3d00232011-07-15 02:31:25 +00006777 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006778{
Alexander Duyckd3d00232011-07-15 02:31:25 +00006779 dma_addr_t dma;
Alexander Duyck729739b2012-02-08 07:51:06 +00006780 struct sk_buff *skb = first->skb;
6781 struct ixgbe_tx_buffer *tx_buffer;
6782 union ixgbe_adv_tx_desc *tx_desc;
6783 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
Alexander Duyckd3d00232011-07-15 02:31:25 +00006784 unsigned int data_len = skb->data_len;
6785 unsigned int size = skb_headlen(skb);
Alexander Duyck729739b2012-02-08 07:51:06 +00006786 unsigned int paylen = skb->len - hdr_len;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006787 u32 tx_flags = first->tx_flags;
Alexander Duyck729739b2012-02-08 07:51:06 +00006788 __le32 cmd_type;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006789 u16 i = tx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07006790
Alexander Duyck729739b2012-02-08 07:51:06 +00006791 tx_desc = IXGBE_TX_DESC(tx_ring, i);
6792
6793 ixgbe_tx_olinfo_status(tx_desc, tx_flags, paylen);
6794 cmd_type = ixgbe_tx_cmd_type(tx_flags);
6795
Alexander Duyckd3d00232011-07-15 02:31:25 +00006796#ifdef IXGBE_FCOE
6797 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
Alexander Duyck729739b2012-02-08 07:51:06 +00006798 if (data_len < sizeof(struct fcoe_crc_eof)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00006799 size -= sizeof(struct fcoe_crc_eof) - data_len;
6800 data_len = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00006801 } else {
6802 data_len -= sizeof(struct fcoe_crc_eof);
Alexander Duyck44df32c2009-03-31 21:34:23 +00006803 }
Auke Kok9a799d72007-09-15 14:07:45 -07006804 }
6805
Alexander Duyckd3d00232011-07-15 02:31:25 +00006806#endif
Alexander Duyck729739b2012-02-08 07:51:06 +00006807 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
6808 if (dma_mapping_error(tx_ring->dev, dma))
Alexander Duyckd3d00232011-07-15 02:31:25 +00006809 goto dma_error;
6810
Alexander Duyck729739b2012-02-08 07:51:06 +00006811 /* record length, and DMA address */
6812 dma_unmap_len_set(first, len, size);
6813 dma_unmap_addr_set(first, dma, dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006814
Alexander Duyck729739b2012-02-08 07:51:06 +00006815 tx_desc->read.buffer_addr = cpu_to_le64(dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006816
6817 for (;;) {
Alexander Duyck729739b2012-02-08 07:51:06 +00006818 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00006819 tx_desc->read.cmd_type_len =
6820 cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006821
Alexander Duyckd3d00232011-07-15 02:31:25 +00006822 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00006823 tx_desc++;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006824 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00006825 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006826 i = 0;
6827 }
Alexander Duyck729739b2012-02-08 07:51:06 +00006828
6829 dma += IXGBE_MAX_DATA_PER_TXD;
6830 size -= IXGBE_MAX_DATA_PER_TXD;
6831
6832 tx_desc->read.buffer_addr = cpu_to_le64(dma);
6833 tx_desc->read.olinfo_status = 0;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006834 }
6835
Alexander Duyck729739b2012-02-08 07:51:06 +00006836 if (likely(!data_len))
6837 break;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006838
Ben Greearf43f3132012-03-06 09:42:04 +00006839 if (unlikely(skb->no_fcs))
6840 cmd_type &= ~(cpu_to_le32(IXGBE_ADVTXD_DCMD_IFCS));
Alexander Duyckd3d00232011-07-15 02:31:25 +00006841 tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006842
Alexander Duyck729739b2012-02-08 07:51:06 +00006843 i++;
6844 tx_desc++;
6845 if (i == tx_ring->count) {
6846 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
6847 i = 0;
6848 }
Auke Kok9a799d72007-09-15 14:07:45 -07006849
Alexander Duyckd3d00232011-07-15 02:31:25 +00006850#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00006851 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00006852#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00006853 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006854#endif
6855 data_len -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006856
Alexander Duyck729739b2012-02-08 07:51:06 +00006857 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
6858 DMA_TO_DEVICE);
6859 if (dma_mapping_error(tx_ring->dev, dma))
Alexander Duyckd3d00232011-07-15 02:31:25 +00006860 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006861
Alexander Duyck729739b2012-02-08 07:51:06 +00006862 tx_buffer = &tx_ring->tx_buffer_info[i];
6863 dma_unmap_len_set(tx_buffer, len, size);
6864 dma_unmap_addr_set(tx_buffer, dma, dma);
6865
6866 tx_desc->read.buffer_addr = cpu_to_le64(dma);
6867 tx_desc->read.olinfo_status = 0;
6868
6869 frag++;
Auke Kok9a799d72007-09-15 14:07:45 -07006870 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006871
Alexander Duyck729739b2012-02-08 07:51:06 +00006872 /* write last descriptor with RS and EOP bits */
6873 cmd_type |= cpu_to_le32(size) | cpu_to_le32(IXGBE_TXD_CMD);
6874 tx_desc->read.cmd_type_len = cmd_type;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006875
Alexander Duyck091a6242012-02-08 07:51:01 +00006876 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
Alexander Duyckb2d96e02012-02-07 08:14:33 +00006877
Alexander Duyckd3d00232011-07-15 02:31:25 +00006878 /* set the timestamp */
6879 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07006880
6881 /*
Alexander Duyck729739b2012-02-08 07:51:06 +00006882 * Force memory writes to complete before letting h/w know there
6883 * are new descriptors to fetch. (Only applicable for weak-ordered
6884 * memory model archs, such as IA-64).
6885 *
6886 * We also need this memory barrier to make certain all of the
6887 * status bits have been updated before next_to_watch is written.
Auke Kok9a799d72007-09-15 14:07:45 -07006888 */
6889 wmb();
6890
Alexander Duyckd3d00232011-07-15 02:31:25 +00006891 /* set next_to_watch value indicating a packet is present */
6892 first->next_to_watch = tx_desc;
6893
Alexander Duyck729739b2012-02-08 07:51:06 +00006894 i++;
6895 if (i == tx_ring->count)
6896 i = 0;
6897
6898 tx_ring->next_to_use = i;
6899
Alexander Duyckd3d00232011-07-15 02:31:25 +00006900 /* notify HW of packet */
Alexander Duyck84ea2592010-11-16 19:26:49 -08006901 writel(i, tx_ring->tail);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006902
6903 return;
6904dma_error:
Alexander Duyck729739b2012-02-08 07:51:06 +00006905 dev_err(tx_ring->dev, "TX DMA map failed\n");
Alexander Duyckd3d00232011-07-15 02:31:25 +00006906
6907 /* clear dma mappings for failed tx_buffer_info map */
6908 for (;;) {
Alexander Duyck729739b2012-02-08 07:51:06 +00006909 tx_buffer = &tx_ring->tx_buffer_info[i];
6910 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer);
6911 if (tx_buffer == first)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006912 break;
6913 if (i == 0)
6914 i = tx_ring->count;
6915 i--;
6916 }
6917
Alexander Duyckd3d00232011-07-15 02:31:25 +00006918 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07006919}
6920
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006921static void ixgbe_atr(struct ixgbe_ring *ring,
Alexander Duyck244e27a2012-02-08 07:51:11 +00006922 struct ixgbe_tx_buffer *first)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006923{
Alexander Duyck69830522011-01-06 14:29:58 +00006924 struct ixgbe_q_vector *q_vector = ring->q_vector;
6925 union ixgbe_atr_hash_dword input = { .dword = 0 };
6926 union ixgbe_atr_hash_dword common = { .dword = 0 };
6927 union {
6928 unsigned char *network;
6929 struct iphdr *ipv4;
6930 struct ipv6hdr *ipv6;
6931 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006932 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006933 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006934
Alexander Duyck69830522011-01-06 14:29:58 +00006935 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6936 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006937 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006938
Alexander Duyck69830522011-01-06 14:29:58 +00006939 /* do nothing if sampling is disabled */
6940 if (!ring->atr_sample_rate)
6941 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006942
Alexander Duyck69830522011-01-06 14:29:58 +00006943 ring->atr_count++;
6944
6945 /* snag network header to get L4 type and address */
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006946 hdr.network = skb_network_header(first->skb);
Alexander Duyck69830522011-01-06 14:29:58 +00006947
6948 /* Currently only IPv4/IPv6 with TCP is supported */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006949 if ((first->protocol != __constant_htons(ETH_P_IPV6) ||
Alexander Duyck69830522011-01-06 14:29:58 +00006950 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
Alexander Duyck244e27a2012-02-08 07:51:11 +00006951 (first->protocol != __constant_htons(ETH_P_IP) ||
Alexander Duyck69830522011-01-06 14:29:58 +00006952 hdr.ipv4->protocol != IPPROTO_TCP))
6953 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006954
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006955 th = tcp_hdr(first->skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006956
Alexander Duyck66f32a82011-06-29 05:43:22 +00006957 /* skip this packet since it is invalid or the socket is closing */
6958 if (!th || th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00006959 return;
6960
6961 /* sample on all syn packets or once every atr sample count */
6962 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6963 return;
6964
6965 /* reset sample count */
6966 ring->atr_count = 0;
6967
Alexander Duyck244e27a2012-02-08 07:51:11 +00006968 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
Alexander Duyck69830522011-01-06 14:29:58 +00006969
6970 /*
6971 * src and dst are inverted, think how the receiver sees them
6972 *
6973 * The input is broken into two sections, a non-compressed section
6974 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6975 * is XORed together and stored in the compressed dword.
6976 */
6977 input.formatted.vlan_id = vlan_id;
6978
6979 /*
6980 * since src port and flex bytes occupy the same word XOR them together
6981 * and write the value to source port portion of compressed dword
6982 */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006983 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Alexander Duyck69830522011-01-06 14:29:58 +00006984 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6985 else
Alexander Duyck244e27a2012-02-08 07:51:11 +00006986 common.port.src ^= th->dest ^ first->protocol;
Alexander Duyck69830522011-01-06 14:29:58 +00006987 common.port.dst ^= th->source;
6988
Alexander Duyck244e27a2012-02-08 07:51:11 +00006989 if (first->protocol == __constant_htons(ETH_P_IP)) {
Alexander Duyck69830522011-01-06 14:29:58 +00006990 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6991 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6992 } else {
6993 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6994 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6995 hdr.ipv6->saddr.s6_addr32[1] ^
6996 hdr.ipv6->saddr.s6_addr32[2] ^
6997 hdr.ipv6->saddr.s6_addr32[3] ^
6998 hdr.ipv6->daddr.s6_addr32[0] ^
6999 hdr.ipv6->daddr.s6_addr32[1] ^
7000 hdr.ipv6->daddr.s6_addr32[2] ^
7001 hdr.ipv6->daddr.s6_addr32[3];
7002 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007003
7004 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00007005 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
7006 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007007}
7008
Alexander Duyck63544e92011-05-27 05:31:42 +00007009static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08007010{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08007011 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08007012 /* Herbert's original patch had:
7013 * smp_mb__after_netif_stop_queue();
7014 * but since that doesn't exist yet, just open code it. */
7015 smp_mb();
7016
7017 /* We need to check again in a case another CPU has just
7018 * made room available. */
Alexander Duyck7d4987d2011-05-27 05:31:37 +00007019 if (likely(ixgbe_desc_unused(tx_ring) < size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08007020 return -EBUSY;
7021
7022 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08007023 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08007024 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08007025 return 0;
7026}
7027
Alexander Duyck82d4e462011-06-11 01:44:58 +00007028static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08007029{
Alexander Duyck7d4987d2011-05-27 05:31:37 +00007030 if (likely(ixgbe_desc_unused(tx_ring) >= size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08007031 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08007032 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08007033}
7034
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007035static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
7036{
7037 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck64407522011-06-11 01:44:53 +00007038 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
7039 smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00007040#ifdef IXGBE_FCOE
Alexander Duyck64407522011-06-11 01:44:53 +00007041 __be16 protocol = vlan_get_protocol(skb);
Hao Zheng5e09a102010-11-11 13:47:59 +00007042
John Fastabende5b64632011-03-08 03:44:52 +00007043 if (((protocol == htons(ETH_P_FCOE)) ||
7044 (protocol == htons(ETH_P_FIP))) &&
7045 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
7046 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
7047 txq += adapter->ring_feature[RING_F_FCOE].mask;
7048 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00007049 }
7050#endif
7051
Krishna Kumarfdd3d632010-02-03 13:13:10 +00007052 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
7053 while (unlikely(txq >= dev->real_num_tx_queues))
7054 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00007055 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00007056 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007057
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007058 return skb_tx_hash(dev, skb);
7059}
7060
Alexander Duyckfc77dc32010-11-16 19:26:51 -08007061netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00007062 struct ixgbe_adapter *adapter,
7063 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07007064{
Alexander Duyckd3d00232011-07-15 02:31:25 +00007065 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00007066 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007067 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00007068#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
7069 unsigned short f;
7070#endif
Alexander Duycka535c302011-05-27 05:31:52 +00007071 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00007072 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00007073 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00007074
Alexander Duycka535c302011-05-27 05:31:52 +00007075 /*
7076 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00007077 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00007078 * + 2 desc gap to keep tail from touching head,
7079 * + 1 desc for context descriptor,
7080 * otherwise try next time
7081 */
7082#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
7083 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
7084 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
7085#else
7086 count += skb_shinfo(skb)->nr_frags;
7087#endif
7088 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
7089 tx_ring->tx_stats.tx_busy++;
7090 return NETDEV_TX_BUSY;
7091 }
7092
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007093 /* record the location of the first descriptor for this packet */
7094 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
7095 first->skb = skb;
Alexander Duyck091a6242012-02-08 07:51:01 +00007096 first->bytecount = skb->len;
7097 first->gso_segs = 1;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007098
Alexander Duyck66f32a82011-06-29 05:43:22 +00007099 /* if we have a HW VLAN tag being added default to the HW one */
Jesse Grosseab6d182010-10-20 13:56:03 +00007100 if (vlan_tx_tag_present(skb)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007101 tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
7102 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7103 /* else if it is a SW VLAN check the next protocol and store the tag */
7104 } else if (protocol == __constant_htons(ETH_P_8021Q)) {
7105 struct vlan_hdr *vhdr, _vhdr;
7106 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
7107 if (!vhdr)
7108 goto out_drop;
7109
7110 protocol = vhdr->h_vlan_encapsulated_proto;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007111 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
7112 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007113 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07007114 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007115
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007116#ifdef CONFIG_PCI_IOV
7117 /*
7118 * Use the l2switch_enable flag - would be false if the DMA
7119 * Tx switch had been disabled.
7120 */
7121 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7122 tx_flags |= IXGBE_TX_FLAGS_TXSW;
7123
7124#endif
John Fastabend32701dc2011-09-27 03:51:56 +00007125 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00007126 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00007127 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
7128 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007129 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00007130 tx_flags |= (skb->priority & 0x7) <<
7131 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007132 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
7133 struct vlan_ethhdr *vhdr;
7134 if (skb_header_cloned(skb) &&
7135 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
7136 goto out_drop;
7137 vhdr = (struct vlan_ethhdr *)skb->data;
7138 vhdr->h_vlan_TCI = htons(tx_flags >>
7139 IXGBE_TX_FLAGS_VLAN_SHIFT);
7140 } else {
7141 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7142 }
7143 }
Alexander Duycka535c302011-05-27 05:31:52 +00007144
Alexander Duyck244e27a2012-02-08 07:51:11 +00007145 /* record initial flags and protocol */
7146 first->tx_flags = tx_flags;
7147 first->protocol = protocol;
7148
Yi Zoueacd73f2009-05-13 13:11:06 +00007149#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00007150 /* setup tx offload for FCoE */
7151 if ((protocol == __constant_htons(ETH_P_FCOE)) &&
7152 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00007153 tso = ixgbe_fso(tx_ring, first, &hdr_len);
Alexander Duyck897ab152011-05-27 05:31:47 +00007154 if (tso < 0)
7155 goto out_drop;
Auke Kok9a799d72007-09-15 14:07:45 -07007156
Alexander Duyck66f32a82011-06-29 05:43:22 +00007157 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00007158 }
Auke Kok9a799d72007-09-15 14:07:45 -07007159
Auke Kok9a799d72007-09-15 14:07:45 -07007160#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00007161 tso = ixgbe_tso(tx_ring, first, &hdr_len);
Alexander Duyck66f32a82011-06-29 05:43:22 +00007162 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07007163 goto out_drop;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007164 else if (!tso)
7165 ixgbe_tx_csum(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00007166
7167 /* add the ATR filter if ATR is on */
7168 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
Alexander Duyck244e27a2012-02-08 07:51:11 +00007169 ixgbe_atr(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00007170
7171#ifdef IXGBE_FCOE
7172xmit_fcoe:
7173#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00007174 ixgbe_tx_map(tx_ring, first, hdr_len);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007175
7176 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07007177
7178 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007179
7180out_drop:
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007181 dev_kfree_skb_any(first->skb);
7182 first->skb = NULL;
7183
Alexander Duyck897ab152011-05-27 05:31:47 +00007184 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07007185}
7186
Alexander Duycka50c29d2012-02-08 07:50:40 +00007187static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
7188 struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07007189{
7190 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007191 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07007192
Alexander Duycka50c29d2012-02-08 07:50:40 +00007193 if (skb->len <= 0) {
7194 dev_kfree_skb_any(skb);
7195 return NETDEV_TX_OK;
7196 }
7197
7198 /*
7199 * The minimum packet size for olinfo paylen is 17 so pad the skb
7200 * in order to meet this minimum size requirement.
7201 */
7202 if (skb->len < 17) {
7203 if (skb_padto(skb, 17))
7204 return NETDEV_TX_OK;
7205 skb->len = 17;
7206 }
7207
Auke Kok9a799d72007-09-15 14:07:45 -07007208 tx_ring = adapter->tx_ring[skb->queue_mapping];
7209 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
7210}
7211
7212/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007213 * ixgbe_set_mac - Change the Ethernet Address of the NIC
Auke Kok9a799d72007-09-15 14:07:45 -07007214 * @netdev: network interface device structure
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007215 * @p: pointer to an address structure
7216 *
Auke Kok9a799d72007-09-15 14:07:45 -07007217 * Returns 0 on success, negative on failure
7218 **/
7219static int ixgbe_set_mac(struct net_device *netdev, void *p)
7220{
Ben Hutchings6b73e102009-04-29 08:08:58 +00007221 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7222 struct ixgbe_hw *hw = &adapter->hw;
7223 struct sockaddr *addr = p;
7224
7225 if (!is_valid_ether_addr(addr->sa_data))
7226 return -EADDRNOTAVAIL;
7227
7228 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
7229 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
7230
7231 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
7232 IXGBE_RAH_AV);
7233
7234 return 0;
7235}
7236
7237static int
7238ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
7239{
7240 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7241 struct ixgbe_hw *hw = &adapter->hw;
7242 u16 value;
7243 int rc;
7244
7245 if (prtad != hw->phy.mdio.prtad)
7246 return -EINVAL;
7247 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
7248 if (!rc)
7249 rc = value;
7250 return rc;
7251}
7252
7253static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
7254 u16 addr, u16 value)
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007255{
7256 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jiri Pirko31278e72009-06-17 01:12:19 +00007257 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007258
7259 if (prtad != hw->phy.mdio.prtad)
7260 return -EINVAL;
7261 return hw->phy.ops.write_reg(hw, addr, devad, value);
7262}
7263
7264static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
7265{
7266 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7267
7268 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
7269}
7270
7271/**
7272 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
7273 * netdev->dev_addrs
7274 * @netdev: network interface device structure
7275 *
7276 * Returns non-zero on failure
7277 **/
Jiri Pirko31278e72009-06-17 01:12:19 +00007278static int ixgbe_add_sanmac_netdev(struct net_device *dev)
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007279{
7280 int err = 0;
7281 struct ixgbe_adapter *adapter = netdev_priv(dev);
7282 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7283
7284 if (is_valid_ether_addr(mac->san_addr)) {
7285 rtnl_lock();
7286 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
7287 rtnl_unlock();
7288 }
7289 return err;
7290}
7291
7292/**
7293 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
7294 * netdev->dev_addrs
7295 * @netdev: network interface device structure
7296 *
Auke Kok9a799d72007-09-15 14:07:45 -07007297 * Returns non-zero on failure
7298 **/
7299static int ixgbe_del_sanmac_netdev(struct net_device *dev)
7300{
7301 int err = 0;
7302 struct ixgbe_adapter *adapter = netdev_priv(dev);
7303 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7304
7305 if (is_valid_ether_addr(mac->san_addr)) {
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007306 rtnl_lock();
Auke Kok9a799d72007-09-15 14:07:45 -07007307 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
Alexander Duyck1a647bd2010-01-13 01:49:13 +00007308 rtnl_unlock();
7309 }
7310 return err;
7311}
Auke Kok9a799d72007-09-15 14:07:45 -07007312
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007313#ifdef CONFIG_NET_POLL_CONTROLLER
7314/*
7315 * Polling 'interrupt' - used by things like netconsole to send skbs
7316 * without having to re-enable interrupts. It's not called while
7317 * the interrupt routine is executing.
7318 */
7319static void ixgbe_netpoll(struct net_device *netdev)
7320{
7321 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007322 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07007323
7324 /* if interface is down do nothing */
7325 if (test_bit(__IXGBE_DOWN, &adapter->state))
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007326 return;
7327
7328 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Stephen Hemminger00829822008-11-20 20:14:53 -08007329 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007330 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Chris Leeche90d4002009-03-10 16:00:24 +00007331 for (i = 0; i < num_q_vectors; i++) {
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007332 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00007333 ixgbe_msix_clean_rings(0, q_vector);
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007334 }
7335 } else {
7336 ixgbe_intr(adapter->pdev->irq, netdev);
7337 }
7338 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
7339}
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007340
Alexander Duyck581330b2012-02-08 07:51:47 +00007341#endif
Eric Dumazetde1036b2010-10-20 23:00:04 +00007342static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
7343 struct rtnl_link_stats64 *stats)
7344{
7345 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7346 int i;
7347
Eric Dumazet1a515022010-11-16 19:26:42 -08007348 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007349 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08007350 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00007351 u64 bytes, packets;
7352 unsigned int start;
7353
Eric Dumazet1a515022010-11-16 19:26:42 -08007354 if (ring) {
7355 do {
7356 start = u64_stats_fetch_begin_bh(&ring->syncp);
7357 packets = ring->stats.packets;
7358 bytes = ring->stats.bytes;
7359 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7360 stats->rx_packets += packets;
7361 stats->rx_bytes += bytes;
7362 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00007363 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007364
7365 for (i = 0; i < adapter->num_tx_queues; i++) {
7366 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7367 u64 bytes, packets;
7368 unsigned int start;
7369
7370 if (ring) {
7371 do {
7372 start = u64_stats_fetch_begin_bh(&ring->syncp);
7373 packets = ring->stats.packets;
7374 bytes = ring->stats.bytes;
7375 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7376 stats->tx_packets += packets;
7377 stats->tx_bytes += bytes;
7378 }
7379 }
Eric Dumazet1a515022010-11-16 19:26:42 -08007380 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007381 /* following stats updated by ixgbe_watchdog_task() */
7382 stats->multicast = netdev->stats.multicast;
7383 stats->rx_errors = netdev->stats.rx_errors;
7384 stats->rx_length_errors = netdev->stats.rx_length_errors;
7385 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7386 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7387 return stats;
7388}
7389
John Fastabend8b1c0b22011-05-03 02:26:48 +00007390/* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
7391 * #adapter: pointer to ixgbe_adapter
7392 * @tc: number of traffic classes currently enabled
7393 *
7394 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
7395 * 802.1Q priority maps to a packet buffer that exists.
7396 */
7397static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
7398{
7399 struct ixgbe_hw *hw = &adapter->hw;
7400 u32 reg, rsave;
7401 int i;
7402
7403 /* 82598 have a static priority to TC mapping that can not
7404 * be changed so no validation is needed.
7405 */
7406 if (hw->mac.type == ixgbe_mac_82598EB)
7407 return;
7408
7409 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
7410 rsave = reg;
7411
7412 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
7413 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
7414
7415 /* If up2tc is out of bounds default to zero */
7416 if (up2tc > tc)
7417 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
7418 }
7419
7420 if (reg != rsave)
7421 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
7422
7423 return;
7424}
7425
John Fastabend8b1c0b22011-05-03 02:26:48 +00007426/* ixgbe_setup_tc - routine to configure net_device for multiple traffic
7427 * classes.
7428 *
7429 * @netdev: net device to configure
7430 * @tc: number of traffic classes to enable
7431 */
7432int ixgbe_setup_tc(struct net_device *dev, u8 tc)
7433{
John Fastabend8b1c0b22011-05-03 02:26:48 +00007434 struct ixgbe_adapter *adapter = netdev_priv(dev);
7435 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00007436
John Fastabende7589ea2011-07-18 22:38:36 +00007437 /* Multiple traffic classes requires multiple queues */
7438 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
7439 e_err(drv, "Enable failed, needs MSI-X\n");
7440 return -EINVAL;
7441 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00007442
7443 /* Hardware supports up to 8 traffic classes */
John Fastabend4de2a022011-09-27 03:52:01 +00007444 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
Alexander Duyck581330b2012-02-08 07:51:47 +00007445 (hw->mac.type == ixgbe_mac_82598EB &&
7446 tc < MAX_TRAFFIC_CLASS))
John Fastabend8b1c0b22011-05-03 02:26:48 +00007447 return -EINVAL;
7448
7449 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00007450 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00007451 * hardware is not flexible enough to do this dynamically.
7452 */
7453 if (netif_running(dev))
7454 ixgbe_close(dev);
7455 ixgbe_clear_interrupt_scheme(adapter);
7456
John Fastabende7589ea2011-07-18 22:38:36 +00007457 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007458 netdev_set_num_tc(dev, tc);
John Fastabende7589ea2011-07-18 22:38:36 +00007459 adapter->last_lfc_mode = adapter->hw.fc.current_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00007460 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
7461 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7462
7463 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
7464 adapter->hw.fc.requested_mode = ixgbe_fc_none;
7465 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007466 netdev_reset_tc(dev);
John Fastabende7589ea2011-07-18 22:38:36 +00007467 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
7468
7469 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
7470 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7471
7472 adapter->temp_dcb_cfg.pfc_mode_enable = false;
7473 adapter->dcb_cfg.pfc_mode_enable = false;
7474 }
7475
John Fastabend8b1c0b22011-05-03 02:26:48 +00007476 ixgbe_init_interrupt_scheme(adapter);
7477 ixgbe_validate_rtr(adapter, tc);
7478 if (netif_running(dev))
7479 ixgbe_open(dev);
7480
7481 return 0;
7482}
Eric Dumazetde1036b2010-10-20 23:00:04 +00007483
Don Skidmore082757a2011-07-21 05:55:00 +00007484void ixgbe_do_reset(struct net_device *netdev)
7485{
7486 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7487
7488 if (netif_running(netdev))
7489 ixgbe_reinit_locked(adapter);
7490 else
7491 ixgbe_reset(adapter);
7492}
7493
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007494static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
7495 netdev_features_t data)
Don Skidmore082757a2011-07-21 05:55:00 +00007496{
7497 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7498
7499#ifdef CONFIG_DCB
7500 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
7501 data &= ~NETIF_F_HW_VLAN_RX;
7502#endif
7503
7504 /* return error if RXHASH is being enabled when RSS is not supported */
7505 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
7506 data &= ~NETIF_F_RXHASH;
7507
7508 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7509 if (!(data & NETIF_F_RXCSUM))
7510 data &= ~NETIF_F_LRO;
7511
7512 /* Turn off LRO if not RSC capable or invalid ITR settings */
7513 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) {
7514 data &= ~NETIF_F_LRO;
7515 } else if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
7516 (adapter->rx_itr_setting != 1 &&
7517 adapter->rx_itr_setting > IXGBE_MAX_RSC_INT_RATE)) {
7518 data &= ~NETIF_F_LRO;
7519 e_info(probe, "rx-usecs set too low, not enabling RSC\n");
7520 }
7521
7522 return data;
7523}
7524
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007525static int ixgbe_set_features(struct net_device *netdev,
7526 netdev_features_t data)
Don Skidmore082757a2011-07-21 05:55:00 +00007527{
7528 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Ben Greear3f2d1c02012-03-08 08:28:41 +00007529 netdev_features_t changed = netdev->features ^ data;
Don Skidmore082757a2011-07-21 05:55:00 +00007530 bool need_reset = false;
7531
Don Skidmore082757a2011-07-21 05:55:00 +00007532 /* Make sure RSC matches LRO, reset if change */
7533 if (!!(data & NETIF_F_LRO) !=
7534 !!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
7535 adapter->flags2 ^= IXGBE_FLAG2_RSC_ENABLED;
7536 switch (adapter->hw.mac.type) {
7537 case ixgbe_mac_X540:
7538 case ixgbe_mac_82599EB:
7539 need_reset = true;
7540 break;
7541 default:
7542 break;
7543 }
7544 }
7545
7546 /*
7547 * Check if Flow Director n-tuple support was enabled or disabled. If
7548 * the state changed, we need to reset.
7549 */
7550 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
7551 /* turn off ATR, enable perfect filters and reset */
7552 if (data & NETIF_F_NTUPLE) {
7553 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7554 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7555 need_reset = true;
7556 }
7557 } else if (!(data & NETIF_F_NTUPLE)) {
7558 /* turn off Flow Director, set ATR and reset */
7559 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7560 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
7561 !(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
7562 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7563 need_reset = true;
7564 }
7565
Ben Greear3f2d1c02012-03-08 08:28:41 +00007566 if (changed & NETIF_F_RXALL)
7567 need_reset = true;
7568
7569 netdev->features = data;
Don Skidmore082757a2011-07-21 05:55:00 +00007570 if (need_reset)
7571 ixgbe_do_reset(netdev);
7572
7573 return 0;
7574
7575}
7576
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007577static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007578 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007579 .ndo_stop = ixgbe_close,
7580 .ndo_start_xmit = ixgbe_xmit_frame,
7581 .ndo_select_queue = ixgbe_select_queue,
Alexander Duyck581330b2012-02-08 07:51:47 +00007582 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007583 .ndo_validate_addr = eth_validate_addr,
7584 .ndo_set_mac_address = ixgbe_set_mac,
7585 .ndo_change_mtu = ixgbe_change_mtu,
7586 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007587 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7588 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007589 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007590 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7591 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7592 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
Alexander Duyck581330b2012-02-08 07:51:47 +00007593 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Greg Rose7f016482010-05-04 22:12:06 +00007594 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007595 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabend24095aa2011-02-23 05:58:03 +00007596 .ndo_setup_tc = ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007597#ifdef CONFIG_NET_POLL_CONTROLLER
7598 .ndo_poll_controller = ixgbe_netpoll,
7599#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007600#ifdef IXGBE_FCOE
7601 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007602 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007603 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007604 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7605 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007606 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00007607 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00007608#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00007609 .ndo_set_features = ixgbe_set_features,
7610 .ndo_fix_features = ixgbe_fix_features,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007611};
7612
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007613static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
7614 const struct ixgbe_info *ii)
7615{
7616#ifdef CONFIG_PCI_IOV
7617 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007618
Greg Rosec6bda302011-08-24 02:37:55 +00007619 if (hw->mac.type == ixgbe_mac_82598EB)
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007620 return;
7621
7622 /* The 82599 supports up to 64 VFs per physical function
7623 * but this implementation limits allocation to 63 so that
7624 * basic networking resources are still available to the
7625 * physical function
7626 */
7627 adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
Greg Rosec6bda302011-08-24 02:37:55 +00007628 ixgbe_enable_sriov(adapter, ii);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007629#endif /* CONFIG_PCI_IOV */
7630}
7631
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007632/**
Auke Kok9a799d72007-09-15 14:07:45 -07007633 * ixgbe_probe - Device Initialization Routine
7634 * @pdev: PCI device information struct
7635 * @ent: entry in ixgbe_pci_tbl
7636 *
7637 * Returns 0 on success, negative on failure
7638 *
7639 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7640 * The OS initialization, configuring of the adapter private structure,
7641 * and a hardware reset occur.
7642 **/
7643static int __devinit ixgbe_probe(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007644 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007645{
7646 struct net_device *netdev;
7647 struct ixgbe_adapter *adapter = NULL;
7648 struct ixgbe_hw *hw;
7649 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007650 static int cards_found;
7651 int i, err, pci_using_dac;
Don Skidmore289700d2010-12-03 03:32:58 +00007652 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00007653 unsigned int indices = num_possible_cpus();
Yi Zoueacd73f2009-05-13 13:11:06 +00007654#ifdef IXGBE_FCOE
7655 u16 device_caps;
7656#endif
Don Skidmore289700d2010-12-03 03:32:58 +00007657 u32 eec;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007658 u16 wol_cap;
Auke Kok9a799d72007-09-15 14:07:45 -07007659
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007660 /* Catch broken hardware that put the wrong VF device ID in
7661 * the PCIe SR-IOV capability.
7662 */
7663 if (pdev->is_virtfn) {
7664 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7665 pci_name(pdev), pdev->vendor, pdev->device);
7666 return -EINVAL;
7667 }
7668
gouji-new9ce77662009-05-06 10:44:45 +00007669 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007670 if (err)
7671 return err;
7672
Nick Nunley1b507732010-04-27 13:10:27 +00007673 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7674 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007675 pci_using_dac = 1;
7676 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007677 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007678 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007679 err = dma_set_coherent_mask(&pdev->dev,
7680 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007681 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007682 dev_err(&pdev->dev,
7683 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007684 goto err_dma;
7685 }
7686 }
7687 pci_using_dac = 0;
7688 }
7689
gouji-new9ce77662009-05-06 10:44:45 +00007690 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007691 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007692 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007693 dev_err(&pdev->dev,
7694 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007695 goto err_pci_reg;
7696 }
7697
Frans Pop19d5afd2009-10-02 10:04:12 -07007698 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007699
Auke Kok9a799d72007-09-15 14:07:45 -07007700 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007701 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007702
John Fastabende901acd2011-04-26 07:26:08 +00007703#ifdef CONFIG_IXGBE_DCB
7704 indices *= MAX_TRAFFIC_CLASS;
7705#endif
7706
John Fastabendc85a2612010-02-25 23:15:21 +00007707 if (ii->mac == ixgbe_mac_82598EB)
7708 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7709 else
7710 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7711
John Fastabende901acd2011-04-26 07:26:08 +00007712#ifdef IXGBE_FCOE
John Fastabendc85a2612010-02-25 23:15:21 +00007713 indices += min_t(unsigned int, num_possible_cpus(),
7714 IXGBE_MAX_FCOE_INDICES);
7715#endif
John Fastabendc85a2612010-02-25 23:15:21 +00007716 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007717 if (!netdev) {
7718 err = -ENOMEM;
7719 goto err_alloc_etherdev;
7720 }
7721
Auke Kok9a799d72007-09-15 14:07:45 -07007722 SET_NETDEV_DEV(netdev, &pdev->dev);
7723
Auke Kok9a799d72007-09-15 14:07:45 -07007724 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007725 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007726
7727 adapter->netdev = netdev;
7728 adapter->pdev = pdev;
7729 hw = &adapter->hw;
7730 hw->back = adapter;
7731 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
7732
Jeff Kirsher05857982008-09-11 19:57:00 -07007733 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007734 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007735 if (!hw->hw_addr) {
7736 err = -EIO;
7737 goto err_ioremap;
7738 }
7739
7740 for (i = 1; i <= 5; i++) {
7741 if (pci_resource_len(pdev, i) == 0)
7742 continue;
7743 }
7744
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007745 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007746 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007747 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007748 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007749
Auke Kok9a799d72007-09-15 14:07:45 -07007750 adapter->bd_number = cards_found;
7751
Auke Kok9a799d72007-09-15 14:07:45 -07007752 /* Setup hw api */
7753 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007754 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007755
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007756 /* EEPROM */
7757 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7758 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7759 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7760 if (!(eec & (1 << 8)))
7761 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7762
7763 /* PHY */
7764 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007765 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007766 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7767 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7768 hw->phy.mdio.mmds = 0;
7769 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7770 hw->phy.mdio.dev = netdev;
7771 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7772 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007773
Don Skidmore8ca783a2009-05-26 20:40:47 -07007774 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007775
7776 /* setup the private structure */
7777 err = ixgbe_sw_init(adapter);
7778 if (err)
7779 goto err_sw_init;
7780
Don Skidmoree86bff02010-02-11 04:14:08 +00007781 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007782 switch (adapter->hw.mac.type) {
7783 case ixgbe_mac_82599EB:
7784 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007785 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007786 break;
7787 default:
7788 break;
7789 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007790
Don Skidmorebf069c92009-05-07 10:39:54 +00007791 /*
7792 * If there is a fan on this device and it has failed log the
7793 * failure.
7794 */
7795 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7796 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7797 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007798 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007799 }
7800
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00007801 if (allow_unsupported_sfp)
7802 hw->allow_unsupported_sfp = allow_unsupported_sfp;
7803
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007804 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007805 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007806 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007807 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007808 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7809 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007810 err = 0;
7811 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007812 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007813 "module type was detected.\n");
7814 e_dev_err("Reload the driver after installing a supported "
7815 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007816 goto err_sw_init;
7817 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007818 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007819 goto err_sw_init;
7820 }
7821
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007822 ixgbe_probe_vf(adapter, ii);
7823
Emil Tantilov396e7992010-07-01 20:05:12 +00007824 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007825 NETIF_F_IP_CSUM |
Don Skidmore082757a2011-07-21 05:55:00 +00007826 NETIF_F_IPV6_CSUM |
Joe Perchese8e9f692010-09-07 21:34:53 +00007827 NETIF_F_HW_VLAN_TX |
7828 NETIF_F_HW_VLAN_RX |
Don Skidmore082757a2011-07-21 05:55:00 +00007829 NETIF_F_HW_VLAN_FILTER |
7830 NETIF_F_TSO |
7831 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00007832 NETIF_F_RXHASH |
7833 NETIF_F_RXCSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007834
Don Skidmore082757a2011-07-21 05:55:00 +00007835 netdev->hw_features = netdev->features;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007836
Don Skidmore58be7662011-04-12 09:42:11 +00007837 switch (adapter->hw.mac.type) {
7838 case ixgbe_mac_82599EB:
7839 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007840 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore082757a2011-07-21 05:55:00 +00007841 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7842 NETIF_F_NTUPLE;
Don Skidmore58be7662011-04-12 09:42:11 +00007843 break;
7844 default:
7845 break;
7846 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007847
Ben Greear3f2d1c02012-03-08 08:28:41 +00007848 netdev->hw_features |= NETIF_F_RXALL;
7849
Jeff Kirsherad31c402008-06-05 04:05:30 -07007850 netdev->vlan_features |= NETIF_F_TSO;
7851 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007852 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007853 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007854 netdev->vlan_features |= NETIF_F_SG;
7855
Jiri Pirko01789342011-08-16 06:29:00 +00007856 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +00007857 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +00007858
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007859 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7860 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
7861 IXGBE_FLAG_DCB_ENABLED);
Alexander Duyck2f90b862008-11-20 20:52:10 -08007862
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007863#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007864 netdev->dcbnl_ops = &dcbnl_ops;
7865#endif
7866
Yi Zoueacd73f2009-05-13 13:11:06 +00007867#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007868 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00007869 if (hw->mac.ops.get_device_caps) {
7870 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007871 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7872 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007873 }
7874 }
Yi Zou5e09d7f2010-07-19 13:59:52 +00007875 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7876 netdev->vlan_features |= NETIF_F_FCOE_CRC;
7877 netdev->vlan_features |= NETIF_F_FSO;
7878 netdev->vlan_features |= NETIF_F_FCOE_MTU;
7879 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007880#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007881 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007882 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007883 netdev->vlan_features |= NETIF_F_HIGHDMA;
7884 }
Auke Kok9a799d72007-09-15 14:07:45 -07007885
Don Skidmore082757a2011-07-21 05:55:00 +00007886 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
7887 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007888 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007889 netdev->features |= NETIF_F_LRO;
7890
Auke Kok9a799d72007-09-15 14:07:45 -07007891 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007892 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007893 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007894 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00007895 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007896 }
7897
7898 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7899 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7900
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007901 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007902 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007903 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00007904 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007905 }
7906
Alexander Duyck70864002011-04-27 09:13:56 +00007907 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
Alexander Duyck581330b2012-02-08 07:51:47 +00007908 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007909
Alexander Duyck70864002011-04-27 09:13:56 +00007910 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7911 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007912
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007913 err = ixgbe_init_interrupt_scheme(adapter);
7914 if (err)
7915 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007916
Don Skidmore082757a2011-07-21 05:55:00 +00007917 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
7918 netdev->hw_features &= ~NETIF_F_RXHASH;
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007919 netdev->features &= ~NETIF_F_RXHASH;
Don Skidmore082757a2011-07-21 05:55:00 +00007920 }
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007921
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007922 /* WOL not supported for all but the following */
7923 adapter->wol = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007924 switch (pdev->device) {
Don Skidmore0b077fe2010-12-03 03:32:13 +00007925 case IXGBE_DEV_ID_82599_SFP:
Don Skidmore0e22d042011-12-10 06:49:43 +00007926 /* Only these subdevice supports WOL */
7927 switch (pdev->subsystem_device) {
7928 case IXGBE_SUBDEV_ID_82599_560FLR:
7929 /* only support first port */
7930 if (hw->bus.func != 0)
7931 break;
7932 case IXGBE_SUBDEV_ID_82599_SFP:
Andy Gospodarek9417c462011-07-16 07:31:33 +00007933 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0e22d042011-12-10 06:49:43 +00007934 break;
7935 }
Don Skidmore0b077fe2010-12-03 03:32:13 +00007936 break;
Alexander Duyck50d6c682010-11-16 19:27:05 -08007937 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7938 /* All except this subdevice support WOL */
Don Skidmore0b077fe2010-12-03 03:32:13 +00007939 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
Andy Gospodarek9417c462011-07-16 07:31:33 +00007940 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0b077fe2010-12-03 03:32:13 +00007941 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007942 case IXGBE_DEV_ID_82599_KX4:
Andy Gospodarek9417c462011-07-16 07:31:33 +00007943 adapter->wol = IXGBE_WUFC_MAG;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007944 break;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007945 case IXGBE_DEV_ID_X540T:
7946 /* Check eeprom to see if it is enabled */
7947 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
7948 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
7949
7950 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
7951 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
7952 (hw->bus.func == 0)))
7953 adapter->wol = IXGBE_WUFC_MAG;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007954 break;
7955 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007956 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7957
Emil Tantilov15e52092011-09-29 05:01:29 +00007958 /* save off EEPROM version number */
7959 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
7960 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
7961
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007962 /* pick up the PCI bus settings for reporting later */
7963 hw->mac.ops.get_bus_info(hw);
7964
Auke Kok9a799d72007-09-15 14:07:45 -07007965 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007966 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007967 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7968 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007969 "Unknown"),
7970 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7971 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7972 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7973 "Unknown"),
7974 netdev->dev_addr);
Don Skidmore289700d2010-12-03 03:32:58 +00007975
7976 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7977 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007978 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007979 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700d2010-12-03 03:32:58 +00007980 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007981 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700d2010-12-03 03:32:58 +00007982 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007983 else
Don Skidmore289700d2010-12-03 03:32:58 +00007984 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7985 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007986
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007987 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007988 e_dev_warn("PCI-Express bandwidth available for this card is "
7989 "not sufficient for optimal performance.\n");
7990 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7991 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007992 }
7993
Auke Kok9a799d72007-09-15 14:07:45 -07007994 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007995 err = hw->mac.ops.start_hw(hw);
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007996 if (err == IXGBE_ERR_EEPROM_VERSION) {
7997 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007998 e_dev_warn("This device is a pre-production adapter/LOM. "
7999 "Please be aware there may be issues associated "
8000 "with your hardware. If you are experiencing "
8001 "problems please contact your Intel or hardware "
8002 "representative who provided you with this "
8003 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00008004 }
Auke Kok9a799d72007-09-15 14:07:45 -07008005 strcpy(netdev->name, "eth%d");
8006 err = register_netdev(netdev);
8007 if (err)
8008 goto err_register;
8009
Emil Tantilov93d3ce82011-10-19 07:59:55 +00008010 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
8011 if (hw->mac.ops.disable_tx_laser &&
8012 ((hw->phy.multispeed_fiber) ||
8013 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
8014 (hw->mac.type == ixgbe_mac_82599EB))))
8015 hw->mac.ops.disable_tx_laser(hw);
8016
Jesse Brandeburg54386462009-04-17 20:44:27 +00008017 /* carrier off reporting is important to ethtool even BEFORE open */
8018 netif_carrier_off(netdev);
8019
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008020#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03008021 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008022 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008023 ixgbe_setup_dca(adapter);
8024 }
8025#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008026 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00008027 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008028 for (i = 0; i < adapter->num_vfs; i++)
8029 ixgbe_vf_configuration(pdev, (i | 0x10000000));
8030 }
8031
Jacob Keller2466dd92011-09-08 03:50:54 +00008032 /* firmware requires driver version to be 0xFFFFFFFF
8033 * since os does not support feature
8034 */
Emil Tantilov9612de92011-05-07 07:40:20 +00008035 if (hw->mac.ops.set_fw_drv_ver)
Jacob Keller2466dd92011-09-08 03:50:54 +00008036 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
8037 0xFF);
Emil Tantilov9612de92011-05-07 07:40:20 +00008038
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008039 /* add san mac addr to netdev */
8040 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008041
Neerav Parikhea818752012-01-04 20:23:40 +00008042 e_dev_info("%s\n", ixgbe_default_device_descr);
Auke Kok9a799d72007-09-15 14:07:45 -07008043 cards_found++;
8044 return 0;
8045
8046err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08008047 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00008048 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008049err_sw_init:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008050 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
8051 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00008052 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07008053 iounmap(hw->hw_addr);
8054err_ioremap:
8055 free_netdev(netdev);
8056err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00008057 pci_release_selected_regions(pdev,
8058 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07008059err_pci_reg:
8060err_dma:
8061 pci_disable_device(pdev);
8062 return err;
8063}
8064
8065/**
8066 * ixgbe_remove - Device Removal Routine
8067 * @pdev: PCI device information struct
8068 *
8069 * ixgbe_remove is called by the PCI subsystem to alert the driver
8070 * that it should release a PCI device. The could be caused by a
8071 * Hot-Plug event, or because the driver is going to be removed from
8072 * memory.
8073 **/
8074static void __devexit ixgbe_remove(struct pci_dev *pdev)
8075{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008076 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8077 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008078
8079 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00008080 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07008081
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008082#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008083 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
8084 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
8085 dca_remove_requester(&pdev->dev);
8086 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
8087 }
8088
8089#endif
Yi Zou332d4a72009-05-13 13:11:53 +00008090#ifdef IXGBE_FCOE
8091 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
8092 ixgbe_cleanup_fcoe(adapter);
8093
8094#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008095
8096 /* remove the added san mac */
8097 ixgbe_del_sanmac_netdev(netdev);
8098
Donald Skidmorec4900be2008-11-20 21:11:42 -08008099 if (netdev->reg_state == NETREG_REGISTERED)
8100 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008101
Greg Rosec6bda302011-08-24 02:37:55 +00008102 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
8103 if (!(ixgbe_check_vf_assignment(adapter)))
8104 ixgbe_disable_sriov(adapter);
8105 else
8106 e_dev_warn("Unloading driver while VFs are assigned "
8107 "- VFs will not be deallocated\n");
8108 }
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008109
Alexander Duyck7a921c92009-05-06 10:43:28 +00008110 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08008111
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008112 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008113
8114 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00008115 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00008116 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07008117
Emil Tantilov849c4542010-06-03 16:53:41 +00008118 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008119
Auke Kok9a799d72007-09-15 14:07:45 -07008120 free_netdev(netdev);
8121
Frans Pop19d5afd2009-10-02 10:04:12 -07008122 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008123
Auke Kok9a799d72007-09-15 14:07:45 -07008124 pci_disable_device(pdev);
8125}
8126
8127/**
8128 * ixgbe_io_error_detected - called when PCI error is detected
8129 * @pdev: Pointer to PCI device
8130 * @state: The current pci connection state
8131 *
8132 * This function is called after a PCI bus error affecting
8133 * this device has been detected.
8134 */
8135static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00008136 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07008137{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008138 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8139 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008140
Greg Rose83c61fa2011-09-07 05:59:35 +00008141#ifdef CONFIG_PCI_IOV
8142 struct pci_dev *bdev, *vfdev;
8143 u32 dw0, dw1, dw2, dw3;
8144 int vf, pos;
8145 u16 req_id, pf_func;
8146
8147 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
8148 adapter->num_vfs == 0)
8149 goto skip_bad_vf_detection;
8150
8151 bdev = pdev->bus->self;
8152 while (bdev && (bdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT))
8153 bdev = bdev->bus->self;
8154
8155 if (!bdev)
8156 goto skip_bad_vf_detection;
8157
8158 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
8159 if (!pos)
8160 goto skip_bad_vf_detection;
8161
8162 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0);
8163 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1);
8164 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2);
8165 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3);
8166
8167 req_id = dw1 >> 16;
8168 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
8169 if (!(req_id & 0x0080))
8170 goto skip_bad_vf_detection;
8171
8172 pf_func = req_id & 0x01;
8173 if ((pf_func & 1) == (pdev->devfn & 1)) {
8174 unsigned int device_id;
8175
8176 vf = (req_id & 0x7F) >> 1;
8177 e_dev_err("VF %d has caused a PCIe error\n", vf);
8178 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
8179 "%8.8x\tdw3: %8.8x\n",
8180 dw0, dw1, dw2, dw3);
8181 switch (adapter->hw.mac.type) {
8182 case ixgbe_mac_82599EB:
8183 device_id = IXGBE_82599_VF_DEVICE_ID;
8184 break;
8185 case ixgbe_mac_X540:
8186 device_id = IXGBE_X540_VF_DEVICE_ID;
8187 break;
8188 default:
8189 device_id = 0;
8190 break;
8191 }
8192
8193 /* Find the pci device of the offending VF */
8194 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID, device_id, NULL);
8195 while (vfdev) {
8196 if (vfdev->devfn == (req_id & 0xFF))
8197 break;
8198 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID,
8199 device_id, vfdev);
8200 }
8201 /*
8202 * There's a slim chance the VF could have been hot plugged,
8203 * so if it is no longer present we don't need to issue the
8204 * VFLR. Just clean up the AER in that case.
8205 */
8206 if (vfdev) {
8207 e_dev_err("Issuing VFLR to VF %d\n", vf);
8208 pci_write_config_dword(vfdev, 0xA8, 0x00008000);
8209 }
8210
8211 pci_cleanup_aer_uncorrect_error_status(pdev);
8212 }
8213
8214 /*
8215 * Even though the error may have occurred on the other port
8216 * we still need to increment the vf error reference count for
8217 * both ports because the I/O resume function will be called
8218 * for both of them.
8219 */
8220 adapter->vferr_refcount++;
8221
8222 return PCI_ERS_RESULT_RECOVERED;
8223
8224skip_bad_vf_detection:
8225#endif /* CONFIG_PCI_IOV */
Auke Kok9a799d72007-09-15 14:07:45 -07008226 netif_device_detach(netdev);
8227
Breno Leitao3044b8d2009-05-06 10:44:26 +00008228 if (state == pci_channel_io_perm_failure)
8229 return PCI_ERS_RESULT_DISCONNECT;
8230
Auke Kok9a799d72007-09-15 14:07:45 -07008231 if (netif_running(netdev))
8232 ixgbe_down(adapter);
8233 pci_disable_device(pdev);
8234
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008235 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07008236 return PCI_ERS_RESULT_NEED_RESET;
8237}
8238
8239/**
8240 * ixgbe_io_slot_reset - called after the pci bus has been reset.
8241 * @pdev: Pointer to PCI device
8242 *
8243 * Restart the card from scratch, as if from a cold-boot.
8244 */
8245static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
8246{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008247 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008248 pci_ers_result_t result;
8249 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07008250
gouji-new9ce77662009-05-06 10:44:45 +00008251 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00008252 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008253 result = PCI_ERS_RESULT_DISCONNECT;
8254 } else {
8255 pci_set_master(pdev);
8256 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00008257 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008258
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07008259 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008260
8261 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00008262 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008263 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07008264 }
Auke Kok9a799d72007-09-15 14:07:45 -07008265
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008266 err = pci_cleanup_aer_uncorrect_error_status(pdev);
8267 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00008268 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
8269 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008270 /* non-fatal, continue */
8271 }
Auke Kok9a799d72007-09-15 14:07:45 -07008272
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008273 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07008274}
8275
8276/**
8277 * ixgbe_io_resume - called when traffic can start flowing again.
8278 * @pdev: Pointer to PCI device
8279 *
8280 * This callback is called when the error recovery driver tells us that
8281 * its OK to resume normal operation.
8282 */
8283static void ixgbe_io_resume(struct pci_dev *pdev)
8284{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008285 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8286 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008287
Greg Rose83c61fa2011-09-07 05:59:35 +00008288#ifdef CONFIG_PCI_IOV
8289 if (adapter->vferr_refcount) {
8290 e_info(drv, "Resuming after VF err\n");
8291 adapter->vferr_refcount--;
8292 return;
8293 }
8294
8295#endif
Alexander Duyckc7ccde02011-07-21 00:40:40 +00008296 if (netif_running(netdev))
8297 ixgbe_up(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008298
8299 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008300}
8301
8302static struct pci_error_handlers ixgbe_err_handler = {
8303 .error_detected = ixgbe_io_error_detected,
8304 .slot_reset = ixgbe_io_slot_reset,
8305 .resume = ixgbe_io_resume,
8306};
8307
8308static struct pci_driver ixgbe_driver = {
8309 .name = ixgbe_driver_name,
8310 .id_table = ixgbe_pci_tbl,
8311 .probe = ixgbe_probe,
8312 .remove = __devexit_p(ixgbe_remove),
8313#ifdef CONFIG_PM
8314 .suspend = ixgbe_suspend,
8315 .resume = ixgbe_resume,
8316#endif
8317 .shutdown = ixgbe_shutdown,
8318 .err_handler = &ixgbe_err_handler
8319};
8320
8321/**
8322 * ixgbe_init_module - Driver Registration Routine
8323 *
8324 * ixgbe_init_module is the first routine called when the driver is
8325 * loaded. All it does is register with the PCI subsystem.
8326 **/
8327static int __init ixgbe_init_module(void)
8328{
8329 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00008330 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00008331 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07008332
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008333#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008334 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008335#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008336
Auke Kok9a799d72007-09-15 14:07:45 -07008337 ret = pci_register_driver(&ixgbe_driver);
8338 return ret;
8339}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008340
Auke Kok9a799d72007-09-15 14:07:45 -07008341module_init(ixgbe_init_module);
8342
8343/**
8344 * ixgbe_exit_module - Driver Exit Cleanup Routine
8345 *
8346 * ixgbe_exit_module is called just before the driver is removed
8347 * from memory.
8348 **/
8349static void __exit ixgbe_exit_module(void)
8350{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008351#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008352 dca_unregister_notify(&dca_notifier);
8353#endif
Auke Kok9a799d72007-09-15 14:07:45 -07008354 pci_unregister_driver(&ixgbe_driver);
Eric Dumazet1a515022010-11-16 19:26:42 -08008355 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07008356}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008357
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008358#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008359static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00008360 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008361{
8362 int ret_val;
8363
8364 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00008365 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008366
8367 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
8368}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008369
Alexander Duyckb4533682009-03-31 21:32:42 +00008370#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00008371
Auke Kok9a799d72007-09-15 14:07:45 -07008372module_exit(ixgbe_exit_module);
8373
8374/* ixgbe_main.c */