blob: 79636eaeb74d160285d5d9f89f09ece0f2304a61 [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Don Skidmorea52055e2011-02-23 09:58:39 +00004 Copyright(c) 1999 - 2011 Intel Corporation.
Auke Kok9a799d72007-09-15 14:07:45 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
Auke Kok9a799d72007-09-15 14:07:45 -070023 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26*******************************************************************************/
27
28#include <linux/types.h>
29#include <linux/module.h>
30#include <linux/pci.h>
31#include <linux/netdevice.h>
32#include <linux/vmalloc.h>
33#include <linux/string.h>
34#include <linux/in.h>
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";
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000058#define MAJ 3
Don Skidmorea38a1042011-05-20 03:05:14 +000059#define MIN 4
Don Skidmorec89c7112011-04-14 07:40:11 +000060#define BUILD 8
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000061#define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
Don Skidmorea38a1042011-05-20 03:05:14 +000062 __stringify(BUILD) "-k"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070063const char ixgbe_driver_version[] = DRV_VERSION;
Don Skidmorea52055e2011-02-23 09:58:39 +000064static const char ixgbe_copyright[] =
65 "Copyright (c) 1999-2011 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070066
67static const struct ixgbe_info *ixgbe_info_tbl[] = {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070068 [board_82598] = &ixgbe_82598_info,
PJ Waskiewicze8e26352009-02-27 15:45:05 +000069 [board_82599] = &ixgbe_82599_info,
Don Skidmorefe15e8e12010-11-16 19:27:16 -080070 [board_X540] = &ixgbe_X540_info,
Auke Kok9a799d72007-09-15 14:07:45 -070071};
72
73/* ixgbe_pci_tbl - PCI Device ID Table
74 *
75 * Wildcard entries (PCI_ANY_ID) should come last
76 * Last entry must be all 0s
77 *
78 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
79 * Class, Class Mask, private data (not used) }
80 */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000081static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
Alexander Duyck54239c62011-07-15 03:06:06 +000082 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
83 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
84 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
85 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
86 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
87 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
88 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
89 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
90 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
91 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
92 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
93 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
94 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
95 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
96 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
97 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
98 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
99 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
100 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
102 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
Auke Kok9a799d72007-09-15 14:07:45 -0700108 /* required last entry */
109 {0, }
110};
111MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
112
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400113#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800114static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000115 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800116static struct notifier_block dca_notifier = {
117 .notifier_call = ixgbe_notify_dca,
118 .next = NULL,
119 .priority = 0
120};
121#endif
122
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000123#ifdef CONFIG_PCI_IOV
124static unsigned int max_vfs;
125module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000126MODULE_PARM_DESC(max_vfs,
127 "Maximum number of virtual functions to allocate per physical function");
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000128#endif /* CONFIG_PCI_IOV */
129
Auke Kok9a799d72007-09-15 14:07:45 -0700130MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
131MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
132MODULE_LICENSE("GPL");
133MODULE_VERSION(DRV_VERSION);
134
135#define DEFAULT_DEBUG_LEVEL_SHIFT 3
136
Alexander Duyck70864002011-04-27 09:13:56 +0000137static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
138{
139 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
140 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
141 schedule_work(&adapter->service_task);
142}
143
144static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
145{
146 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
147
148 /* flush memory to make sure state is correct before next watchog */
149 smp_mb__before_clear_bit();
150 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
151}
152
Taku Izumidcd79ae2010-04-27 14:39:53 +0000153struct ixgbe_reg_info {
154 u32 ofs;
155 char *name;
156};
157
158static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
159
160 /* General Registers */
161 {IXGBE_CTRL, "CTRL"},
162 {IXGBE_STATUS, "STATUS"},
163 {IXGBE_CTRL_EXT, "CTRL_EXT"},
164
165 /* Interrupt Registers */
166 {IXGBE_EICR, "EICR"},
167
168 /* RX Registers */
169 {IXGBE_SRRCTL(0), "SRRCTL"},
170 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
171 {IXGBE_RDLEN(0), "RDLEN"},
172 {IXGBE_RDH(0), "RDH"},
173 {IXGBE_RDT(0), "RDT"},
174 {IXGBE_RXDCTL(0), "RXDCTL"},
175 {IXGBE_RDBAL(0), "RDBAL"},
176 {IXGBE_RDBAH(0), "RDBAH"},
177
178 /* TX Registers */
179 {IXGBE_TDBAL(0), "TDBAL"},
180 {IXGBE_TDBAH(0), "TDBAH"},
181 {IXGBE_TDLEN(0), "TDLEN"},
182 {IXGBE_TDH(0), "TDH"},
183 {IXGBE_TDT(0), "TDT"},
184 {IXGBE_TXDCTL(0), "TXDCTL"},
185
186 /* List Terminator */
187 {}
188};
189
190
191/*
192 * ixgbe_regdump - register printout routine
193 */
194static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
195{
196 int i = 0, j = 0;
197 char rname[16];
198 u32 regs[64];
199
200 switch (reginfo->ofs) {
201 case IXGBE_SRRCTL(0):
202 for (i = 0; i < 64; i++)
203 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
204 break;
205 case IXGBE_DCA_RXCTRL(0):
206 for (i = 0; i < 64; i++)
207 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
208 break;
209 case IXGBE_RDLEN(0):
210 for (i = 0; i < 64; i++)
211 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
212 break;
213 case IXGBE_RDH(0):
214 for (i = 0; i < 64; i++)
215 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
216 break;
217 case IXGBE_RDT(0):
218 for (i = 0; i < 64; i++)
219 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
220 break;
221 case IXGBE_RXDCTL(0):
222 for (i = 0; i < 64; i++)
223 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
224 break;
225 case IXGBE_RDBAL(0):
226 for (i = 0; i < 64; i++)
227 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
228 break;
229 case IXGBE_RDBAH(0):
230 for (i = 0; i < 64; i++)
231 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
232 break;
233 case IXGBE_TDBAL(0):
234 for (i = 0; i < 64; i++)
235 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
236 break;
237 case IXGBE_TDBAH(0):
238 for (i = 0; i < 64; i++)
239 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
240 break;
241 case IXGBE_TDLEN(0):
242 for (i = 0; i < 64; i++)
243 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
244 break;
245 case IXGBE_TDH(0):
246 for (i = 0; i < 64; i++)
247 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
248 break;
249 case IXGBE_TDT(0):
250 for (i = 0; i < 64; i++)
251 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
252 break;
253 case IXGBE_TXDCTL(0):
254 for (i = 0; i < 64; i++)
255 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
256 break;
257 default:
Joe Perchesc7689572010-09-07 21:35:17 +0000258 pr_info("%-15s %08x\n", reginfo->name,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000259 IXGBE_READ_REG(hw, reginfo->ofs));
260 return;
261 }
262
263 for (i = 0; i < 8; i++) {
264 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
Joe Perchesc7689572010-09-07 21:35:17 +0000265 pr_err("%-15s", rname);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000266 for (j = 0; j < 8; j++)
Joe Perchesc7689572010-09-07 21:35:17 +0000267 pr_cont(" %08x", regs[i*8+j]);
268 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000269 }
270
271}
272
273/*
274 * ixgbe_dump - Print registers, tx-rings and rx-rings
275 */
276static void ixgbe_dump(struct ixgbe_adapter *adapter)
277{
278 struct net_device *netdev = adapter->netdev;
279 struct ixgbe_hw *hw = &adapter->hw;
280 struct ixgbe_reg_info *reginfo;
281 int n = 0;
282 struct ixgbe_ring *tx_ring;
283 struct ixgbe_tx_buffer *tx_buffer_info;
284 union ixgbe_adv_tx_desc *tx_desc;
285 struct my_u0 { u64 a; u64 b; } *u0;
286 struct ixgbe_ring *rx_ring;
287 union ixgbe_adv_rx_desc *rx_desc;
288 struct ixgbe_rx_buffer *rx_buffer_info;
289 u32 staterr;
290 int i = 0;
291
292 if (!netif_msg_hw(adapter))
293 return;
294
295 /* Print netdevice Info */
296 if (netdev) {
297 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000298 pr_info("Device Name state "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000299 "trans_start last_rx\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000300 pr_info("%-15s %016lX %016lX %016lX\n",
301 netdev->name,
302 netdev->state,
303 netdev->trans_start,
304 netdev->last_rx);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000305 }
306
307 /* Print Registers */
308 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000309 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000310 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
311 reginfo->name; reginfo++) {
312 ixgbe_regdump(hw, reginfo);
313 }
314
315 /* Print TX Ring Summary */
316 if (!netdev || !netif_running(netdev))
317 goto exit;
318
319 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000320 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000321 for (n = 0; n < adapter->num_tx_queues; n++) {
322 tx_ring = adapter->tx_ring[n];
323 tx_buffer_info =
324 &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Alexander Duyckd3d00232011-07-15 02:31:25 +0000325 pr_info(" %5d %5X %5X %016llX %04X %p %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000326 n, tx_ring->next_to_use, tx_ring->next_to_clean,
327 (u64)tx_buffer_info->dma,
328 tx_buffer_info->length,
329 tx_buffer_info->next_to_watch,
330 (u64)tx_buffer_info->time_stamp);
331 }
332
333 /* Print TX Rings */
334 if (!netif_msg_tx_done(adapter))
335 goto rx_ring_summary;
336
337 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
338
339 /* Transmit Descriptor Formats
340 *
341 * Advanced Transmit Descriptor
342 * +--------------------------------------------------------------+
343 * 0 | Buffer Address [63:0] |
344 * +--------------------------------------------------------------+
345 * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
346 * +--------------------------------------------------------------+
347 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
348 */
349
350 for (n = 0; n < adapter->num_tx_queues; n++) {
351 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000352 pr_info("------------------------------------\n");
353 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
354 pr_info("------------------------------------\n");
355 pr_info("T [desc] [address 63:0 ] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000356 "[PlPOIdStDDt Ln] [bi->dma ] "
357 "leng ntw timestamp bi->skb\n");
358
359 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duyck31f05a22010-08-19 13:40:31 +0000360 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000361 tx_buffer_info = &tx_ring->tx_buffer_info[i];
362 u0 = (struct my_u0 *)tx_desc;
Joe Perchesc7689572010-09-07 21:35:17 +0000363 pr_info("T [0x%03X] %016llX %016llX %016llX"
Alexander Duyckd3d00232011-07-15 02:31:25 +0000364 " %04X %p %016llX %p", i,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000365 le64_to_cpu(u0->a),
366 le64_to_cpu(u0->b),
367 (u64)tx_buffer_info->dma,
368 tx_buffer_info->length,
369 tx_buffer_info->next_to_watch,
370 (u64)tx_buffer_info->time_stamp,
371 tx_buffer_info->skb);
372 if (i == tx_ring->next_to_use &&
373 i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000374 pr_cont(" NTC/U\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000375 else if (i == tx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000376 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000377 else if (i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000378 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000379 else
Joe Perchesc7689572010-09-07 21:35:17 +0000380 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000381
382 if (netif_msg_pktdata(adapter) &&
383 tx_buffer_info->dma != 0)
384 print_hex_dump(KERN_INFO, "",
385 DUMP_PREFIX_ADDRESS, 16, 1,
386 phys_to_virt(tx_buffer_info->dma),
387 tx_buffer_info->length, true);
388 }
389 }
390
391 /* Print RX Rings Summary */
392rx_ring_summary:
393 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000394 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000395 for (n = 0; n < adapter->num_rx_queues; n++) {
396 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000397 pr_info("%5d %5X %5X\n",
398 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000399 }
400
401 /* Print RX Rings */
402 if (!netif_msg_rx_status(adapter))
403 goto exit;
404
405 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
406
407 /* Advanced Receive Descriptor (Read) Format
408 * 63 1 0
409 * +-----------------------------------------------------+
410 * 0 | Packet Buffer Address [63:1] |A0/NSE|
411 * +----------------------------------------------+------+
412 * 8 | Header Buffer Address [63:1] | DD |
413 * +-----------------------------------------------------+
414 *
415 *
416 * Advanced Receive Descriptor (Write-Back) Format
417 *
418 * 63 48 47 32 31 30 21 20 16 15 4 3 0
419 * +------------------------------------------------------+
420 * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
421 * | Checksum Ident | | | | Type | Type |
422 * +------------------------------------------------------+
423 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
424 * +------------------------------------------------------+
425 * 63 48 47 32 31 20 19 0
426 */
427 for (n = 0; n < adapter->num_rx_queues; n++) {
428 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000429 pr_info("------------------------------------\n");
430 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
431 pr_info("------------------------------------\n");
432 pr_info("R [desc] [ PktBuf A0] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000433 "[ HeadBuf DD] [bi->dma ] [bi->skb] "
434 "<-- Adv Rx Read format\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000435 pr_info("RWB[desc] [PcsmIpSHl PtRs] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000436 "[vl er S cks ln] ---------------- [bi->skb] "
437 "<-- Adv Rx Write-Back format\n");
438
439 for (i = 0; i < rx_ring->count; i++) {
440 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +0000441 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000442 u0 = (struct my_u0 *)rx_desc;
443 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
444 if (staterr & IXGBE_RXD_STAT_DD) {
445 /* Descriptor Done */
Joe Perchesc7689572010-09-07 21:35:17 +0000446 pr_info("RWB[0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000447 "%016llX ---------------- %p", i,
448 le64_to_cpu(u0->a),
449 le64_to_cpu(u0->b),
450 rx_buffer_info->skb);
451 } else {
Joe Perchesc7689572010-09-07 21:35:17 +0000452 pr_info("R [0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000453 "%016llX %016llX %p", i,
454 le64_to_cpu(u0->a),
455 le64_to_cpu(u0->b),
456 (u64)rx_buffer_info->dma,
457 rx_buffer_info->skb);
458
459 if (netif_msg_pktdata(adapter)) {
460 print_hex_dump(KERN_INFO, "",
461 DUMP_PREFIX_ADDRESS, 16, 1,
462 phys_to_virt(rx_buffer_info->dma),
463 rx_ring->rx_buf_len, true);
464
465 if (rx_ring->rx_buf_len
Alexander Duyck919e78a2011-08-26 09:52:38 +0000466 < IXGBE_RXBUFFER_2K)
Taku Izumidcd79ae2010-04-27 14:39:53 +0000467 print_hex_dump(KERN_INFO, "",
468 DUMP_PREFIX_ADDRESS, 16, 1,
469 phys_to_virt(
470 rx_buffer_info->page_dma +
471 rx_buffer_info->page_offset
472 ),
473 PAGE_SIZE/2, true);
474 }
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 Duyckd3d00232011-07-15 02:31:25 +0000583static inline void ixgbe_unmap_tx_resource(struct ixgbe_ring *ring,
584 struct ixgbe_tx_buffer *tx_buffer)
585{
586 if (tx_buffer->dma) {
587 if (tx_buffer->tx_flags & IXGBE_TX_FLAGS_MAPPED_AS_PAGE)
588 dma_unmap_page(ring->dev,
589 tx_buffer->dma,
590 tx_buffer->length,
591 DMA_TO_DEVICE);
592 else
593 dma_unmap_single(ring->dev,
594 tx_buffer->dma,
595 tx_buffer->length,
596 DMA_TO_DEVICE);
597 }
598 tx_buffer->dma = 0;
599}
600
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800601void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *tx_ring,
602 struct ixgbe_tx_buffer *tx_buffer_info)
Auke Kok9a799d72007-09-15 14:07:45 -0700603{
Alexander Duyckd3d00232011-07-15 02:31:25 +0000604 ixgbe_unmap_tx_resource(tx_ring, tx_buffer_info);
605 if (tx_buffer_info->skb)
Auke Kok9a799d72007-09-15 14:07:45 -0700606 dev_kfree_skb_any(tx_buffer_info->skb);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000607 tx_buffer_info->skb = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -0700608 /* tx_buffer_info must be completely set up in the transmit path */
609}
610
John Fastabendc84d3242010-11-16 19:27:12 -0800611static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700612{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700613 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800614 struct ixgbe_hw_stats *hwstats = &adapter->stats;
615 u32 data = 0;
616 u32 xoff[8] = {0};
617 int i;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700618
John Fastabendc84d3242010-11-16 19:27:12 -0800619 if ((hw->fc.current_mode == ixgbe_fc_full) ||
620 (hw->fc.current_mode == ixgbe_fc_rx_pause)) {
621 switch (hw->mac.type) {
622 case ixgbe_mac_82598EB:
623 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
624 break;
625 default:
626 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
627 }
628 hwstats->lxoffrxc += data;
629
630 /* refill credits (no tx hang) if we received xoff */
631 if (!data)
632 return;
633
634 for (i = 0; i < adapter->num_tx_queues; i++)
635 clear_bit(__IXGBE_HANG_CHECK_ARMED,
636 &adapter->tx_ring[i]->state);
637 return;
638 } else if (!(adapter->dcb_cfg.pfc_mode_enable))
639 return;
640
641 /* update stats for each tc, only valid with PFC enabled */
642 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
643 switch (hw->mac.type) {
644 case ixgbe_mac_82598EB:
645 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
646 break;
647 default:
648 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
649 }
650 hwstats->pxoffrxc[i] += xoff[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700651 }
652
John Fastabendc84d3242010-11-16 19:27:12 -0800653 /* disarm tx queues that have received xoff frames */
654 for (i = 0; i < adapter->num_tx_queues; i++) {
655 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendfb5475f2011-04-26 07:26:36 +0000656 u8 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800657
658 if (xoff[tc])
659 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
660 }
661}
662
663static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
664{
665 return ring->tx_stats.completed;
666}
667
668static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
669{
670 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
671 struct ixgbe_hw *hw = &adapter->hw;
672
673 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
674 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
675
676 if (head != tail)
677 return (head < tail) ?
678 tail - head : (tail + ring->count - head);
679
680 return 0;
681}
682
683static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
684{
685 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
686 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
687 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
688 bool ret = false;
689
690 clear_check_for_tx_hang(tx_ring);
691
692 /*
693 * Check for a hung queue, but be thorough. This verifies
694 * that a transmit has been completed since the previous
695 * check AND there is at least one packet pending. The
696 * ARMED bit is set to indicate a potential hang. The
697 * bit is cleared if a pause frame is received to remove
698 * false hang detection due to PFC or 802.3x frames. By
699 * requiring this to fail twice we avoid races with
700 * pfc clearing the ARMED bit and conditions where we
701 * run the check_tx_hang logic with a transmit completion
702 * pending but without time to complete it yet.
703 */
704 if ((tx_done_old == tx_done) && tx_pending) {
705 /* make sure it is true for two checks in a row */
706 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
707 &tx_ring->state);
708 } else {
709 /* update completed stats and continue */
710 tx_ring->tx_stats.tx_done_old = tx_done;
711 /* reset the countdown */
712 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
713 }
714
715 return ret;
Auke Kok9a799d72007-09-15 14:07:45 -0700716}
717
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000718/**
719 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
720 * @adapter: driver private struct
721 **/
722static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
723{
724
725 /* Do the reset outside of interrupt context */
726 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
727 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
728 ixgbe_service_event_schedule(adapter);
729 }
730}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700731
Auke Kok9a799d72007-09-15 14:07:45 -0700732/**
733 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000734 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700735 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700736 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000737static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +0000738 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700739{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000740 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000741 struct ixgbe_tx_buffer *tx_buffer;
742 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700743 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +0000744 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000745 u16 i = tx_ring->next_to_clean;
Auke Kok9a799d72007-09-15 14:07:45 -0700746
Alexander Duyckd3d00232011-07-15 02:31:25 +0000747 tx_buffer = &tx_ring->tx_buffer_info[i];
748 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800749
Alexander Duyck30065e62011-07-15 03:05:14 +0000750 for (; budget; budget--) {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000751 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -0700752
Alexander Duyckd3d00232011-07-15 02:31:25 +0000753 /* if next_to_watch is not set then there is no work pending */
754 if (!eop_desc)
755 break;
756
757 /* if DD is not set pending work has not been completed */
758 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
759 break;
760
761 /* count the packet as being completed */
762 tx_ring->tx_stats.completed++;
763
764 /* clear next_to_watch to prevent false hangs */
765 tx_buffer->next_to_watch = NULL;
766
767 /* prevent any other reads prior to eop_desc being verified */
768 rmb();
769
770 do {
771 ixgbe_unmap_tx_resource(tx_ring, tx_buffer);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800772 tx_desc->wb.status = 0;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000773 if (likely(tx_desc == eop_desc)) {
774 eop_desc = NULL;
775 dev_kfree_skb_any(tx_buffer->skb);
776 tx_buffer->skb = NULL;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800777
Alexander Duyckd3d00232011-07-15 02:31:25 +0000778 total_bytes += tx_buffer->bytecount;
779 total_packets += tx_buffer->gso_segs;
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800780 }
781
Alexander Duyckd3d00232011-07-15 02:31:25 +0000782 tx_buffer++;
783 tx_desc++;
784 i++;
785 if (unlikely(i == tx_ring->count)) {
786 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700787
Alexander Duyckd3d00232011-07-15 02:31:25 +0000788 tx_buffer = tx_ring->tx_buffer_info;
789 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, 0);
790 }
791
792 } while (eop_desc);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800793 }
794
Auke Kok9a799d72007-09-15 14:07:45 -0700795 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000796 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -0800797 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +0000798 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000799 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +0000800 q_vector->tx.total_bytes += total_bytes;
801 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -0800802
John Fastabendc84d3242010-11-16 19:27:12 -0800803 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -0800804 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -0800805 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000806 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
John Fastabendc84d3242010-11-16 19:27:12 -0800807 e_err(drv, "Detected Tx Unit Hang\n"
808 " Tx Queue <%d>\n"
809 " TDH, TDT <%x>, <%x>\n"
810 " next_to_use <%x>\n"
811 " next_to_clean <%x>\n"
812 "tx_buffer_info[next_to_clean]\n"
813 " time_stamp <%lx>\n"
814 " jiffies <%lx>\n",
815 tx_ring->queue_index,
816 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
817 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +0000818 tx_ring->next_to_use, i,
819 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -0800820
821 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
822
823 e_info(probe,
824 "tx hang %d detected on queue %d, resetting adapter\n",
825 adapter->tx_timeout_count + 1, tx_ring->queue_index);
826
827 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000828 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -0800829
830 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +0000831 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -0800832 }
Auke Kok9a799d72007-09-15 14:07:45 -0700833
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800834#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +0000835 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +0000836 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800837 /* Make sure that anybody stopping the queue after this
838 * sees the new next_to_clean.
839 */
840 smp_mb();
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800841 if (__netif_subqueue_stopped(tx_ring->netdev, tx_ring->queue_index) &&
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800842 !test_bit(__IXGBE_DOWN, &adapter->state)) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800843 netif_wake_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -0800844 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800845 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800846 }
Auke Kok9a799d72007-09-15 14:07:45 -0700847
Alexander Duyck59224552011-08-31 00:01:06 +0000848 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -0700849}
850
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400851#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800852static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800853 struct ixgbe_ring *rx_ring,
854 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800855{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800856 struct ixgbe_hw *hw = &adapter->hw;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800857 u32 rxctrl;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800858 u8 reg_idx = rx_ring->reg_idx;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800859
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800860 rxctrl = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(reg_idx));
861 switch (hw->mac.type) {
862 case ixgbe_mac_82598EB:
863 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
Alexander Duyck263a84e2011-07-15 03:05:46 +0000864 rxctrl |= dca3_get_tag(rx_ring->dev, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800865 break;
866 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800867 case ixgbe_mac_X540:
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800868 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
Alexander Duyck263a84e2011-07-15 03:05:46 +0000869 rxctrl |= (dca3_get_tag(rx_ring->dev, cpu) <<
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800870 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
871 break;
872 default:
873 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800874 }
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800875 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
876 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
877 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800878 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800879}
880
881static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800882 struct ixgbe_ring *tx_ring,
883 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800884{
Don Skidmoreee5f7842009-11-06 12:56:20 +0000885 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800886 u32 txctrl;
887 u8 reg_idx = tx_ring->reg_idx;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800888
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800889 switch (hw->mac.type) {
890 case ixgbe_mac_82598EB:
891 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(reg_idx));
892 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
Alexander Duyck263a84e2011-07-15 03:05:46 +0000893 txctrl |= dca3_get_tag(tx_ring->dev, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800894 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800895 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(reg_idx), txctrl);
896 break;
897 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800898 case ixgbe_mac_X540:
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800899 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx));
900 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
Alexander Duyck263a84e2011-07-15 03:05:46 +0000901 txctrl |= (dca3_get_tag(tx_ring->dev, cpu) <<
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800902 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
903 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800904 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx), txctrl);
905 break;
906 default:
907 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800908 }
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800909}
910
911static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
912{
913 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000914 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800915 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800916
917 if (q_vector->cpu == cpu)
918 goto out_no_update;
919
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000920 for (ring = q_vector->tx.ring; ring != NULL; ring = ring->next)
921 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800922
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000923 for (ring = q_vector->rx.ring; ring != NULL; ring = ring->next)
924 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800925
926 q_vector->cpu = cpu;
927out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800928 put_cpu();
929}
930
931static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
932{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800933 int num_q_vectors;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800934 int i;
935
936 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
937 return;
938
Alexander Duycke35ec122009-05-21 13:07:12 +0000939 /* always use CB2 mode, difference is masked in the CB driver */
940 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
941
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800942 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
943 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
944 else
945 num_q_vectors = 1;
946
947 for (i = 0; i < num_q_vectors; i++) {
948 adapter->q_vector[i]->cpu = -1;
949 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800950 }
951}
952
953static int __ixgbe_notify_dca(struct device *dev, void *data)
954{
Alexander Duyckc60fbb02010-11-16 19:26:54 -0800955 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800956 unsigned long event = *(unsigned long *)data;
957
Don Skidmore2a72c312011-07-20 02:27:05 +0000958 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800959 return 0;
960
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800961 switch (event) {
962 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700963 /* if we're already enabled, don't do it again */
964 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
965 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +0300966 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700967 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800968 ixgbe_setup_dca(adapter);
969 break;
970 }
971 /* Fall Through since DCA is disabled. */
972 case DCA_PROVIDER_REMOVE:
973 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
974 dca_remove_requester(dev);
975 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
976 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
977 }
978 break;
979 }
980
Denis V. Lunev652f0932008-03-27 14:39:17 +0300981 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800982}
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400983#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov67a74ee2011-04-23 04:50:40 +0000984
985static inline void ixgbe_rx_hash(union ixgbe_adv_rx_desc *rx_desc,
986 struct sk_buff *skb)
987{
988 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
989}
990
Auke Kok9a799d72007-09-15 14:07:45 -0700991/**
Alexander Duyckff886df2011-06-11 01:45:13 +0000992 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
993 * @adapter: address of board private structure
994 * @rx_desc: advanced rx descriptor
995 *
996 * Returns : true if it is FCoE pkt
997 */
998static inline bool ixgbe_rx_is_fcoe(struct ixgbe_adapter *adapter,
999 union ixgbe_adv_rx_desc *rx_desc)
1000{
1001 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1002
1003 return (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
1004 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1005 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1006 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1007}
1008
1009/**
Auke Kok9a799d72007-09-15 14:07:45 -07001010 * ixgbe_receive_skb - Send a completed packet up the stack
1011 * @adapter: board private structure
1012 * @skb: packet to send up
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001013 * @status: hardware indication of status of receive
1014 * @rx_ring: rx descriptor ring (for a specific queue) to setup
1015 * @rx_desc: rx descriptor
Auke Kok9a799d72007-09-15 14:07:45 -07001016 **/
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001017static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001018 struct sk_buff *skb, u8 status,
1019 struct ixgbe_ring *ring,
1020 union ixgbe_adv_rx_desc *rx_desc)
Auke Kok9a799d72007-09-15 14:07:45 -07001021{
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001022 struct ixgbe_adapter *adapter = q_vector->adapter;
1023 struct napi_struct *napi = &q_vector->napi;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001024 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
1025 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
Auke Kok9a799d72007-09-15 14:07:45 -07001026
Jesse Grossf62bbb52010-10-20 13:56:10 +00001027 if (is_vlan && (tag & VLAN_VID_MASK))
1028 __vlan_hwaccel_put_tag(skb, tag);
1029
1030 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1031 napi_gro_receive(napi, skb);
1032 else
1033 netif_rx(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001034}
1035
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001036/**
1037 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
1038 * @adapter: address of board private structure
1039 * @status_err: hardware indication of status of receive
1040 * @skb: skb currently being received and modified
Alexander Duyckff886df2011-06-11 01:45:13 +00001041 * @status_err: status error value of last descriptor in packet
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001042 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001043static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001044 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckff886df2011-06-11 01:45:13 +00001045 struct sk_buff *skb,
1046 u32 status_err)
Auke Kok9a799d72007-09-15 14:07:45 -07001047{
Alexander Duyckff886df2011-06-11 01:45:13 +00001048 skb->ip_summed = CHECKSUM_NONE;
Auke Kok9a799d72007-09-15 14:07:45 -07001049
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001050 /* Rx csum disabled */
1051 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07001052 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001053
1054 /* if IP and error */
1055 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
1056 (status_err & IXGBE_RXDADV_ERR_IPE)) {
Auke Kok9a799d72007-09-15 14:07:45 -07001057 adapter->hw_csum_rx_error++;
1058 return;
1059 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001060
1061 if (!(status_err & IXGBE_RXD_STAT_L4CS))
1062 return;
1063
1064 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
Don Skidmore8bae1b22009-07-23 18:00:39 +00001065 u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1066
1067 /*
1068 * 82599 errata, UDP frames with a 0 checksum can be marked as
1069 * checksum errors.
1070 */
1071 if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) &&
1072 (adapter->hw.mac.type == ixgbe_mac_82599EB))
1073 return;
1074
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001075 adapter->hw_csum_rx_error++;
1076 return;
1077 }
1078
Auke Kok9a799d72007-09-15 14:07:45 -07001079 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001080 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001081}
1082
Alexander Duyck84ea2592010-11-16 19:26:49 -08001083static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001084{
1085 /*
1086 * Force memory writes to complete before letting h/w
1087 * know there are new descriptors to fetch. (Only
1088 * applicable for weak-ordered memory model archs,
1089 * such as IA-64).
1090 */
1091 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001092 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001093}
1094
Auke Kok9a799d72007-09-15 14:07:45 -07001095/**
1096 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001097 * @rx_ring: ring to place buffers on
1098 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001099 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001100void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001101{
Auke Kok9a799d72007-09-15 14:07:45 -07001102 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001103 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001104 struct sk_buff *skb;
1105 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001106
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001107 /* do nothing if no valid netdev defined */
1108 if (!rx_ring->netdev)
1109 return;
1110
Auke Kok9a799d72007-09-15 14:07:45 -07001111 while (cleaned_count--) {
Alexander Duyck31f05a22010-08-19 13:40:31 +00001112 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001113 bi = &rx_ring->rx_buffer_info[i];
1114 skb = bi->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001115
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001116 if (!skb) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001117 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001118 rx_ring->rx_buf_len);
Auke Kok9a799d72007-09-15 14:07:45 -07001119 if (!skb) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001120 rx_ring->rx_stats.alloc_rx_buff_failed++;
Auke Kok9a799d72007-09-15 14:07:45 -07001121 goto no_buffers;
1122 }
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001123 /* initialize queue mapping */
1124 skb_record_rx_queue(skb, rx_ring->queue_index);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001125 bi->skb = skb;
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001126 }
Auke Kok9a799d72007-09-15 14:07:45 -07001127
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001128 if (!bi->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001129 bi->dma = dma_map_single(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001130 skb->data,
Joe Perchese8e9f692010-09-07 21:34:53 +00001131 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00001132 DMA_FROM_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001133 if (dma_mapping_error(rx_ring->dev, bi->dma)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001134 rx_ring->rx_stats.alloc_rx_buff_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001135 bi->dma = 0;
1136 goto no_buffers;
1137 }
Auke Kok9a799d72007-09-15 14:07:45 -07001138 }
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001139
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001140 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001141 if (!bi->page) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001142 bi->page = netdev_alloc_page(rx_ring->netdev);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001143 if (!bi->page) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001144 rx_ring->rx_stats.alloc_rx_page_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001145 goto no_buffers;
1146 }
1147 }
1148
1149 if (!bi->page_dma) {
1150 /* use a half page if we're re-using */
1151 bi->page_offset ^= PAGE_SIZE / 2;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001152 bi->page_dma = dma_map_page(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001153 bi->page,
1154 bi->page_offset,
1155 PAGE_SIZE / 2,
1156 DMA_FROM_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001157 if (dma_mapping_error(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001158 bi->page_dma)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001159 rx_ring->rx_stats.alloc_rx_page_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001160 bi->page_dma = 0;
1161 goto no_buffers;
1162 }
1163 }
1164
1165 /* Refresh the desc even if buffer_addrs didn't change
1166 * because each write-back erases this info. */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001167 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
1168 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07001169 } else {
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001170 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
Alexander Duyck84418e32010-08-19 13:40:54 +00001171 rx_desc->read.hdr_addr = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001172 }
1173
1174 i++;
1175 if (i == rx_ring->count)
1176 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001177 }
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001178
Auke Kok9a799d72007-09-15 14:07:45 -07001179no_buffers:
1180 if (rx_ring->next_to_use != i) {
1181 rx_ring->next_to_use = i;
Alexander Duyck84ea2592010-11-16 19:26:49 -08001182 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001183 }
1184}
1185
Alexander Duyckc267fc12010-11-16 19:27:00 -08001186static inline u16 ixgbe_get_hlen(union ixgbe_adv_rx_desc *rx_desc)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001187{
Alexander Duyckc267fc12010-11-16 19:27:00 -08001188 /* HW will not DMA in data larger than the given buffer, even if it
1189 * parses the (NFS, of course) header to be larger. In that case, it
1190 * fills the header buffer and spills the rest into the page.
1191 */
1192 u16 hdr_info = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.hdr_info);
1193 u16 hlen = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
1194 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
1195 if (hlen > IXGBE_RX_HDR_SIZE)
1196 hlen = IXGBE_RX_HDR_SIZE;
1197 return hlen;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001198}
1199
Alexander Duyckf8212f92009-04-27 22:42:37 +00001200/**
1201 * ixgbe_transform_rsc_queue - change rsc queue into a full packet
1202 * @skb: pointer to the last skb in the rsc queue
1203 *
1204 * This function changes a queue full of hw rsc buffers into a completed
1205 * packet. It uses the ->prev pointers to find the first packet and then
1206 * turns it into the frag list owner.
1207 **/
Alexander Duyckaa801752010-11-16 19:27:02 -08001208static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb)
Alexander Duyckf8212f92009-04-27 22:42:37 +00001209{
1210 unsigned int frag_list_size = 0;
Alexander Duyckaa801752010-11-16 19:27:02 -08001211 unsigned int skb_cnt = 1;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001212
1213 while (skb->prev) {
1214 struct sk_buff *prev = skb->prev;
1215 frag_list_size += skb->len;
1216 skb->prev = NULL;
1217 skb = prev;
Alexander Duyckaa801752010-11-16 19:27:02 -08001218 skb_cnt++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001219 }
1220
1221 skb_shinfo(skb)->frag_list = skb->next;
1222 skb->next = NULL;
1223 skb->len += frag_list_size;
1224 skb->data_len += frag_list_size;
1225 skb->truesize += frag_list_size;
Alexander Duyckaa801752010-11-16 19:27:02 -08001226 IXGBE_RSC_CB(skb)->skb_cnt = skb_cnt;
1227
Alexander Duyckf8212f92009-04-27 22:42:37 +00001228 return skb;
1229}
1230
Alexander Duyckaa801752010-11-16 19:27:02 -08001231static inline bool ixgbe_get_rsc_state(union ixgbe_adv_rx_desc *rx_desc)
1232{
1233 return !!(le32_to_cpu(rx_desc->wb.lower.lo_dword.data) &
1234 IXGBE_RXDADV_RSCCNT_MASK);
1235}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001236
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001237static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001238 struct ixgbe_ring *rx_ring,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001239 int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001240{
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001241 struct ixgbe_adapter *adapter = q_vector->adapter;
Auke Kok9a799d72007-09-15 14:07:45 -07001242 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
1243 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
1244 struct sk_buff *skb;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001245 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001246 const int current_node = numa_node_id();
Yi Zou3d8fd382009-06-08 14:38:44 +00001247#ifdef IXGBE_FCOE
1248 int ddp_bytes = 0;
1249#endif /* IXGBE_FCOE */
Alexander Duyckc267fc12010-11-16 19:27:00 -08001250 u32 staterr;
1251 u16 i;
1252 u16 cleaned_count = 0;
Alexander Duyckaa801752010-11-16 19:27:02 -08001253 bool pkt_is_rsc = false;
Auke Kok9a799d72007-09-15 14:07:45 -07001254
1255 i = rx_ring->next_to_clean;
Alexander Duyck31f05a22010-08-19 13:40:31 +00001256 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001257 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kok9a799d72007-09-15 14:07:45 -07001258
1259 while (staterr & IXGBE_RXD_STAT_DD) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001260 u32 upper_len = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001261
Milton Miller3c945e52010-02-19 17:44:42 +00001262 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kok9a799d72007-09-15 14:07:45 -07001263
Alexander Duyckc267fc12010-11-16 19:27:00 -08001264 rx_buffer_info = &rx_ring->rx_buffer_info[i];
1265
Auke Kok9a799d72007-09-15 14:07:45 -07001266 skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001267 rx_buffer_info->skb = NULL;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001268 prefetch(skb->data);
Auke Kok9a799d72007-09-15 14:07:45 -07001269
Alexander Duyckc267fc12010-11-16 19:27:00 -08001270 if (ring_is_rsc_enabled(rx_ring))
Alexander Duyckaa801752010-11-16 19:27:02 -08001271 pkt_is_rsc = ixgbe_get_rsc_state(rx_desc);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001272
David S. Miller8decf862011-09-22 03:23:13 -04001273 /* linear means we are building an skb from multiple pages */
1274 if (!skb_is_nonlinear(skb)) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001275 u16 hlen;
Alexander Duyckaa801752010-11-16 19:27:02 -08001276 if (pkt_is_rsc &&
Alexander Duyckc267fc12010-11-16 19:27:00 -08001277 !(staterr & IXGBE_RXD_STAT_EOP) &&
1278 !skb->prev) {
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001279 /*
1280 * When HWRSC is enabled, delay unmapping
1281 * of the first packet. It carries the
1282 * header information, HW may still
1283 * access the header after the writeback.
1284 * Only unmap it when EOP is reached
1285 */
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001286 IXGBE_RSC_CB(skb)->delay_unmap = true;
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001287 IXGBE_RSC_CB(skb)->dma = rx_buffer_info->dma;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001288 } else {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001289 dma_unmap_single(rx_ring->dev,
Joe Perchese8e9f692010-09-07 21:34:53 +00001290 rx_buffer_info->dma,
1291 rx_ring->rx_buf_len,
1292 DMA_FROM_DEVICE);
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001293 }
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00001294 rx_buffer_info->dma = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001295
1296 if (ring_is_ps_enabled(rx_ring)) {
1297 hlen = ixgbe_get_hlen(rx_desc);
1298 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
1299 } else {
1300 hlen = le16_to_cpu(rx_desc->wb.upper.length);
1301 }
1302
1303 skb_put(skb, hlen);
1304 } else {
1305 /* assume packet split since header is unmapped */
1306 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kok9a799d72007-09-15 14:07:45 -07001307 }
1308
1309 if (upper_len) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001310 dma_unmap_page(rx_ring->dev,
1311 rx_buffer_info->page_dma,
1312 PAGE_SIZE / 2,
1313 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001314 rx_buffer_info->page_dma = 0;
1315 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Joe Perchese8e9f692010-09-07 21:34:53 +00001316 rx_buffer_info->page,
1317 rx_buffer_info->page_offset,
1318 upper_len);
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001319
Alexander Duyckc267fc12010-11-16 19:27:00 -08001320 if ((page_count(rx_buffer_info->page) == 1) &&
1321 (page_to_nid(rx_buffer_info->page) == current_node))
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001322 get_page(rx_buffer_info->page);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001323 else
1324 rx_buffer_info->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001325
1326 skb->len += upper_len;
1327 skb->data_len += upper_len;
1328 skb->truesize += upper_len;
1329 }
1330
1331 i++;
1332 if (i == rx_ring->count)
1333 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001334
Alexander Duyck31f05a22010-08-19 13:40:31 +00001335 next_rxd = IXGBE_RX_DESC_ADV(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001336 prefetch(next_rxd);
Auke Kok9a799d72007-09-15 14:07:45 -07001337 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001338
Alexander Duyckaa801752010-11-16 19:27:02 -08001339 if (pkt_is_rsc) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00001340 u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >>
1341 IXGBE_RXDADV_NEXTP_SHIFT;
1342 next_buffer = &rx_ring->rx_buffer_info[nextp];
Alexander Duyckf8212f92009-04-27 22:42:37 +00001343 } else {
1344 next_buffer = &rx_ring->rx_buffer_info[i];
1345 }
1346
Alexander Duyckc267fc12010-11-16 19:27:00 -08001347 if (!(staterr & IXGBE_RXD_STAT_EOP)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001348 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00001349 rx_buffer_info->skb = next_buffer->skb;
1350 rx_buffer_info->dma = next_buffer->dma;
1351 next_buffer->skb = skb;
1352 next_buffer->dma = 0;
1353 } else {
1354 skb->next = next_buffer->skb;
1355 skb->next->prev = skb;
1356 }
Alexander Duyck5b7da512010-11-16 19:26:50 -08001357 rx_ring->rx_stats.non_eop_descs++;
Auke Kok9a799d72007-09-15 14:07:45 -07001358 goto next_desc;
1359 }
1360
Alexander Duyckaa801752010-11-16 19:27:02 -08001361 if (skb->prev) {
1362 skb = ixgbe_transform_rsc_queue(skb);
1363 /* if we got here without RSC the packet is invalid */
1364 if (!pkt_is_rsc) {
1365 __pskb_trim(skb, 0);
1366 rx_buffer_info->skb = skb;
1367 goto next_desc;
1368 }
1369 }
Alexander Duyckc267fc12010-11-16 19:27:00 -08001370
1371 if (ring_is_rsc_enabled(rx_ring)) {
1372 if (IXGBE_RSC_CB(skb)->delay_unmap) {
1373 dma_unmap_single(rx_ring->dev,
1374 IXGBE_RSC_CB(skb)->dma,
1375 rx_ring->rx_buf_len,
1376 DMA_FROM_DEVICE);
1377 IXGBE_RSC_CB(skb)->dma = 0;
1378 IXGBE_RSC_CB(skb)->delay_unmap = false;
1379 }
Alexander Duyckaa801752010-11-16 19:27:02 -08001380 }
1381 if (pkt_is_rsc) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001382 if (ring_is_ps_enabled(rx_ring))
1383 rx_ring->rx_stats.rsc_count +=
Alexander Duyckaa801752010-11-16 19:27:02 -08001384 skb_shinfo(skb)->nr_frags;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001385 else
Alexander Duyckaa801752010-11-16 19:27:02 -08001386 rx_ring->rx_stats.rsc_count +=
1387 IXGBE_RSC_CB(skb)->skb_cnt;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001388 rx_ring->rx_stats.rsc_flush++;
1389 }
1390
1391 /* ERR_MASK will only have valid bits if EOP set */
Alexander Duyckff886df2011-06-11 01:45:13 +00001392 if (unlikely(staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK)) {
1393 dev_kfree_skb_any(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001394 goto next_desc;
1395 }
1396
Alexander Duyckff886df2011-06-11 01:45:13 +00001397 ixgbe_rx_checksum(adapter, rx_desc, skb, staterr);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001398 if (adapter->netdev->features & NETIF_F_RXHASH)
1399 ixgbe_rx_hash(rx_desc, skb);
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001400
1401 /* probably a little skewed due to removing CRC */
1402 total_rx_bytes += skb->len;
1403 total_rx_packets++;
1404
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001405 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
Yi Zou332d4a72009-05-13 13:11:53 +00001406#ifdef IXGBE_FCOE
1407 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyckff886df2011-06-11 01:45:13 +00001408 if (ixgbe_rx_is_fcoe(adapter, rx_desc)) {
1409 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb,
1410 staterr);
David S. Miller823dcd22011-08-20 10:39:12 -07001411 if (!ddp_bytes) {
1412 dev_kfree_skb_any(skb);
Yi Zou332d4a72009-05-13 13:11:53 +00001413 goto next_desc;
David S. Miller823dcd22011-08-20 10:39:12 -07001414 }
Yi Zou3d8fd382009-06-08 14:38:44 +00001415 }
Yi Zou332d4a72009-05-13 13:11:53 +00001416#endif /* IXGBE_FCOE */
Alexander Duyckfdaff1c2009-05-06 10:43:47 +00001417 ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
Auke Kok9a799d72007-09-15 14:07:45 -07001418
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001419 budget--;
Auke Kok9a799d72007-09-15 14:07:45 -07001420next_desc:
1421 rx_desc->wb.upper.status_error = 0;
1422
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001423 if (!budget)
Alexander Duyckc267fc12010-11-16 19:27:00 -08001424 break;
1425
Auke Kok9a799d72007-09-15 14:07:45 -07001426 /* return some buffers to hardware, one at a time is too slow */
1427 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001428 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001429 cleaned_count = 0;
1430 }
1431
1432 /* use prefetched values */
1433 rx_desc = next_rxd;
Auke Kok9a799d72007-09-15 14:07:45 -07001434 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001435 }
1436
Auke Kok9a799d72007-09-15 14:07:45 -07001437 rx_ring->next_to_clean = i;
Alexander Duyck7d4987d2011-05-27 05:31:37 +00001438 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07001439
1440 if (cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001441 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001442
Yi Zou3d8fd382009-06-08 14:38:44 +00001443#ifdef IXGBE_FCOE
1444 /* include DDPed FCoE data */
1445 if (ddp_bytes > 0) {
1446 unsigned int mss;
1447
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001448 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
Yi Zou3d8fd382009-06-08 14:38:44 +00001449 sizeof(struct fc_frame_header) -
1450 sizeof(struct fcoe_crc_eof);
1451 if (mss > 512)
1452 mss &= ~511;
1453 total_rx_bytes += ddp_bytes;
1454 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1455 }
1456#endif /* IXGBE_FCOE */
1457
Alexander Duyckc267fc12010-11-16 19:27:00 -08001458 u64_stats_update_begin(&rx_ring->syncp);
1459 rx_ring->stats.packets += total_rx_packets;
1460 rx_ring->stats.bytes += total_rx_bytes;
1461 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001462 q_vector->rx.total_packets += total_rx_packets;
1463 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001464
1465 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001466}
1467
Auke Kok9a799d72007-09-15 14:07:45 -07001468/**
1469 * ixgbe_configure_msix - Configure MSI-X hardware
1470 * @adapter: board private structure
1471 *
1472 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1473 * interrupts.
1474 **/
1475static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1476{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001477 struct ixgbe_q_vector *q_vector;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001478 int q_vectors, v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001479 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001480
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001481 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1482
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00001483 /* Populate MSIX to EITR Select */
1484 if (adapter->num_vfs > 32) {
1485 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
1486 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
1487 }
1488
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001489 /*
1490 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001491 * corresponding register.
1492 */
1493 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001494 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00001495 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001496
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001497 for (ring = q_vector->rx.ring; ring != NULL; ring = ring->next)
1498 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001499
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001500 for (ring = q_vector->tx.ring; ring != NULL; ring = ring->next)
1501 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001502
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001503 if (q_vector->tx.ring && !q_vector->rx.ring) {
1504 /* tx only vector */
1505 if (adapter->tx_itr_setting == 1)
1506 q_vector->itr = IXGBE_10K_ITR;
1507 else
1508 q_vector->itr = adapter->tx_itr_setting;
1509 } else {
1510 /* rx or rx/tx vector */
1511 if (adapter->rx_itr_setting == 1)
1512 q_vector->itr = IXGBE_20K_ITR;
1513 else
1514 q_vector->itr = adapter->rx_itr_setting;
1515 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001516
Alexander Duyckfe49f042009-06-04 16:00:09 +00001517 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001518 }
1519
Alexander Duyckbd508172010-11-16 19:27:03 -08001520 switch (adapter->hw.mac.type) {
1521 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001522 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001523 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001524 break;
1525 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001526 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001527 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001528 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08001529 default:
1530 break;
1531 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001532 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001533
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001534 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001535 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001536 mask &= ~(IXGBE_EIMS_OTHER |
1537 IXGBE_EIMS_MAILBOX |
1538 IXGBE_EIMS_LSC);
1539
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001540 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001541}
1542
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001543enum latency_range {
1544 lowest_latency = 0,
1545 low_latency = 1,
1546 bulk_latency = 2,
1547 latency_invalid = 255
1548};
1549
1550/**
1551 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00001552 * @q_vector: structure containing interrupt and ring information
1553 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001554 *
1555 * Stores a new ITR value based on packets and byte
1556 * counts during the last interrupt. The advantage of per interrupt
1557 * computation is faster updates and more accurate ITR for the current
1558 * traffic pattern. Constants in this function were computed
1559 * based on theoretical maximum wire speed and thresholds were set based
1560 * on testing data as well as attempting to minimize response time
1561 * while increasing bulk throughput.
1562 * this functionality is controlled by the InterruptThrottleRate module
1563 * parameter (see ixgbe_param.c)
1564 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00001565static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
1566 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001567{
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001568 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00001569 struct ixgbe_adapter *adapter = q_vector->adapter;
1570 int bytes = ring_container->total_bytes;
1571 int packets = ring_container->total_packets;
1572 u32 timepassed_us;
1573 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001574
1575 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00001576 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001577
1578 /* simple throttlerate management
1579 * 0-20MB/s lowest (100000 ints/s)
1580 * 20-100MB/s low (20000 ints/s)
1581 * 100-1249MB/s bulk (8000 ints/s)
1582 */
1583 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001584 timepassed_us = q_vector->itr >> 2;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001585 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1586
1587 switch (itr_setting) {
1588 case lowest_latency:
1589 if (bytes_perint > adapter->eitr_low)
Alexander Duyckbd198052011-06-11 01:45:08 +00001590 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001591 break;
1592 case low_latency:
1593 if (bytes_perint > adapter->eitr_high)
Alexander Duyckbd198052011-06-11 01:45:08 +00001594 itr_setting = bulk_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001595 else if (bytes_perint <= adapter->eitr_low)
Alexander Duyckbd198052011-06-11 01:45:08 +00001596 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001597 break;
1598 case bulk_latency:
1599 if (bytes_perint <= adapter->eitr_high)
Alexander Duyckbd198052011-06-11 01:45:08 +00001600 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001601 break;
1602 }
1603
Alexander Duyckbd198052011-06-11 01:45:08 +00001604 /* clear work counters since we have the values we need */
1605 ring_container->total_bytes = 0;
1606 ring_container->total_packets = 0;
1607
1608 /* write updated itr to ring container */
1609 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001610}
1611
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001612/**
1613 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001614 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001615 *
1616 * This function is made to be called by ethtool and by the driver
1617 * when it needs to update EITR registers at runtime. Hardware
1618 * specific quirks/differences are taken care of here.
1619 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001620void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001621{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001622 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001623 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001624 int v_idx = q_vector->v_idx;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001625 u32 itr_reg = q_vector->itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001626
Alexander Duyckbd508172010-11-16 19:27:03 -08001627 switch (adapter->hw.mac.type) {
1628 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001629 /* must write high and low 16 bits to reset counter */
1630 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08001631 break;
1632 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001633 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001634 /*
1635 * set the WDIS bit to not clear the timer bits and cause an
1636 * immediate assertion of the interrupt
1637 */
1638 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08001639 break;
1640 default:
1641 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001642 }
1643 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1644}
1645
Alexander Duyckbd198052011-06-11 01:45:08 +00001646static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001647{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001648 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00001649 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001650
Alexander Duyckbd198052011-06-11 01:45:08 +00001651 ixgbe_update_itr(q_vector, &q_vector->tx);
1652 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001653
Alexander Duyck08c88332011-06-11 01:45:03 +00001654 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001655
1656 switch (current_itr) {
1657 /* counts and packets in update_itr are dependent on these numbers */
1658 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001659 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001660 break;
1661 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001662 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001663 break;
1664 case bulk_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001665 new_itr = IXGBE_8K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001666 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00001667 default:
1668 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001669 }
1670
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001671 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001672 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001673 new_itr = (10 * new_itr * q_vector->itr) /
1674 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001675
Alexander Duyckbd198052011-06-11 01:45:08 +00001676 /* save the algorithm value here */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001677 q_vector->itr = new_itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001678
1679 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001680 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001681}
1682
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001683/**
Alexander Duyckf0f97782011-04-22 04:08:09 +00001684 * ixgbe_check_overtemp_subtask - check for over tempurature
1685 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001686 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00001687static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001688{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001689 struct ixgbe_hw *hw = &adapter->hw;
1690 u32 eicr = adapter->interrupt_event;
1691
Alexander Duyckf0f97782011-04-22 04:08:09 +00001692 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00001693 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001694
Alexander Duyckf0f97782011-04-22 04:08:09 +00001695 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1696 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
1697 return;
1698
1699 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1700
Joe Perches7ca647b2010-09-07 21:35:40 +00001701 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00001702 case IXGBE_DEV_ID_82599_T3_LOM:
1703 /*
1704 * Since the warning interrupt is for both ports
1705 * we don't have to check if:
1706 * - This interrupt wasn't for our port.
1707 * - We may have missed the interrupt so always have to
1708 * check if we got a LSC
1709 */
1710 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
1711 !(eicr & IXGBE_EICR_LSC))
1712 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001713
Alexander Duyckf0f97782011-04-22 04:08:09 +00001714 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
1715 u32 autoneg;
1716 bool link_up = false;
1717
Joe Perches7ca647b2010-09-07 21:35:40 +00001718 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
1719
Alexander Duyckf0f97782011-04-22 04:08:09 +00001720 if (link_up)
1721 return;
1722 }
1723
1724 /* Check if this is not due to overtemp */
1725 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
1726 return;
1727
1728 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00001729 default:
1730 if (!(eicr & IXGBE_EICR_GPI_SDP0))
1731 return;
1732 break;
1733 }
1734 e_crit(drv,
1735 "Network adapter has been stopped because it has over heated. "
1736 "Restart the computer. If the problem persists, "
1737 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00001738
1739 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001740}
1741
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001742static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1743{
1744 struct ixgbe_hw *hw = &adapter->hw;
1745
1746 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1747 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00001748 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001749 /* write to clear the interrupt */
1750 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1751 }
1752}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001753
Jacob Keller4f51bf72011-08-20 04:49:45 +00001754static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
1755{
1756 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
1757 return;
1758
1759 switch (adapter->hw.mac.type) {
1760 case ixgbe_mac_82599EB:
1761 /*
1762 * Need to check link state so complete overtemp check
1763 * on service task
1764 */
1765 if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) &&
1766 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
1767 adapter->interrupt_event = eicr;
1768 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1769 ixgbe_service_event_schedule(adapter);
1770 return;
1771 }
1772 return;
1773 case ixgbe_mac_X540:
1774 if (!(eicr & IXGBE_EICR_TS))
1775 return;
1776 break;
1777 default:
1778 return;
1779 }
1780
1781 e_crit(drv,
1782 "Network adapter has been stopped because it has over heated. "
1783 "Restart the computer. If the problem persists, "
1784 "power off the system and replace the adapter\n");
1785}
1786
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001787static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1788{
1789 struct ixgbe_hw *hw = &adapter->hw;
1790
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001791 if (eicr & IXGBE_EICR_GPI_SDP2) {
1792 /* Clear the interrupt */
1793 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00001794 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1795 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
1796 ixgbe_service_event_schedule(adapter);
1797 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001798 }
1799
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001800 if (eicr & IXGBE_EICR_GPI_SDP1) {
1801 /* Clear the interrupt */
1802 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00001803 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1804 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
1805 ixgbe_service_event_schedule(adapter);
1806 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001807 }
1808}
1809
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001810static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
1811{
1812 struct ixgbe_hw *hw = &adapter->hw;
1813
1814 adapter->lsc_int++;
1815 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1816 adapter->link_check_timeout = jiffies;
1817 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1818 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00001819 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00001820 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001821 }
1822}
1823
Alexander Duyckfe49f042009-06-04 16:00:09 +00001824static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
1825 u64 qmask)
1826{
1827 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08001828 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001829
Alexander Duyckbd508172010-11-16 19:27:03 -08001830 switch (hw->mac.type) {
1831 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001832 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08001833 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
1834 break;
1835 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001836 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001837 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08001838 if (mask)
1839 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00001840 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08001841 if (mask)
1842 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
1843 break;
1844 default:
1845 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001846 }
1847 /* skip the flush */
1848}
1849
1850static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00001851 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00001852{
1853 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08001854 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001855
Alexander Duyckbd508172010-11-16 19:27:03 -08001856 switch (hw->mac.type) {
1857 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001858 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08001859 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
1860 break;
1861 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001862 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001863 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08001864 if (mask)
1865 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00001866 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08001867 if (mask)
1868 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
1869 break;
1870 default:
1871 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001872 }
1873 /* skip the flush */
1874}
1875
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001876/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00001877 * ixgbe_irq_enable - Enable default interrupt generation settings
1878 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001879 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00001880static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
1881 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07001882{
Alexander Duyck2c4af692011-07-15 07:29:55 +00001883 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001884
Alexander Duyck2c4af692011-07-15 07:29:55 +00001885 /* don't reenable LSC while waiting for link */
1886 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
1887 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001888
Alexander Duyck2c4af692011-07-15 07:29:55 +00001889 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00001890 switch (adapter->hw.mac.type) {
1891 case ixgbe_mac_82599EB:
1892 mask |= IXGBE_EIMS_GPI_SDP0;
1893 break;
1894 case ixgbe_mac_X540:
1895 mask |= IXGBE_EIMS_TS;
1896 break;
1897 default:
1898 break;
1899 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00001900 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
1901 mask |= IXGBE_EIMS_GPI_SDP1;
1902 switch (adapter->hw.mac.type) {
1903 case ixgbe_mac_82599EB:
Alexander Duyck2c4af692011-07-15 07:29:55 +00001904 mask |= IXGBE_EIMS_GPI_SDP1;
1905 mask |= IXGBE_EIMS_GPI_SDP2;
Don Skidmore858bc082011-08-04 09:28:30 +00001906 case ixgbe_mac_X540:
1907 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00001908 mask |= IXGBE_EIMS_MAILBOX;
1909 break;
1910 default:
1911 break;
1912 }
1913 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
1914 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
1915 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001916
Alexander Duyck2c4af692011-07-15 07:29:55 +00001917 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
1918 if (queues)
1919 ixgbe_irq_enable_queues(adapter, ~0);
1920 if (flush)
1921 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07001922}
1923
Alexander Duyck2c4af692011-07-15 07:29:55 +00001924static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001925{
Alexander Duyck2c4af692011-07-15 07:29:55 +00001926 struct ixgbe_adapter *adapter = data;
1927 struct ixgbe_hw *hw = &adapter->hw;
1928 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00001929
Alexander Duyck2c4af692011-07-15 07:29:55 +00001930 /*
1931 * Workaround for Silicon errata. Use clear-by-write instead
1932 * of clear-by-read. Reading with EICS will return the
1933 * interrupt causes without clearing, which later be done
1934 * with the write to EICR.
1935 */
1936 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1937 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00001938
Alexander Duyck2c4af692011-07-15 07:29:55 +00001939 if (eicr & IXGBE_EICR_LSC)
1940 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001941
Alexander Duyck2c4af692011-07-15 07:29:55 +00001942 if (eicr & IXGBE_EICR_MAILBOX)
1943 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001944
Alexander Duyck2c4af692011-07-15 07:29:55 +00001945 switch (hw->mac.type) {
1946 case ixgbe_mac_82599EB:
1947 case ixgbe_mac_X540:
1948 if (eicr & IXGBE_EICR_ECC)
1949 e_info(link, "Received unrecoverable ECC Err, please "
1950 "reboot\n");
1951 /* Handle Flow Director Full threshold interrupt */
1952 if (eicr & IXGBE_EICR_FLOW_DIR) {
1953 int reinit_count = 0;
1954 int i;
1955 for (i = 0; i < adapter->num_tx_queues; i++) {
1956 struct ixgbe_ring *ring = adapter->tx_ring[i];
1957 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
1958 &ring->state))
1959 reinit_count++;
1960 }
1961 if (reinit_count) {
1962 /* no more flow director interrupts until after init */
1963 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
1964 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
1965 ixgbe_service_event_schedule(adapter);
1966 }
1967 }
1968 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00001969 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00001970 break;
1971 default:
1972 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001973 }
1974
Alexander Duyck2c4af692011-07-15 07:29:55 +00001975 ixgbe_check_fan_failure(adapter, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07001976
Alexander Duyck2c4af692011-07-15 07:29:55 +00001977 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001978 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00001979 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00001980
Alexander Duyck2c4af692011-07-15 07:29:55 +00001981 return IRQ_HANDLED;
1982}
1983
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001984static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07001985{
1986 struct ixgbe_q_vector *q_vector = data;
1987
Auke Kok9a799d72007-09-15 14:07:45 -07001988 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001989
1990 if (q_vector->rx.ring || q_vector->tx.ring)
1991 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07001992
1993 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00001994}
1995
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001996static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001997 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07001998{
Alexander Duyck7a921c92009-05-06 10:43:28 +00001999 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002000 struct ixgbe_ring *rx_ring = a->rx_ring[r_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002001
Alexander Duyck22745432010-11-16 19:27:10 -08002002 rx_ring->q_vector = q_vector;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002003 rx_ring->next = q_vector->rx.ring;
2004 q_vector->rx.ring = rx_ring;
2005 q_vector->rx.count++;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002006}
Auke Kok9a799d72007-09-15 14:07:45 -07002007
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002008static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002009 int t_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002010{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002011 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002012 struct ixgbe_ring *tx_ring = a->tx_ring[t_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002013
Alexander Duyck22745432010-11-16 19:27:10 -08002014 tx_ring->q_vector = q_vector;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002015 tx_ring->next = q_vector->tx.ring;
2016 q_vector->tx.ring = tx_ring;
2017 q_vector->tx.count++;
Alexander Duyckbd198052011-06-11 01:45:08 +00002018 q_vector->tx.work_limit = a->tx_work_limit;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002019}
Auke Kok9a799d72007-09-15 14:07:45 -07002020
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002021/**
2022 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
2023 * @adapter: board private structure to initialize
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002024 *
2025 * This function maps descriptor rings to the queue-specific vectors
2026 * we were allotted through the MSI-X enabling code. Ideally, we'd have
2027 * one vector per ring/queue, but on a constrained vector budget, we
2028 * group the rings as "efficiently" as possible. You would add new
2029 * mapping configurations in here.
2030 **/
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002031static void ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002032{
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002033 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2034 int rxr_remaining = adapter->num_rx_queues, rxr_idx = 0;
2035 int txr_remaining = adapter->num_tx_queues, txr_idx = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002036 int v_start = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002037
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002038 /* only one q_vector if MSI-X is disabled. */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002039 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002040 q_vectors = 1;
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002041
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002042 /*
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002043 * If we don't have enough vectors for a 1-to-1 mapping, we'll have to
2044 * group them so there are multiple queues per vector.
2045 *
2046 * Re-adjusting *qpv takes care of the remainder.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002047 */
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002048 for (; v_start < q_vectors && rxr_remaining; v_start++) {
2049 int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - v_start);
2050 for (; rqpv; rqpv--, rxr_idx++, rxr_remaining--)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002051 map_vector_to_rxq(adapter, v_start, rxr_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002052 }
2053
2054 /*
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002055 * If there are not enough q_vectors for each ring to have it's own
2056 * vector then we must pair up Rx/Tx on a each vector
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002057 */
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002058 if ((v_start + txr_remaining) > q_vectors)
2059 v_start = 0;
2060
2061 for (; v_start < q_vectors && txr_remaining; v_start++) {
2062 int tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - v_start);
2063 for (; tqpv; tqpv--, txr_idx++, txr_remaining--)
2064 map_vector_to_txq(adapter, v_start, txr_idx);
Auke Kok9a799d72007-09-15 14:07:45 -07002065 }
Auke Kok9a799d72007-09-15 14:07:45 -07002066}
2067
2068/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002069 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2070 * @adapter: board private structure
2071 *
2072 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2073 * interrupts from the kernel.
2074 **/
2075static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2076{
2077 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002078 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2079 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002080 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002081
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002082 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002083 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002084 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002085
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002086 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002087 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002088 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002089 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002090 } else if (q_vector->rx.ring) {
2091 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2092 "%s-%s-%d", netdev->name, "rx", ri++);
2093 } else if (q_vector->tx.ring) {
2094 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2095 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002096 } else {
2097 /* skip this unused q_vector */
2098 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002099 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002100 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2101 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002102 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002103 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002104 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002105 goto free_queue_irqs;
2106 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002107 /* If Flow Director is enabled, set interrupt affinity */
2108 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2109 /* assign the mask for this irq */
2110 irq_set_affinity_hint(entry->vector,
2111 q_vector->affinity_mask);
2112 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002113 }
2114
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002115 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00002116 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002117 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002118 e_err(probe, "request_irq for msix_lsc failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002119 goto free_queue_irqs;
2120 }
2121
2122 return 0;
2123
2124free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00002125 while (vector) {
2126 vector--;
2127 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2128 NULL);
2129 free_irq(adapter->msix_entries[vector].vector,
2130 adapter->q_vector[vector]);
2131 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002132 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2133 pci_disable_msix(adapter->pdev);
2134 kfree(adapter->msix_entries);
2135 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002136 return err;
2137}
2138
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002139/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002140 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002141 * @irq: interrupt number
2142 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002143 **/
2144static irqreturn_t ixgbe_intr(int irq, void *data)
2145{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002146 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002147 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002148 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002149 u32 eicr;
2150
Don Skidmore54037502009-02-21 15:42:56 -08002151 /*
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002152 * Workaround for silicon errata on 82598. Mask the interrupts
Don Skidmore54037502009-02-21 15:42:56 -08002153 * before the read of EICR.
2154 */
2155 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2156
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002157 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
2158 * therefore no explict interrupt disable is necessary */
2159 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002160 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002161 /*
2162 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002163 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002164 * have disabled interrupts due to EIAM
2165 * finish the workaround of silicon errata on 82598. Unmask
2166 * the interrupt that we masked before the EICR read.
2167 */
2168 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2169 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002170 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002171 }
Auke Kok9a799d72007-09-15 14:07:45 -07002172
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002173 if (eicr & IXGBE_EICR_LSC)
2174 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002175
Alexander Duyckbd508172010-11-16 19:27:03 -08002176 switch (hw->mac.type) {
2177 case ixgbe_mac_82599EB:
Jacob Keller4f51bf72011-08-20 04:49:45 +00002178 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002179 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002180 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002181 break;
2182 default:
2183 break;
2184 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002185
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002186 ixgbe_check_fan_failure(adapter, eicr);
2187
Alexander Duyck7a921c92009-05-06 10:43:28 +00002188 if (napi_schedule_prep(&(q_vector->napi))) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002189 /* would disable interrupts here but EIAM disabled it */
Alexander Duyck7a921c92009-05-06 10:43:28 +00002190 __napi_schedule(&(q_vector->napi));
Auke Kok9a799d72007-09-15 14:07:45 -07002191 }
2192
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002193 /*
2194 * re-enable link(maybe) and non-queue interrupts, no flush.
2195 * ixgbe_poll will re-enable the queue interrupts
2196 */
2197
2198 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2199 ixgbe_irq_enable(adapter, false, false);
2200
Auke Kok9a799d72007-09-15 14:07:45 -07002201 return IRQ_HANDLED;
2202}
2203
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002204static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
2205{
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002206 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2207 int i;
2208
2209 /* legacy and MSI only use one vector */
2210 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2211 q_vectors = 1;
2212
2213 for (i = 0; i < adapter->num_rx_queues; i++) {
2214 adapter->rx_ring[i]->q_vector = NULL;
2215 adapter->rx_ring[i]->next = NULL;
2216 }
2217 for (i = 0; i < adapter->num_tx_queues; i++) {
2218 adapter->tx_ring[i]->q_vector = NULL;
2219 adapter->tx_ring[i]->next = NULL;
2220 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002221
2222 for (i = 0; i < q_vectors; i++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00002223 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002224 memset(&q_vector->rx, 0, sizeof(struct ixgbe_ring_container));
2225 memset(&q_vector->tx, 0, sizeof(struct ixgbe_ring_container));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002226 }
2227}
2228
Auke Kok9a799d72007-09-15 14:07:45 -07002229/**
2230 * ixgbe_request_irq - initialize interrupts
2231 * @adapter: board private structure
2232 *
2233 * Attempts to configure interrupts using the best available
2234 * capabilities of the hardware and kernel.
2235 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002236static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002237{
2238 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002239 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002240
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002241 /* map all of the rings to the q_vectors */
2242 ixgbe_map_rings_to_vectors(adapter);
2243
2244 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002245 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002246 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08002247 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002248 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002249 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08002250 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002251 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002252
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002253 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002254 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002255
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002256 /* place q_vectors and rings back into a known good state */
2257 ixgbe_reset_q_vectors(adapter);
2258 }
2259
Auke Kok9a799d72007-09-15 14:07:45 -07002260 return err;
2261}
2262
2263static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2264{
Auke Kok9a799d72007-09-15 14:07:45 -07002265 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002266 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07002267
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002268 q_vectors = adapter->num_msix_vectors;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002269 i = q_vectors - 1;
Alexander Duycka65151ba22011-05-27 05:31:32 +00002270 free_irq(adapter->msix_entries[i].vector, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002271 i--;
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002272
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002273 for (; i >= 0; i--) {
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002274 /* free only the irqs that were actually requested */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002275 if (!adapter->q_vector[i]->rx.ring &&
2276 !adapter->q_vector[i]->tx.ring)
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002277 continue;
2278
Alexander Duyck207867f2011-07-15 03:05:37 +00002279 /* clear the affinity_mask in the IRQ descriptor */
2280 irq_set_affinity_hint(adapter->msix_entries[i].vector,
2281 NULL);
2282
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002283 free_irq(adapter->msix_entries[i].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002284 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002285 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002286 } else {
Alexander Duycka65151ba22011-05-27 05:31:32 +00002287 free_irq(adapter->pdev->irq, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002288 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002289
2290 /* clear q_vector state information */
2291 ixgbe_reset_q_vectors(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002292}
2293
2294/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002295 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2296 * @adapter: board private structure
2297 **/
2298static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2299{
Alexander Duyckbd508172010-11-16 19:27:03 -08002300 switch (adapter->hw.mac.type) {
2301 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002302 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002303 break;
2304 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002305 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002306 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2307 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002308 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002309 break;
2310 default:
2311 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002312 }
2313 IXGBE_WRITE_FLUSH(&adapter->hw);
2314 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2315 int i;
2316 for (i = 0; i < adapter->num_msix_vectors; i++)
2317 synchronize_irq(adapter->msix_entries[i].vector);
2318 } else {
2319 synchronize_irq(adapter->pdev->irq);
2320 }
2321}
2322
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002323/**
Auke Kok9a799d72007-09-15 14:07:45 -07002324 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2325 *
2326 **/
2327static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2328{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002329 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002330
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002331 /* rx/tx vector */
2332 if (adapter->rx_itr_setting == 1)
2333 q_vector->itr = IXGBE_20K_ITR;
2334 else
2335 q_vector->itr = adapter->rx_itr_setting;
2336
2337 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002338
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002339 ixgbe_set_ivar(adapter, 0, 0, 0);
2340 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002341
Emil Tantilov396e7992010-07-01 20:05:12 +00002342 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002343}
2344
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002345/**
2346 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2347 * @adapter: board private structure
2348 * @ring: structure containing ring specific data
2349 *
2350 * Configure the Tx descriptor ring after a reset.
2351 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002352void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2353 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002354{
2355 struct ixgbe_hw *hw = &adapter->hw;
2356 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002357 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002358 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002359 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002360
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002361 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002362 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002363 IXGBE_WRITE_FLUSH(hw);
2364
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002365 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002366 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002367 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2368 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2369 ring->count * sizeof(union ixgbe_adv_tx_desc));
2370 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2371 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002372 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002373
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002374 /*
2375 * set WTHRESH to encourage burst writeback, it should not be set
2376 * higher than 1 when ITR is 0 as it could cause false TX hangs
2377 *
2378 * In order to avoid issues WTHRESH + PTHRESH should always be equal
2379 * to or less than the number of on chip descriptors, which is
2380 * currently 40.
2381 */
2382 if (!adapter->tx_itr_setting || !adapter->rx_itr_setting)
2383 txdctl |= (1 << 16); /* WTHRESH = 1 */
2384 else
2385 txdctl |= (8 << 16); /* WTHRESH = 8 */
2386
2387 /* PTHRESH=32 is needed to avoid a Tx hang with DFP enabled. */
2388 txdctl |= (1 << 8) | /* HTHRESH = 1 */
2389 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002390
2391 /* reinitialize flowdirector state */
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002392 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2393 adapter->atr_sample_rate) {
2394 ring->atr_sample_rate = adapter->atr_sample_rate;
2395 ring->atr_count = 0;
2396 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2397 } else {
2398 ring->atr_sample_rate = 0;
2399 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002400
John Fastabendc84d3242010-11-16 19:27:12 -08002401 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2402
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002403 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002404 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2405
2406 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2407 if (hw->mac.type == ixgbe_mac_82598EB &&
2408 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2409 return;
2410
2411 /* poll to verify queue is enabled */
2412 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002413 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002414 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2415 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2416 if (!wait_loop)
2417 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002418}
2419
Alexander Duyck120ff942010-08-19 13:34:50 +00002420static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2421{
2422 struct ixgbe_hw *hw = &adapter->hw;
2423 u32 rttdcs;
John Fastabend72a32f12011-04-26 07:25:58 +00002424 u32 reg;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002425 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00002426
2427 if (hw->mac.type == ixgbe_mac_82598EB)
2428 return;
2429
2430 /* disable the arbiter while setting MTQC */
2431 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2432 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2433 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2434
2435 /* set transmit pool layout */
John Fastabend8b1c0b22011-05-03 02:26:48 +00002436 switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Alexander Duyck120ff942010-08-19 13:34:50 +00002437 case (IXGBE_FLAG_SRIOV_ENABLED):
2438 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2439 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2440 break;
Alexander Duyck120ff942010-08-19 13:34:50 +00002441 default:
John Fastabend8b1c0b22011-05-03 02:26:48 +00002442 if (!tcs)
2443 reg = IXGBE_MTQC_64Q_1PB;
2444 else if (tcs <= 4)
2445 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2446 else
2447 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2448
2449 IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
2450
2451 /* Enable Security TX Buffer IFG for multiple pb */
2452 if (tcs) {
2453 reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2454 reg |= IXGBE_SECTX_DCB;
2455 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
2456 }
Alexander Duyck120ff942010-08-19 13:34:50 +00002457 break;
2458 }
2459
2460 /* re-enable the arbiter */
2461 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2462 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2463}
2464
Auke Kok9a799d72007-09-15 14:07:45 -07002465/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002466 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002467 * @adapter: board private structure
2468 *
2469 * Configure the Tx unit of the MAC after a reset.
2470 **/
2471static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2472{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002473 struct ixgbe_hw *hw = &adapter->hw;
2474 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002475 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002476
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002477 ixgbe_setup_mtqc(adapter);
2478
2479 if (hw->mac.type != ixgbe_mac_82598EB) {
2480 /* DMATXCTL.EN must be before Tx queues are enabled */
2481 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2482 dmatxctl |= IXGBE_DMATXCTL_TE;
2483 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2484 }
2485
Auke Kok9a799d72007-09-15 14:07:45 -07002486 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002487 for (i = 0; i < adapter->num_tx_queues; i++)
2488 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002489}
2490
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002491#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002492
Yi Zoua6616b42009-08-06 13:05:23 +00002493static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002494 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002495{
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002496 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002497 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002498
Alexander Duyckbd508172010-11-16 19:27:03 -08002499 switch (adapter->hw.mac.type) {
2500 case ixgbe_mac_82598EB: {
2501 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2502 const int mask = feature[RING_F_RSS].mask;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002503 reg_idx = reg_idx & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002504 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002505 break;
2506 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002507 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08002508 default:
2509 break;
2510 }
2511
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002512 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002513
2514 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2515 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002516 if (adapter->num_vfs)
2517 srrctl |= IXGBE_SRRCTL_DROP_EN;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002518
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002519 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2520 IXGBE_SRRCTL_BSIZEHDR_MASK;
2521
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002522 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002523#if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
2524 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2525#else
2526 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2527#endif
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002528 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002529 } else {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002530 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
2531 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002532 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002533 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002534
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002535 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002536}
2537
Alexander Duyck05abb122010-08-19 13:35:41 +00002538static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002539{
Alexander Duyck05abb122010-08-19 13:35:41 +00002540 struct ixgbe_hw *hw = &adapter->hw;
2541 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00002542 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2543 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00002544 u32 mrqc = 0, reta = 0;
2545 u32 rxcsum;
2546 int i, j;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002547 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend86b4db32011-04-26 07:26:19 +00002548 int maxq = adapter->ring_feature[RING_F_RSS].indices;
2549
2550 if (tcs)
2551 maxq = min(maxq, adapter->num_tx_queues / tcs);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002552
Alexander Duyck05abb122010-08-19 13:35:41 +00002553 /* Fill out hash function seeds */
2554 for (i = 0; i < 10; i++)
2555 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002556
Alexander Duyck05abb122010-08-19 13:35:41 +00002557 /* Fill out redirection table */
2558 for (i = 0, j = 0; i < 128; i++, j++) {
John Fastabend86b4db32011-04-26 07:26:19 +00002559 if (j == maxq)
Alexander Duyck05abb122010-08-19 13:35:41 +00002560 j = 0;
2561 /* reta = 4-byte sliding window of
2562 * 0x00..(indices-1)(indices-1)00..etc. */
2563 reta = (reta << 8) | (j * 0x11);
2564 if ((i & 3) == 3)
2565 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2566 }
2567
2568 /* Disable indicating checksum in descriptor, enables RSS hash */
2569 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2570 rxcsum |= IXGBE_RXCSUM_PCSD;
2571 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2572
John Fastabend8b1c0b22011-05-03 02:26:48 +00002573 if (adapter->hw.mac.type == ixgbe_mac_82598EB &&
2574 (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002575 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002576 } else {
2577 int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
2578 | IXGBE_FLAG_SRIOV_ENABLED);
2579
2580 switch (mask) {
2581 case (IXGBE_FLAG_RSS_ENABLED):
2582 if (!tcs)
2583 mrqc = IXGBE_MRQC_RSSEN;
2584 else if (tcs <= 4)
2585 mrqc = IXGBE_MRQC_RTRSS4TCEN;
2586 else
2587 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2588 break;
2589 case (IXGBE_FLAG_SRIOV_ENABLED):
2590 mrqc = IXGBE_MRQC_VMDQEN;
2591 break;
2592 default:
2593 break;
2594 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002595 }
2596
Alexander Duyck05abb122010-08-19 13:35:41 +00002597 /* Perform hash on these packet types */
2598 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2599 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2600 | IXGBE_MRQC_RSS_FIELD_IPV6
2601 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2602
2603 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002604}
2605
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002606/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002607 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2608 * @adapter: address of board private structure
2609 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002610 **/
Don Skidmore082757a2011-07-21 05:55:00 +00002611static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00002612 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002613{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002614 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002615 u32 rscctrl;
Mallikarjuna R Chilakalaedd2ea552009-11-23 10:45:11 -08002616 int rx_buf_len;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002617 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002618
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002619 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00002620 return;
2621
2622 rx_buf_len = ring->rx_buf_len;
2623 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002624 rscctrl |= IXGBE_RSCCTL_RSCEN;
2625 /*
2626 * we must limit the number of descriptors so that the
2627 * total size of max desc * buf_len is not greater
2628 * than 65535
2629 */
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002630 if (ring_is_ps_enabled(ring)) {
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002631#if (MAX_SKB_FRAGS > 16)
2632 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2633#elif (MAX_SKB_FRAGS > 8)
2634 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2635#elif (MAX_SKB_FRAGS > 4)
2636 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2637#else
2638 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
2639#endif
2640 } else {
Alexander Duyck919e78a2011-08-26 09:52:38 +00002641 if (rx_buf_len < IXGBE_RXBUFFER_4K)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002642 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck919e78a2011-08-26 09:52:38 +00002643 else if (rx_buf_len < IXGBE_RXBUFFER_8K)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002644 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2645 else
2646 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2647 }
Alexander Duyck73670962010-08-19 13:38:34 +00002648 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002649}
2650
Alexander Duyck9e10e042010-08-19 13:40:06 +00002651/**
2652 * ixgbe_set_uta - Set unicast filter table address
2653 * @adapter: board private structure
2654 *
2655 * The unicast table address is a register array of 32-bit registers.
2656 * The table is meant to be used in a way similar to how the MTA is used
2657 * however due to certain limitations in the hardware it is necessary to
2658 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
2659 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
2660 **/
2661static void ixgbe_set_uta(struct ixgbe_adapter *adapter)
2662{
2663 struct ixgbe_hw *hw = &adapter->hw;
2664 int i;
2665
2666 /* The UTA table only exists on 82599 hardware and newer */
2667 if (hw->mac.type < ixgbe_mac_82599EB)
2668 return;
2669
2670 /* we only need to do this if VMDq is enabled */
2671 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
2672 return;
2673
2674 for (i = 0; i < 128; i++)
2675 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
2676}
2677
2678#define IXGBE_MAX_RX_DESC_POLL 10
2679static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2680 struct ixgbe_ring *ring)
2681{
2682 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002683 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2684 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002685 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002686
2687 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2688 if (hw->mac.type == ixgbe_mac_82598EB &&
2689 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2690 return;
2691
2692 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002693 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002694 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2695 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
2696
2697 if (!wait_loop) {
2698 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
2699 "the polling period\n", reg_idx);
2700 }
2701}
2702
Yi Zou2d39d572011-01-06 14:29:56 +00002703void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
2704 struct ixgbe_ring *ring)
2705{
2706 struct ixgbe_hw *hw = &adapter->hw;
2707 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2708 u32 rxdctl;
2709 u8 reg_idx = ring->reg_idx;
2710
2711 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2712 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
2713
2714 /* write value back with RXDCTL.ENABLE bit cleared */
2715 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2716
2717 if (hw->mac.type == ixgbe_mac_82598EB &&
2718 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2719 return;
2720
2721 /* the hardware may take up to 100us to really disable the rx queue */
2722 do {
2723 udelay(10);
2724 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2725 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
2726
2727 if (!wait_loop) {
2728 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
2729 "the polling period\n", reg_idx);
2730 }
2731}
2732
Alexander Duyck84418e32010-08-19 13:40:54 +00002733void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
2734 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00002735{
2736 struct ixgbe_hw *hw = &adapter->hw;
2737 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002738 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002739 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00002740
Alexander Duyck9e10e042010-08-19 13:40:06 +00002741 /* disable queue to avoid issues while updating state */
2742 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00002743 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002744
Alexander Duyckacd37172010-08-19 13:36:05 +00002745 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
2746 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
2747 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
2748 ring->count * sizeof(union ixgbe_adv_rx_desc));
2749 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
2750 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002751 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002752
2753 ixgbe_configure_srrctl(adapter, ring);
2754 ixgbe_configure_rscctl(adapter, ring);
2755
Greg Rosee9f98072011-01-26 01:06:07 +00002756 /* If operating in IOV mode set RLPML for X540 */
2757 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
2758 hw->mac.type == ixgbe_mac_X540) {
2759 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
2760 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
2761 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
2762 }
2763
Alexander Duyck9e10e042010-08-19 13:40:06 +00002764 if (hw->mac.type == ixgbe_mac_82598EB) {
2765 /*
2766 * enable cache line friendly hardware writes:
2767 * PTHRESH=32 descriptors (half the internal cache),
2768 * this also removes ugly rx_no_buffer_count increment
2769 * HTHRESH=4 descriptors (to minimize latency on fetch)
2770 * WTHRESH=8 burst writeback up to two cache lines
2771 */
2772 rxdctl &= ~0x3FFFFF;
2773 rxdctl |= 0x080420;
2774 }
2775
2776 /* enable receive descriptor ring */
2777 rxdctl |= IXGBE_RXDCTL_ENABLE;
2778 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2779
2780 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00002781 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00002782}
2783
Alexander Duyck48654522010-08-19 13:36:27 +00002784static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
2785{
2786 struct ixgbe_hw *hw = &adapter->hw;
2787 int p;
2788
2789 /* PSRTYPE must be initialized in non 82598 adapters */
2790 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00002791 IXGBE_PSRTYPE_UDPHDR |
2792 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00002793 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00002794 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00002795
2796 if (hw->mac.type == ixgbe_mac_82598EB)
2797 return;
2798
2799 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
2800 psrtype |= (adapter->num_rx_queues_per_pool << 29);
2801
2802 for (p = 0; p < adapter->num_rx_pools; p++)
2803 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
2804 psrtype);
2805}
2806
Alexander Duyckf5b4a522010-08-19 13:38:57 +00002807static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
2808{
2809 struct ixgbe_hw *hw = &adapter->hw;
2810 u32 gcr_ext;
2811 u32 vt_reg_bits;
2812 u32 reg_offset, vf_shift;
2813 u32 vmdctl;
2814
2815 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
2816 return;
2817
2818 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
2819 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
2820 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
2821 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
2822
2823 vf_shift = adapter->num_vfs % 32;
2824 reg_offset = (adapter->num_vfs > 32) ? 1 : 0;
2825
2826 /* Enable only the PF's pool for Tx/Rx */
2827 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
2828 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
2829 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
2830 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
2831 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
2832
2833 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
2834 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
2835
2836 /*
2837 * Set up VF register offsets for selected VT Mode,
2838 * i.e. 32 or 64 VFs for SR-IOV
2839 */
2840 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
2841 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
2842 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
2843 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
2844
2845 /* enable Tx loopback for VF/PF communication */
2846 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Greg Rosea985b6c32010-11-18 03:02:52 +00002847 /* Enable MAC Anti-Spoofing */
Greg Rosea1cbb15c2011-05-13 01:33:48 +00002848 hw->mac.ops.set_mac_anti_spoofing(hw,
2849 (adapter->antispoofing_enabled =
2850 (adapter->num_vfs != 0)),
Greg Rosea985b6c32010-11-18 03:02:52 +00002851 adapter->num_vfs);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00002852}
2853
Alexander Duyck477de6e2010-08-19 13:38:11 +00002854static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002855{
Auke Kok9a799d72007-09-15 14:07:45 -07002856 struct ixgbe_hw *hw = &adapter->hw;
2857 struct net_device *netdev = adapter->netdev;
2858 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002859 int rx_buf_len;
Alexander Duyck477de6e2010-08-19 13:38:11 +00002860 struct ixgbe_ring *rx_ring;
2861 int i;
2862 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00002863
Auke Kok9a799d72007-09-15 14:07:45 -07002864 /* Decide whether to use packet split mode or not */
Don Skidmorea1243392011-01-18 22:53:47 +00002865 /* On by default */
2866 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
2867
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002868 /* Do not use packet split if we're in SR-IOV Mode */
Don Skidmorea1243392011-01-18 22:53:47 +00002869 if (adapter->num_vfs)
2870 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
2871
2872 /* Disable packet split due to 82599 erratum #45 */
2873 if (hw->mac.type == ixgbe_mac_82599EB)
2874 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07002875
Alexander Duyck477de6e2010-08-19 13:38:11 +00002876#ifdef IXGBE_FCOE
2877 /* adjust max frame to be able to do baby jumbo for FCoE */
2878 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
2879 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
2880 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
2881
2882#endif /* IXGBE_FCOE */
2883 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
2884 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
2885 mhadd &= ~IXGBE_MHADD_MFS_MASK;
2886 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
2887
2888 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07002889 }
2890
Alexander Duyck919e78a2011-08-26 09:52:38 +00002891 /* MHADD will allow an extra 4 bytes past for vlan tagged frames */
2892 max_frame += VLAN_HLEN;
2893
2894 /* Set the RX buffer length according to the mode */
2895 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
2896 rx_buf_len = IXGBE_RX_HDR_SIZE;
2897 } else {
2898 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
2899 (netdev->mtu <= ETH_DATA_LEN))
2900 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
2901 /*
2902 * Make best use of allocation by using all but 1K of a
2903 * power of 2 allocation that will be used for skb->head.
2904 */
2905 else if (max_frame <= IXGBE_RXBUFFER_3K)
2906 rx_buf_len = IXGBE_RXBUFFER_3K;
2907 else if (max_frame <= IXGBE_RXBUFFER_7K)
2908 rx_buf_len = IXGBE_RXBUFFER_7K;
2909 else if (max_frame <= IXGBE_RXBUFFER_15K)
2910 rx_buf_len = IXGBE_RXBUFFER_15K;
2911 else
2912 rx_buf_len = IXGBE_MAX_RXBUFFER;
2913 }
2914
Auke Kok9a799d72007-09-15 14:07:45 -07002915 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00002916 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
2917 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07002918 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
2919
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002920 /*
2921 * Setup the HW Rx Head and Tail Descriptor Pointers and
2922 * the Base and Length of the Rx Descriptor Ring
2923 */
Auke Kok9a799d72007-09-15 14:07:45 -07002924 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002925 rx_ring = adapter->rx_ring[i];
Yi Zoua6616b42009-08-06 13:05:23 +00002926 rx_ring->rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002927
Yi Zou6e455b892009-08-06 13:05:44 +00002928 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002929 set_ring_ps_enabled(rx_ring);
Peter P Waskiewicz Jr1b3ff022009-09-14 07:47:27 +00002930 else
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002931 clear_ring_ps_enabled(rx_ring);
2932
2933 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
2934 set_ring_rsc_enabled(rx_ring);
2935 else
2936 clear_ring_rsc_enabled(rx_ring);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002937
Yi Zou63f39bd2009-05-17 12:34:35 +00002938#ifdef IXGBE_FCOE
Joe Perchese8e9f692010-09-07 21:34:53 +00002939 if (netdev->features & NETIF_F_FCOE_MTU) {
Yi Zou63f39bd2009-05-17 12:34:35 +00002940 struct ixgbe_ring_feature *f;
2941 f = &adapter->ring_feature[RING_F_FCOE];
Yi Zou6e455b892009-08-06 13:05:44 +00002942 if ((i >= f->mask) && (i < f->mask + f->indices)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002943 clear_ring_ps_enabled(rx_ring);
Yi Zou6e455b892009-08-06 13:05:44 +00002944 if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
2945 rx_ring->rx_buf_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00002946 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002947 } else if (!ring_is_rsc_enabled(rx_ring) &&
2948 !ring_is_ps_enabled(rx_ring)) {
2949 rx_ring->rx_buf_len =
2950 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Yi Zou6e455b892009-08-06 13:05:44 +00002951 }
Yi Zou63f39bd2009-05-17 12:34:35 +00002952 }
Yi Zou63f39bd2009-05-17 12:34:35 +00002953#endif /* IXGBE_FCOE */
Alexander Duyck477de6e2010-08-19 13:38:11 +00002954 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00002955}
2956
Alexander Duyck73670962010-08-19 13:38:34 +00002957static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
2958{
2959 struct ixgbe_hw *hw = &adapter->hw;
2960 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
2961
2962 switch (hw->mac.type) {
2963 case ixgbe_mac_82598EB:
2964 /*
2965 * For VMDq support of different descriptor types or
2966 * buffer sizes through the use of multiple SRRCTL
2967 * registers, RDRXCTL.MVMEN must be set to 1
2968 *
2969 * also, the manual doesn't mention it clearly but DCA hints
2970 * will only use queue 0's tags unless this bit is set. Side
2971 * effects of setting this bit are only that SRRCTL must be
2972 * fully programmed [0..15]
2973 */
2974 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
2975 break;
2976 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002977 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00002978 /* Disable RSC for ACK packets */
2979 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
2980 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
2981 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
2982 /* hardware requires some bits to be set by default */
2983 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
2984 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
2985 break;
2986 default:
2987 /* We should do nothing since we don't know this hardware */
2988 return;
2989 }
2990
2991 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
2992}
2993
Alexander Duyck477de6e2010-08-19 13:38:11 +00002994/**
2995 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
2996 * @adapter: board private structure
2997 *
2998 * Configure the Rx unit of the MAC after a reset.
2999 **/
3000static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3001{
3002 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003003 int i;
3004 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003005
3006 /* disable receives while setting up the descriptors */
3007 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3008 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3009
3010 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003011 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003012
Alexander Duyck9e10e042010-08-19 13:40:06 +00003013 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003014 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003015
Alexander Duyck9e10e042010-08-19 13:40:06 +00003016 ixgbe_set_uta(adapter);
3017
Alexander Duyck477de6e2010-08-19 13:38:11 +00003018 /* set_rx_buffer_len must be called before ring initialization */
3019 ixgbe_set_rx_buffer_len(adapter);
3020
3021 /*
3022 * Setup the HW Rx Head and Tail Descriptor Pointers and
3023 * the Base and Length of the Rx Descriptor Ring
3024 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003025 for (i = 0; i < adapter->num_rx_queues; i++)
3026 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003027
Alexander Duyck9e10e042010-08-19 13:40:06 +00003028 /* disable drop enable for 82598 parts */
3029 if (hw->mac.type == ixgbe_mac_82598EB)
3030 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3031
3032 /* enable all receives */
3033 rxctrl |= IXGBE_RXCTRL_RXEN;
3034 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003035}
3036
Auke Kok9a799d72007-09-15 14:07:45 -07003037static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
3038{
3039 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003040 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003041 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003042
3043 /* add VID to filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003044 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003045 set_bit(vid, adapter->active_vlans);
Auke Kok9a799d72007-09-15 14:07:45 -07003046}
3047
3048static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
3049{
3050 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003051 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003052 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003053
Auke Kok9a799d72007-09-15 14:07:45 -07003054 /* remove VID from filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003055 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003056 clear_bit(vid, adapter->active_vlans);
Auke Kok9a799d72007-09-15 14:07:45 -07003057}
3058
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003059/**
3060 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3061 * @adapter: driver data
3062 */
3063static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3064{
3065 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003066 u32 vlnctrl;
3067
3068 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3069 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3070 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3071}
3072
3073/**
3074 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3075 * @adapter: driver data
3076 */
3077static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3078{
3079 struct ixgbe_hw *hw = &adapter->hw;
3080 u32 vlnctrl;
3081
3082 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3083 vlnctrl |= IXGBE_VLNCTRL_VFE;
3084 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3085 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3086}
3087
3088/**
3089 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3090 * @adapter: driver data
3091 */
3092static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3093{
3094 struct ixgbe_hw *hw = &adapter->hw;
3095 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003096 int i, j;
3097
3098 switch (hw->mac.type) {
3099 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003100 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3101 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003102 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3103 break;
3104 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003105 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003106 for (i = 0; i < adapter->num_rx_queues; i++) {
3107 j = adapter->rx_ring[i]->reg_idx;
3108 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3109 vlnctrl &= ~IXGBE_RXDCTL_VME;
3110 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3111 }
3112 break;
3113 default:
3114 break;
3115 }
3116}
3117
3118/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003119 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003120 * @adapter: driver data
3121 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003122static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003123{
3124 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003125 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003126 int i, j;
3127
3128 switch (hw->mac.type) {
3129 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003130 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3131 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003132 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3133 break;
3134 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003135 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003136 for (i = 0; i < adapter->num_rx_queues; i++) {
3137 j = adapter->rx_ring[i]->reg_idx;
3138 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3139 vlnctrl |= IXGBE_RXDCTL_VME;
3140 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3141 }
3142 break;
3143 default:
3144 break;
3145 }
3146}
3147
Auke Kok9a799d72007-09-15 14:07:45 -07003148static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3149{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003150 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003151
Jesse Grossf62bbb52010-10-20 13:56:10 +00003152 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3153
3154 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3155 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003156}
3157
3158/**
Alexander Duyck28500622010-06-15 09:25:48 +00003159 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3160 * @netdev: network interface device structure
3161 *
3162 * Writes unicast address list to the RAR table.
3163 * Returns: -ENOMEM on failure/insufficient address space
3164 * 0 on no addresses written
3165 * X on writing X addresses to the RAR table
3166 **/
3167static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3168{
3169 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3170 struct ixgbe_hw *hw = &adapter->hw;
3171 unsigned int vfn = adapter->num_vfs;
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003172 unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS;
Alexander Duyck28500622010-06-15 09:25:48 +00003173 int count = 0;
3174
3175 /* return ENOMEM indicating insufficient memory for addresses */
3176 if (netdev_uc_count(netdev) > rar_entries)
3177 return -ENOMEM;
3178
3179 if (!netdev_uc_empty(netdev) && rar_entries) {
3180 struct netdev_hw_addr *ha;
3181 /* return error if we do not support writing to RAR table */
3182 if (!hw->mac.ops.set_rar)
3183 return -ENOMEM;
3184
3185 netdev_for_each_uc_addr(ha, netdev) {
3186 if (!rar_entries)
3187 break;
3188 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3189 vfn, IXGBE_RAH_AV);
3190 count++;
3191 }
3192 }
3193 /* write the addresses in reverse order to avoid write combining */
3194 for (; rar_entries > 0 ; rar_entries--)
3195 hw->mac.ops.clear_rar(hw, rar_entries);
3196
3197 return count;
3198}
3199
3200/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003201 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003202 * @netdev: network interface device structure
3203 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003204 * The set_rx_method entry point is called whenever the unicast/multicast
3205 * address list or the network interface flags are updated. This routine is
3206 * responsible for configuring the hardware for proper unicast, multicast and
3207 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003208 **/
Greg Rose7f870472010-01-09 02:25:29 +00003209void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003210{
3211 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3212 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003213 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3214 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003215
3216 /* Check for Promiscuous and All Multicast modes */
3217
3218 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3219
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003220 /* set all bits that we expect to always be set */
3221 fctrl |= IXGBE_FCTRL_BAM;
3222 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3223 fctrl |= IXGBE_FCTRL_PMCF;
3224
Alexander Duyck28500622010-06-15 09:25:48 +00003225 /* clear the bits we are changing the status of */
3226 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3227
Auke Kok9a799d72007-09-15 14:07:45 -07003228 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003229 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003230 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003231 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003232 /* don't hardware filter vlans in promisc mode */
3233 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003234 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003235 if (netdev->flags & IFF_ALLMULTI) {
3236 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003237 vmolr |= IXGBE_VMOLR_MPE;
3238 } else {
3239 /*
3240 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003241 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003242 * that we can at least receive multicast traffic
3243 */
3244 hw->mac.ops.update_mc_addr_list(hw, netdev);
3245 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003246 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003247 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003248 hw->addr_ctrl.user_set_promisc = false;
Alexander Duyck28500622010-06-15 09:25:48 +00003249 /*
3250 * Write addresses to available RAR registers, if there is not
3251 * sufficient space to store all the addresses then enable
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003252 * unicast promiscuous mode
Alexander Duyck28500622010-06-15 09:25:48 +00003253 */
3254 count = ixgbe_write_uc_addr_list(netdev);
3255 if (count < 0) {
3256 fctrl |= IXGBE_FCTRL_UPE;
3257 vmolr |= IXGBE_VMOLR_ROPE;
3258 }
3259 }
3260
3261 if (adapter->num_vfs) {
3262 ixgbe_restore_vf_multicasts(adapter);
3263 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3264 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3265 IXGBE_VMOLR_ROPE);
3266 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003267 }
3268
3269 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003270
3271 if (netdev->features & NETIF_F_HW_VLAN_RX)
3272 ixgbe_vlan_strip_enable(adapter);
3273 else
3274 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003275}
3276
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003277static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3278{
3279 int q_idx;
3280 struct ixgbe_q_vector *q_vector;
3281 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3282
3283 /* legacy and MSI only use one vector */
3284 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3285 q_vectors = 1;
3286
3287 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003288 q_vector = adapter->q_vector[q_idx];
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003289 napi_enable(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003290 }
3291}
3292
3293static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3294{
3295 int q_idx;
3296 struct ixgbe_q_vector *q_vector;
3297 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3298
3299 /* legacy and MSI only use one vector */
3300 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3301 q_vectors = 1;
3302
3303 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003304 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003305 napi_disable(&q_vector->napi);
3306 }
3307}
3308
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003309#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003310/*
3311 * ixgbe_configure_dcb - Configure DCB hardware
3312 * @adapter: ixgbe adapter struct
3313 *
3314 * This is called by the driver on open to configure the DCB hardware.
3315 * This is also called by the gennetlink interface when reconfiguring
3316 * the DCB state.
3317 */
3318static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3319{
3320 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend9806307a2010-10-28 00:59:57 +00003321 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003322
Alexander Duyck67ebd792010-08-19 13:34:04 +00003323 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3324 if (hw->mac.type == ixgbe_mac_82598EB)
3325 netif_set_gso_max_size(adapter->netdev, 65536);
3326 return;
3327 }
3328
3329 if (hw->mac.type == ixgbe_mac_82598EB)
3330 netif_set_gso_max_size(adapter->netdev, 32768);
3331
Alexander Duyck2f90b862008-11-20 20:52:10 -08003332
Alexander Duyck2f90b862008-11-20 20:52:10 -08003333 /* Enable VLAN tag insert/strip */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003334 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003335
Alexander Duyck2f90b862008-11-20 20:52:10 -08003336 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003337
3338 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00003339 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
Alexander Duyck971060b2011-07-15 02:31:30 +00003340#ifdef IXGBE_FCOE
John Fastabendc27931d2011-02-23 05:58:25 +00003341 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3342 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3343#endif
3344 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3345 DCB_TX_CONFIG);
3346 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3347 DCB_RX_CONFIG);
3348 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
3349 } else {
3350 struct net_device *dev = adapter->netdev;
3351
John Fastabend4c09f3a2011-08-04 05:47:07 +00003352 if (adapter->ixgbe_ieee_ets) {
3353 struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
3354 int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
3355
3356 ixgbe_dcb_hw_ets(&adapter->hw, ets, max_frame);
3357 }
3358
3359 if (adapter->ixgbe_ieee_pfc) {
3360 struct ieee_pfc *pfc = adapter->ixgbe_ieee_pfc;
3361
3362 ixgbe_dcb_hw_pfc_config(&adapter->hw, pfc->pfc_en);
3363 }
John Fastabendc27931d2011-02-23 05:58:25 +00003364 }
John Fastabend8187cd42011-02-23 05:58:08 +00003365
3366 /* Enable RSS Hash per TC */
3367 if (hw->mac.type != ixgbe_mac_82598EB) {
3368 int i;
3369 u32 reg = 0;
3370
3371 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3372 u8 msb = 0;
3373 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3374
3375 while (cnt >>= 1)
3376 msb++;
3377
3378 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3379 }
3380 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3381 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003382}
John Fastabend9da712d2011-08-23 03:14:22 +00003383#endif
3384
3385/* Additional bittime to account for IXGBE framing */
3386#define IXGBE_ETH_FRAMING 20
3387
3388/*
3389 * ixgbe_hpbthresh - calculate high water mark for flow control
3390 *
3391 * @adapter: board private structure to calculate for
3392 * @pb - packet buffer to calculate
3393 */
3394static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
3395{
3396 struct ixgbe_hw *hw = &adapter->hw;
3397 struct net_device *dev = adapter->netdev;
3398 int link, tc, kb, marker;
3399 u32 dv_id, rx_pba;
3400
3401 /* Calculate max LAN frame size */
3402 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
3403
3404#ifdef IXGBE_FCOE
3405 /* FCoE traffic class uses FCOE jumbo frames */
3406 if (dev->features & NETIF_F_FCOE_MTU) {
3407 int fcoe_pb = 0;
3408
3409#ifdef CONFIG_IXGBE_DCB
3410 fcoe_pb = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003411
3412#endif
John Fastabend9da712d2011-08-23 03:14:22 +00003413 if (fcoe_pb == pb && tc < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3414 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3415 }
3416#endif
3417
3418 /* Calculate delay value for device */
3419 switch (hw->mac.type) {
3420 case ixgbe_mac_X540:
3421 dv_id = IXGBE_DV_X540(link, tc);
3422 break;
3423 default:
3424 dv_id = IXGBE_DV(link, tc);
3425 break;
3426 }
3427
3428 /* Loopback switch introduces additional latency */
3429 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3430 dv_id += IXGBE_B2BT(tc);
3431
3432 /* Delay value is calculated in bit times convert to KB */
3433 kb = IXGBE_BT2KB(dv_id);
3434 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
3435
3436 marker = rx_pba - kb;
3437
3438 /* It is possible that the packet buffer is not large enough
3439 * to provide required headroom. In this case throw an error
3440 * to user and a do the best we can.
3441 */
3442 if (marker < 0) {
3443 e_warn(drv, "Packet Buffer(%i) can not provide enough"
3444 "headroom to support flow control."
3445 "Decrease MTU or number of traffic classes\n", pb);
3446 marker = tc + 1;
3447 }
3448
3449 return marker;
3450}
3451
3452/*
3453 * ixgbe_lpbthresh - calculate low water mark for for flow control
3454 *
3455 * @adapter: board private structure to calculate for
3456 * @pb - packet buffer to calculate
3457 */
3458static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter)
3459{
3460 struct ixgbe_hw *hw = &adapter->hw;
3461 struct net_device *dev = adapter->netdev;
3462 int tc;
3463 u32 dv_id;
3464
3465 /* Calculate max LAN frame size */
3466 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
3467
3468 /* Calculate delay value for device */
3469 switch (hw->mac.type) {
3470 case ixgbe_mac_X540:
3471 dv_id = IXGBE_LOW_DV_X540(tc);
3472 break;
3473 default:
3474 dv_id = IXGBE_LOW_DV(tc);
3475 break;
3476 }
3477
3478 /* Delay value is calculated in bit times convert to KB */
3479 return IXGBE_BT2KB(dv_id);
3480}
3481
3482/*
3483 * ixgbe_pbthresh_setup - calculate and setup high low water marks
3484 */
3485static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
3486{
3487 struct ixgbe_hw *hw = &adapter->hw;
3488 int num_tc = netdev_get_num_tc(adapter->netdev);
3489 int i;
3490
3491 if (!num_tc)
3492 num_tc = 1;
3493
3494 hw->fc.low_water = ixgbe_lpbthresh(adapter);
3495
3496 for (i = 0; i < num_tc; i++) {
3497 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
3498
3499 /* Low water marks must not be larger than high water marks */
3500 if (hw->fc.low_water > hw->fc.high_water[i])
3501 hw->fc.low_water = 0;
3502 }
3503}
John Fastabend80605c652011-05-02 12:34:10 +00003504
3505static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3506{
John Fastabend80605c652011-05-02 12:34:10 +00003507 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00003508 int hdrm;
3509 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00003510
3511 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3512 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00003513 hdrm = 32 << adapter->fdir_pballoc;
3514 else
3515 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00003516
Alexander Duyckf7e10272011-07-21 00:40:35 +00003517 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00003518 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00003519}
3520
Alexander Duycke4911d52011-05-11 07:18:52 +00003521static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3522{
3523 struct ixgbe_hw *hw = &adapter->hw;
3524 struct hlist_node *node, *node2;
3525 struct ixgbe_fdir_filter *filter;
3526
3527 spin_lock(&adapter->fdir_perfect_lock);
3528
3529 if (!hlist_empty(&adapter->fdir_filter_list))
3530 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3531
3532 hlist_for_each_entry_safe(filter, node, node2,
3533 &adapter->fdir_filter_list, fdir_node) {
3534 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00003535 &filter->filter,
3536 filter->sw_idx,
3537 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3538 IXGBE_FDIR_DROP_QUEUE :
3539 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00003540 }
3541
3542 spin_unlock(&adapter->fdir_perfect_lock);
3543}
3544
Auke Kok9a799d72007-09-15 14:07:45 -07003545static void ixgbe_configure(struct ixgbe_adapter *adapter)
3546{
John Fastabend80605c652011-05-02 12:34:10 +00003547 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003548#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003549 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003550#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003551
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003552 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003553 ixgbe_restore_vlan(adapter);
3554
Yi Zoueacd73f2009-05-13 13:11:06 +00003555#ifdef IXGBE_FCOE
3556 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3557 ixgbe_configure_fcoe(adapter);
3558
3559#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003560 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003561 ixgbe_init_fdir_signature_82599(&adapter->hw,
3562 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00003563 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3564 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3565 adapter->fdir_pballoc);
3566 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003567 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003568
Alexander Duyck933d41f2010-09-07 21:34:29 +00003569 ixgbe_configure_virtualization(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003570
Auke Kok9a799d72007-09-15 14:07:45 -07003571 ixgbe_configure_tx(adapter);
3572 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003573}
3574
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003575static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3576{
3577 switch (hw->phy.type) {
3578 case ixgbe_phy_sfp_avago:
3579 case ixgbe_phy_sfp_ftl:
3580 case ixgbe_phy_sfp_intel:
3581 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003582 case ixgbe_phy_sfp_passive_tyco:
3583 case ixgbe_phy_sfp_passive_unknown:
3584 case ixgbe_phy_sfp_active_unknown:
3585 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003586 return true;
Alexander Duyck8917b442011-07-21 00:40:51 +00003587 case ixgbe_phy_nl:
3588 if (hw->mac.type == ixgbe_mac_82598EB)
3589 return true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003590 default:
3591 return false;
3592 }
3593}
3594
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003595/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003596 * ixgbe_sfp_link_config - set up SFP+ link
3597 * @adapter: pointer to private adapter struct
3598 **/
3599static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3600{
Alexander Duyck70864002011-04-27 09:13:56 +00003601 /*
3602 * We are assuming the worst case scenerio here, and that
3603 * is that an SFP was inserted/removed after the reset
3604 * but before SFP detection was enabled. As such the best
3605 * solution is to just start searching as soon as we start
3606 */
3607 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3608 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003609
Alexander Duyck70864002011-04-27 09:13:56 +00003610 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003611}
3612
3613/**
3614 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003615 * @hw: pointer to private hardware struct
3616 *
3617 * Returns 0 on success, negative on failure
3618 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003619static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003620{
3621 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003622 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003623 u32 ret = IXGBE_ERR_LINK_SETUP;
3624
3625 if (hw->mac.ops.check_link)
3626 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3627
3628 if (ret)
3629 goto link_cfg_out;
3630
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00003631 autoneg = hw->phy.autoneg_advertised;
3632 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00003633 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3634 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003635 if (ret)
3636 goto link_cfg_out;
3637
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003638 if (hw->mac.ops.setup_link)
3639 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003640link_cfg_out:
3641 return ret;
3642}
3643
Alexander Duycka34bcff2010-08-19 13:39:20 +00003644static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003645{
Auke Kok9a799d72007-09-15 14:07:45 -07003646 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003647 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003648
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003649 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00003650 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3651 IXGBE_GPIE_OCD;
3652 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003653 /*
3654 * use EIAM to auto-mask when MSI-X interrupt is asserted
3655 * this saves a register write for every interrupt
3656 */
3657 switch (hw->mac.type) {
3658 case ixgbe_mac_82598EB:
3659 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3660 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003661 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003662 case ixgbe_mac_X540:
3663 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003664 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3665 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3666 break;
3667 }
3668 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003669 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3670 * specifically only auto mask tx and rx interrupts */
3671 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003672 }
3673
Alexander Duycka34bcff2010-08-19 13:39:20 +00003674 /* XXX: to interrupt immediately for EICS writes, enable this */
3675 /* gpie |= IXGBE_GPIE_EIMEN; */
3676
3677 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3678 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3679 gpie |= IXGBE_GPIE_VTMODE_64;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07003680 }
3681
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00003682 /* Enable Thermal over heat sensor interrupt */
3683 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
3684 gpie |= IXGBE_SDP0_GPIEN;
3685
Alexander Duycka34bcff2010-08-19 13:39:20 +00003686 /* Enable fan failure interrupt */
3687 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003688 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003689
Don Skidmore2698b202011-04-13 07:01:52 +00003690 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003691 gpie |= IXGBE_SDP1_GPIEN;
3692 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00003693 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00003694
3695 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3696}
3697
Alexander Duyckc7ccde02011-07-21 00:40:40 +00003698static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00003699{
3700 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003701 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003702 u32 ctrl_ext;
3703
3704 ixgbe_get_hw_control(adapter);
3705 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003706
Auke Kok9a799d72007-09-15 14:07:45 -07003707 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3708 ixgbe_configure_msix(adapter);
3709 else
3710 ixgbe_configure_msi_and_legacy(adapter);
3711
Don Skidmorec6ecf392010-12-03 03:31:51 +00003712 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3713 if (hw->mac.ops.enable_tx_laser &&
3714 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00003715 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00003716 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00003717 hw->mac.ops.enable_tx_laser(hw);
3718
Auke Kok9a799d72007-09-15 14:07:45 -07003719 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003720 ixgbe_napi_enable_all(adapter);
3721
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08003722 if (ixgbe_is_sfp(hw)) {
3723 ixgbe_sfp_link_config(adapter);
3724 } else {
3725 err = ixgbe_non_sfp_link_config(hw);
3726 if (err)
3727 e_err(probe, "link_config FAILED %d\n", err);
3728 }
3729
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003730 /* clear any pending interrupts, may auto mask */
3731 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003732 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003733
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003734 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00003735 * If this adapter has a fan, check to see if we had a failure
3736 * before we enabled the interrupt.
3737 */
3738 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
3739 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3740 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00003741 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00003742 }
3743
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003744 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003745 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003746
Auke Kok9a799d72007-09-15 14:07:45 -07003747 /* bring the link up in the watchdog, this could race with our first
3748 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003749 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3750 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00003751 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00003752
3753 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3754 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
3755 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
3756 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07003757}
3758
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003759void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
3760{
3761 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00003762 /* put off any impending NetWatchDogTimeout */
3763 adapter->netdev->trans_start = jiffies;
3764
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003765 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00003766 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003767 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00003768 /*
3769 * If SR-IOV enabled then wait a bit before bringing the adapter
3770 * back up to give the VFs time to respond to the reset. The
3771 * two second wait is based upon the watchdog timer cycle in
3772 * the VF driver.
3773 */
3774 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3775 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003776 ixgbe_up(adapter);
3777 clear_bit(__IXGBE_RESETTING, &adapter->state);
3778}
3779
Alexander Duyckc7ccde02011-07-21 00:40:40 +00003780void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003781{
3782 /* hardware has been reset, we need to reload some things */
3783 ixgbe_configure(adapter);
3784
Alexander Duyckc7ccde02011-07-21 00:40:40 +00003785 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003786}
3787
3788void ixgbe_reset(struct ixgbe_adapter *adapter)
3789{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003790 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07003791 int err;
3792
Alexander Duyck70864002011-04-27 09:13:56 +00003793 /* lock SFP init bit to prevent race conditions with the watchdog */
3794 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
3795 usleep_range(1000, 2000);
3796
3797 /* clear all SFP and link config related flags while holding SFP_INIT */
3798 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
3799 IXGBE_FLAG2_SFP_NEEDS_RESET);
3800 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
3801
Don Skidmore8ca783a2009-05-26 20:40:47 -07003802 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003803 switch (err) {
3804 case 0:
3805 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00003806 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003807 break;
3808 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00003809 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003810 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00003811 case IXGBE_ERR_EEPROM_VERSION:
3812 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00003813 e_dev_warn("This device is a pre-production adapter/LOM. "
3814 "Please be aware there may be issuesassociated with "
3815 "your hardware. If you are experiencing problems "
3816 "please contact your Intel or hardware "
3817 "representative who provided you with this "
3818 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00003819 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003820 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00003821 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003822 }
Auke Kok9a799d72007-09-15 14:07:45 -07003823
Alexander Duyck70864002011-04-27 09:13:56 +00003824 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
3825
Auke Kok9a799d72007-09-15 14:07:45 -07003826 /* reprogram the RAR[0] in case user changed it. */
Greg Rose1cdd1ec2010-01-09 02:26:46 +00003827 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
3828 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07003829}
3830
Auke Kok9a799d72007-09-15 14:07:45 -07003831/**
3832 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07003833 * @rx_ring: ring to free buffers from
3834 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003835static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003836{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003837 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07003838 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003839 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07003840
Alexander Duyck84418e32010-08-19 13:40:54 +00003841 /* ring already cleared, nothing to do */
3842 if (!rx_ring->rx_buffer_info)
3843 return;
Auke Kok9a799d72007-09-15 14:07:45 -07003844
Alexander Duyck84418e32010-08-19 13:40:54 +00003845 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07003846 for (i = 0; i < rx_ring->count; i++) {
3847 struct ixgbe_rx_buffer *rx_buffer_info;
3848
3849 rx_buffer_info = &rx_ring->rx_buffer_info[i];
3850 if (rx_buffer_info->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003851 dma_unmap_single(rx_ring->dev, rx_buffer_info->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00003852 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00003853 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07003854 rx_buffer_info->dma = 0;
3855 }
3856 if (rx_buffer_info->skb) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00003857 struct sk_buff *skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07003858 rx_buffer_info->skb = NULL;
Alexander Duyckf8212f92009-04-27 22:42:37 +00003859 do {
3860 struct sk_buff *this = skb;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00003861 if (IXGBE_RSC_CB(this)->delay_unmap) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003862 dma_unmap_single(dev,
Nick Nunley1b507732010-04-27 13:10:27 +00003863 IXGBE_RSC_CB(this)->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00003864 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00003865 DMA_FROM_DEVICE);
Mallikarjuna R Chilakalafd3686a2010-03-19 04:41:33 +00003866 IXGBE_RSC_CB(this)->dma = 0;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00003867 IXGBE_RSC_CB(skb)->delay_unmap = false;
Mallikarjuna R Chilakalafd3686a2010-03-19 04:41:33 +00003868 }
Alexander Duyckf8212f92009-04-27 22:42:37 +00003869 skb = skb->prev;
3870 dev_kfree_skb(this);
3871 } while (skb);
Auke Kok9a799d72007-09-15 14:07:45 -07003872 }
3873 if (!rx_buffer_info->page)
3874 continue;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00003875 if (rx_buffer_info->page_dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003876 dma_unmap_page(dev, rx_buffer_info->page_dma,
Nick Nunley1b507732010-04-27 13:10:27 +00003877 PAGE_SIZE / 2, DMA_FROM_DEVICE);
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00003878 rx_buffer_info->page_dma = 0;
3879 }
Auke Kok9a799d72007-09-15 14:07:45 -07003880 put_page(rx_buffer_info->page);
3881 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07003882 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003883 }
3884
3885 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
3886 memset(rx_ring->rx_buffer_info, 0, size);
3887
3888 /* Zero out the descriptor ring */
3889 memset(rx_ring->desc, 0, rx_ring->size);
3890
3891 rx_ring->next_to_clean = 0;
3892 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003893}
3894
3895/**
3896 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07003897 * @tx_ring: ring to be cleaned
3898 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003899static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003900{
3901 struct ixgbe_tx_buffer *tx_buffer_info;
3902 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003903 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07003904
Alexander Duyck84418e32010-08-19 13:40:54 +00003905 /* ring already cleared, nothing to do */
3906 if (!tx_ring->tx_buffer_info)
3907 return;
Auke Kok9a799d72007-09-15 14:07:45 -07003908
Alexander Duyck84418e32010-08-19 13:40:54 +00003909 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07003910 for (i = 0; i < tx_ring->count; i++) {
3911 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003912 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07003913 }
3914
3915 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
3916 memset(tx_ring->tx_buffer_info, 0, size);
3917
3918 /* Zero out the descriptor ring */
3919 memset(tx_ring->desc, 0, tx_ring->size);
3920
3921 tx_ring->next_to_use = 0;
3922 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003923}
3924
3925/**
Auke Kok9a799d72007-09-15 14:07:45 -07003926 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
3927 * @adapter: board private structure
3928 **/
3929static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
3930{
3931 int i;
3932
3933 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003934 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07003935}
3936
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003937/**
3938 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
3939 * @adapter: board private structure
3940 **/
3941static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
3942{
3943 int i;
3944
3945 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003946 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003947}
3948
Alexander Duycke4911d52011-05-11 07:18:52 +00003949static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
3950{
3951 struct hlist_node *node, *node2;
3952 struct ixgbe_fdir_filter *filter;
3953
3954 spin_lock(&adapter->fdir_perfect_lock);
3955
3956 hlist_for_each_entry_safe(filter, node, node2,
3957 &adapter->fdir_filter_list, fdir_node) {
3958 hlist_del(&filter->fdir_node);
3959 kfree(filter);
3960 }
3961 adapter->fdir_filter_count = 0;
3962
3963 spin_unlock(&adapter->fdir_perfect_lock);
3964}
3965
Auke Kok9a799d72007-09-15 14:07:45 -07003966void ixgbe_down(struct ixgbe_adapter *adapter)
3967{
3968 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07003969 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003970 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003971 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07003972
3973 /* signal that we are down to the interrupt handler */
3974 set_bit(__IXGBE_DOWN, &adapter->state);
3975
3976 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07003977 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3978 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07003979
Yi Zou2d39d572011-01-06 14:29:56 +00003980 /* disable all enabled rx queues */
3981 for (i = 0; i < adapter->num_rx_queues; i++)
3982 /* this call also flushes the previous write */
3983 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
3984
Don Skidmore032b4322011-03-18 09:32:53 +00003985 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07003986
Jesse Brandeburg7f821872008-09-11 20:00:16 -07003987 netif_tx_stop_all_queues(netdev);
3988
Alexander Duyck70864002011-04-27 09:13:56 +00003989 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00003990 netif_carrier_off(netdev);
3991 netif_tx_disable(netdev);
3992
3993 ixgbe_irq_disable(adapter);
3994
3995 ixgbe_napi_disable_all(adapter);
3996
Alexander Duyckd034acf2011-04-27 09:25:34 +00003997 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
3998 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00003999 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4000
4001 del_timer_sync(&adapter->service_timer);
4002
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004003 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004004 /* Clear EITR Select mapping */
4005 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
4006
4007 /* Mark all the VFs as inactive */
4008 for (i = 0 ; i < adapter->num_vfs; i++)
4009 adapter->vfinfo[i].clear_to_send = 0;
4010
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004011 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004012 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004013
Auke Kok9a799d72007-09-15 14:07:45 -07004014 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004015 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004016 }
4017
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004018 /* disable transmits in the hardware now that interrupts are off */
4019 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004020 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004021 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004022 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004023
4024 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004025 switch (hw->mac.type) {
4026 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004027 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004028 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004029 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4030 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004031 break;
4032 default:
4033 break;
4034 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004035
Paul Larson6f4a0e42008-06-24 17:00:56 -07004036 if (!pci_channel_offline(adapter->pdev))
4037 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004038
4039 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4040 if (hw->mac.ops.disable_tx_laser &&
4041 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004042 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004043 (hw->mac.type == ixgbe_mac_82599EB))))
4044 hw->mac.ops.disable_tx_laser(hw);
4045
Auke Kok9a799d72007-09-15 14:07:45 -07004046 ixgbe_clean_all_tx_rings(adapter);
4047 ixgbe_clean_all_rx_rings(adapter);
4048
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004049#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004050 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004051 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004052#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004053}
4054
Auke Kok9a799d72007-09-15 14:07:45 -07004055/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004056 * ixgbe_poll - NAPI Rx polling callback
4057 * @napi: structure for representing this polling device
4058 * @budget: how many packets driver is allowed to clean
4059 *
4060 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07004061 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004062static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07004063{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004064 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00004065 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004066 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004067 struct ixgbe_ring *ring;
4068 int per_ring_budget;
4069 bool clean_complete = true;
Auke Kok9a799d72007-09-15 14:07:45 -07004070
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004071#ifdef CONFIG_IXGBE_DCA
Alexander Duyck33cf09c2010-11-16 19:26:55 -08004072 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
4073 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004074#endif
4075
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004076 for (ring = q_vector->tx.ring; ring != NULL; ring = ring->next)
4077 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
Auke Kok9a799d72007-09-15 14:07:45 -07004078
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004079 /* attempt to distribute budget to each queue fairly, but don't allow
4080 * the budget to go below 1 because we'll exit polling */
4081 if (q_vector->rx.count > 1)
4082 per_ring_budget = max(budget/q_vector->rx.count, 1);
4083 else
4084 per_ring_budget = budget;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08004085
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004086 for (ring = q_vector->rx.ring; ring != NULL; ring = ring->next)
4087 clean_complete &= ixgbe_clean_rx_irq(q_vector, ring,
4088 per_ring_budget);
4089
4090 /* If all work not completed, return budget and keep polling */
4091 if (!clean_complete)
4092 return budget;
4093
4094 /* all work done, exit the polling mode */
4095 napi_complete(napi);
4096 if (adapter->rx_itr_setting & 1)
4097 ixgbe_set_itr(q_vector);
4098 if (!test_bit(__IXGBE_DOWN, &adapter->state))
4099 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
4100
4101 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004102}
4103
4104/**
4105 * ixgbe_tx_timeout - Respond to a Tx Hang
4106 * @netdev: network interface device structure
4107 **/
4108static void ixgbe_tx_timeout(struct net_device *netdev)
4109{
4110 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4111
4112 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004113 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004114}
4115
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004116/**
4117 * ixgbe_set_rss_queues: Allocate queues for RSS
4118 * @adapter: board private structure to initialize
4119 *
4120 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
4121 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
4122 *
4123 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004124static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
4125{
4126 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004127 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004128
4129 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004130 f->mask = 0xF;
4131 adapter->num_rx_queues = f->indices;
4132 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004133 ret = true;
4134 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004135 ret = false;
4136 }
4137
4138 return ret;
4139}
4140
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004141/**
4142 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
4143 * @adapter: board private structure to initialize
4144 *
4145 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
4146 * to the original CPU that initiated the Tx session. This runs in addition
4147 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
4148 * Rx load across CPUs using RSS.
4149 *
4150 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004151static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004152{
4153 bool ret = false;
4154 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
4155
4156 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
4157 f_fdir->mask = 0;
4158
4159 /* Flow Director must have RSS enabled */
Alexander Duyck03ecf912011-05-20 07:36:17 +00004160 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4161 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004162 adapter->num_tx_queues = f_fdir->indices;
4163 adapter->num_rx_queues = f_fdir->indices;
4164 ret = true;
4165 } else {
4166 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004167 }
4168 return ret;
4169}
4170
Yi Zou0331a832009-05-17 12:33:52 +00004171#ifdef IXGBE_FCOE
4172/**
4173 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
4174 * @adapter: board private structure to initialize
4175 *
4176 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
4177 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
4178 * rx queues out of the max number of rx queues, instead, it is used as the
4179 * index of the first rx queue used by FCoE.
4180 *
4181 **/
4182static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
4183{
Yi Zou0331a832009-05-17 12:33:52 +00004184 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4185
John Fastabende5b64632011-03-08 03:44:52 +00004186 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4187 return false;
4188
John Fastabende901acd2011-04-26 07:26:08 +00004189 f->indices = min((int)num_online_cpus(), f->indices);
John Fastabende5b64632011-03-08 03:44:52 +00004190
John Fastabende901acd2011-04-26 07:26:08 +00004191 adapter->num_rx_queues = 1;
4192 adapter->num_tx_queues = 1;
John Fastabende5b64632011-03-08 03:44:52 +00004193
John Fastabende901acd2011-04-26 07:26:08 +00004194 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4195 e_info(probe, "FCoE enabled with RSS\n");
Alexander Duyck03ecf912011-05-20 07:36:17 +00004196 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
John Fastabende901acd2011-04-26 07:26:08 +00004197 ixgbe_set_fdir_queues(adapter);
4198 else
4199 ixgbe_set_rss_queues(adapter);
Yi Zou0331a832009-05-17 12:33:52 +00004200 }
Alexander Duyck03ecf912011-05-20 07:36:17 +00004201
John Fastabende901acd2011-04-26 07:26:08 +00004202 /* adding FCoE rx rings to the end */
4203 f->mask = adapter->num_rx_queues;
4204 adapter->num_rx_queues += f->indices;
4205 adapter->num_tx_queues += f->indices;
Yi Zou0331a832009-05-17 12:33:52 +00004206
John Fastabende5b64632011-03-08 03:44:52 +00004207 return true;
4208}
4209#endif /* IXGBE_FCOE */
4210
John Fastabende901acd2011-04-26 07:26:08 +00004211/* Artificial max queue cap per traffic class in DCB mode */
4212#define DCB_QUEUE_CAP 8
4213
John Fastabende5b64632011-03-08 03:44:52 +00004214#ifdef CONFIG_IXGBE_DCB
4215static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
4216{
John Fastabende901acd2011-04-26 07:26:08 +00004217 int per_tc_q, q, i, offset = 0;
4218 struct net_device *dev = adapter->netdev;
4219 int tcs = netdev_get_num_tc(dev);
John Fastabende5b64632011-03-08 03:44:52 +00004220
John Fastabende901acd2011-04-26 07:26:08 +00004221 if (!tcs)
4222 return false;
John Fastabende5b64632011-03-08 03:44:52 +00004223
John Fastabende901acd2011-04-26 07:26:08 +00004224 /* Map queue offset and counts onto allocated tx queues */
4225 per_tc_q = min(dev->num_tx_queues / tcs, (unsigned int)DCB_QUEUE_CAP);
4226 q = min((int)num_online_cpus(), per_tc_q);
John Fastabend8b1c0b22011-05-03 02:26:48 +00004227
John Fastabend8b1c0b22011-05-03 02:26:48 +00004228 for (i = 0; i < tcs; i++) {
John Fastabende901acd2011-04-26 07:26:08 +00004229 netdev_set_prio_tc_map(dev, i, i);
4230 netdev_set_tc_queue(dev, i, q, offset);
4231 offset += q;
John Fastabende5b64632011-03-08 03:44:52 +00004232 }
4233
John Fastabende901acd2011-04-26 07:26:08 +00004234 adapter->num_tx_queues = q * tcs;
4235 adapter->num_rx_queues = q * tcs;
John Fastabende5b64632011-03-08 03:44:52 +00004236
4237#ifdef IXGBE_FCOE
John Fastabende901acd2011-04-26 07:26:08 +00004238 /* FCoE enabled queues require special configuration indexed
4239 * by feature specific indices and mask. Here we map FCoE
4240 * indices onto the DCB queue pairs allowing FCoE to own
4241 * configuration later.
John Fastabende5b64632011-03-08 03:44:52 +00004242 */
John Fastabende901acd2011-04-26 07:26:08 +00004243 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
4244 int tc;
4245 struct ixgbe_ring_feature *f =
4246 &adapter->ring_feature[RING_F_FCOE];
4247
4248 tc = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
4249 f->indices = dev->tc_to_txq[tc].count;
4250 f->mask = dev->tc_to_txq[tc].offset;
4251 }
John Fastabende5b64632011-03-08 03:44:52 +00004252#endif
4253
John Fastabende901acd2011-04-26 07:26:08 +00004254 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004255}
John Fastabende5b64632011-03-08 03:44:52 +00004256#endif
Yi Zou0331a832009-05-17 12:33:52 +00004257
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004258/**
4259 * ixgbe_set_sriov_queues: Allocate queues for IOV use
4260 * @adapter: board private structure to initialize
4261 *
4262 * IOV doesn't actually use anything, so just NAK the
4263 * request for now and let the other queue routines
4264 * figure out what to do.
4265 */
4266static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
4267{
4268 return false;
4269}
4270
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004271/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004272 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004273 * @adapter: board private structure to initialize
4274 *
4275 * This is the top level queue allocation routine. The order here is very
4276 * important, starting with the "most" number of features turned on at once,
4277 * and ending with the smallest set of features. This way large combinations
4278 * can be allocated if they're turned on, and smaller combinations are the
4279 * fallthrough conditions.
4280 *
4281 **/
Ben Hutchings847f53f2010-09-27 08:28:56 +00004282static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004283{
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004284 /* Start with base case */
4285 adapter->num_rx_queues = 1;
4286 adapter->num_tx_queues = 1;
4287 adapter->num_rx_pools = adapter->num_rx_queues;
4288 adapter->num_rx_queues_per_pool = 1;
4289
4290 if (ixgbe_set_sriov_queues(adapter))
Ben Hutchings847f53f2010-09-27 08:28:56 +00004291 goto done;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004292
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004293#ifdef CONFIG_IXGBE_DCB
4294 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004295 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004296
4297#endif
John Fastabende5b64632011-03-08 03:44:52 +00004298#ifdef IXGBE_FCOE
4299 if (ixgbe_set_fcoe_queues(adapter))
4300 goto done;
4301
4302#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004303 if (ixgbe_set_fdir_queues(adapter))
4304 goto done;
4305
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004306 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004307 goto done;
4308
4309 /* fallback to base case */
4310 adapter->num_rx_queues = 1;
4311 adapter->num_tx_queues = 1;
4312
4313done:
Ben Hutchings847f53f2010-09-27 08:28:56 +00004314 /* Notify the stack of the (possibly) reduced queue counts. */
John Fastabendf0796d52010-07-01 13:21:57 +00004315 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
Ben Hutchings847f53f2010-09-27 08:28:56 +00004316 return netif_set_real_num_rx_queues(adapter->netdev,
4317 adapter->num_rx_queues);
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004318}
4319
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004320static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00004321 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004322{
4323 int err, vector_threshold;
4324
4325 /* We'll want at least 3 (vector_threshold):
4326 * 1) TxQ[0] Cleanup
4327 * 2) RxQ[0] Cleanup
4328 * 3) Other (Link Status Change, etc.)
4329 * 4) TCP Timer (optional)
4330 */
4331 vector_threshold = MIN_MSIX_COUNT;
4332
4333 /* The more we get, the more we will assign to Tx/Rx Cleanup
4334 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
4335 * Right now, we simply care about how many we'll get; we'll
4336 * set them up later while requesting irq's.
4337 */
4338 while (vectors >= vector_threshold) {
4339 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Joe Perchese8e9f692010-09-07 21:34:53 +00004340 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004341 if (!err) /* Success in acquiring all requested vectors. */
4342 break;
4343 else if (err < 0)
4344 vectors = 0; /* Nasty failure, quit now */
4345 else /* err == number of vectors we should try again with */
4346 vectors = err;
4347 }
4348
4349 if (vectors < vector_threshold) {
4350 /* Can't allocate enough MSI-X interrupts? Oh well.
4351 * This just means we'll go with either a single MSI
4352 * vector or fall back to legacy interrupts.
4353 */
Emil Tantilov849c4542010-06-03 16:53:41 +00004354 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4355 "Unable to allocate MSI-X interrupts\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004356 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4357 kfree(adapter->msix_entries);
4358 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004359 } else {
4360 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08004361 /*
4362 * Adjust for only the vectors we'll use, which is minimum
4363 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
4364 * vectors we were allocated.
4365 */
4366 adapter->num_msix_vectors = min(vectors,
Joe Perchese8e9f692010-09-07 21:34:53 +00004367 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004368 }
4369}
4370
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004371/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004372 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004373 * @adapter: board private structure to initialize
4374 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004375 * Cache the descriptor ring offsets for RSS to the assigned rings.
4376 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004377 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004378static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004379{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004380 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004381
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004382 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
4383 return false;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004384
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004385 for (i = 0; i < adapter->num_rx_queues; i++)
4386 adapter->rx_ring[i]->reg_idx = i;
4387 for (i = 0; i < adapter->num_tx_queues; i++)
4388 adapter->tx_ring[i]->reg_idx = i;
4389
4390 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004391}
4392
4393#ifdef CONFIG_IXGBE_DCB
John Fastabende5b64632011-03-08 03:44:52 +00004394
4395/* ixgbe_get_first_reg_idx - Return first register index associated with ring */
John Fastabendb32c8dc2011-04-12 02:44:55 +00004396static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc,
4397 unsigned int *tx, unsigned int *rx)
John Fastabende5b64632011-03-08 03:44:52 +00004398{
4399 struct net_device *dev = adapter->netdev;
4400 struct ixgbe_hw *hw = &adapter->hw;
4401 u8 num_tcs = netdev_get_num_tc(dev);
4402
4403 *tx = 0;
4404 *rx = 0;
4405
4406 switch (hw->mac.type) {
4407 case ixgbe_mac_82598EB:
John Fastabendaba70d52011-04-26 07:26:14 +00004408 *tx = tc << 2;
4409 *rx = tc << 3;
John Fastabende5b64632011-03-08 03:44:52 +00004410 break;
4411 case ixgbe_mac_82599EB:
4412 case ixgbe_mac_X540:
John Fastabend4fa2e0e2011-07-18 22:38:25 +00004413 if (num_tcs > 4) {
John Fastabende5b64632011-03-08 03:44:52 +00004414 if (tc < 3) {
4415 *tx = tc << 5;
4416 *rx = tc << 4;
4417 } else if (tc < 5) {
4418 *tx = ((tc + 2) << 4);
4419 *rx = tc << 4;
4420 } else if (tc < num_tcs) {
4421 *tx = ((tc + 8) << 3);
4422 *rx = tc << 4;
4423 }
John Fastabend4fa2e0e2011-07-18 22:38:25 +00004424 } else {
John Fastabende5b64632011-03-08 03:44:52 +00004425 *rx = tc << 5;
4426 switch (tc) {
4427 case 0:
4428 *tx = 0;
4429 break;
4430 case 1:
4431 *tx = 64;
4432 break;
4433 case 2:
4434 *tx = 96;
4435 break;
4436 case 3:
4437 *tx = 112;
4438 break;
4439 default:
4440 break;
4441 }
4442 }
4443 break;
4444 default:
4445 break;
4446 }
4447}
4448
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004449/**
4450 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
4451 * @adapter: board private structure to initialize
4452 *
4453 * Cache the descriptor ring offsets for DCB to the assigned rings.
4454 *
4455 **/
4456static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
4457{
John Fastabende5b64632011-03-08 03:44:52 +00004458 struct net_device *dev = adapter->netdev;
4459 int i, j, k;
4460 u8 num_tcs = netdev_get_num_tc(dev);
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004461
John Fastabend8b1c0b22011-05-03 02:26:48 +00004462 if (!num_tcs)
Alexander Duyckbd508172010-11-16 19:27:03 -08004463 return false;
4464
John Fastabende5b64632011-03-08 03:44:52 +00004465 for (i = 0, k = 0; i < num_tcs; i++) {
4466 unsigned int tx_s, rx_s;
4467 u16 count = dev->tc_to_txq[i].count;
4468
4469 ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s);
4470 for (j = 0; j < count; j++, k++) {
4471 adapter->tx_ring[k]->reg_idx = tx_s + j;
4472 adapter->rx_ring[k]->reg_idx = rx_s + j;
4473 adapter->tx_ring[k]->dcb_tc = i;
4474 adapter->rx_ring[k]->dcb_tc = i;
Alexander Duyckbd508172010-11-16 19:27:03 -08004475 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004476 }
John Fastabende5b64632011-03-08 03:44:52 +00004477
4478 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004479}
4480#endif
4481
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004482/**
4483 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
4484 * @adapter: board private structure to initialize
4485 *
4486 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
4487 *
4488 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004489static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004490{
4491 int i;
4492 bool ret = false;
4493
Alexander Duyck03ecf912011-05-20 07:36:17 +00004494 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4495 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004496 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004497 adapter->rx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004498 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004499 adapter->tx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004500 ret = true;
4501 }
4502
4503 return ret;
4504}
4505
Yi Zou0331a832009-05-17 12:33:52 +00004506#ifdef IXGBE_FCOE
4507/**
4508 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
4509 * @adapter: board private structure to initialize
4510 *
4511 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
4512 *
4513 */
4514static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
4515{
Yi Zou0331a832009-05-17 12:33:52 +00004516 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004517 int i;
4518 u8 fcoe_rx_i = 0, fcoe_tx_i = 0;
Yi Zou0331a832009-05-17 12:33:52 +00004519
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004520 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4521 return false;
4522
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004523 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Alexander Duyck03ecf912011-05-20 07:36:17 +00004524 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004525 ixgbe_cache_ring_fdir(adapter);
4526 else
4527 ixgbe_cache_ring_rss(adapter);
4528
4529 fcoe_rx_i = f->mask;
4530 fcoe_tx_i = f->mask;
4531 }
4532 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
4533 adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
4534 adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
4535 }
4536 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004537}
4538
4539#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004540/**
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004541 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
4542 * @adapter: board private structure to initialize
4543 *
4544 * SR-IOV doesn't use any descriptor rings but changes the default if
4545 * no other mapping is used.
4546 *
4547 */
4548static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
4549{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004550 adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
4551 adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004552 if (adapter->num_vfs)
4553 return true;
4554 else
4555 return false;
4556}
4557
4558/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004559 * ixgbe_cache_ring_register - Descriptor ring to register mapping
4560 * @adapter: board private structure to initialize
4561 *
4562 * Once we know the feature-set enabled for the device, we'll cache
4563 * the register offset the descriptor ring is assigned to.
4564 *
4565 * Note, the order the various feature calls is important. It must start with
4566 * the "most" features enabled at the same time, then trickle down to the
4567 * least amount of features turned on at once.
4568 **/
4569static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
4570{
4571 /* start with default case */
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004572 adapter->rx_ring[0]->reg_idx = 0;
4573 adapter->tx_ring[0]->reg_idx = 0;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004574
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004575 if (ixgbe_cache_ring_sriov(adapter))
4576 return;
4577
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004578#ifdef CONFIG_IXGBE_DCB
4579 if (ixgbe_cache_ring_dcb(adapter))
4580 return;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004581#endif
John Fastabende5b64632011-03-08 03:44:52 +00004582
4583#ifdef IXGBE_FCOE
4584 if (ixgbe_cache_ring_fcoe(adapter))
4585 return;
4586#endif /* IXGBE_FCOE */
4587
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004588 if (ixgbe_cache_ring_fdir(adapter))
4589 return;
4590
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004591 if (ixgbe_cache_ring_rss(adapter))
4592 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004593}
4594
Auke Kok9a799d72007-09-15 14:07:45 -07004595/**
4596 * ixgbe_alloc_queues - Allocate memory for all rings
4597 * @adapter: board private structure to initialize
4598 *
4599 * We allocate one ring per queue at run-time since we don't know the
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004600 * number of queues at compile-time. The polling_netdev array is
4601 * intended for Multiqueue, but should work fine with a single queue.
Auke Kok9a799d72007-09-15 14:07:45 -07004602 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08004603static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004604{
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004605 int rx = 0, tx = 0, nid = adapter->node;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004606
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004607 if (nid < 0 || !node_online(nid))
4608 nid = first_online_node;
4609
4610 for (; tx < adapter->num_tx_queues; tx++) {
4611 struct ixgbe_ring *ring;
4612
4613 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004614 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004615 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004616 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004617 goto err_allocation;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004618 ring->count = adapter->tx_ring_count;
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004619 ring->queue_index = tx;
4620 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004621 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004622 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004623
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004624 adapter->tx_ring[tx] = ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004625 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004626
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004627 for (; rx < adapter->num_rx_queues; rx++) {
4628 struct ixgbe_ring *ring;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004629
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004630 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004631 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004632 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004633 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004634 goto err_allocation;
4635 ring->count = adapter->rx_ring_count;
4636 ring->queue_index = rx;
4637 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004638 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004639 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004640
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004641 adapter->rx_ring[rx] = ring;
Auke Kok9a799d72007-09-15 14:07:45 -07004642 }
4643
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004644 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004645
4646 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004647
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004648err_allocation:
4649 while (tx)
4650 kfree(adapter->tx_ring[--tx]);
4651
4652 while (rx)
4653 kfree(adapter->rx_ring[--rx]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004654 return -ENOMEM;
4655}
4656
4657/**
4658 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
4659 * @adapter: board private structure to initialize
4660 *
4661 * Attempt to configure the interrupts using the best available
4662 * capabilities of the hardware and the kernel.
4663 **/
Al Virofeea6a52008-11-27 15:34:07 -08004664static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004665{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004666 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004667 int err = 0;
4668 int vector, v_budget;
4669
4670 /*
4671 * It's easy to be greedy for MSI-X vectors, but it really
4672 * doesn't do us much good if we have a lot more vectors
4673 * than CPU's. So let's be conservative and only ask for
PJ Waskiewicz342bde12009-11-12 23:50:43 +00004674 * (roughly) the same number of vectors as there are CPU's.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004675 */
4676 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00004677 (int)num_online_cpus()) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004678
4679 /*
4680 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004681 * hw.mac->max_msix_vectors vectors. With features
4682 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
4683 * descriptor queues supported by our device. Thus, we cap it off in
4684 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004685 */
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004686 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004687
4688 /* A failure in MSI-X entry allocation isn't fatal, but it does
4689 * mean we disable MSI-X capabilities of the adapter. */
4690 adapter->msix_entries = kcalloc(v_budget,
Joe Perchese8e9f692010-09-07 21:34:53 +00004691 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004692 if (adapter->msix_entries) {
4693 for (vector = 0; vector < v_budget; vector++)
4694 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004695
Alexander Duyck7a921c92009-05-06 10:43:28 +00004696 ixgbe_acquire_msix_vectors(adapter, v_budget);
4697
4698 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4699 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004700 }
David S. Miller26d27842010-05-03 15:18:22 -07004701
Alexander Duyck7a921c92009-05-06 10:43:28 +00004702 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
4703 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck03ecf912011-05-20 07:36:17 +00004704 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck45b9f502011-01-06 14:29:59 +00004705 e_err(probe,
Alexander Duyck03ecf912011-05-20 07:36:17 +00004706 "ATR is not supported while multiple "
Alexander Duyck45b9f502011-01-06 14:29:59 +00004707 "queues are disabled. Disabling Flow Director\n");
4708 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004709 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004710 adapter->atr_sample_rate = 0;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004711 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4712 ixgbe_disable_sriov(adapter);
4713
Ben Hutchings847f53f2010-09-27 08:28:56 +00004714 err = ixgbe_set_num_queues(adapter);
4715 if (err)
4716 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004717
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004718 err = pci_enable_msi(adapter->pdev);
4719 if (!err) {
4720 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
4721 } else {
Emil Tantilov849c4542010-06-03 16:53:41 +00004722 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4723 "Unable to allocate MSI interrupt, "
4724 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004725 /* reset err */
4726 err = 0;
4727 }
4728
4729out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004730 return err;
4731}
4732
Alexander Duyck7a921c92009-05-06 10:43:28 +00004733/**
4734 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
4735 * @adapter: board private structure to initialize
4736 *
4737 * We allocate one q_vector per queue interrupt. If allocation fails we
4738 * return -ENOMEM.
4739 **/
4740static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
4741{
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004742 int v_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004743 struct ixgbe_q_vector *q_vector;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004744
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004745 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00004746 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004747 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00004748 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004749
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004750 for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004751 q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00004752 GFP_KERNEL, adapter->node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004753 if (!q_vector)
4754 q_vector = kzalloc(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00004755 GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004756 if (!q_vector)
4757 goto err_out;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004758
Alexander Duyck7a921c92009-05-06 10:43:28 +00004759 q_vector->adapter = adapter;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004760 q_vector->v_idx = v_idx;
4761
Alexander Duyck207867f2011-07-15 03:05:37 +00004762 /* Allocate the affinity_hint cpumask, configure the mask */
4763 if (!alloc_cpumask_var(&q_vector->affinity_mask, GFP_KERNEL))
4764 goto err_out;
4765 cpumask_set_cpu(v_idx, q_vector->affinity_mask);
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004766 netif_napi_add(adapter->netdev, &q_vector->napi,
4767 ixgbe_poll, 64);
4768 adapter->q_vector[v_idx] = q_vector;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004769 }
4770
4771 return 0;
4772
4773err_out:
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004774 while (v_idx) {
4775 v_idx--;
4776 q_vector = adapter->q_vector[v_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00004777 netif_napi_del(&q_vector->napi);
Alexander Duyck207867f2011-07-15 03:05:37 +00004778 free_cpumask_var(q_vector->affinity_mask);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004779 kfree(q_vector);
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004780 adapter->q_vector[v_idx] = NULL;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004781 }
4782 return -ENOMEM;
4783}
4784
4785/**
4786 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
4787 * @adapter: board private structure to initialize
4788 *
4789 * This function frees the memory allocated to the q_vectors. In addition if
4790 * NAPI is enabled it will delete any references to the NAPI struct prior
4791 * to freeing the q_vector.
4792 **/
4793static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
4794{
Alexander Duyck207867f2011-07-15 03:05:37 +00004795 int v_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004796
Alexander Duyck91281fd2009-06-04 16:00:27 +00004797 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00004798 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004799 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00004800 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004801
Alexander Duyck207867f2011-07-15 03:05:37 +00004802 for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
4803 struct ixgbe_q_vector *q_vector = adapter->q_vector[v_idx];
4804 adapter->q_vector[v_idx] = NULL;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004805 netif_napi_del(&q_vector->napi);
Alexander Duyck207867f2011-07-15 03:05:37 +00004806 free_cpumask_var(q_vector->affinity_mask);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004807 kfree(q_vector);
4808 }
4809}
4810
Don Skidmore7b25cdb2009-08-25 04:47:32 +00004811static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004812{
4813 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
4814 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4815 pci_disable_msix(adapter->pdev);
4816 kfree(adapter->msix_entries);
4817 adapter->msix_entries = NULL;
4818 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
4819 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
4820 pci_disable_msi(adapter->pdev);
4821 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004822}
4823
4824/**
4825 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
4826 * @adapter: board private structure to initialize
4827 *
4828 * We determine which interrupt scheme to use based on...
4829 * - Kernel support (MSI, MSI-X)
4830 * - which can be user-defined (via MODULE_PARAM)
4831 * - Hardware queue count (num_*_queues)
4832 * - defined by miscellaneous hardware support/features (RSS, etc.)
4833 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08004834int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004835{
4836 int err;
4837
4838 /* Number of supported queues */
Ben Hutchings847f53f2010-09-27 08:28:56 +00004839 err = ixgbe_set_num_queues(adapter);
4840 if (err)
4841 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004842
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004843 err = ixgbe_set_interrupt_capability(adapter);
4844 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004845 e_dev_err("Unable to setup interrupt capabilities\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004846 goto err_set_interrupt;
4847 }
4848
Alexander Duyck7a921c92009-05-06 10:43:28 +00004849 err = ixgbe_alloc_q_vectors(adapter);
4850 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004851 e_dev_err("Unable to allocate memory for queue vectors\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00004852 goto err_alloc_q_vectors;
4853 }
4854
4855 err = ixgbe_alloc_queues(adapter);
4856 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004857 e_dev_err("Unable to allocate memory for queues\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00004858 goto err_alloc_queues;
4859 }
4860
Emil Tantilov849c4542010-06-03 16:53:41 +00004861 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
Emil Tantilov396e7992010-07-01 20:05:12 +00004862 (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
4863 adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004864
4865 set_bit(__IXGBE_DOWN, &adapter->state);
4866
4867 return 0;
4868
Alexander Duyck7a921c92009-05-06 10:43:28 +00004869err_alloc_queues:
4870 ixgbe_free_q_vectors(adapter);
4871err_alloc_q_vectors:
4872 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004873err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00004874 return err;
4875}
4876
4877/**
4878 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
4879 * @adapter: board private structure to clear interrupt scheme on
4880 *
4881 * We go through and clear interrupt specific resources and reset the structure
4882 * to pre-load conditions
4883 **/
4884void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
4885{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004886 int i;
4887
4888 for (i = 0; i < adapter->num_tx_queues; i++) {
4889 kfree(adapter->tx_ring[i]);
4890 adapter->tx_ring[i] = NULL;
4891 }
4892 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08004893 struct ixgbe_ring *ring = adapter->rx_ring[i];
4894
4895 /* ixgbe_get_stats64() might access this ring, we must wait
4896 * a grace period before freeing it.
4897 */
Lai Jiangshanbcec8b62011-03-18 11:57:21 +08004898 kfree_rcu(ring, rcu);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004899 adapter->rx_ring[i] = NULL;
4900 }
Alexander Duyck7a921c92009-05-06 10:43:28 +00004901
Don Skidmoreb8eb3a12010-12-01 20:54:53 +00004902 adapter->num_tx_queues = 0;
4903 adapter->num_rx_queues = 0;
4904
Alexander Duyck7a921c92009-05-06 10:43:28 +00004905 ixgbe_free_q_vectors(adapter);
4906 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004907}
4908
4909/**
4910 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
4911 * @adapter: board private structure to initialize
4912 *
4913 * ixgbe_sw_init initializes the Adapter private data structure.
4914 * Fields are initialized based on PCI device information and
4915 * OS network device settings (MTU size).
4916 **/
4917static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
4918{
4919 struct ixgbe_hw *hw = &adapter->hw;
4920 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004921 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004922#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08004923 int j;
4924 struct tc_configuration *tc;
4925#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004926
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004927 /* PCI config space info */
4928
4929 hw->vendor_id = pdev->vendor;
4930 hw->device_id = pdev->device;
4931 hw->revision_id = pdev->revision;
4932 hw->subsystem_vendor_id = pdev->subsystem_vendor;
4933 hw->subsystem_device_id = pdev->subsystem_device;
4934
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004935 /* Set capability flags */
4936 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
4937 adapter->ring_feature[RING_F_RSS].indices = rss;
4938 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyckbd508172010-11-16 19:27:03 -08004939 switch (hw->mac.type) {
4940 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00004941 if (hw->device_id == IXGBE_DEV_ID_82598AT)
4942 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004943 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08004944 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08004945 case ixgbe_mac_X540:
Jacob Keller4f51bf72011-08-20 04:49:45 +00004946 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
4947 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004948 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00004949 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
4950 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07004951 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
4952 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00004953 /* Flow Director hash filters enabled */
4954 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
4955 adapter->atr_sample_rate = 20;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004956 adapter->ring_feature[RING_F_FDIR].indices =
Joe Perchese8e9f692010-09-07 21:34:53 +00004957 IXGBE_MAX_FDIR_INDICES;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00004958 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
Yi Zoueacd73f2009-05-13 13:11:06 +00004959#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00004960 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
4961 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
4962 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou61a0f422009-12-03 11:32:22 +00004963#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00004964 /* Default traffic class to use for FCoE */
John Fastabend56075a92010-07-26 20:41:31 +00004965 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00004966#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00004967#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08004968 break;
4969 default:
4970 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00004971 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08004972
Alexander Duyck1fc5f032011-06-02 04:28:39 +00004973 /* n-tuple support exists, always init our spinlock */
4974 spin_lock_init(&adapter->fdir_perfect_lock);
4975
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004976#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08004977 /* Configure DCB traffic classes */
4978 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
4979 tc = &adapter->dcb_cfg.tc_config[j];
4980 tc->path[DCB_TX_CONFIG].bwg_id = 0;
4981 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
4982 tc->path[DCB_RX_CONFIG].bwg_id = 0;
4983 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
4984 tc->dcb_pfc = pfc_disabled;
4985 }
4986 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
4987 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004988 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004989 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00004990 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004991 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
John Fastabende5b64632011-03-08 03:44:52 +00004992 MAX_TRAFFIC_CLASS);
Alexander Duyck2f90b862008-11-20 20:52:10 -08004993
4994#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004995
4996 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00004997 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00004998 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004999#ifdef CONFIG_DCB
5000 adapter->last_lfc_mode = hw->fc.current_mode;
5001#endif
John Fastabend9da712d2011-08-23 03:14:22 +00005002 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005003 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5004 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00005005 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07005006
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005007 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005008 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005009 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005010
5011 /* set defaults for eitr in MegaBytes */
5012 adapter->eitr_low = 10;
5013 adapter->eitr_high = 20;
5014
5015 /* set default ring sizes */
5016 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5017 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5018
Alexander Duyckbd198052011-06-11 01:45:08 +00005019 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00005020 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00005021
Auke Kok9a799d72007-09-15 14:07:45 -07005022 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005023 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005024 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005025 return -EIO;
5026 }
5027
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005028 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07005029 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
5030
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005031 /* get assigned NUMA node */
5032 adapter->node = dev_to_node(&pdev->dev);
5033
Auke Kok9a799d72007-09-15 14:07:45 -07005034 set_bit(__IXGBE_DOWN, &adapter->state);
5035
5036 return 0;
5037}
5038
5039/**
5040 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005041 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005042 *
5043 * Return 0 on success, negative on failure
5044 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005045int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005046{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005047 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07005048 int size;
5049
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005050 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005051 tx_ring->tx_buffer_info = vzalloc_node(size, tx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005052 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005053 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005054 if (!tx_ring->tx_buffer_info)
5055 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005056
5057 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005058 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005059 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005060
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005061 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005062 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005063 if (!tx_ring->desc)
5064 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005065
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005066 tx_ring->next_to_use = 0;
5067 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005068 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005069
5070err:
5071 vfree(tx_ring->tx_buffer_info);
5072 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005073 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005074 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005075}
5076
5077/**
Alexander Duyck69888672008-09-11 20:05:39 -07005078 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5079 * @adapter: board private structure
5080 *
5081 * If this function returns with an error, then it's possible one or
5082 * more of the rings is populated (while the rest are not). It is the
5083 * callers duty to clean those orphaned rings.
5084 *
5085 * Return 0 on success, negative on failure
5086 **/
5087static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5088{
5089 int i, err = 0;
5090
5091 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005092 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005093 if (!err)
5094 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005095 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005096 break;
5097 }
5098
5099 return err;
5100}
5101
5102/**
Auke Kok9a799d72007-09-15 14:07:45 -07005103 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005104 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005105 *
5106 * Returns 0 on success, negative on failure
5107 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005108int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005109{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005110 struct device *dev = rx_ring->dev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005111 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005112
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005113 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005114 rx_ring->rx_buffer_info = vzalloc_node(size, rx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005115 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005116 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005117 if (!rx_ring->rx_buffer_info)
5118 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005119
Auke Kok9a799d72007-09-15 14:07:45 -07005120 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005121 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5122 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005123
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005124 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005125 &rx_ring->dma, GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07005126
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005127 if (!rx_ring->desc)
5128 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005129
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005130 rx_ring->next_to_clean = 0;
5131 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005132
5133 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005134err:
5135 vfree(rx_ring->rx_buffer_info);
5136 rx_ring->rx_buffer_info = NULL;
5137 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005138 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005139}
5140
5141/**
Alexander Duyck69888672008-09-11 20:05:39 -07005142 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5143 * @adapter: board private structure
5144 *
5145 * If this function returns with an error, then it's possible one or
5146 * more of the rings is populated (while the rest are not). It is the
5147 * callers duty to clean those orphaned rings.
5148 *
5149 * Return 0 on success, negative on failure
5150 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005151static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5152{
5153 int i, err = 0;
5154
5155 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005156 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005157 if (!err)
5158 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005159 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005160 break;
5161 }
5162
5163 return err;
5164}
5165
5166/**
Auke Kok9a799d72007-09-15 14:07:45 -07005167 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005168 * @tx_ring: Tx descriptor ring for a specific queue
5169 *
5170 * Free all transmit software resources
5171 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005172void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005173{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005174 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005175
5176 vfree(tx_ring->tx_buffer_info);
5177 tx_ring->tx_buffer_info = NULL;
5178
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005179 /* if not set, then don't free */
5180 if (!tx_ring->desc)
5181 return;
5182
5183 dma_free_coherent(tx_ring->dev, tx_ring->size,
5184 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005185
5186 tx_ring->desc = NULL;
5187}
5188
5189/**
5190 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5191 * @adapter: board private structure
5192 *
5193 * Free all transmit software resources
5194 **/
5195static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5196{
5197 int i;
5198
5199 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005200 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005201 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005202}
5203
5204/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005205 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005206 * @rx_ring: ring to clean the resources from
5207 *
5208 * Free all receive software resources
5209 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005210void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005211{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005212 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005213
5214 vfree(rx_ring->rx_buffer_info);
5215 rx_ring->rx_buffer_info = NULL;
5216
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005217 /* if not set, then don't free */
5218 if (!rx_ring->desc)
5219 return;
5220
5221 dma_free_coherent(rx_ring->dev, rx_ring->size,
5222 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005223
5224 rx_ring->desc = NULL;
5225}
5226
5227/**
5228 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5229 * @adapter: board private structure
5230 *
5231 * Free all receive software resources
5232 **/
5233static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5234{
5235 int i;
5236
5237 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005238 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005239 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005240}
5241
5242/**
Auke Kok9a799d72007-09-15 14:07:45 -07005243 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5244 * @netdev: network interface device structure
5245 * @new_mtu: new value for maximum frame size
5246 *
5247 * Returns 0 on success, negative on failure
5248 **/
5249static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5250{
5251 struct ixgbe_adapter *adapter = netdev_priv(netdev);
John Fastabend16b61be2010-11-16 19:26:44 -08005252 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07005253 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5254
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07005255 /* MTU < 68 is an error and causes problems on some kernels */
Greg Rosee9f98072011-01-26 01:06:07 +00005256 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED &&
5257 hw->mac.type != ixgbe_mac_X540) {
5258 if ((new_mtu < 68) || (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
5259 return -EINVAL;
5260 } else {
5261 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5262 return -EINVAL;
5263 }
Auke Kok9a799d72007-09-15 14:07:45 -07005264
Emil Tantilov396e7992010-07-01 20:05:12 +00005265 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005266 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07005267 netdev->mtu = new_mtu;
5268
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005269 if (netif_running(netdev))
5270 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005271
5272 return 0;
5273}
5274
5275/**
5276 * ixgbe_open - Called when a network interface is made active
5277 * @netdev: network interface device structure
5278 *
5279 * Returns 0 on success, negative value on failure
5280 *
5281 * The open entry point is called when a network interface is made
5282 * active by the system (IFF_UP). At this point all resources needed
5283 * for transmit and receive operations are allocated, the interrupt
5284 * handler is registered with the OS, the watchdog timer is started,
5285 * and the stack is notified that the interface is ready.
5286 **/
5287static int ixgbe_open(struct net_device *netdev)
5288{
5289 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5290 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005291
Auke Kok4bebfaa2008-02-11 09:26:01 -08005292 /* disallow open during test */
5293 if (test_bit(__IXGBE_TESTING, &adapter->state))
5294 return -EBUSY;
5295
Jesse Brandeburg54386462009-04-17 20:44:27 +00005296 netif_carrier_off(netdev);
5297
Auke Kok9a799d72007-09-15 14:07:45 -07005298 /* allocate transmit descriptors */
5299 err = ixgbe_setup_all_tx_resources(adapter);
5300 if (err)
5301 goto err_setup_tx;
5302
Auke Kok9a799d72007-09-15 14:07:45 -07005303 /* allocate receive descriptors */
5304 err = ixgbe_setup_all_rx_resources(adapter);
5305 if (err)
5306 goto err_setup_rx;
5307
5308 ixgbe_configure(adapter);
5309
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005310 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005311 if (err)
5312 goto err_req_irq;
5313
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005314 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005315
5316 return 0;
5317
Auke Kok9a799d72007-09-15 14:07:45 -07005318err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07005319err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005320 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005321err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005322 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005323 ixgbe_reset(adapter);
5324
5325 return err;
5326}
5327
5328/**
5329 * ixgbe_close - Disables a network interface
5330 * @netdev: network interface device structure
5331 *
5332 * Returns 0, this is not allowed to fail
5333 *
5334 * The close entry point is called when an interface is de-activated
5335 * by the OS. The hardware is still under the drivers control, but
5336 * needs to be disabled. A global MAC reset is issued to stop the
5337 * hardware, and all transmit and receive resources are freed.
5338 **/
5339static int ixgbe_close(struct net_device *netdev)
5340{
5341 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005342
5343 ixgbe_down(adapter);
5344 ixgbe_free_irq(adapter);
5345
Alexander Duycke4911d52011-05-11 07:18:52 +00005346 ixgbe_fdir_filter_exit(adapter);
5347
Auke Kok9a799d72007-09-15 14:07:45 -07005348 ixgbe_free_all_tx_resources(adapter);
5349 ixgbe_free_all_rx_resources(adapter);
5350
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005351 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005352
5353 return 0;
5354}
5355
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005356#ifdef CONFIG_PM
5357static int ixgbe_resume(struct pci_dev *pdev)
5358{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005359 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5360 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005361 u32 err;
5362
5363 pci_set_power_state(pdev, PCI_D0);
5364 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005365 /*
5366 * pci_restore_state clears dev->state_saved so call
5367 * pci_save_state to restore it.
5368 */
5369 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005370
5371 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005372 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005373 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005374 return err;
5375 }
5376 pci_set_master(pdev);
5377
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005378 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005379
5380 err = ixgbe_init_interrupt_scheme(adapter);
5381 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005382 e_dev_err("Cannot initialize interrupts for device\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005383 return err;
5384 }
5385
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005386 ixgbe_reset(adapter);
5387
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005388 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5389
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005390 if (netif_running(netdev)) {
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005391 err = ixgbe_open(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005392 if (err)
5393 return err;
5394 }
5395
5396 netif_device_attach(netdev);
5397
5398 return 0;
5399}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005400#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005401
5402static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005403{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005404 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5405 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005406 struct ixgbe_hw *hw = &adapter->hw;
5407 u32 ctrl, fctrl;
5408 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005409#ifdef CONFIG_PM
5410 int retval = 0;
5411#endif
5412
5413 netif_device_detach(netdev);
5414
5415 if (netif_running(netdev)) {
5416 ixgbe_down(adapter);
5417 ixgbe_free_irq(adapter);
5418 ixgbe_free_all_tx_resources(adapter);
5419 ixgbe_free_all_rx_resources(adapter);
5420 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005421
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005422 ixgbe_clear_interrupt_scheme(adapter);
John Fastabendd033d522011-02-10 14:40:01 +00005423#ifdef CONFIG_DCB
5424 kfree(adapter->ixgbe_ieee_pfc);
5425 kfree(adapter->ixgbe_ieee_ets);
5426#endif
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005427
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005428#ifdef CONFIG_PM
5429 retval = pci_save_state(pdev);
5430 if (retval)
5431 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005432
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005433#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005434 if (wufc) {
5435 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005436
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005437 /* turn on all-multi mode if wake on multicast is enabled */
5438 if (wufc & IXGBE_WUFC_MC) {
5439 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5440 fctrl |= IXGBE_FCTRL_MPE;
5441 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5442 }
5443
5444 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5445 ctrl |= IXGBE_CTRL_GIO_DIS;
5446 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5447
5448 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5449 } else {
5450 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5451 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5452 }
5453
Alexander Duyckbd508172010-11-16 19:27:03 -08005454 switch (hw->mac.type) {
5455 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005456 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005457 break;
5458 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005459 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005460 pci_wake_from_d3(pdev, !!wufc);
5461 break;
5462 default:
5463 break;
5464 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005465
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005466 *enable_wake = !!wufc;
5467
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005468 ixgbe_release_hw_control(adapter);
5469
5470 pci_disable_device(pdev);
5471
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005472 return 0;
5473}
5474
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005475#ifdef CONFIG_PM
5476static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5477{
5478 int retval;
5479 bool wake;
5480
5481 retval = __ixgbe_shutdown(pdev, &wake);
5482 if (retval)
5483 return retval;
5484
5485 if (wake) {
5486 pci_prepare_to_sleep(pdev);
5487 } else {
5488 pci_wake_from_d3(pdev, false);
5489 pci_set_power_state(pdev, PCI_D3hot);
5490 }
5491
5492 return 0;
5493}
5494#endif /* CONFIG_PM */
5495
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005496static void ixgbe_shutdown(struct pci_dev *pdev)
5497{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005498 bool wake;
5499
5500 __ixgbe_shutdown(pdev, &wake);
5501
5502 if (system_state == SYSTEM_POWER_OFF) {
5503 pci_wake_from_d3(pdev, wake);
5504 pci_set_power_state(pdev, PCI_D3hot);
5505 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005506}
5507
5508/**
Auke Kok9a799d72007-09-15 14:07:45 -07005509 * ixgbe_update_stats - Update the board statistics counters.
5510 * @adapter: board private structure
5511 **/
5512void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5513{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005514 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005515 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005516 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005517 u64 total_mpc = 0;
5518 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005519 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5520 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
5521 u64 bytes = 0, packets = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005522
Don Skidmored08935c2010-06-11 13:20:29 +00005523 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5524 test_bit(__IXGBE_RESETTING, &adapter->state))
5525 return;
5526
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005527 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005528 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005529 u64 rsc_flush = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005530 for (i = 0; i < 16; i++)
5531 adapter->hw_rx_no_dma_resources +=
Joe Perches7ca647b2010-09-07 21:35:40 +00005532 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005533 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005534 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5535 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005536 }
5537 adapter->rsc_total_count = rsc_count;
5538 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005539 }
5540
Alexander Duyck5b7da512010-11-16 19:26:50 -08005541 for (i = 0; i < adapter->num_rx_queues; i++) {
5542 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5543 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5544 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5545 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
5546 bytes += rx_ring->stats.bytes;
5547 packets += rx_ring->stats.packets;
5548 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005549 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005550 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5551 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
5552 netdev->stats.rx_bytes = bytes;
5553 netdev->stats.rx_packets = packets;
5554
5555 bytes = 0;
5556 packets = 0;
5557 /* gather some stats to the adapter struct that are per queue */
5558 for (i = 0; i < adapter->num_tx_queues; i++) {
5559 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5560 restart_queue += tx_ring->tx_stats.restart_queue;
5561 tx_busy += tx_ring->tx_stats.tx_busy;
5562 bytes += tx_ring->stats.bytes;
5563 packets += tx_ring->stats.packets;
5564 }
5565 adapter->restart_queue = restart_queue;
5566 adapter->tx_busy = tx_busy;
5567 netdev->stats.tx_bytes = bytes;
5568 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005569
Joe Perches7ca647b2010-09-07 21:35:40 +00005570 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005571
5572 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005573 for (i = 0; i < 8; i++) {
5574 /* for packet buffers not used, the register should read 0 */
5575 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5576 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005577 hwstats->mpc[i] += mpc;
5578 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005579 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5580 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005581 switch (hw->mac.type) {
5582 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005583 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5584 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5585 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005586 hwstats->pxonrxc[i] +=
5587 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005588 break;
5589 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005590 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005591 hwstats->pxonrxc[i] +=
5592 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005593 break;
5594 default:
5595 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005596 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005597 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005598
5599 /*16 register reads */
5600 for (i = 0; i < 16; i++) {
5601 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5602 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5603 if ((hw->mac.type == ixgbe_mac_82599EB) ||
5604 (hw->mac.type == ixgbe_mac_X540)) {
5605 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
5606 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
5607 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
5608 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
5609 }
5610 }
5611
Joe Perches7ca647b2010-09-07 21:35:40 +00005612 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005613 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005614 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005615
John Fastabendc84d3242010-11-16 19:27:12 -08005616 ixgbe_update_xoff_received(adapter);
5617
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005618 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005619 switch (hw->mac.type) {
5620 case ixgbe_mac_82598EB:
5621 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005622 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5623 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5624 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5625 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005626 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005627 /* OS2BMC stats are X540 only*/
5628 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5629 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5630 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5631 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5632 case ixgbe_mac_82599EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005633 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005634 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005635 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005636 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005637 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005638 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005639 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005640 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5641 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005642#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005643 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5644 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5645 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5646 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5647 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5648 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Yi Zou6d455222009-05-13 13:12:16 +00005649#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005650 break;
5651 default:
5652 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005653 }
Auke Kok9a799d72007-09-15 14:07:45 -07005654 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005655 hwstats->bprc += bprc;
5656 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005657 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005658 hwstats->mprc -= bprc;
5659 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5660 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5661 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5662 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5663 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5664 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5665 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5666 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005667 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005668 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005669 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005670 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005671 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5672 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005673 /*
5674 * 82598 errata - tx of flow control packets is included in tx counters
5675 */
5676 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005677 hwstats->gptc -= xon_off_tot;
5678 hwstats->mptc -= xon_off_tot;
5679 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5680 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5681 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5682 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5683 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5684 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5685 hwstats->ptc64 -= xon_off_tot;
5686 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5687 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5688 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5689 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5690 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5691 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005692
5693 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005694 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005695
5696 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005697 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005698 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005699 netdev->stats.rx_length_errors = hwstats->rlec;
5700 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005701 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005702}
5703
5704/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00005705 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
5706 * @adapter - pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07005707 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00005708static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005709{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005710 struct ixgbe_hw *hw = &adapter->hw;
5711 int i;
5712
Alexander Duyckd034acf2011-04-27 09:25:34 +00005713 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5714 return;
5715
5716 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5717
5718 /* if interface is down do nothing */
5719 if (test_bit(__IXGBE_DOWN, &adapter->state))
5720 return;
5721
5722 /* do nothing if we are not using signature filters */
5723 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5724 return;
5725
5726 adapter->fdir_overflow++;
5727
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005728 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5729 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08005730 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00005731 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00005732 /* re-enable flow director interrupts */
5733 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005734 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00005735 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00005736 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005737 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005738}
5739
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005740/**
5741 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
5742 * @adapter - pointer to the device adapter structure
5743 *
5744 * This function serves two purposes. First it strobes the interrupt lines
5745 * in order to make certain interrupts are occuring. Secondly it sets the
5746 * bits needed to check for TX hangs. As a result we should immediately
5747 * determine if a hang has occured.
5748 */
5749static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
5750{
Auke Kok9a799d72007-09-15 14:07:45 -07005751 struct ixgbe_hw *hw = &adapter->hw;
5752 u64 eics = 0;
5753 int i;
5754
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005755 /* If we're down or resetting, just bail */
5756 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5757 test_bit(__IXGBE_RESETTING, &adapter->state))
5758 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00005759
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005760 /* Force detection of hung controller */
5761 if (netif_carrier_ok(adapter->netdev)) {
5762 for (i = 0; i < adapter->num_tx_queues; i++)
5763 set_check_for_tx_hang(adapter->tx_ring[i]);
5764 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005765
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005766 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00005767 /*
5768 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005769 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00005770 * would set *both* EIMS and EICS for any bit in EIAM
5771 */
5772 IXGBE_WRITE_REG(hw, IXGBE_EICS,
5773 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005774 } else {
5775 /* get one bit for every active tx/rx interrupt vector */
5776 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
5777 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00005778 if (qv->rx.ring || qv->tx.ring)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005779 eics |= ((u64)1 << i);
5780 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005781 }
5782
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005783 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00005784 ixgbe_irq_rearm_queues(adapter, eics);
5785
Alexander Duyckfe49f042009-06-04 16:00:09 +00005786}
5787
5788/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005789 * ixgbe_watchdog_update_link - update the link status
5790 * @adapter - pointer to the device adapter structure
5791 * @link_speed - pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005792 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005793static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005794{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005795 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005796 u32 link_speed = adapter->link_speed;
5797 bool link_up = adapter->link_up;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005798 int i;
5799
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005800 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5801 return;
5802
5803 if (hw->mac.ops.check_link) {
5804 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005805 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005806 /* always assume link is up, if no check link function */
5807 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
5808 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005809 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005810 if (link_up) {
5811 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
5812 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
5813 hw->mac.ops.fc_enable(hw, i);
5814 } else {
5815 hw->mac.ops.fc_enable(hw, 0);
5816 }
5817 }
5818
5819 if (link_up ||
5820 time_after(jiffies, (adapter->link_check_timeout +
5821 IXGBE_TRY_LINK_TIMEOUT))) {
5822 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5823 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
5824 IXGBE_WRITE_FLUSH(hw);
5825 }
5826
5827 adapter->link_up = link_up;
5828 adapter->link_speed = link_speed;
5829}
5830
5831/**
5832 * ixgbe_watchdog_link_is_up - update netif_carrier status and
5833 * print link up message
5834 * @adapter - pointer to the device adapter structure
5835 **/
5836static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
5837{
5838 struct net_device *netdev = adapter->netdev;
5839 struct ixgbe_hw *hw = &adapter->hw;
5840 u32 link_speed = adapter->link_speed;
5841 bool flow_rx, flow_tx;
5842
5843 /* only continue if link was previously down */
5844 if (netif_carrier_ok(netdev))
5845 return;
5846
5847 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
5848
5849 switch (hw->mac.type) {
5850 case ixgbe_mac_82598EB: {
5851 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5852 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
5853 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
5854 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
5855 }
5856 break;
5857 case ixgbe_mac_X540:
5858 case ixgbe_mac_82599EB: {
5859 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
5860 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
5861 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
5862 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
5863 }
5864 break;
5865 default:
5866 flow_tx = false;
5867 flow_rx = false;
5868 break;
5869 }
5870 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
5871 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
5872 "10 Gbps" :
5873 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
5874 "1 Gbps" :
5875 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
5876 "100 Mbps" :
5877 "unknown speed"))),
5878 ((flow_rx && flow_tx) ? "RX/TX" :
5879 (flow_rx ? "RX" :
5880 (flow_tx ? "TX" : "None"))));
5881
5882 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005883 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005884}
5885
5886/**
5887 * ixgbe_watchdog_link_is_down - update netif_carrier status and
5888 * print link down message
5889 * @adapter - pointer to the adapter structure
5890 **/
5891static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter)
5892{
5893 struct net_device *netdev = adapter->netdev;
5894 struct ixgbe_hw *hw = &adapter->hw;
5895
5896 adapter->link_up = false;
5897 adapter->link_speed = 0;
5898
5899 /* only continue if link was up previously */
5900 if (!netif_carrier_ok(netdev))
5901 return;
5902
5903 /* poll for SFP+ cable when link is down */
5904 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
5905 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
5906
5907 e_info(drv, "NIC Link is Down\n");
5908 netif_carrier_off(netdev);
5909}
5910
5911/**
5912 * ixgbe_watchdog_flush_tx - flush queues on link down
5913 * @adapter - pointer to the device adapter structure
5914 **/
5915static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
5916{
5917 int i;
5918 int some_tx_pending = 0;
5919
5920 if (!netif_carrier_ok(adapter->netdev)) {
5921 for (i = 0; i < adapter->num_tx_queues; i++) {
5922 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5923 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
5924 some_tx_pending = 1;
5925 break;
5926 }
5927 }
5928
5929 if (some_tx_pending) {
5930 /* We've lost link, so the controller stops DMA,
5931 * but we've got queued Tx work that's never going
5932 * to get done, so reset controller to flush Tx.
5933 * (Do the reset outside of interrupt context).
5934 */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005935 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005936 }
5937 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005938}
5939
Greg Rosea985b6c32010-11-18 03:02:52 +00005940static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
5941{
5942 u32 ssvpc;
5943
5944 /* Do not perform spoof check for 82598 */
5945 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
5946 return;
5947
5948 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
5949
5950 /*
5951 * ssvpc register is cleared on read, if zero then no
5952 * spoofed packets in the last interval.
5953 */
5954 if (!ssvpc)
5955 return;
5956
5957 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
5958}
5959
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005960/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005961 * ixgbe_watchdog_subtask - check and bring link up
5962 * @adapter - pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005963 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005964static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005965{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005966 /* if interface is down do nothing */
5967 if (test_bit(__IXGBE_DOWN, &adapter->state))
5968 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005969
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005970 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00005971
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005972 if (adapter->link_up)
5973 ixgbe_watchdog_link_is_up(adapter);
5974 else
5975 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00005976
Greg Rosea985b6c32010-11-18 03:02:52 +00005977 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005978 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005979
5980 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005981}
5982
Alexander Duyck70864002011-04-27 09:13:56 +00005983/**
5984 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
5985 * @adapter - the ixgbe adapter structure
5986 **/
5987static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
5988{
5989 struct ixgbe_hw *hw = &adapter->hw;
5990 s32 err;
5991
5992 /* not searching for SFP so there is nothing to do here */
5993 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
5994 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
5995 return;
5996
5997 /* someone else is in init, wait until next service event */
5998 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5999 return;
6000
6001 err = hw->phy.ops.identify_sfp(hw);
6002 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6003 goto sfp_out;
6004
6005 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6006 /* If no cable is present, then we need to reset
6007 * the next time we find a good cable. */
6008 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6009 }
6010
6011 /* exit on error */
6012 if (err)
6013 goto sfp_out;
6014
6015 /* exit if reset not needed */
6016 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6017 goto sfp_out;
6018
6019 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6020
6021 /*
6022 * A module may be identified correctly, but the EEPROM may not have
6023 * support for that module. setup_sfp() will fail in that case, so
6024 * we should not allow that module to load.
6025 */
6026 if (hw->mac.type == ixgbe_mac_82598EB)
6027 err = hw->phy.ops.reset(hw);
6028 else
6029 err = hw->mac.ops.setup_sfp(hw);
6030
6031 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6032 goto sfp_out;
6033
6034 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6035 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6036
6037sfp_out:
6038 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6039
6040 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6041 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6042 e_dev_err("failed to initialize because an unsupported "
6043 "SFP+ module type was detected.\n");
6044 e_dev_err("Reload the driver after installing a "
6045 "supported module.\n");
6046 unregister_netdev(adapter->netdev);
6047 }
6048}
6049
6050/**
6051 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
6052 * @adapter - the ixgbe adapter structure
6053 **/
6054static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6055{
6056 struct ixgbe_hw *hw = &adapter->hw;
6057 u32 autoneg;
6058 bool negotiation;
6059
6060 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6061 return;
6062
6063 /* someone else is in init, wait until next service event */
6064 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6065 return;
6066
6067 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6068
6069 autoneg = hw->phy.autoneg_advertised;
6070 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
6071 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
6072 hw->mac.autotry_restart = false;
6073 if (hw->mac.ops.setup_link)
6074 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
6075
6076 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6077 adapter->link_check_timeout = jiffies;
6078 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6079}
6080
6081/**
6082 * ixgbe_service_timer - Timer Call-back
6083 * @data: pointer to adapter cast into an unsigned long
6084 **/
6085static void ixgbe_service_timer(unsigned long data)
6086{
6087 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6088 unsigned long next_event_offset;
6089
6090 /* poll faster when waiting for link */
6091 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6092 next_event_offset = HZ / 10;
6093 else
6094 next_event_offset = HZ * 2;
6095
6096 /* Reset the timer */
6097 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6098
6099 ixgbe_service_event_schedule(adapter);
6100}
6101
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006102static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6103{
6104 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6105 return;
6106
6107 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6108
6109 /* If we're already down or resetting, just bail */
6110 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6111 test_bit(__IXGBE_RESETTING, &adapter->state))
6112 return;
6113
6114 ixgbe_dump(adapter);
6115 netdev_err(adapter->netdev, "Reset adapter\n");
6116 adapter->tx_timeout_count++;
6117
6118 ixgbe_reinit_locked(adapter);
6119}
6120
Alexander Duyck70864002011-04-27 09:13:56 +00006121/**
6122 * ixgbe_service_task - manages and runs subtasks
6123 * @work: pointer to work_struct containing our data
6124 **/
6125static void ixgbe_service_task(struct work_struct *work)
6126{
6127 struct ixgbe_adapter *adapter = container_of(work,
6128 struct ixgbe_adapter,
6129 service_task);
6130
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006131 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006132 ixgbe_sfp_detection_subtask(adapter);
6133 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00006134 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006135 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00006136 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006137 ixgbe_check_hang_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006138
6139 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006140}
6141
Alexander Duyck897ab152011-05-27 05:31:47 +00006142void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens,
6143 u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07006144{
6145 struct ixgbe_adv_tx_context_desc *context_desc;
Alexander Duyck897ab152011-05-27 05:31:47 +00006146 u16 i = tx_ring->next_to_use;
6147
6148 context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
6149
6150 i++;
6151 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
6152
6153 /* set bits to identify this as an advanced context descriptor */
6154 type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
6155
6156 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6157 context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof);
6158 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
6159 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
6160}
6161
6162static int ixgbe_tso(struct ixgbe_ring *tx_ring, struct sk_buff *skb,
6163 u32 tx_flags, __be16 protocol, u8 *hdr_len)
6164{
Auke Kok9a799d72007-09-15 14:07:45 -07006165 int err;
Alexander Duyck897ab152011-05-27 05:31:47 +00006166 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006167 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07006168
Alexander Duyck897ab152011-05-27 05:31:47 +00006169 if (!skb_is_gso(skb))
6170 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006171
Alexander Duyck897ab152011-05-27 05:31:47 +00006172 if (skb_header_cloned(skb)) {
6173 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
6174 if (err)
6175 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00006176 }
6177
Alexander Duyck897ab152011-05-27 05:31:47 +00006178 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
6179 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
6180
6181 if (protocol == __constant_htons(ETH_P_IP)) {
6182 struct iphdr *iph = ip_hdr(skb);
6183 iph->tot_len = 0;
6184 iph->check = 0;
6185 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
6186 iph->daddr, 0,
6187 IPPROTO_TCP,
6188 0);
6189 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6190 } else if (skb_is_gso_v6(skb)) {
6191 ipv6_hdr(skb)->payload_len = 0;
6192 tcp_hdr(skb)->check =
6193 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
6194 &ipv6_hdr(skb)->daddr,
6195 0, IPPROTO_TCP, 0);
6196 }
6197
6198 l4len = tcp_hdrlen(skb);
6199 *hdr_len = skb_transport_offset(skb) + l4len;
6200
6201 /* mss_l4len_id: use 1 as index for TSO */
6202 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
6203 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
6204 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
6205
6206 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
6207 vlan_macip_lens = skb_network_header_len(skb);
6208 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6209 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6210
6211 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
6212 mss_l4len_idx);
6213
6214 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00006215}
6216
Alexander Duyck897ab152011-05-27 05:31:47 +00006217static bool ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
Hao Zheng5e09a102010-11-11 13:47:59 +00006218 struct sk_buff *skb, u32 tx_flags,
6219 __be16 protocol)
Auke Kok9a799d72007-09-15 14:07:45 -07006220{
Alexander Duyck897ab152011-05-27 05:31:47 +00006221 u32 vlan_macip_lens = 0;
6222 u32 mss_l4len_idx = 0;
6223 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006224
Alexander Duyck897ab152011-05-27 05:31:47 +00006225 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006226 if (!(tx_flags & IXGBE_TX_FLAGS_HW_VLAN) &&
6227 !(tx_flags & IXGBE_TX_FLAGS_TXSW))
Alexander Duyck897ab152011-05-27 05:31:47 +00006228 return false;
6229 } else {
6230 u8 l4_hdr = 0;
6231 switch (protocol) {
6232 case __constant_htons(ETH_P_IP):
6233 vlan_macip_lens |= skb_network_header_len(skb);
6234 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6235 l4_hdr = ip_hdr(skb)->protocol;
6236 break;
6237 case __constant_htons(ETH_P_IPV6):
6238 vlan_macip_lens |= skb_network_header_len(skb);
6239 l4_hdr = ipv6_hdr(skb)->nexthdr;
6240 break;
6241 default:
6242 if (unlikely(net_ratelimit())) {
6243 dev_warn(tx_ring->dev,
6244 "partial checksum but proto=%x!\n",
6245 skb->protocol);
6246 }
6247 break;
6248 }
Auke Kok9a799d72007-09-15 14:07:45 -07006249
Alexander Duyck897ab152011-05-27 05:31:47 +00006250 switch (l4_hdr) {
6251 case IPPROTO_TCP:
6252 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6253 mss_l4len_idx = tcp_hdrlen(skb) <<
6254 IXGBE_ADVTXD_L4LEN_SHIFT;
6255 break;
6256 case IPPROTO_SCTP:
6257 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6258 mss_l4len_idx = sizeof(struct sctphdr) <<
6259 IXGBE_ADVTXD_L4LEN_SHIFT;
6260 break;
6261 case IPPROTO_UDP:
6262 mss_l4len_idx = sizeof(struct udphdr) <<
6263 IXGBE_ADVTXD_L4LEN_SHIFT;
6264 break;
6265 default:
6266 if (unlikely(net_ratelimit())) {
6267 dev_warn(tx_ring->dev,
6268 "partial checksum but l4 proto=%x!\n",
6269 skb->protocol);
6270 }
6271 break;
6272 }
Auke Kok9a799d72007-09-15 14:07:45 -07006273 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006274
Alexander Duyck897ab152011-05-27 05:31:47 +00006275 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6276 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6277
6278 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6279 type_tucmd, mss_l4len_idx);
6280
6281 return (skb->ip_summed == CHECKSUM_PARTIAL);
Auke Kok9a799d72007-09-15 14:07:45 -07006282}
6283
Alexander Duyckd3d00232011-07-15 02:31:25 +00006284static __le32 ixgbe_tx_cmd_type(u32 tx_flags)
6285{
6286 /* set type for advanced descriptor with frame checksum insertion */
6287 __le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA |
6288 IXGBE_ADVTXD_DCMD_IFCS |
6289 IXGBE_ADVTXD_DCMD_DEXT);
6290
6291 /* set HW vlan bit if vlan is present */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006292 if (tx_flags & IXGBE_TX_FLAGS_HW_VLAN)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006293 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE);
6294
6295 /* set segmentation enable bits for TSO/FSO */
6296#ifdef IXGBE_FCOE
6297 if ((tx_flags & IXGBE_TX_FLAGS_TSO) || (tx_flags & IXGBE_TX_FLAGS_FSO))
6298#else
6299 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6300#endif
6301 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE);
6302
6303 return cmd_type;
6304}
6305
6306static __le32 ixgbe_tx_olinfo_status(u32 tx_flags, unsigned int paylen)
6307{
6308 __le32 olinfo_status =
6309 cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT);
6310
6311 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
6312 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM |
6313 (1 << IXGBE_ADVTXD_IDX_SHIFT));
6314 /* enble IPv4 checksum for TSO */
6315 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6316 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM);
6317 }
6318
6319 /* enable L4 checksum for TSO and TX checksum offload */
6320 if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6321 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM);
6322
6323#ifdef IXGBE_FCOE
6324 /* use index 1 context for FCOE/FSO */
6325 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
6326 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC |
6327 (1 << IXGBE_ADVTXD_IDX_SHIFT));
6328
6329#endif
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006330 /*
6331 * Check Context must be set if Tx switch is enabled, which it
6332 * always is for case where virtual functions are running
6333 */
6334 if (tx_flags & IXGBE_TX_FLAGS_TXSW)
6335 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC);
6336
Alexander Duyckd3d00232011-07-15 02:31:25 +00006337 return olinfo_status;
6338}
6339
6340#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
6341 IXGBE_TXD_CMD_RS)
6342
6343static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
6344 struct sk_buff *skb,
6345 struct ixgbe_tx_buffer *first,
6346 u32 tx_flags,
6347 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006348{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006349 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07006350 struct ixgbe_tx_buffer *tx_buffer_info;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006351 union ixgbe_adv_tx_desc *tx_desc;
6352 dma_addr_t dma;
6353 __le32 cmd_type, olinfo_status;
6354 struct skb_frag_struct *frag;
6355 unsigned int f = 0;
6356 unsigned int data_len = skb->data_len;
6357 unsigned int size = skb_headlen(skb);
6358 u32 offset = 0;
6359 u32 paylen = skb->len - hdr_len;
6360 u16 i = tx_ring->next_to_use;
6361 u16 gso_segs;
Auke Kok9a799d72007-09-15 14:07:45 -07006362
Alexander Duyckd3d00232011-07-15 02:31:25 +00006363#ifdef IXGBE_FCOE
6364 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6365 if (data_len >= sizeof(struct fcoe_crc_eof)) {
6366 data_len -= sizeof(struct fcoe_crc_eof);
6367 } else {
6368 size -= sizeof(struct fcoe_crc_eof) - data_len;
6369 data_len = 0;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006370 }
Auke Kok9a799d72007-09-15 14:07:45 -07006371 }
6372
Alexander Duyckd3d00232011-07-15 02:31:25 +00006373#endif
6374 dma = dma_map_single(dev, skb->data, size, DMA_TO_DEVICE);
6375 if (dma_mapping_error(dev, dma))
6376 goto dma_error;
6377
6378 cmd_type = ixgbe_tx_cmd_type(tx_flags);
6379 olinfo_status = ixgbe_tx_olinfo_status(tx_flags, paylen);
6380
6381 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
6382
6383 for (;;) {
6384 while (size > IXGBE_MAX_DATA_PER_TXD) {
6385 tx_desc->read.buffer_addr = cpu_to_le64(dma + offset);
6386 tx_desc->read.cmd_type_len =
6387 cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD);
6388 tx_desc->read.olinfo_status = olinfo_status;
6389
6390 offset += IXGBE_MAX_DATA_PER_TXD;
6391 size -= IXGBE_MAX_DATA_PER_TXD;
6392
6393 tx_desc++;
6394 i++;
6395 if (i == tx_ring->count) {
6396 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, 0);
6397 i = 0;
6398 }
6399 }
6400
6401 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6402 tx_buffer_info->length = offset + size;
6403 tx_buffer_info->tx_flags = tx_flags;
6404 tx_buffer_info->dma = dma;
6405
6406 tx_desc->read.buffer_addr = cpu_to_le64(dma + offset);
6407 tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size);
6408 tx_desc->read.olinfo_status = olinfo_status;
6409
6410 if (!data_len)
6411 break;
Auke Kok9a799d72007-09-15 14:07:45 -07006412
6413 frag = &skb_shinfo(skb)->frags[f];
Alexander Duyckd3d00232011-07-15 02:31:25 +00006414#ifdef IXGBE_FCOE
6415 size = min_t(unsigned int, data_len, frag->size);
6416#else
6417 size = frag->size;
6418#endif
6419 data_len -= size;
6420 f++;
Auke Kok9a799d72007-09-15 14:07:45 -07006421
Alexander Duyckd3d00232011-07-15 02:31:25 +00006422 offset = 0;
6423 tx_flags |= IXGBE_TX_FLAGS_MAPPED_AS_PAGE;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006424
Ian Campbell877749b2011-08-29 23:18:26 +00006425 dma = skb_frag_dma_map(dev, frag, 0, size, DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006426 if (dma_mapping_error(dev, dma))
6427 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006428
Alexander Duyckd3d00232011-07-15 02:31:25 +00006429 tx_desc++;
6430 i++;
6431 if (i == tx_ring->count) {
6432 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, 0);
6433 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006434 }
6435 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006436
Alexander Duyckd3d00232011-07-15 02:31:25 +00006437 tx_desc->read.cmd_type_len |= cpu_to_le32(IXGBE_TXD_CMD);
6438
6439 i++;
6440 if (i == tx_ring->count)
6441 i = 0;
6442
6443 tx_ring->next_to_use = i;
6444
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006445 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6446 gso_segs = skb_shinfo(skb)->gso_segs;
6447#ifdef IXGBE_FCOE
6448 /* adjust for FCoE Sequence Offload */
6449 else if (tx_flags & IXGBE_TX_FLAGS_FSO)
6450 gso_segs = DIV_ROUND_UP(skb->len - hdr_len,
6451 skb_shinfo(skb)->gso_size);
6452#endif /* IXGBE_FCOE */
Alexander Duyckd3d00232011-07-15 02:31:25 +00006453 else
6454 gso_segs = 1;
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006455
6456 /* multiply data chunks by size of headers */
Alexander Duyckd3d00232011-07-15 02:31:25 +00006457 tx_buffer_info->bytecount = paylen + (gso_segs * hdr_len);
6458 tx_buffer_info->gso_segs = gso_segs;
6459 tx_buffer_info->skb = skb;
Auke Kok9a799d72007-09-15 14:07:45 -07006460
Alexander Duyckd3d00232011-07-15 02:31:25 +00006461 /* set the timestamp */
6462 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07006463
6464 /*
6465 * Force memory writes to complete before letting h/w
6466 * know there are new descriptors to fetch. (Only
6467 * applicable for weak-ordered memory model archs,
6468 * such as IA-64).
6469 */
6470 wmb();
6471
Alexander Duyckd3d00232011-07-15 02:31:25 +00006472 /* set next_to_watch value indicating a packet is present */
6473 first->next_to_watch = tx_desc;
6474
6475 /* notify HW of packet */
Alexander Duyck84ea2592010-11-16 19:26:49 -08006476 writel(i, tx_ring->tail);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006477
6478 return;
6479dma_error:
6480 dev_err(dev, "TX DMA map failed\n");
6481
6482 /* clear dma mappings for failed tx_buffer_info map */
6483 for (;;) {
6484 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6485 ixgbe_unmap_tx_resource(tx_ring, tx_buffer_info);
6486 if (tx_buffer_info == first)
6487 break;
6488 if (i == 0)
6489 i = tx_ring->count;
6490 i--;
6491 }
6492
6493 dev_kfree_skb_any(skb);
6494
6495 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07006496}
6497
Alexander Duyck69830522011-01-06 14:29:58 +00006498static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb,
6499 u32 tx_flags, __be16 protocol)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006500{
Alexander Duyck69830522011-01-06 14:29:58 +00006501 struct ixgbe_q_vector *q_vector = ring->q_vector;
6502 union ixgbe_atr_hash_dword input = { .dword = 0 };
6503 union ixgbe_atr_hash_dword common = { .dword = 0 };
6504 union {
6505 unsigned char *network;
6506 struct iphdr *ipv4;
6507 struct ipv6hdr *ipv6;
6508 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006509 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006510 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006511
Alexander Duyck69830522011-01-06 14:29:58 +00006512 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6513 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006514 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006515
Alexander Duyck69830522011-01-06 14:29:58 +00006516 /* do nothing if sampling is disabled */
6517 if (!ring->atr_sample_rate)
6518 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006519
Alexander Duyck69830522011-01-06 14:29:58 +00006520 ring->atr_count++;
6521
6522 /* snag network header to get L4 type and address */
6523 hdr.network = skb_network_header(skb);
6524
6525 /* Currently only IPv4/IPv6 with TCP is supported */
6526 if ((protocol != __constant_htons(ETH_P_IPV6) ||
6527 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
6528 (protocol != __constant_htons(ETH_P_IP) ||
6529 hdr.ipv4->protocol != IPPROTO_TCP))
6530 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006531
6532 th = tcp_hdr(skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006533
Alexander Duyck66f32a82011-06-29 05:43:22 +00006534 /* skip this packet since it is invalid or the socket is closing */
6535 if (!th || th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00006536 return;
6537
6538 /* sample on all syn packets or once every atr sample count */
6539 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6540 return;
6541
6542 /* reset sample count */
6543 ring->atr_count = 0;
6544
6545 vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
6546
6547 /*
6548 * src and dst are inverted, think how the receiver sees them
6549 *
6550 * The input is broken into two sections, a non-compressed section
6551 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6552 * is XORed together and stored in the compressed dword.
6553 */
6554 input.formatted.vlan_id = vlan_id;
6555
6556 /*
6557 * since src port and flex bytes occupy the same word XOR them together
6558 * and write the value to source port portion of compressed dword
6559 */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006560 if (tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Alexander Duyck69830522011-01-06 14:29:58 +00006561 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6562 else
6563 common.port.src ^= th->dest ^ protocol;
6564 common.port.dst ^= th->source;
6565
6566 if (protocol == __constant_htons(ETH_P_IP)) {
6567 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6568 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6569 } else {
6570 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6571 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6572 hdr.ipv6->saddr.s6_addr32[1] ^
6573 hdr.ipv6->saddr.s6_addr32[2] ^
6574 hdr.ipv6->saddr.s6_addr32[3] ^
6575 hdr.ipv6->daddr.s6_addr32[0] ^
6576 hdr.ipv6->daddr.s6_addr32[1] ^
6577 hdr.ipv6->daddr.s6_addr32[2] ^
6578 hdr.ipv6->daddr.s6_addr32[3];
6579 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006580
6581 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006582 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6583 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006584}
6585
Alexander Duyck63544e92011-05-27 05:31:42 +00006586static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006587{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006588 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006589 /* Herbert's original patch had:
6590 * smp_mb__after_netif_stop_queue();
6591 * but since that doesn't exist yet, just open code it. */
6592 smp_mb();
6593
6594 /* We need to check again in a case another CPU has just
6595 * made room available. */
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006596 if (likely(ixgbe_desc_unused(tx_ring) < size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006597 return -EBUSY;
6598
6599 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006600 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006601 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006602 return 0;
6603}
6604
Alexander Duyck82d4e462011-06-11 01:44:58 +00006605static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006606{
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006607 if (likely(ixgbe_desc_unused(tx_ring) >= size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006608 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006609 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006610}
6611
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006612static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6613{
6614 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck64407522011-06-11 01:44:53 +00006615 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
6616 smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00006617#ifdef IXGBE_FCOE
Alexander Duyck64407522011-06-11 01:44:53 +00006618 __be16 protocol = vlan_get_protocol(skb);
Hao Zheng5e09a102010-11-11 13:47:59 +00006619
John Fastabende5b64632011-03-08 03:44:52 +00006620 if (((protocol == htons(ETH_P_FCOE)) ||
6621 (protocol == htons(ETH_P_FIP))) &&
6622 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6623 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
6624 txq += adapter->ring_feature[RING_F_FCOE].mask;
6625 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00006626 }
6627#endif
6628
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006629 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6630 while (unlikely(txq >= dev->real_num_tx_queues))
6631 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00006632 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006633 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006634
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006635 return skb_tx_hash(dev, skb);
6636}
6637
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006638netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00006639 struct ixgbe_adapter *adapter,
6640 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006641{
Alexander Duyckd3d00232011-07-15 02:31:25 +00006642 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00006643 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006644 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00006645#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6646 unsigned short f;
6647#endif
Alexander Duycka535c302011-05-27 05:31:52 +00006648 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00006649 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00006650 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00006651
Alexander Duycka535c302011-05-27 05:31:52 +00006652 /*
6653 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
6654 * + 1 desc for skb_head_len/IXGBE_MAX_DATA_PER_TXD,
6655 * + 2 desc gap to keep tail from touching head,
6656 * + 1 desc for context descriptor,
6657 * otherwise try next time
6658 */
6659#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6660 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
6661 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6662#else
6663 count += skb_shinfo(skb)->nr_frags;
6664#endif
6665 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
6666 tx_ring->tx_stats.tx_busy++;
6667 return NETDEV_TX_BUSY;
6668 }
6669
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006670#ifdef CONFIG_PCI_IOV
6671 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
6672 tx_flags |= IXGBE_TX_FLAGS_TXSW;
6673
6674#endif
Alexander Duyck66f32a82011-06-29 05:43:22 +00006675 /* if we have a HW VLAN tag being added default to the HW one */
Jesse Grosseab6d182010-10-20 13:56:03 +00006676 if (vlan_tx_tag_present(skb)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00006677 tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
6678 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6679 /* else if it is a SW VLAN check the next protocol and store the tag */
6680 } else if (protocol == __constant_htons(ETH_P_8021Q)) {
6681 struct vlan_hdr *vhdr, _vhdr;
6682 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
6683 if (!vhdr)
6684 goto out_drop;
6685
6686 protocol = vhdr->h_vlan_encapsulated_proto;
6687 tx_flags |= ntohs(vhdr->h_vlan_TCI) << IXGBE_TX_FLAGS_VLAN_SHIFT;
6688 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07006689 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006690
Alexander Duyck66f32a82011-06-29 05:43:22 +00006691 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00006692 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
6693 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00006694 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
6695 tx_flags |= tx_ring->dcb_tc <<
6696 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
6697 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
6698 struct vlan_ethhdr *vhdr;
6699 if (skb_header_cloned(skb) &&
6700 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
6701 goto out_drop;
6702 vhdr = (struct vlan_ethhdr *)skb->data;
6703 vhdr->h_vlan_TCI = htons(tx_flags >>
6704 IXGBE_TX_FLAGS_VLAN_SHIFT);
6705 } else {
6706 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6707 }
6708 }
Alexander Duycka535c302011-05-27 05:31:52 +00006709
Alexander Duycka535c302011-05-27 05:31:52 +00006710 /* record the location of the first descriptor for this packet */
Alexander Duyckd3d00232011-07-15 02:31:25 +00006711 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
Alexander Duycka535c302011-05-27 05:31:52 +00006712
Yi Zoueacd73f2009-05-13 13:11:06 +00006713#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00006714 /* setup tx offload for FCoE */
6715 if ((protocol == __constant_htons(ETH_P_FCOE)) &&
6716 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
Alexander Duyck897ab152011-05-27 05:31:47 +00006717 tso = ixgbe_fso(tx_ring, skb, tx_flags, &hdr_len);
6718 if (tso < 0)
6719 goto out_drop;
6720 else if (tso)
Alexander Duyck66f32a82011-06-29 05:43:22 +00006721 tx_flags |= IXGBE_TX_FLAGS_FSO |
6722 IXGBE_TX_FLAGS_FCOE;
6723 else
6724 tx_flags |= IXGBE_TX_FLAGS_FCOE;
Auke Kok9a799d72007-09-15 14:07:45 -07006725
Alexander Duyck66f32a82011-06-29 05:43:22 +00006726 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006727 }
Auke Kok9a799d72007-09-15 14:07:45 -07006728
Auke Kok9a799d72007-09-15 14:07:45 -07006729#endif /* IXGBE_FCOE */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006730 /* setup IPv4/IPv6 offloads */
6731 if (protocol == __constant_htons(ETH_P_IP))
6732 tx_flags |= IXGBE_TX_FLAGS_IPV4;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006733
Alexander Duyck66f32a82011-06-29 05:43:22 +00006734 tso = ixgbe_tso(tx_ring, skb, tx_flags, protocol, &hdr_len);
6735 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07006736 goto out_drop;
Alexander Duyck66f32a82011-06-29 05:43:22 +00006737 else if (tso)
6738 tx_flags |= IXGBE_TX_FLAGS_TSO;
6739 else if (ixgbe_tx_csum(tx_ring, skb, tx_flags, protocol))
6740 tx_flags |= IXGBE_TX_FLAGS_CSUM;
6741
6742 /* add the ATR filter if ATR is on */
6743 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
6744 ixgbe_atr(tx_ring, skb, tx_flags, protocol);
6745
6746#ifdef IXGBE_FCOE
6747xmit_fcoe:
6748#endif /* IXGBE_FCOE */
Alexander Duyckd3d00232011-07-15 02:31:25 +00006749 ixgbe_tx_map(tx_ring, skb, first, tx_flags, hdr_len);
6750
6751 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07006752
6753 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006754
6755out_drop:
6756 dev_kfree_skb_any(skb);
6757 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07006758}
6759
6760static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
6761{
6762 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6763 struct ixgbe_ring *tx_ring;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006764
Auke Kok9a799d72007-09-15 14:07:45 -07006765 tx_ring = adapter->tx_ring[skb->queue_mapping];
6766 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
6767}
6768
6769/**
6770 * ixgbe_set_mac - Change the Ethernet Address of the NIC
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006771 * @netdev: network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07006772 * @p: pointer to an address structure
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006773 *
Auke Kok9a799d72007-09-15 14:07:45 -07006774 * Returns 0 on success, negative on failure
6775 **/
6776static int ixgbe_set_mac(struct net_device *netdev, void *p)
6777{
Ben Hutchings6b73e102009-04-29 08:08:58 +00006778 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6779 struct ixgbe_hw *hw = &adapter->hw;
6780 struct sockaddr *addr = p;
6781
6782 if (!is_valid_ether_addr(addr->sa_data))
6783 return -EADDRNOTAVAIL;
6784
6785 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
6786 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
6787
6788 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
6789 IXGBE_RAH_AV);
6790
6791 return 0;
6792}
6793
6794static int
6795ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
6796{
6797 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6798 struct ixgbe_hw *hw = &adapter->hw;
6799 u16 value;
6800 int rc;
6801
6802 if (prtad != hw->phy.mdio.prtad)
6803 return -EINVAL;
6804 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
6805 if (!rc)
6806 rc = value;
6807 return rc;
6808}
6809
6810static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
6811 u16 addr, u16 value)
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006812{
6813 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jiri Pirko31278e72009-06-17 01:12:19 +00006814 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006815
6816 if (prtad != hw->phy.mdio.prtad)
6817 return -EINVAL;
6818 return hw->phy.ops.write_reg(hw, addr, devad, value);
6819}
6820
6821static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
6822{
6823 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6824
6825 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
6826}
6827
6828/**
6829 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
6830 * netdev->dev_addrs
6831 * @netdev: network interface device structure
6832 *
6833 * Returns non-zero on failure
6834 **/
Jiri Pirko31278e72009-06-17 01:12:19 +00006835static int ixgbe_add_sanmac_netdev(struct net_device *dev)
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006836{
6837 int err = 0;
6838 struct ixgbe_adapter *adapter = netdev_priv(dev);
6839 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6840
6841 if (is_valid_ether_addr(mac->san_addr)) {
6842 rtnl_lock();
6843 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6844 rtnl_unlock();
6845 }
6846 return err;
6847}
6848
6849/**
6850 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
6851 * netdev->dev_addrs
6852 * @netdev: network interface device structure
6853 *
Auke Kok9a799d72007-09-15 14:07:45 -07006854 * Returns non-zero on failure
6855 **/
6856static int ixgbe_del_sanmac_netdev(struct net_device *dev)
6857{
6858 int err = 0;
6859 struct ixgbe_adapter *adapter = netdev_priv(dev);
6860 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6861
6862 if (is_valid_ether_addr(mac->san_addr)) {
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006863 rtnl_lock();
Auke Kok9a799d72007-09-15 14:07:45 -07006864 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
Alexander Duyck1a647bd2010-01-13 01:49:13 +00006865 rtnl_unlock();
6866 }
6867 return err;
6868}
Auke Kok9a799d72007-09-15 14:07:45 -07006869
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006870#ifdef CONFIG_NET_POLL_CONTROLLER
6871/*
6872 * Polling 'interrupt' - used by things like netconsole to send skbs
6873 * without having to re-enable interrupts. It's not called while
6874 * the interrupt routine is executing.
6875 */
6876static void ixgbe_netpoll(struct net_device *netdev)
6877{
6878 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006879 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07006880
6881 /* if interface is down do nothing */
6882 if (test_bit(__IXGBE_DOWN, &adapter->state))
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006883 return;
6884
6885 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Stephen Hemminger00829822008-11-20 20:14:53 -08006886 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006887 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Chris Leeche90d4002009-03-10 16:00:24 +00006888 for (i = 0; i < num_q_vectors; i++) {
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006889 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00006890 ixgbe_msix_clean_rings(0, q_vector);
Stephen Hemminger0edc3522008-11-19 22:24:29 -08006891 }
6892 } else {
6893 ixgbe_intr(adapter->pdev->irq, netdev);
6894 }
6895 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
6896}
6897#endif
6898
Eric Dumazetde1036b2010-10-20 23:00:04 +00006899static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
6900 struct rtnl_link_stats64 *stats)
6901{
6902 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6903 int i;
6904
Eric Dumazet1a515022010-11-16 19:26:42 -08006905 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00006906 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08006907 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00006908 u64 bytes, packets;
6909 unsigned int start;
6910
Eric Dumazet1a515022010-11-16 19:26:42 -08006911 if (ring) {
6912 do {
6913 start = u64_stats_fetch_begin_bh(&ring->syncp);
6914 packets = ring->stats.packets;
6915 bytes = ring->stats.bytes;
6916 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6917 stats->rx_packets += packets;
6918 stats->rx_bytes += bytes;
6919 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00006920 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00006921
6922 for (i = 0; i < adapter->num_tx_queues; i++) {
6923 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
6924 u64 bytes, packets;
6925 unsigned int start;
6926
6927 if (ring) {
6928 do {
6929 start = u64_stats_fetch_begin_bh(&ring->syncp);
6930 packets = ring->stats.packets;
6931 bytes = ring->stats.bytes;
6932 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6933 stats->tx_packets += packets;
6934 stats->tx_bytes += bytes;
6935 }
6936 }
Eric Dumazet1a515022010-11-16 19:26:42 -08006937 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00006938 /* following stats updated by ixgbe_watchdog_task() */
6939 stats->multicast = netdev->stats.multicast;
6940 stats->rx_errors = netdev->stats.rx_errors;
6941 stats->rx_length_errors = netdev->stats.rx_length_errors;
6942 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
6943 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
6944 return stats;
6945}
6946
John Fastabend8b1c0b22011-05-03 02:26:48 +00006947/* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
6948 * #adapter: pointer to ixgbe_adapter
6949 * @tc: number of traffic classes currently enabled
6950 *
6951 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
6952 * 802.1Q priority maps to a packet buffer that exists.
6953 */
6954static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
6955{
6956 struct ixgbe_hw *hw = &adapter->hw;
6957 u32 reg, rsave;
6958 int i;
6959
6960 /* 82598 have a static priority to TC mapping that can not
6961 * be changed so no validation is needed.
6962 */
6963 if (hw->mac.type == ixgbe_mac_82598EB)
6964 return;
6965
6966 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
6967 rsave = reg;
6968
6969 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
6970 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
6971
6972 /* If up2tc is out of bounds default to zero */
6973 if (up2tc > tc)
6974 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
6975 }
6976
6977 if (reg != rsave)
6978 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
6979
6980 return;
6981}
6982
6983
6984/* ixgbe_setup_tc - routine to configure net_device for multiple traffic
6985 * classes.
6986 *
6987 * @netdev: net device to configure
6988 * @tc: number of traffic classes to enable
6989 */
6990int ixgbe_setup_tc(struct net_device *dev, u8 tc)
6991{
John Fastabend8b1c0b22011-05-03 02:26:48 +00006992 struct ixgbe_adapter *adapter = netdev_priv(dev);
6993 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00006994
John Fastabende7589ea2011-07-18 22:38:36 +00006995 /* Multiple traffic classes requires multiple queues */
6996 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
6997 e_err(drv, "Enable failed, needs MSI-X\n");
6998 return -EINVAL;
6999 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00007000
7001 /* Hardware supports up to 8 traffic classes */
7002 if (tc > MAX_TRAFFIC_CLASS ||
7003 (hw->mac.type == ixgbe_mac_82598EB && tc < MAX_TRAFFIC_CLASS))
7004 return -EINVAL;
7005
7006 /* Hardware has to reinitialize queues and interrupts to
7007 * match packet buffer alignment. Unfortunantly, the
7008 * hardware is not flexible enough to do this dynamically.
7009 */
7010 if (netif_running(dev))
7011 ixgbe_close(dev);
7012 ixgbe_clear_interrupt_scheme(adapter);
7013
John Fastabende7589ea2011-07-18 22:38:36 +00007014 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007015 netdev_set_num_tc(dev, tc);
John Fastabende7589ea2011-07-18 22:38:36 +00007016 adapter->last_lfc_mode = adapter->hw.fc.current_mode;
7017
7018 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
7019 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7020
7021 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
7022 adapter->hw.fc.requested_mode = ixgbe_fc_none;
7023 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007024 netdev_reset_tc(dev);
7025
John Fastabende7589ea2011-07-18 22:38:36 +00007026 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
7027
7028 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
7029 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7030
7031 adapter->temp_dcb_cfg.pfc_mode_enable = false;
7032 adapter->dcb_cfg.pfc_mode_enable = false;
7033 }
7034
John Fastabend8b1c0b22011-05-03 02:26:48 +00007035 ixgbe_init_interrupt_scheme(adapter);
7036 ixgbe_validate_rtr(adapter, tc);
7037 if (netif_running(dev))
7038 ixgbe_open(dev);
7039
7040 return 0;
7041}
Eric Dumazetde1036b2010-10-20 23:00:04 +00007042
Don Skidmore082757a2011-07-21 05:55:00 +00007043void ixgbe_do_reset(struct net_device *netdev)
7044{
7045 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7046
7047 if (netif_running(netdev))
7048 ixgbe_reinit_locked(adapter);
7049 else
7050 ixgbe_reset(adapter);
7051}
7052
7053static u32 ixgbe_fix_features(struct net_device *netdev, u32 data)
7054{
7055 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7056
7057#ifdef CONFIG_DCB
7058 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
7059 data &= ~NETIF_F_HW_VLAN_RX;
7060#endif
7061
7062 /* return error if RXHASH is being enabled when RSS is not supported */
7063 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
7064 data &= ~NETIF_F_RXHASH;
7065
7066 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7067 if (!(data & NETIF_F_RXCSUM))
7068 data &= ~NETIF_F_LRO;
7069
7070 /* Turn off LRO if not RSC capable or invalid ITR settings */
7071 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) {
7072 data &= ~NETIF_F_LRO;
7073 } else if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
7074 (adapter->rx_itr_setting != 1 &&
7075 adapter->rx_itr_setting > IXGBE_MAX_RSC_INT_RATE)) {
7076 data &= ~NETIF_F_LRO;
7077 e_info(probe, "rx-usecs set too low, not enabling RSC\n");
7078 }
7079
7080 return data;
7081}
7082
7083static int ixgbe_set_features(struct net_device *netdev, u32 data)
7084{
7085 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7086 bool need_reset = false;
7087
7088 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7089 if (!(data & NETIF_F_RXCSUM))
7090 adapter->flags &= ~IXGBE_FLAG_RX_CSUM_ENABLED;
7091 else
7092 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
7093
7094 /* Make sure RSC matches LRO, reset if change */
7095 if (!!(data & NETIF_F_LRO) !=
7096 !!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
7097 adapter->flags2 ^= IXGBE_FLAG2_RSC_ENABLED;
7098 switch (adapter->hw.mac.type) {
7099 case ixgbe_mac_X540:
7100 case ixgbe_mac_82599EB:
7101 need_reset = true;
7102 break;
7103 default:
7104 break;
7105 }
7106 }
7107
7108 /*
7109 * Check if Flow Director n-tuple support was enabled or disabled. If
7110 * the state changed, we need to reset.
7111 */
7112 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
7113 /* turn off ATR, enable perfect filters and reset */
7114 if (data & NETIF_F_NTUPLE) {
7115 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7116 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7117 need_reset = true;
7118 }
7119 } else if (!(data & NETIF_F_NTUPLE)) {
7120 /* turn off Flow Director, set ATR and reset */
7121 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7122 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
7123 !(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
7124 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7125 need_reset = true;
7126 }
7127
7128 if (need_reset)
7129 ixgbe_do_reset(netdev);
7130
7131 return 0;
7132
7133}
7134
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007135static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007136 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007137 .ndo_stop = ixgbe_close,
7138 .ndo_start_xmit = ixgbe_xmit_frame,
7139 .ndo_select_queue = ixgbe_select_queue,
7140 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007141 .ndo_validate_addr = eth_validate_addr,
7142 .ndo_set_mac_address = ixgbe_set_mac,
7143 .ndo_change_mtu = ixgbe_change_mtu,
7144 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007145 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7146 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007147 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007148 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7149 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7150 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
7151 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007152 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabend24095aa2011-02-23 05:58:03 +00007153 .ndo_setup_tc = ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007154#ifdef CONFIG_NET_POLL_CONTROLLER
7155 .ndo_poll_controller = ixgbe_netpoll,
7156#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007157#ifdef IXGBE_FCOE
7158 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007159 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007160 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007161 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7162 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007163 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Yi Zou332d4a72009-05-13 13:11:53 +00007164#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00007165 .ndo_set_features = ixgbe_set_features,
7166 .ndo_fix_features = ixgbe_fix_features,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007167};
7168
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007169static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
7170 const struct ixgbe_info *ii)
7171{
7172#ifdef CONFIG_PCI_IOV
7173 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007174
Greg Rosec6bda302011-08-24 02:37:55 +00007175 if (hw->mac.type == ixgbe_mac_82598EB)
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007176 return;
7177
7178 /* The 82599 supports up to 64 VFs per physical function
7179 * but this implementation limits allocation to 63 so that
7180 * basic networking resources are still available to the
7181 * physical function
7182 */
7183 adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
Greg Rosec6bda302011-08-24 02:37:55 +00007184 ixgbe_enable_sriov(adapter, ii);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007185#endif /* CONFIG_PCI_IOV */
7186}
7187
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007188/**
Auke Kok9a799d72007-09-15 14:07:45 -07007189 * ixgbe_probe - Device Initialization Routine
7190 * @pdev: PCI device information struct
7191 * @ent: entry in ixgbe_pci_tbl
7192 *
7193 * Returns 0 on success, negative on failure
7194 *
7195 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7196 * The OS initialization, configuring of the adapter private structure,
7197 * and a hardware reset occur.
7198 **/
7199static int __devinit ixgbe_probe(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007200 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007201{
7202 struct net_device *netdev;
7203 struct ixgbe_adapter *adapter = NULL;
7204 struct ixgbe_hw *hw;
7205 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007206 static int cards_found;
7207 int i, err, pci_using_dac;
Don Skidmore289700db2010-12-03 03:32:58 +00007208 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00007209 unsigned int indices = num_possible_cpus();
Yi Zoueacd73f2009-05-13 13:11:06 +00007210#ifdef IXGBE_FCOE
7211 u16 device_caps;
7212#endif
Don Skidmore289700db2010-12-03 03:32:58 +00007213 u32 eec;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007214 u16 wol_cap;
Auke Kok9a799d72007-09-15 14:07:45 -07007215
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007216 /* Catch broken hardware that put the wrong VF device ID in
7217 * the PCIe SR-IOV capability.
7218 */
7219 if (pdev->is_virtfn) {
7220 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7221 pci_name(pdev), pdev->vendor, pdev->device);
7222 return -EINVAL;
7223 }
7224
gouji-new9ce77662009-05-06 10:44:45 +00007225 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007226 if (err)
7227 return err;
7228
Nick Nunley1b507732010-04-27 13:10:27 +00007229 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7230 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007231 pci_using_dac = 1;
7232 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007233 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007234 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007235 err = dma_set_coherent_mask(&pdev->dev,
7236 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007237 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007238 dev_err(&pdev->dev,
7239 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007240 goto err_dma;
7241 }
7242 }
7243 pci_using_dac = 0;
7244 }
7245
gouji-new9ce77662009-05-06 10:44:45 +00007246 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007247 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007248 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007249 dev_err(&pdev->dev,
7250 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007251 goto err_pci_reg;
7252 }
7253
Frans Pop19d5afd2009-10-02 10:04:12 -07007254 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007255
Auke Kok9a799d72007-09-15 14:07:45 -07007256 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007257 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007258
John Fastabende901acd2011-04-26 07:26:08 +00007259#ifdef CONFIG_IXGBE_DCB
7260 indices *= MAX_TRAFFIC_CLASS;
7261#endif
7262
John Fastabendc85a2612010-02-25 23:15:21 +00007263 if (ii->mac == ixgbe_mac_82598EB)
7264 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7265 else
7266 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7267
John Fastabende901acd2011-04-26 07:26:08 +00007268#ifdef IXGBE_FCOE
John Fastabendc85a2612010-02-25 23:15:21 +00007269 indices += min_t(unsigned int, num_possible_cpus(),
7270 IXGBE_MAX_FCOE_INDICES);
7271#endif
John Fastabendc85a2612010-02-25 23:15:21 +00007272 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007273 if (!netdev) {
7274 err = -ENOMEM;
7275 goto err_alloc_etherdev;
7276 }
7277
Auke Kok9a799d72007-09-15 14:07:45 -07007278 SET_NETDEV_DEV(netdev, &pdev->dev);
7279
Auke Kok9a799d72007-09-15 14:07:45 -07007280 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007281 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007282
7283 adapter->netdev = netdev;
7284 adapter->pdev = pdev;
7285 hw = &adapter->hw;
7286 hw->back = adapter;
7287 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
7288
Jeff Kirsher05857982008-09-11 19:57:00 -07007289 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007290 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007291 if (!hw->hw_addr) {
7292 err = -EIO;
7293 goto err_ioremap;
7294 }
7295
7296 for (i = 1; i <= 5; i++) {
7297 if (pci_resource_len(pdev, i) == 0)
7298 continue;
7299 }
7300
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007301 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007302 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007303 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007304 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007305
Auke Kok9a799d72007-09-15 14:07:45 -07007306 adapter->bd_number = cards_found;
7307
Auke Kok9a799d72007-09-15 14:07:45 -07007308 /* Setup hw api */
7309 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007310 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007311
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007312 /* EEPROM */
7313 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7314 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7315 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7316 if (!(eec & (1 << 8)))
7317 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7318
7319 /* PHY */
7320 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007321 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007322 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7323 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7324 hw->phy.mdio.mmds = 0;
7325 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7326 hw->phy.mdio.dev = netdev;
7327 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7328 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007329
Don Skidmore8ca783a2009-05-26 20:40:47 -07007330 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007331
7332 /* setup the private structure */
7333 err = ixgbe_sw_init(adapter);
7334 if (err)
7335 goto err_sw_init;
7336
Don Skidmoree86bff02010-02-11 04:14:08 +00007337 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007338 switch (adapter->hw.mac.type) {
7339 case ixgbe_mac_82599EB:
7340 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007341 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007342 break;
7343 default:
7344 break;
7345 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007346
Don Skidmorebf069c92009-05-07 10:39:54 +00007347 /*
7348 * If there is a fan on this device and it has failed log the
7349 * failure.
7350 */
7351 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7352 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7353 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007354 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007355 }
7356
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007357 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007358 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007359 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007360 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007361 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7362 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007363 err = 0;
7364 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007365 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007366 "module type was detected.\n");
7367 e_dev_err("Reload the driver after installing a supported "
7368 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007369 goto err_sw_init;
7370 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007371 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007372 goto err_sw_init;
7373 }
7374
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007375 ixgbe_probe_vf(adapter, ii);
7376
Emil Tantilov396e7992010-07-01 20:05:12 +00007377 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007378 NETIF_F_IP_CSUM |
Don Skidmore082757a2011-07-21 05:55:00 +00007379 NETIF_F_IPV6_CSUM |
Joe Perchese8e9f692010-09-07 21:34:53 +00007380 NETIF_F_HW_VLAN_TX |
7381 NETIF_F_HW_VLAN_RX |
Don Skidmore082757a2011-07-21 05:55:00 +00007382 NETIF_F_HW_VLAN_FILTER |
7383 NETIF_F_TSO |
7384 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00007385 NETIF_F_RXHASH |
7386 NETIF_F_RXCSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007387
Don Skidmore082757a2011-07-21 05:55:00 +00007388 netdev->hw_features = netdev->features;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007389
Don Skidmore58be7662011-04-12 09:42:11 +00007390 switch (adapter->hw.mac.type) {
7391 case ixgbe_mac_82599EB:
7392 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007393 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore082757a2011-07-21 05:55:00 +00007394 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7395 NETIF_F_NTUPLE;
Don Skidmore58be7662011-04-12 09:42:11 +00007396 break;
7397 default:
7398 break;
7399 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007400
Jeff Kirsherad31c402008-06-05 04:05:30 -07007401 netdev->vlan_features |= NETIF_F_TSO;
7402 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007403 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007404 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007405 netdev->vlan_features |= NETIF_F_SG;
7406
Jiri Pirko01789342011-08-16 06:29:00 +00007407 netdev->priv_flags |= IFF_UNICAST_FLT;
7408
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007409 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7410 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
7411 IXGBE_FLAG_DCB_ENABLED);
Alexander Duyck2f90b862008-11-20 20:52:10 -08007412
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007413#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007414 netdev->dcbnl_ops = &dcbnl_ops;
7415#endif
7416
Yi Zoueacd73f2009-05-13 13:11:06 +00007417#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007418 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00007419 if (hw->mac.ops.get_device_caps) {
7420 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007421 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7422 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007423 }
7424 }
Yi Zou5e09d7f2010-07-19 13:59:52 +00007425 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7426 netdev->vlan_features |= NETIF_F_FCOE_CRC;
7427 netdev->vlan_features |= NETIF_F_FSO;
7428 netdev->vlan_features |= NETIF_F_FCOE_MTU;
7429 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007430#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007431 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007432 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007433 netdev->vlan_features |= NETIF_F_HIGHDMA;
7434 }
Auke Kok9a799d72007-09-15 14:07:45 -07007435
Don Skidmore082757a2011-07-21 05:55:00 +00007436 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
7437 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007438 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007439 netdev->features |= NETIF_F_LRO;
7440
Auke Kok9a799d72007-09-15 14:07:45 -07007441 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007442 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007443 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007444 err = -EIO;
7445 goto err_eeprom;
7446 }
7447
7448 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7449 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7450
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007451 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007452 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007453 err = -EIO;
7454 goto err_eeprom;
7455 }
7456
Don Skidmorec6ecf392010-12-03 03:31:51 +00007457 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7458 if (hw->mac.ops.disable_tx_laser &&
7459 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00007460 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00007461 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00007462 hw->mac.ops.disable_tx_laser(hw);
7463
Alexander Duyck70864002011-04-27 09:13:56 +00007464 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
7465 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007466
Alexander Duyck70864002011-04-27 09:13:56 +00007467 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7468 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007469
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007470 err = ixgbe_init_interrupt_scheme(adapter);
7471 if (err)
7472 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007473
Don Skidmore082757a2011-07-21 05:55:00 +00007474 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
7475 netdev->hw_features &= ~NETIF_F_RXHASH;
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007476 netdev->features &= ~NETIF_F_RXHASH;
Don Skidmore082757a2011-07-21 05:55:00 +00007477 }
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007478
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007479 /* WOL not supported for all but the following */
7480 adapter->wol = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007481 switch (pdev->device) {
Don Skidmore0b077fe2010-12-03 03:32:13 +00007482 case IXGBE_DEV_ID_82599_SFP:
7483 /* Only this subdevice supports WOL */
7484 if (pdev->subsystem_device == IXGBE_SUBDEV_ID_82599_SFP)
Andy Gospodarek9417c462011-07-16 07:31:33 +00007485 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0b077fe2010-12-03 03:32:13 +00007486 break;
Alexander Duyck50d6c682010-11-16 19:27:05 -08007487 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7488 /* All except this subdevice support WOL */
Don Skidmore0b077fe2010-12-03 03:32:13 +00007489 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
Andy Gospodarek9417c462011-07-16 07:31:33 +00007490 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0b077fe2010-12-03 03:32:13 +00007491 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007492 case IXGBE_DEV_ID_82599_KX4:
Andy Gospodarek9417c462011-07-16 07:31:33 +00007493 adapter->wol = IXGBE_WUFC_MAG;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007494 break;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007495 case IXGBE_DEV_ID_X540T:
7496 /* Check eeprom to see if it is enabled */
7497 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
7498 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
7499
7500 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
7501 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
7502 (hw->bus.func == 0)))
7503 adapter->wol = IXGBE_WUFC_MAG;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007504 break;
7505 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007506 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7507
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007508 /* pick up the PCI bus settings for reporting later */
7509 hw->mac.ops.get_bus_info(hw);
7510
Auke Kok9a799d72007-09-15 14:07:45 -07007511 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007512 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007513 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7514 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007515 "Unknown"),
7516 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7517 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7518 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7519 "Unknown"),
7520 netdev->dev_addr);
Don Skidmore289700db2010-12-03 03:32:58 +00007521
7522 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7523 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007524 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007525 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700db2010-12-03 03:32:58 +00007526 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007527 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700db2010-12-03 03:32:58 +00007528 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007529 else
Don Skidmore289700db2010-12-03 03:32:58 +00007530 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7531 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007532
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007533 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007534 e_dev_warn("PCI-Express bandwidth available for this card is "
7535 "not sufficient for optimal performance.\n");
7536 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7537 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007538 }
7539
Peter P Waskiewicz Jr34b03682009-02-05 23:54:42 -08007540 /* save off EEPROM version number */
7541 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
7542
Auke Kok9a799d72007-09-15 14:07:45 -07007543 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007544 err = hw->mac.ops.start_hw(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007545
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007546 if (err == IXGBE_ERR_EEPROM_VERSION) {
7547 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007548 e_dev_warn("This device is a pre-production adapter/LOM. "
7549 "Please be aware there may be issues associated "
7550 "with your hardware. If you are experiencing "
7551 "problems please contact your Intel or hardware "
7552 "representative who provided you with this "
7553 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007554 }
Auke Kok9a799d72007-09-15 14:07:45 -07007555 strcpy(netdev->name, "eth%d");
7556 err = register_netdev(netdev);
7557 if (err)
7558 goto err_register;
7559
Jesse Brandeburg54386462009-04-17 20:44:27 +00007560 /* carrier off reporting is important to ethtool even BEFORE open */
7561 netif_carrier_off(netdev);
7562
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007563#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007564 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007565 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007566 ixgbe_setup_dca(adapter);
7567 }
7568#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007569 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007570 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007571 for (i = 0; i < adapter->num_vfs; i++)
7572 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7573 }
7574
Emil Tantilov9612de92011-05-07 07:40:20 +00007575 /* Inform firmware of driver version */
7576 if (hw->mac.ops.set_fw_drv_ver)
Don Skidmorea38a1042011-05-20 03:05:14 +00007577 hw->mac.ops.set_fw_drv_ver(hw, MAJ, MIN, BUILD,
7578 FW_CEM_UNUSED_VER);
Emil Tantilov9612de92011-05-07 07:40:20 +00007579
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007580 /* add san mac addr to netdev */
7581 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007582
Emil Tantilov849c4542010-06-03 16:53:41 +00007583 e_dev_info("Intel(R) 10 Gigabit Network Connection\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007584 cards_found++;
7585 return 0;
7586
7587err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007588 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00007589 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007590err_sw_init:
7591err_eeprom:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007592 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7593 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007594 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07007595 iounmap(hw->hw_addr);
7596err_ioremap:
7597 free_netdev(netdev);
7598err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00007599 pci_release_selected_regions(pdev,
7600 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007601err_pci_reg:
7602err_dma:
7603 pci_disable_device(pdev);
7604 return err;
7605}
7606
7607/**
7608 * ixgbe_remove - Device Removal Routine
7609 * @pdev: PCI device information struct
7610 *
7611 * ixgbe_remove is called by the PCI subsystem to alert the driver
7612 * that it should release a PCI device. The could be caused by a
7613 * Hot-Plug event, or because the driver is going to be removed from
7614 * memory.
7615 **/
7616static void __devexit ixgbe_remove(struct pci_dev *pdev)
7617{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007618 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7619 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007620
7621 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00007622 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007623
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007624#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007625 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7626 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7627 dca_remove_requester(&pdev->dev);
7628 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7629 }
7630
7631#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007632#ifdef IXGBE_FCOE
7633 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7634 ixgbe_cleanup_fcoe(adapter);
7635
7636#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007637
7638 /* remove the added san mac */
7639 ixgbe_del_sanmac_netdev(netdev);
7640
Donald Skidmorec4900be2008-11-20 21:11:42 -08007641 if (netdev->reg_state == NETREG_REGISTERED)
7642 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007643
Greg Rosec6bda302011-08-24 02:37:55 +00007644 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
7645 if (!(ixgbe_check_vf_assignment(adapter)))
7646 ixgbe_disable_sriov(adapter);
7647 else
7648 e_dev_warn("Unloading driver while VFs are assigned "
7649 "- VFs will not be deallocated\n");
7650 }
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007651
Alexander Duyck7a921c92009-05-06 10:43:28 +00007652 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007653
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007654 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007655
7656 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00007657 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007658 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007659
Emil Tantilov849c4542010-06-03 16:53:41 +00007660 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007661
Auke Kok9a799d72007-09-15 14:07:45 -07007662 free_netdev(netdev);
7663
Frans Pop19d5afd2009-10-02 10:04:12 -07007664 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007665
Auke Kok9a799d72007-09-15 14:07:45 -07007666 pci_disable_device(pdev);
7667}
7668
7669/**
7670 * ixgbe_io_error_detected - called when PCI error is detected
7671 * @pdev: Pointer to PCI device
7672 * @state: The current pci connection state
7673 *
7674 * This function is called after a PCI bus error affecting
7675 * this device has been detected.
7676 */
7677static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007678 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07007679{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007680 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7681 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007682
7683 netif_device_detach(netdev);
7684
Breno Leitao3044b8d2009-05-06 10:44:26 +00007685 if (state == pci_channel_io_perm_failure)
7686 return PCI_ERS_RESULT_DISCONNECT;
7687
Auke Kok9a799d72007-09-15 14:07:45 -07007688 if (netif_running(netdev))
7689 ixgbe_down(adapter);
7690 pci_disable_device(pdev);
7691
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007692 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07007693 return PCI_ERS_RESULT_NEED_RESET;
7694}
7695
7696/**
7697 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7698 * @pdev: Pointer to PCI device
7699 *
7700 * Restart the card from scratch, as if from a cold-boot.
7701 */
7702static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
7703{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007704 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007705 pci_ers_result_t result;
7706 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007707
gouji-new9ce77662009-05-06 10:44:45 +00007708 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007709 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007710 result = PCI_ERS_RESULT_DISCONNECT;
7711 } else {
7712 pci_set_master(pdev);
7713 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00007714 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007715
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07007716 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007717
7718 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00007719 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007720 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07007721 }
Auke Kok9a799d72007-09-15 14:07:45 -07007722
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007723 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7724 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007725 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7726 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007727 /* non-fatal, continue */
7728 }
Auke Kok9a799d72007-09-15 14:07:45 -07007729
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007730 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07007731}
7732
7733/**
7734 * ixgbe_io_resume - called when traffic can start flowing again.
7735 * @pdev: Pointer to PCI device
7736 *
7737 * This callback is called when the error recovery driver tells us that
7738 * its OK to resume normal operation.
7739 */
7740static void ixgbe_io_resume(struct pci_dev *pdev)
7741{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007742 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7743 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007744
Alexander Duyckc7ccde02011-07-21 00:40:40 +00007745 if (netif_running(netdev))
7746 ixgbe_up(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007747
7748 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007749}
7750
7751static struct pci_error_handlers ixgbe_err_handler = {
7752 .error_detected = ixgbe_io_error_detected,
7753 .slot_reset = ixgbe_io_slot_reset,
7754 .resume = ixgbe_io_resume,
7755};
7756
7757static struct pci_driver ixgbe_driver = {
7758 .name = ixgbe_driver_name,
7759 .id_table = ixgbe_pci_tbl,
7760 .probe = ixgbe_probe,
7761 .remove = __devexit_p(ixgbe_remove),
7762#ifdef CONFIG_PM
7763 .suspend = ixgbe_suspend,
7764 .resume = ixgbe_resume,
7765#endif
7766 .shutdown = ixgbe_shutdown,
7767 .err_handler = &ixgbe_err_handler
7768};
7769
7770/**
7771 * ixgbe_init_module - Driver Registration Routine
7772 *
7773 * ixgbe_init_module is the first routine called when the driver is
7774 * loaded. All it does is register with the PCI subsystem.
7775 **/
7776static int __init ixgbe_init_module(void)
7777{
7778 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00007779 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00007780 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07007781
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007782#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007783 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007784#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007785
Auke Kok9a799d72007-09-15 14:07:45 -07007786 ret = pci_register_driver(&ixgbe_driver);
7787 return ret;
7788}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007789
Auke Kok9a799d72007-09-15 14:07:45 -07007790module_init(ixgbe_init_module);
7791
7792/**
7793 * ixgbe_exit_module - Driver Exit Cleanup Routine
7794 *
7795 * ixgbe_exit_module is called just before the driver is removed
7796 * from memory.
7797 **/
7798static void __exit ixgbe_exit_module(void)
7799{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007800#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007801 dca_unregister_notify(&dca_notifier);
7802#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007803 pci_unregister_driver(&ixgbe_driver);
Eric Dumazet1a515022010-11-16 19:26:42 -08007804 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07007805}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007806
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007807#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007808static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007809 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007810{
7811 int ret_val;
7812
7813 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007814 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007815
7816 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
7817}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007818
Alexander Duyckb4533682009-03-31 21:32:42 +00007819#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00007820
Auke Kok9a799d72007-09-15 14:07:45 -07007821module_exit(ixgbe_exit_module);
7822
7823/* ixgbe_main.c */