usb: gadget: m66592-udc: add pullup function
[zen-stable.git] / drivers / net / ixgbe / ixgbe_main.c
blob08e8e25c159d759d41ec35a64426bd0cec3708a0
1 /*******************************************************************************
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2011 Intel Corporation.
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.
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.
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.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
22 Contact Information:
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *******************************************************************************/
28 #include <linux/types.h>
29 #include <linux/module.h>
30 #include <linux/pci.h>
31 #include <linux/netdevice.h>
32 #include <linux/vmalloc.h>
33 #include <linux/string.h>
34 #include <linux/in.h>
35 #include <linux/ip.h>
36 #include <linux/tcp.h>
37 #include <linux/pkt_sched.h>
38 #include <linux/ipv6.h>
39 #include <linux/slab.h>
40 #include <net/checksum.h>
41 #include <net/ip6_checksum.h>
42 #include <linux/ethtool.h>
43 #include <linux/if_vlan.h>
44 #include <linux/prefetch.h>
45 #include <scsi/fc/fc_fcoe.h>
47 #include "ixgbe.h"
48 #include "ixgbe_common.h"
49 #include "ixgbe_dcb_82599.h"
50 #include "ixgbe_sriov.h"
52 char ixgbe_driver_name[] = "ixgbe";
53 static const char ixgbe_driver_string[] =
54 "Intel(R) 10 Gigabit PCI Express Network Driver";
55 #define MAJ 3
56 #define MIN 3
57 #define BUILD 8
58 #define KFIX 2
59 #define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
60 __stringify(BUILD) "-k" __stringify(KFIX)
61 const char ixgbe_driver_version[] = DRV_VERSION;
62 static const char ixgbe_copyright[] =
63 "Copyright (c) 1999-2011 Intel Corporation.";
65 static const struct ixgbe_info *ixgbe_info_tbl[] = {
66 [board_82598] = &ixgbe_82598_info,
67 [board_82599] = &ixgbe_82599_info,
68 [board_X540] = &ixgbe_X540_info,
71 /* ixgbe_pci_tbl - PCI Device ID Table
73 * Wildcard entries (PCI_ANY_ID) should come last
74 * Last entry must be all 0s
76 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
77 * Class, Class Mask, private data (not used) }
79 static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
80 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598),
81 board_82598 },
82 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT),
83 board_82598 },
84 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT),
85 board_82598 },
86 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT),
87 board_82598 },
88 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2),
89 board_82598 },
90 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4),
91 board_82598 },
92 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT),
93 board_82598 },
94 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT),
95 board_82598 },
96 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM),
97 board_82598 },
98 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR),
99 board_82598 },
100 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM),
101 board_82598 },
102 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX),
103 board_82598 },
104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4),
105 board_82599 },
106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM),
107 board_82599 },
108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR),
109 board_82599 },
110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP),
111 board_82599 },
112 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM),
113 board_82599 },
114 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ),
115 board_82599 },
116 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4),
117 board_82599 },
118 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE),
119 board_82599 },
120 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE),
121 board_82599 },
122 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM),
123 board_82599 },
124 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE),
125 board_82599 },
126 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T),
127 board_X540 },
128 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2),
129 board_82599 },
130 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS),
131 board_82599 },
133 /* required last entry */
134 {0, }
136 MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
138 #ifdef CONFIG_IXGBE_DCA
139 static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
140 void *p);
141 static struct notifier_block dca_notifier = {
142 .notifier_call = ixgbe_notify_dca,
143 .next = NULL,
144 .priority = 0
146 #endif
148 #ifdef CONFIG_PCI_IOV
149 static unsigned int max_vfs;
150 module_param(max_vfs, uint, 0);
151 MODULE_PARM_DESC(max_vfs,
152 "Maximum number of virtual functions to allocate per physical function");
153 #endif /* CONFIG_PCI_IOV */
155 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
156 MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
157 MODULE_LICENSE("GPL");
158 MODULE_VERSION(DRV_VERSION);
160 #define DEFAULT_DEBUG_LEVEL_SHIFT 3
162 static inline void ixgbe_disable_sriov(struct ixgbe_adapter *adapter)
164 struct ixgbe_hw *hw = &adapter->hw;
165 u32 gcr;
166 u32 gpie;
167 u32 vmdctl;
169 #ifdef CONFIG_PCI_IOV
170 /* disable iov and allow time for transactions to clear */
171 pci_disable_sriov(adapter->pdev);
172 #endif
174 /* turn off device IOV mode */
175 gcr = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
176 gcr &= ~(IXGBE_GCR_EXT_SRIOV);
177 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr);
178 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
179 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
180 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
182 /* set default pool back to 0 */
183 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
184 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
185 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
187 /* take a breather then clean up driver data */
188 msleep(100);
190 kfree(adapter->vfinfo);
191 adapter->vfinfo = NULL;
193 adapter->num_vfs = 0;
194 adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
197 static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
199 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
200 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
201 schedule_work(&adapter->service_task);
204 static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
206 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
208 /* flush memory to make sure state is correct before next watchog */
209 smp_mb__before_clear_bit();
210 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
213 struct ixgbe_reg_info {
214 u32 ofs;
215 char *name;
218 static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
220 /* General Registers */
221 {IXGBE_CTRL, "CTRL"},
222 {IXGBE_STATUS, "STATUS"},
223 {IXGBE_CTRL_EXT, "CTRL_EXT"},
225 /* Interrupt Registers */
226 {IXGBE_EICR, "EICR"},
228 /* RX Registers */
229 {IXGBE_SRRCTL(0), "SRRCTL"},
230 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
231 {IXGBE_RDLEN(0), "RDLEN"},
232 {IXGBE_RDH(0), "RDH"},
233 {IXGBE_RDT(0), "RDT"},
234 {IXGBE_RXDCTL(0), "RXDCTL"},
235 {IXGBE_RDBAL(0), "RDBAL"},
236 {IXGBE_RDBAH(0), "RDBAH"},
238 /* TX Registers */
239 {IXGBE_TDBAL(0), "TDBAL"},
240 {IXGBE_TDBAH(0), "TDBAH"},
241 {IXGBE_TDLEN(0), "TDLEN"},
242 {IXGBE_TDH(0), "TDH"},
243 {IXGBE_TDT(0), "TDT"},
244 {IXGBE_TXDCTL(0), "TXDCTL"},
246 /* List Terminator */
252 * ixgbe_regdump - register printout routine
254 static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
256 int i = 0, j = 0;
257 char rname[16];
258 u32 regs[64];
260 switch (reginfo->ofs) {
261 case IXGBE_SRRCTL(0):
262 for (i = 0; i < 64; i++)
263 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
264 break;
265 case IXGBE_DCA_RXCTRL(0):
266 for (i = 0; i < 64; i++)
267 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
268 break;
269 case IXGBE_RDLEN(0):
270 for (i = 0; i < 64; i++)
271 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
272 break;
273 case IXGBE_RDH(0):
274 for (i = 0; i < 64; i++)
275 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
276 break;
277 case IXGBE_RDT(0):
278 for (i = 0; i < 64; i++)
279 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
280 break;
281 case IXGBE_RXDCTL(0):
282 for (i = 0; i < 64; i++)
283 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
284 break;
285 case IXGBE_RDBAL(0):
286 for (i = 0; i < 64; i++)
287 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
288 break;
289 case IXGBE_RDBAH(0):
290 for (i = 0; i < 64; i++)
291 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
292 break;
293 case IXGBE_TDBAL(0):
294 for (i = 0; i < 64; i++)
295 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
296 break;
297 case IXGBE_TDBAH(0):
298 for (i = 0; i < 64; i++)
299 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
300 break;
301 case IXGBE_TDLEN(0):
302 for (i = 0; i < 64; i++)
303 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
304 break;
305 case IXGBE_TDH(0):
306 for (i = 0; i < 64; i++)
307 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
308 break;
309 case IXGBE_TDT(0):
310 for (i = 0; i < 64; i++)
311 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
312 break;
313 case IXGBE_TXDCTL(0):
314 for (i = 0; i < 64; i++)
315 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
316 break;
317 default:
318 pr_info("%-15s %08x\n", reginfo->name,
319 IXGBE_READ_REG(hw, reginfo->ofs));
320 return;
323 for (i = 0; i < 8; i++) {
324 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
325 pr_err("%-15s", rname);
326 for (j = 0; j < 8; j++)
327 pr_cont(" %08x", regs[i*8+j]);
328 pr_cont("\n");
334 * ixgbe_dump - Print registers, tx-rings and rx-rings
336 static void ixgbe_dump(struct ixgbe_adapter *adapter)
338 struct net_device *netdev = adapter->netdev;
339 struct ixgbe_hw *hw = &adapter->hw;
340 struct ixgbe_reg_info *reginfo;
341 int n = 0;
342 struct ixgbe_ring *tx_ring;
343 struct ixgbe_tx_buffer *tx_buffer_info;
344 union ixgbe_adv_tx_desc *tx_desc;
345 struct my_u0 { u64 a; u64 b; } *u0;
346 struct ixgbe_ring *rx_ring;
347 union ixgbe_adv_rx_desc *rx_desc;
348 struct ixgbe_rx_buffer *rx_buffer_info;
349 u32 staterr;
350 int i = 0;
352 if (!netif_msg_hw(adapter))
353 return;
355 /* Print netdevice Info */
356 if (netdev) {
357 dev_info(&adapter->pdev->dev, "Net device Info\n");
358 pr_info("Device Name state "
359 "trans_start last_rx\n");
360 pr_info("%-15s %016lX %016lX %016lX\n",
361 netdev->name,
362 netdev->state,
363 netdev->trans_start,
364 netdev->last_rx);
367 /* Print Registers */
368 dev_info(&adapter->pdev->dev, "Register Dump\n");
369 pr_info(" Register Name Value\n");
370 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
371 reginfo->name; reginfo++) {
372 ixgbe_regdump(hw, reginfo);
375 /* Print TX Ring Summary */
376 if (!netdev || !netif_running(netdev))
377 goto exit;
379 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
380 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
381 for (n = 0; n < adapter->num_tx_queues; n++) {
382 tx_ring = adapter->tx_ring[n];
383 tx_buffer_info =
384 &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
385 pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n",
386 n, tx_ring->next_to_use, tx_ring->next_to_clean,
387 (u64)tx_buffer_info->dma,
388 tx_buffer_info->length,
389 tx_buffer_info->next_to_watch,
390 (u64)tx_buffer_info->time_stamp);
393 /* Print TX Rings */
394 if (!netif_msg_tx_done(adapter))
395 goto rx_ring_summary;
397 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
399 /* Transmit Descriptor Formats
401 * Advanced Transmit Descriptor
402 * +--------------------------------------------------------------+
403 * 0 | Buffer Address [63:0] |
404 * +--------------------------------------------------------------+
405 * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
406 * +--------------------------------------------------------------+
407 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
410 for (n = 0; n < adapter->num_tx_queues; n++) {
411 tx_ring = adapter->tx_ring[n];
412 pr_info("------------------------------------\n");
413 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
414 pr_info("------------------------------------\n");
415 pr_info("T [desc] [address 63:0 ] "
416 "[PlPOIdStDDt Ln] [bi->dma ] "
417 "leng ntw timestamp bi->skb\n");
419 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
420 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
421 tx_buffer_info = &tx_ring->tx_buffer_info[i];
422 u0 = (struct my_u0 *)tx_desc;
423 pr_info("T [0x%03X] %016llX %016llX %016llX"
424 " %04X %3X %016llX %p", i,
425 le64_to_cpu(u0->a),
426 le64_to_cpu(u0->b),
427 (u64)tx_buffer_info->dma,
428 tx_buffer_info->length,
429 tx_buffer_info->next_to_watch,
430 (u64)tx_buffer_info->time_stamp,
431 tx_buffer_info->skb);
432 if (i == tx_ring->next_to_use &&
433 i == tx_ring->next_to_clean)
434 pr_cont(" NTC/U\n");
435 else if (i == tx_ring->next_to_use)
436 pr_cont(" NTU\n");
437 else if (i == tx_ring->next_to_clean)
438 pr_cont(" NTC\n");
439 else
440 pr_cont("\n");
442 if (netif_msg_pktdata(adapter) &&
443 tx_buffer_info->dma != 0)
444 print_hex_dump(KERN_INFO, "",
445 DUMP_PREFIX_ADDRESS, 16, 1,
446 phys_to_virt(tx_buffer_info->dma),
447 tx_buffer_info->length, true);
451 /* Print RX Rings Summary */
452 rx_ring_summary:
453 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
454 pr_info("Queue [NTU] [NTC]\n");
455 for (n = 0; n < adapter->num_rx_queues; n++) {
456 rx_ring = adapter->rx_ring[n];
457 pr_info("%5d %5X %5X\n",
458 n, rx_ring->next_to_use, rx_ring->next_to_clean);
461 /* Print RX Rings */
462 if (!netif_msg_rx_status(adapter))
463 goto exit;
465 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
467 /* Advanced Receive Descriptor (Read) Format
468 * 63 1 0
469 * +-----------------------------------------------------+
470 * 0 | Packet Buffer Address [63:1] |A0/NSE|
471 * +----------------------------------------------+------+
472 * 8 | Header Buffer Address [63:1] | DD |
473 * +-----------------------------------------------------+
476 * Advanced Receive Descriptor (Write-Back) Format
478 * 63 48 47 32 31 30 21 20 16 15 4 3 0
479 * +------------------------------------------------------+
480 * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
481 * | Checksum Ident | | | | Type | Type |
482 * +------------------------------------------------------+
483 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
484 * +------------------------------------------------------+
485 * 63 48 47 32 31 20 19 0
487 for (n = 0; n < adapter->num_rx_queues; n++) {
488 rx_ring = adapter->rx_ring[n];
489 pr_info("------------------------------------\n");
490 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
491 pr_info("------------------------------------\n");
492 pr_info("R [desc] [ PktBuf A0] "
493 "[ HeadBuf DD] [bi->dma ] [bi->skb] "
494 "<-- Adv Rx Read format\n");
495 pr_info("RWB[desc] [PcsmIpSHl PtRs] "
496 "[vl er S cks ln] ---------------- [bi->skb] "
497 "<-- Adv Rx Write-Back format\n");
499 for (i = 0; i < rx_ring->count; i++) {
500 rx_buffer_info = &rx_ring->rx_buffer_info[i];
501 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
502 u0 = (struct my_u0 *)rx_desc;
503 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
504 if (staterr & IXGBE_RXD_STAT_DD) {
505 /* Descriptor Done */
506 pr_info("RWB[0x%03X] %016llX "
507 "%016llX ---------------- %p", i,
508 le64_to_cpu(u0->a),
509 le64_to_cpu(u0->b),
510 rx_buffer_info->skb);
511 } else {
512 pr_info("R [0x%03X] %016llX "
513 "%016llX %016llX %p", i,
514 le64_to_cpu(u0->a),
515 le64_to_cpu(u0->b),
516 (u64)rx_buffer_info->dma,
517 rx_buffer_info->skb);
519 if (netif_msg_pktdata(adapter)) {
520 print_hex_dump(KERN_INFO, "",
521 DUMP_PREFIX_ADDRESS, 16, 1,
522 phys_to_virt(rx_buffer_info->dma),
523 rx_ring->rx_buf_len, true);
525 if (rx_ring->rx_buf_len
526 < IXGBE_RXBUFFER_2048)
527 print_hex_dump(KERN_INFO, "",
528 DUMP_PREFIX_ADDRESS, 16, 1,
529 phys_to_virt(
530 rx_buffer_info->page_dma +
531 rx_buffer_info->page_offset
533 PAGE_SIZE/2, true);
537 if (i == rx_ring->next_to_use)
538 pr_cont(" NTU\n");
539 else if (i == rx_ring->next_to_clean)
540 pr_cont(" NTC\n");
541 else
542 pr_cont("\n");
547 exit:
548 return;
551 static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
553 u32 ctrl_ext;
555 /* Let firmware take over control of h/w */
556 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
557 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
558 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
561 static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
563 u32 ctrl_ext;
565 /* Let firmware know the driver has taken over */
566 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
567 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
568 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
572 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
573 * @adapter: pointer to adapter struct
574 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
575 * @queue: queue to map the corresponding interrupt to
576 * @msix_vector: the vector to map to the corresponding queue
579 static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
580 u8 queue, u8 msix_vector)
582 u32 ivar, index;
583 struct ixgbe_hw *hw = &adapter->hw;
584 switch (hw->mac.type) {
585 case ixgbe_mac_82598EB:
586 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
587 if (direction == -1)
588 direction = 0;
589 index = (((direction * 64) + queue) >> 2) & 0x1F;
590 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
591 ivar &= ~(0xFF << (8 * (queue & 0x3)));
592 ivar |= (msix_vector << (8 * (queue & 0x3)));
593 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
594 break;
595 case ixgbe_mac_82599EB:
596 case ixgbe_mac_X540:
597 if (direction == -1) {
598 /* other causes */
599 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
600 index = ((queue & 1) * 8);
601 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
602 ivar &= ~(0xFF << index);
603 ivar |= (msix_vector << index);
604 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
605 break;
606 } else {
607 /* tx or rx causes */
608 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
609 index = ((16 * (queue & 1)) + (8 * direction));
610 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
611 ivar &= ~(0xFF << index);
612 ivar |= (msix_vector << index);
613 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
614 break;
616 default:
617 break;
621 static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
622 u64 qmask)
624 u32 mask;
626 switch (adapter->hw.mac.type) {
627 case ixgbe_mac_82598EB:
628 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
629 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
630 break;
631 case ixgbe_mac_82599EB:
632 case ixgbe_mac_X540:
633 mask = (qmask & 0xFFFFFFFF);
634 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
635 mask = (qmask >> 32);
636 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
637 break;
638 default:
639 break;
643 void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *tx_ring,
644 struct ixgbe_tx_buffer *tx_buffer_info)
646 if (tx_buffer_info->dma) {
647 if (tx_buffer_info->mapped_as_page)
648 dma_unmap_page(tx_ring->dev,
649 tx_buffer_info->dma,
650 tx_buffer_info->length,
651 DMA_TO_DEVICE);
652 else
653 dma_unmap_single(tx_ring->dev,
654 tx_buffer_info->dma,
655 tx_buffer_info->length,
656 DMA_TO_DEVICE);
657 tx_buffer_info->dma = 0;
659 if (tx_buffer_info->skb) {
660 dev_kfree_skb_any(tx_buffer_info->skb);
661 tx_buffer_info->skb = NULL;
663 tx_buffer_info->time_stamp = 0;
664 /* tx_buffer_info must be completely set up in the transmit path */
668 * ixgbe_dcb_txq_to_tc - convert a reg index to a traffic class
669 * @adapter: driver private struct
670 * @index: reg idx of queue to query (0-127)
672 * Helper function to determine the traffic index for a particular
673 * register index.
675 * Returns : a tc index for use in range 0-7, or 0-3
677 static u8 ixgbe_dcb_txq_to_tc(struct ixgbe_adapter *adapter, u8 reg_idx)
679 int tc = -1;
680 int dcb_i = netdev_get_num_tc(adapter->netdev);
682 /* if DCB is not enabled the queues have no TC */
683 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
684 return tc;
686 /* check valid range */
687 if (reg_idx >= adapter->hw.mac.max_tx_queues)
688 return tc;
690 switch (adapter->hw.mac.type) {
691 case ixgbe_mac_82598EB:
692 tc = reg_idx >> 2;
693 break;
694 default:
695 if (dcb_i != 4 && dcb_i != 8)
696 break;
698 /* if VMDq is enabled the lowest order bits determine TC */
699 if (adapter->flags & (IXGBE_FLAG_SRIOV_ENABLED |
700 IXGBE_FLAG_VMDQ_ENABLED)) {
701 tc = reg_idx & (dcb_i - 1);
702 break;
706 * Convert the reg_idx into the correct TC. This bitmask
707 * targets the last full 32 ring traffic class and assigns
708 * it a value of 1. From there the rest of the rings are
709 * based on shifting the mask further up to include the
710 * reg_idx / 16 and then reg_idx / 8. It assumes dcB_i
711 * will only ever be 8 or 4 and that reg_idx will never
712 * be greater then 128. The code without the power of 2
713 * optimizations would be:
714 * (((reg_idx % 32) + 32) * dcb_i) >> (9 - reg_idx / 32)
716 tc = ((reg_idx & 0X1F) + 0x20) * dcb_i;
717 tc >>= 9 - (reg_idx >> 5);
720 return tc;
723 static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
725 struct ixgbe_hw *hw = &adapter->hw;
726 struct ixgbe_hw_stats *hwstats = &adapter->stats;
727 u32 data = 0;
728 u32 xoff[8] = {0};
729 int i;
731 if ((hw->fc.current_mode == ixgbe_fc_full) ||
732 (hw->fc.current_mode == ixgbe_fc_rx_pause)) {
733 switch (hw->mac.type) {
734 case ixgbe_mac_82598EB:
735 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
736 break;
737 default:
738 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
740 hwstats->lxoffrxc += data;
742 /* refill credits (no tx hang) if we received xoff */
743 if (!data)
744 return;
746 for (i = 0; i < adapter->num_tx_queues; i++)
747 clear_bit(__IXGBE_HANG_CHECK_ARMED,
748 &adapter->tx_ring[i]->state);
749 return;
750 } else if (!(adapter->dcb_cfg.pfc_mode_enable))
751 return;
753 /* update stats for each tc, only valid with PFC enabled */
754 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
755 switch (hw->mac.type) {
756 case ixgbe_mac_82598EB:
757 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
758 break;
759 default:
760 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
762 hwstats->pxoffrxc[i] += xoff[i];
765 /* disarm tx queues that have received xoff frames */
766 for (i = 0; i < adapter->num_tx_queues; i++) {
767 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
768 u32 tc = ixgbe_dcb_txq_to_tc(adapter, tx_ring->reg_idx);
770 if (xoff[tc])
771 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
775 static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
777 return ring->tx_stats.completed;
780 static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
782 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
783 struct ixgbe_hw *hw = &adapter->hw;
785 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
786 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
788 if (head != tail)
789 return (head < tail) ?
790 tail - head : (tail + ring->count - head);
792 return 0;
795 static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
797 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
798 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
799 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
800 bool ret = false;
802 clear_check_for_tx_hang(tx_ring);
805 * Check for a hung queue, but be thorough. This verifies
806 * that a transmit has been completed since the previous
807 * check AND there is at least one packet pending. The
808 * ARMED bit is set to indicate a potential hang. The
809 * bit is cleared if a pause frame is received to remove
810 * false hang detection due to PFC or 802.3x frames. By
811 * requiring this to fail twice we avoid races with
812 * pfc clearing the ARMED bit and conditions where we
813 * run the check_tx_hang logic with a transmit completion
814 * pending but without time to complete it yet.
816 if ((tx_done_old == tx_done) && tx_pending) {
817 /* make sure it is true for two checks in a row */
818 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
819 &tx_ring->state);
820 } else {
821 /* update completed stats and continue */
822 tx_ring->tx_stats.tx_done_old = tx_done;
823 /* reset the countdown */
824 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
827 return ret;
830 #define IXGBE_MAX_TXD_PWR 14
831 #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
833 /* Tx Descriptors needed, worst case */
834 #define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
835 (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
836 #define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
837 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
840 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
841 * @adapter: driver private struct
843 static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
846 /* Do the reset outside of interrupt context */
847 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
848 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
849 ixgbe_service_event_schedule(adapter);
854 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
855 * @q_vector: structure containing interrupt and ring information
856 * @tx_ring: tx ring to clean
858 static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
859 struct ixgbe_ring *tx_ring)
861 struct ixgbe_adapter *adapter = q_vector->adapter;
862 union ixgbe_adv_tx_desc *tx_desc, *eop_desc;
863 struct ixgbe_tx_buffer *tx_buffer_info;
864 unsigned int total_bytes = 0, total_packets = 0;
865 u16 i, eop, count = 0;
867 i = tx_ring->next_to_clean;
868 eop = tx_ring->tx_buffer_info[i].next_to_watch;
869 eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
871 while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) &&
872 (count < tx_ring->work_limit)) {
873 bool cleaned = false;
874 rmb(); /* read buffer_info after eop_desc */
875 for ( ; !cleaned; count++) {
876 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
877 tx_buffer_info = &tx_ring->tx_buffer_info[i];
879 tx_desc->wb.status = 0;
880 cleaned = (i == eop);
882 i++;
883 if (i == tx_ring->count)
884 i = 0;
886 if (cleaned && tx_buffer_info->skb) {
887 total_bytes += tx_buffer_info->bytecount;
888 total_packets += tx_buffer_info->gso_segs;
891 ixgbe_unmap_and_free_tx_resource(tx_ring,
892 tx_buffer_info);
895 tx_ring->tx_stats.completed++;
896 eop = tx_ring->tx_buffer_info[i].next_to_watch;
897 eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
900 tx_ring->next_to_clean = i;
901 tx_ring->total_bytes += total_bytes;
902 tx_ring->total_packets += total_packets;
903 u64_stats_update_begin(&tx_ring->syncp);
904 tx_ring->stats.packets += total_packets;
905 tx_ring->stats.bytes += total_bytes;
906 u64_stats_update_end(&tx_ring->syncp);
908 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
909 /* schedule immediate reset if we believe we hung */
910 struct ixgbe_hw *hw = &adapter->hw;
911 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
912 e_err(drv, "Detected Tx Unit Hang\n"
913 " Tx Queue <%d>\n"
914 " TDH, TDT <%x>, <%x>\n"
915 " next_to_use <%x>\n"
916 " next_to_clean <%x>\n"
917 "tx_buffer_info[next_to_clean]\n"
918 " time_stamp <%lx>\n"
919 " jiffies <%lx>\n",
920 tx_ring->queue_index,
921 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
922 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
923 tx_ring->next_to_use, eop,
924 tx_ring->tx_buffer_info[eop].time_stamp, jiffies);
926 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
928 e_info(probe,
929 "tx hang %d detected on queue %d, resetting adapter\n",
930 adapter->tx_timeout_count + 1, tx_ring->queue_index);
932 /* schedule immediate reset if we believe we hung */
933 ixgbe_tx_timeout_reset(adapter);
935 /* the adapter is about to reset, no point in enabling stuff */
936 return true;
939 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
940 if (unlikely(count && netif_carrier_ok(tx_ring->netdev) &&
941 (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) {
942 /* Make sure that anybody stopping the queue after this
943 * sees the new next_to_clean.
945 smp_mb();
946 if (__netif_subqueue_stopped(tx_ring->netdev, tx_ring->queue_index) &&
947 !test_bit(__IXGBE_DOWN, &adapter->state)) {
948 netif_wake_subqueue(tx_ring->netdev, tx_ring->queue_index);
949 ++tx_ring->tx_stats.restart_queue;
953 return count < tx_ring->work_limit;
956 #ifdef CONFIG_IXGBE_DCA
957 static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
958 struct ixgbe_ring *rx_ring,
959 int cpu)
961 struct ixgbe_hw *hw = &adapter->hw;
962 u32 rxctrl;
963 u8 reg_idx = rx_ring->reg_idx;
965 rxctrl = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(reg_idx));
966 switch (hw->mac.type) {
967 case ixgbe_mac_82598EB:
968 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
969 rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
970 break;
971 case ixgbe_mac_82599EB:
972 case ixgbe_mac_X540:
973 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
974 rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
975 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
976 break;
977 default:
978 break;
980 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
981 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
982 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
983 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
986 static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
987 struct ixgbe_ring *tx_ring,
988 int cpu)
990 struct ixgbe_hw *hw = &adapter->hw;
991 u32 txctrl;
992 u8 reg_idx = tx_ring->reg_idx;
994 switch (hw->mac.type) {
995 case ixgbe_mac_82598EB:
996 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(reg_idx));
997 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
998 txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
999 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
1000 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(reg_idx), txctrl);
1001 break;
1002 case ixgbe_mac_82599EB:
1003 case ixgbe_mac_X540:
1004 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx));
1005 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
1006 txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
1007 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
1008 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
1009 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx), txctrl);
1010 break;
1011 default:
1012 break;
1016 static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
1018 struct ixgbe_adapter *adapter = q_vector->adapter;
1019 int cpu = get_cpu();
1020 long r_idx;
1021 int i;
1023 if (q_vector->cpu == cpu)
1024 goto out_no_update;
1026 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1027 for (i = 0; i < q_vector->txr_count; i++) {
1028 ixgbe_update_tx_dca(adapter, adapter->tx_ring[r_idx], cpu);
1029 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
1030 r_idx + 1);
1033 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1034 for (i = 0; i < q_vector->rxr_count; i++) {
1035 ixgbe_update_rx_dca(adapter, adapter->rx_ring[r_idx], cpu);
1036 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1037 r_idx + 1);
1040 q_vector->cpu = cpu;
1041 out_no_update:
1042 put_cpu();
1045 static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
1047 int num_q_vectors;
1048 int i;
1050 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1051 return;
1053 /* always use CB2 mode, difference is masked in the CB driver */
1054 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
1056 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
1057 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1058 else
1059 num_q_vectors = 1;
1061 for (i = 0; i < num_q_vectors; i++) {
1062 adapter->q_vector[i]->cpu = -1;
1063 ixgbe_update_dca(adapter->q_vector[i]);
1067 static int __ixgbe_notify_dca(struct device *dev, void *data)
1069 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
1070 unsigned long event = *(unsigned long *)data;
1072 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1073 return 0;
1075 switch (event) {
1076 case DCA_PROVIDER_ADD:
1077 /* if we're already enabled, don't do it again */
1078 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1079 break;
1080 if (dca_add_requester(dev) == 0) {
1081 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
1082 ixgbe_setup_dca(adapter);
1083 break;
1085 /* Fall Through since DCA is disabled. */
1086 case DCA_PROVIDER_REMOVE:
1087 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1088 dca_remove_requester(dev);
1089 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1090 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1092 break;
1095 return 0;
1097 #endif /* CONFIG_IXGBE_DCA */
1099 static inline void ixgbe_rx_hash(union ixgbe_adv_rx_desc *rx_desc,
1100 struct sk_buff *skb)
1102 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
1106 * ixgbe_receive_skb - Send a completed packet up the stack
1107 * @adapter: board private structure
1108 * @skb: packet to send up
1109 * @status: hardware indication of status of receive
1110 * @rx_ring: rx descriptor ring (for a specific queue) to setup
1111 * @rx_desc: rx descriptor
1113 static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
1114 struct sk_buff *skb, u8 status,
1115 struct ixgbe_ring *ring,
1116 union ixgbe_adv_rx_desc *rx_desc)
1118 struct ixgbe_adapter *adapter = q_vector->adapter;
1119 struct napi_struct *napi = &q_vector->napi;
1120 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
1121 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
1123 if (is_vlan && (tag & VLAN_VID_MASK))
1124 __vlan_hwaccel_put_tag(skb, tag);
1126 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1127 napi_gro_receive(napi, skb);
1128 else
1129 netif_rx(skb);
1133 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
1134 * @adapter: address of board private structure
1135 * @status_err: hardware indication of status of receive
1136 * @skb: skb currently being received and modified
1138 static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
1139 union ixgbe_adv_rx_desc *rx_desc,
1140 struct sk_buff *skb)
1142 u32 status_err = le32_to_cpu(rx_desc->wb.upper.status_error);
1144 skb_checksum_none_assert(skb);
1146 /* Rx csum disabled */
1147 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
1148 return;
1150 /* if IP and error */
1151 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
1152 (status_err & IXGBE_RXDADV_ERR_IPE)) {
1153 adapter->hw_csum_rx_error++;
1154 return;
1157 if (!(status_err & IXGBE_RXD_STAT_L4CS))
1158 return;
1160 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
1161 u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1164 * 82599 errata, UDP frames with a 0 checksum can be marked as
1165 * checksum errors.
1167 if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) &&
1168 (adapter->hw.mac.type == ixgbe_mac_82599EB))
1169 return;
1171 adapter->hw_csum_rx_error++;
1172 return;
1175 /* It must be a TCP or UDP packet with a valid checksum */
1176 skb->ip_summed = CHECKSUM_UNNECESSARY;
1179 static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
1182 * Force memory writes to complete before letting h/w
1183 * know there are new descriptors to fetch. (Only
1184 * applicable for weak-ordered memory model archs,
1185 * such as IA-64).
1187 wmb();
1188 writel(val, rx_ring->tail);
1192 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
1193 * @rx_ring: ring to place buffers on
1194 * @cleaned_count: number of buffers to replace
1196 void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
1198 union ixgbe_adv_rx_desc *rx_desc;
1199 struct ixgbe_rx_buffer *bi;
1200 struct sk_buff *skb;
1201 u16 i = rx_ring->next_to_use;
1203 /* do nothing if no valid netdev defined */
1204 if (!rx_ring->netdev)
1205 return;
1207 while (cleaned_count--) {
1208 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
1209 bi = &rx_ring->rx_buffer_info[i];
1210 skb = bi->skb;
1212 if (!skb) {
1213 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
1214 rx_ring->rx_buf_len);
1215 if (!skb) {
1216 rx_ring->rx_stats.alloc_rx_buff_failed++;
1217 goto no_buffers;
1219 /* initialize queue mapping */
1220 skb_record_rx_queue(skb, rx_ring->queue_index);
1221 bi->skb = skb;
1224 if (!bi->dma) {
1225 bi->dma = dma_map_single(rx_ring->dev,
1226 skb->data,
1227 rx_ring->rx_buf_len,
1228 DMA_FROM_DEVICE);
1229 if (dma_mapping_error(rx_ring->dev, bi->dma)) {
1230 rx_ring->rx_stats.alloc_rx_buff_failed++;
1231 bi->dma = 0;
1232 goto no_buffers;
1236 if (ring_is_ps_enabled(rx_ring)) {
1237 if (!bi->page) {
1238 bi->page = netdev_alloc_page(rx_ring->netdev);
1239 if (!bi->page) {
1240 rx_ring->rx_stats.alloc_rx_page_failed++;
1241 goto no_buffers;
1245 if (!bi->page_dma) {
1246 /* use a half page if we're re-using */
1247 bi->page_offset ^= PAGE_SIZE / 2;
1248 bi->page_dma = dma_map_page(rx_ring->dev,
1249 bi->page,
1250 bi->page_offset,
1251 PAGE_SIZE / 2,
1252 DMA_FROM_DEVICE);
1253 if (dma_mapping_error(rx_ring->dev,
1254 bi->page_dma)) {
1255 rx_ring->rx_stats.alloc_rx_page_failed++;
1256 bi->page_dma = 0;
1257 goto no_buffers;
1261 /* Refresh the desc even if buffer_addrs didn't change
1262 * because each write-back erases this info. */
1263 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
1264 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
1265 } else {
1266 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
1267 rx_desc->read.hdr_addr = 0;
1270 i++;
1271 if (i == rx_ring->count)
1272 i = 0;
1275 no_buffers:
1276 if (rx_ring->next_to_use != i) {
1277 rx_ring->next_to_use = i;
1278 ixgbe_release_rx_desc(rx_ring, i);
1282 static inline u16 ixgbe_get_hlen(union ixgbe_adv_rx_desc *rx_desc)
1284 /* HW will not DMA in data larger than the given buffer, even if it
1285 * parses the (NFS, of course) header to be larger. In that case, it
1286 * fills the header buffer and spills the rest into the page.
1288 u16 hdr_info = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.hdr_info);
1289 u16 hlen = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
1290 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
1291 if (hlen > IXGBE_RX_HDR_SIZE)
1292 hlen = IXGBE_RX_HDR_SIZE;
1293 return hlen;
1297 * ixgbe_transform_rsc_queue - change rsc queue into a full packet
1298 * @skb: pointer to the last skb in the rsc queue
1300 * This function changes a queue full of hw rsc buffers into a completed
1301 * packet. It uses the ->prev pointers to find the first packet and then
1302 * turns it into the frag list owner.
1304 static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb)
1306 unsigned int frag_list_size = 0;
1307 unsigned int skb_cnt = 1;
1309 while (skb->prev) {
1310 struct sk_buff *prev = skb->prev;
1311 frag_list_size += skb->len;
1312 skb->prev = NULL;
1313 skb = prev;
1314 skb_cnt++;
1317 skb_shinfo(skb)->frag_list = skb->next;
1318 skb->next = NULL;
1319 skb->len += frag_list_size;
1320 skb->data_len += frag_list_size;
1321 skb->truesize += frag_list_size;
1322 IXGBE_RSC_CB(skb)->skb_cnt = skb_cnt;
1324 return skb;
1327 static inline bool ixgbe_get_rsc_state(union ixgbe_adv_rx_desc *rx_desc)
1329 return !!(le32_to_cpu(rx_desc->wb.lower.lo_dword.data) &
1330 IXGBE_RXDADV_RSCCNT_MASK);
1333 static void ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
1334 struct ixgbe_ring *rx_ring,
1335 int *work_done, int work_to_do)
1337 struct ixgbe_adapter *adapter = q_vector->adapter;
1338 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
1339 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
1340 struct sk_buff *skb;
1341 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1342 const int current_node = numa_node_id();
1343 #ifdef IXGBE_FCOE
1344 int ddp_bytes = 0;
1345 #endif /* IXGBE_FCOE */
1346 u32 staterr;
1347 u16 i;
1348 u16 cleaned_count = 0;
1349 bool pkt_is_rsc = false;
1351 i = rx_ring->next_to_clean;
1352 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
1353 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
1355 while (staterr & IXGBE_RXD_STAT_DD) {
1356 u32 upper_len = 0;
1358 rmb(); /* read descriptor and rx_buffer_info after status DD */
1360 rx_buffer_info = &rx_ring->rx_buffer_info[i];
1362 skb = rx_buffer_info->skb;
1363 rx_buffer_info->skb = NULL;
1364 prefetch(skb->data);
1366 if (ring_is_rsc_enabled(rx_ring))
1367 pkt_is_rsc = ixgbe_get_rsc_state(rx_desc);
1369 /* if this is a skb from previous receive DMA will be 0 */
1370 if (rx_buffer_info->dma) {
1371 u16 hlen;
1372 if (pkt_is_rsc &&
1373 !(staterr & IXGBE_RXD_STAT_EOP) &&
1374 !skb->prev) {
1376 * When HWRSC is enabled, delay unmapping
1377 * of the first packet. It carries the
1378 * header information, HW may still
1379 * access the header after the writeback.
1380 * Only unmap it when EOP is reached
1382 IXGBE_RSC_CB(skb)->delay_unmap = true;
1383 IXGBE_RSC_CB(skb)->dma = rx_buffer_info->dma;
1384 } else {
1385 dma_unmap_single(rx_ring->dev,
1386 rx_buffer_info->dma,
1387 rx_ring->rx_buf_len,
1388 DMA_FROM_DEVICE);
1390 rx_buffer_info->dma = 0;
1392 if (ring_is_ps_enabled(rx_ring)) {
1393 hlen = ixgbe_get_hlen(rx_desc);
1394 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
1395 } else {
1396 hlen = le16_to_cpu(rx_desc->wb.upper.length);
1399 skb_put(skb, hlen);
1400 } else {
1401 /* assume packet split since header is unmapped */
1402 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
1405 if (upper_len) {
1406 dma_unmap_page(rx_ring->dev,
1407 rx_buffer_info->page_dma,
1408 PAGE_SIZE / 2,
1409 DMA_FROM_DEVICE);
1410 rx_buffer_info->page_dma = 0;
1411 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
1412 rx_buffer_info->page,
1413 rx_buffer_info->page_offset,
1414 upper_len);
1416 if ((page_count(rx_buffer_info->page) == 1) &&
1417 (page_to_nid(rx_buffer_info->page) == current_node))
1418 get_page(rx_buffer_info->page);
1419 else
1420 rx_buffer_info->page = NULL;
1422 skb->len += upper_len;
1423 skb->data_len += upper_len;
1424 skb->truesize += upper_len;
1427 i++;
1428 if (i == rx_ring->count)
1429 i = 0;
1431 next_rxd = IXGBE_RX_DESC_ADV(rx_ring, i);
1432 prefetch(next_rxd);
1433 cleaned_count++;
1435 if (pkt_is_rsc) {
1436 u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >>
1437 IXGBE_RXDADV_NEXTP_SHIFT;
1438 next_buffer = &rx_ring->rx_buffer_info[nextp];
1439 } else {
1440 next_buffer = &rx_ring->rx_buffer_info[i];
1443 if (!(staterr & IXGBE_RXD_STAT_EOP)) {
1444 if (ring_is_ps_enabled(rx_ring)) {
1445 rx_buffer_info->skb = next_buffer->skb;
1446 rx_buffer_info->dma = next_buffer->dma;
1447 next_buffer->skb = skb;
1448 next_buffer->dma = 0;
1449 } else {
1450 skb->next = next_buffer->skb;
1451 skb->next->prev = skb;
1453 rx_ring->rx_stats.non_eop_descs++;
1454 goto next_desc;
1457 if (skb->prev) {
1458 skb = ixgbe_transform_rsc_queue(skb);
1459 /* if we got here without RSC the packet is invalid */
1460 if (!pkt_is_rsc) {
1461 __pskb_trim(skb, 0);
1462 rx_buffer_info->skb = skb;
1463 goto next_desc;
1467 if (ring_is_rsc_enabled(rx_ring)) {
1468 if (IXGBE_RSC_CB(skb)->delay_unmap) {
1469 dma_unmap_single(rx_ring->dev,
1470 IXGBE_RSC_CB(skb)->dma,
1471 rx_ring->rx_buf_len,
1472 DMA_FROM_DEVICE);
1473 IXGBE_RSC_CB(skb)->dma = 0;
1474 IXGBE_RSC_CB(skb)->delay_unmap = false;
1477 if (pkt_is_rsc) {
1478 if (ring_is_ps_enabled(rx_ring))
1479 rx_ring->rx_stats.rsc_count +=
1480 skb_shinfo(skb)->nr_frags;
1481 else
1482 rx_ring->rx_stats.rsc_count +=
1483 IXGBE_RSC_CB(skb)->skb_cnt;
1484 rx_ring->rx_stats.rsc_flush++;
1487 /* ERR_MASK will only have valid bits if EOP set */
1488 if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) {
1489 /* trim packet back to size 0 and recycle it */
1490 __pskb_trim(skb, 0);
1491 rx_buffer_info->skb = skb;
1492 goto next_desc;
1495 ixgbe_rx_checksum(adapter, rx_desc, skb);
1496 if (adapter->netdev->features & NETIF_F_RXHASH)
1497 ixgbe_rx_hash(rx_desc, skb);
1499 /* probably a little skewed due to removing CRC */
1500 total_rx_bytes += skb->len;
1501 total_rx_packets++;
1503 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
1504 #ifdef IXGBE_FCOE
1505 /* if ddp, not passing to ULD unless for FCP_RSP or error */
1506 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
1507 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
1508 if (!ddp_bytes)
1509 goto next_desc;
1511 #endif /* IXGBE_FCOE */
1512 ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
1514 next_desc:
1515 rx_desc->wb.upper.status_error = 0;
1517 (*work_done)++;
1518 if (*work_done >= work_to_do)
1519 break;
1521 /* return some buffers to hardware, one at a time is too slow */
1522 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
1523 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1524 cleaned_count = 0;
1527 /* use prefetched values */
1528 rx_desc = next_rxd;
1529 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
1532 rx_ring->next_to_clean = i;
1533 cleaned_count = IXGBE_DESC_UNUSED(rx_ring);
1535 if (cleaned_count)
1536 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1538 #ifdef IXGBE_FCOE
1539 /* include DDPed FCoE data */
1540 if (ddp_bytes > 0) {
1541 unsigned int mss;
1543 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
1544 sizeof(struct fc_frame_header) -
1545 sizeof(struct fcoe_crc_eof);
1546 if (mss > 512)
1547 mss &= ~511;
1548 total_rx_bytes += ddp_bytes;
1549 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1551 #endif /* IXGBE_FCOE */
1553 rx_ring->total_packets += total_rx_packets;
1554 rx_ring->total_bytes += total_rx_bytes;
1555 u64_stats_update_begin(&rx_ring->syncp);
1556 rx_ring->stats.packets += total_rx_packets;
1557 rx_ring->stats.bytes += total_rx_bytes;
1558 u64_stats_update_end(&rx_ring->syncp);
1561 static int ixgbe_clean_rxonly(struct napi_struct *, int);
1563 * ixgbe_configure_msix - Configure MSI-X hardware
1564 * @adapter: board private structure
1566 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1567 * interrupts.
1569 static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1571 struct ixgbe_q_vector *q_vector;
1572 int i, q_vectors, v_idx, r_idx;
1573 u32 mask;
1575 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1578 * Populate the IVAR table and set the ITR values to the
1579 * corresponding register.
1581 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
1582 q_vector = adapter->q_vector[v_idx];
1583 /* XXX for_each_set_bit(...) */
1584 r_idx = find_first_bit(q_vector->rxr_idx,
1585 adapter->num_rx_queues);
1587 for (i = 0; i < q_vector->rxr_count; i++) {
1588 u8 reg_idx = adapter->rx_ring[r_idx]->reg_idx;
1589 ixgbe_set_ivar(adapter, 0, reg_idx, v_idx);
1590 r_idx = find_next_bit(q_vector->rxr_idx,
1591 adapter->num_rx_queues,
1592 r_idx + 1);
1594 r_idx = find_first_bit(q_vector->txr_idx,
1595 adapter->num_tx_queues);
1597 for (i = 0; i < q_vector->txr_count; i++) {
1598 u8 reg_idx = adapter->tx_ring[r_idx]->reg_idx;
1599 ixgbe_set_ivar(adapter, 1, reg_idx, v_idx);
1600 r_idx = find_next_bit(q_vector->txr_idx,
1601 adapter->num_tx_queues,
1602 r_idx + 1);
1605 if (q_vector->txr_count && !q_vector->rxr_count)
1606 /* tx only */
1607 q_vector->eitr = adapter->tx_eitr_param;
1608 else if (q_vector->rxr_count)
1609 /* rx or mixed */
1610 q_vector->eitr = adapter->rx_eitr_param;
1612 ixgbe_write_eitr(q_vector);
1613 /* If Flow Director is enabled, set interrupt affinity */
1614 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
1615 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
1617 * Allocate the affinity_hint cpumask, assign the mask
1618 * for this vector, and set our affinity_hint for
1619 * this irq.
1621 if (!alloc_cpumask_var(&q_vector->affinity_mask,
1622 GFP_KERNEL))
1623 return;
1624 cpumask_set_cpu(v_idx, q_vector->affinity_mask);
1625 irq_set_affinity_hint(adapter->msix_entries[v_idx].vector,
1626 q_vector->affinity_mask);
1630 switch (adapter->hw.mac.type) {
1631 case ixgbe_mac_82598EB:
1632 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
1633 v_idx);
1634 break;
1635 case ixgbe_mac_82599EB:
1636 case ixgbe_mac_X540:
1637 ixgbe_set_ivar(adapter, -1, 1, v_idx);
1638 break;
1640 default:
1641 break;
1643 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
1645 /* set up to autoclear timer, and the vectors */
1646 mask = IXGBE_EIMS_ENABLE_MASK;
1647 if (adapter->num_vfs)
1648 mask &= ~(IXGBE_EIMS_OTHER |
1649 IXGBE_EIMS_MAILBOX |
1650 IXGBE_EIMS_LSC);
1651 else
1652 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
1653 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
1656 enum latency_range {
1657 lowest_latency = 0,
1658 low_latency = 1,
1659 bulk_latency = 2,
1660 latency_invalid = 255
1664 * ixgbe_update_itr - update the dynamic ITR value based on statistics
1665 * @adapter: pointer to adapter
1666 * @eitr: eitr setting (ints per sec) to give last timeslice
1667 * @itr_setting: current throttle rate in ints/second
1668 * @packets: the number of packets during this measurement interval
1669 * @bytes: the number of bytes during this measurement interval
1671 * Stores a new ITR value based on packets and byte
1672 * counts during the last interrupt. The advantage of per interrupt
1673 * computation is faster updates and more accurate ITR for the current
1674 * traffic pattern. Constants in this function were computed
1675 * based on theoretical maximum wire speed and thresholds were set based
1676 * on testing data as well as attempting to minimize response time
1677 * while increasing bulk throughput.
1678 * this functionality is controlled by the InterruptThrottleRate module
1679 * parameter (see ixgbe_param.c)
1681 static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter,
1682 u32 eitr, u8 itr_setting,
1683 int packets, int bytes)
1685 unsigned int retval = itr_setting;
1686 u32 timepassed_us;
1687 u64 bytes_perint;
1689 if (packets == 0)
1690 goto update_itr_done;
1693 /* simple throttlerate management
1694 * 0-20MB/s lowest (100000 ints/s)
1695 * 20-100MB/s low (20000 ints/s)
1696 * 100-1249MB/s bulk (8000 ints/s)
1698 /* what was last interrupt timeslice? */
1699 timepassed_us = 1000000/eitr;
1700 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1702 switch (itr_setting) {
1703 case lowest_latency:
1704 if (bytes_perint > adapter->eitr_low)
1705 retval = low_latency;
1706 break;
1707 case low_latency:
1708 if (bytes_perint > adapter->eitr_high)
1709 retval = bulk_latency;
1710 else if (bytes_perint <= adapter->eitr_low)
1711 retval = lowest_latency;
1712 break;
1713 case bulk_latency:
1714 if (bytes_perint <= adapter->eitr_high)
1715 retval = low_latency;
1716 break;
1719 update_itr_done:
1720 return retval;
1724 * ixgbe_write_eitr - write EITR register in hardware specific way
1725 * @q_vector: structure containing interrupt and ring information
1727 * This function is made to be called by ethtool and by the driver
1728 * when it needs to update EITR registers at runtime. Hardware
1729 * specific quirks/differences are taken care of here.
1731 void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
1733 struct ixgbe_adapter *adapter = q_vector->adapter;
1734 struct ixgbe_hw *hw = &adapter->hw;
1735 int v_idx = q_vector->v_idx;
1736 u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr);
1738 switch (adapter->hw.mac.type) {
1739 case ixgbe_mac_82598EB:
1740 /* must write high and low 16 bits to reset counter */
1741 itr_reg |= (itr_reg << 16);
1742 break;
1743 case ixgbe_mac_82599EB:
1744 case ixgbe_mac_X540:
1746 * 82599 and X540 can support a value of zero, so allow it for
1747 * max interrupt rate, but there is an errata where it can
1748 * not be zero with RSC
1750 if (itr_reg == 8 &&
1751 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
1752 itr_reg = 0;
1755 * set the WDIS bit to not clear the timer bits and cause an
1756 * immediate assertion of the interrupt
1758 itr_reg |= IXGBE_EITR_CNT_WDIS;
1759 break;
1760 default:
1761 break;
1763 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1766 static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector)
1768 struct ixgbe_adapter *adapter = q_vector->adapter;
1769 int i, r_idx;
1770 u32 new_itr;
1771 u8 current_itr, ret_itr;
1773 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1774 for (i = 0; i < q_vector->txr_count; i++) {
1775 struct ixgbe_ring *tx_ring = adapter->tx_ring[r_idx];
1776 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
1777 q_vector->tx_itr,
1778 tx_ring->total_packets,
1779 tx_ring->total_bytes);
1780 /* if the result for this queue would decrease interrupt
1781 * rate for this vector then use that result */
1782 q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ?
1783 q_vector->tx_itr - 1 : ret_itr);
1784 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
1785 r_idx + 1);
1788 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1789 for (i = 0; i < q_vector->rxr_count; i++) {
1790 struct ixgbe_ring *rx_ring = adapter->rx_ring[r_idx];
1791 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
1792 q_vector->rx_itr,
1793 rx_ring->total_packets,
1794 rx_ring->total_bytes);
1795 /* if the result for this queue would decrease interrupt
1796 * rate for this vector then use that result */
1797 q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ?
1798 q_vector->rx_itr - 1 : ret_itr);
1799 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1800 r_idx + 1);
1803 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
1805 switch (current_itr) {
1806 /* counts and packets in update_itr are dependent on these numbers */
1807 case lowest_latency:
1808 new_itr = 100000;
1809 break;
1810 case low_latency:
1811 new_itr = 20000; /* aka hwitr = ~200 */
1812 break;
1813 case bulk_latency:
1814 default:
1815 new_itr = 8000;
1816 break;
1819 if (new_itr != q_vector->eitr) {
1820 /* do an exponential smoothing */
1821 new_itr = ((q_vector->eitr * 9) + new_itr)/10;
1823 /* save the algorithm value here, not the smoothed one */
1824 q_vector->eitr = new_itr;
1826 ixgbe_write_eitr(q_vector);
1831 * ixgbe_check_overtemp_subtask - check for over tempurature
1832 * @adapter: pointer to adapter
1834 static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
1836 struct ixgbe_hw *hw = &adapter->hw;
1837 u32 eicr = adapter->interrupt_event;
1839 if (test_bit(__IXGBE_DOWN, &adapter->state))
1840 return;
1842 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1843 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
1844 return;
1846 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1848 switch (hw->device_id) {
1849 case IXGBE_DEV_ID_82599_T3_LOM:
1851 * Since the warning interrupt is for both ports
1852 * we don't have to check if:
1853 * - This interrupt wasn't for our port.
1854 * - We may have missed the interrupt so always have to
1855 * check if we got a LSC
1857 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
1858 !(eicr & IXGBE_EICR_LSC))
1859 return;
1861 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
1862 u32 autoneg;
1863 bool link_up = false;
1865 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
1867 if (link_up)
1868 return;
1871 /* Check if this is not due to overtemp */
1872 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
1873 return;
1875 break;
1876 default:
1877 if (!(eicr & IXGBE_EICR_GPI_SDP0))
1878 return;
1879 break;
1881 e_crit(drv,
1882 "Network adapter has been stopped because it has over heated. "
1883 "Restart the computer. If the problem persists, "
1884 "power off the system and replace the adapter\n");
1886 adapter->interrupt_event = 0;
1889 static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1891 struct ixgbe_hw *hw = &adapter->hw;
1893 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1894 (eicr & IXGBE_EICR_GPI_SDP1)) {
1895 e_crit(probe, "Fan has stopped, replace the adapter\n");
1896 /* write to clear the interrupt */
1897 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1901 static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1903 struct ixgbe_hw *hw = &adapter->hw;
1905 if (eicr & IXGBE_EICR_GPI_SDP2) {
1906 /* Clear the interrupt */
1907 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
1908 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1909 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
1910 ixgbe_service_event_schedule(adapter);
1914 if (eicr & IXGBE_EICR_GPI_SDP1) {
1915 /* Clear the interrupt */
1916 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1917 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1918 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
1919 ixgbe_service_event_schedule(adapter);
1924 static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
1926 struct ixgbe_hw *hw = &adapter->hw;
1928 adapter->lsc_int++;
1929 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1930 adapter->link_check_timeout = jiffies;
1931 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1932 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
1933 IXGBE_WRITE_FLUSH(hw);
1934 ixgbe_service_event_schedule(adapter);
1938 static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
1940 struct net_device *netdev = data;
1941 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1942 struct ixgbe_hw *hw = &adapter->hw;
1943 u32 eicr;
1946 * Workaround for Silicon errata. Use clear-by-write instead
1947 * of clear-by-read. Reading with EICS will return the
1948 * interrupt causes without clearing, which later be done
1949 * with the write to EICR.
1951 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1952 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
1954 if (eicr & IXGBE_EICR_LSC)
1955 ixgbe_check_lsc(adapter);
1957 if (eicr & IXGBE_EICR_MAILBOX)
1958 ixgbe_msg_task(adapter);
1960 switch (hw->mac.type) {
1961 case ixgbe_mac_82599EB:
1962 case ixgbe_mac_X540:
1963 /* Handle Flow Director Full threshold interrupt */
1964 if (eicr & IXGBE_EICR_FLOW_DIR) {
1965 int reinit_count = 0;
1966 int i;
1967 for (i = 0; i < adapter->num_tx_queues; i++) {
1968 struct ixgbe_ring *ring = adapter->tx_ring[i];
1969 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
1970 &ring->state))
1971 reinit_count++;
1973 if (reinit_count) {
1974 /* no more flow director interrupts until after init */
1975 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
1976 eicr &= ~IXGBE_EICR_FLOW_DIR;
1977 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
1978 ixgbe_service_event_schedule(adapter);
1981 ixgbe_check_sfp_event(adapter, eicr);
1982 if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1983 ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) {
1984 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1985 adapter->interrupt_event = eicr;
1986 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1987 ixgbe_service_event_schedule(adapter);
1990 break;
1991 default:
1992 break;
1995 ixgbe_check_fan_failure(adapter, eicr);
1997 /* re-enable the original interrupt state, no lsc, no queues */
1998 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1999 IXGBE_WRITE_REG(hw, IXGBE_EIMS, eicr &
2000 ~(IXGBE_EIMS_LSC | IXGBE_EIMS_RTX_QUEUE));
2002 return IRQ_HANDLED;
2005 static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2006 u64 qmask)
2008 u32 mask;
2009 struct ixgbe_hw *hw = &adapter->hw;
2011 switch (hw->mac.type) {
2012 case ixgbe_mac_82598EB:
2013 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
2014 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2015 break;
2016 case ixgbe_mac_82599EB:
2017 case ixgbe_mac_X540:
2018 mask = (qmask & 0xFFFFFFFF);
2019 if (mask)
2020 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
2021 mask = (qmask >> 32);
2022 if (mask)
2023 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2024 break;
2025 default:
2026 break;
2028 /* skip the flush */
2031 static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
2032 u64 qmask)
2034 u32 mask;
2035 struct ixgbe_hw *hw = &adapter->hw;
2037 switch (hw->mac.type) {
2038 case ixgbe_mac_82598EB:
2039 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
2040 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2041 break;
2042 case ixgbe_mac_82599EB:
2043 case ixgbe_mac_X540:
2044 mask = (qmask & 0xFFFFFFFF);
2045 if (mask)
2046 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
2047 mask = (qmask >> 32);
2048 if (mask)
2049 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2050 break;
2051 default:
2052 break;
2054 /* skip the flush */
2057 static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
2059 struct ixgbe_q_vector *q_vector = data;
2060 struct ixgbe_adapter *adapter = q_vector->adapter;
2061 struct ixgbe_ring *tx_ring;
2062 int i, r_idx;
2064 if (!q_vector->txr_count)
2065 return IRQ_HANDLED;
2067 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2068 for (i = 0; i < q_vector->txr_count; i++) {
2069 tx_ring = adapter->tx_ring[r_idx];
2070 tx_ring->total_bytes = 0;
2071 tx_ring->total_packets = 0;
2072 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
2073 r_idx + 1);
2076 /* EIAM disabled interrupts (on this vector) for us */
2077 napi_schedule(&q_vector->napi);
2079 return IRQ_HANDLED;
2083 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
2084 * @irq: unused
2085 * @data: pointer to our q_vector struct for this interrupt vector
2087 static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
2089 struct ixgbe_q_vector *q_vector = data;
2090 struct ixgbe_adapter *adapter = q_vector->adapter;
2091 struct ixgbe_ring *rx_ring;
2092 int r_idx;
2093 int i;
2095 #ifdef CONFIG_IXGBE_DCA
2096 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2097 ixgbe_update_dca(q_vector);
2098 #endif
2100 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
2101 for (i = 0; i < q_vector->rxr_count; i++) {
2102 rx_ring = adapter->rx_ring[r_idx];
2103 rx_ring->total_bytes = 0;
2104 rx_ring->total_packets = 0;
2105 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
2106 r_idx + 1);
2109 if (!q_vector->rxr_count)
2110 return IRQ_HANDLED;
2112 /* EIAM disabled interrupts (on this vector) for us */
2113 napi_schedule(&q_vector->napi);
2115 return IRQ_HANDLED;
2118 static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
2120 struct ixgbe_q_vector *q_vector = data;
2121 struct ixgbe_adapter *adapter = q_vector->adapter;
2122 struct ixgbe_ring *ring;
2123 int r_idx;
2124 int i;
2126 if (!q_vector->txr_count && !q_vector->rxr_count)
2127 return IRQ_HANDLED;
2129 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2130 for (i = 0; i < q_vector->txr_count; i++) {
2131 ring = adapter->tx_ring[r_idx];
2132 ring->total_bytes = 0;
2133 ring->total_packets = 0;
2134 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
2135 r_idx + 1);
2138 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
2139 for (i = 0; i < q_vector->rxr_count; i++) {
2140 ring = adapter->rx_ring[r_idx];
2141 ring->total_bytes = 0;
2142 ring->total_packets = 0;
2143 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
2144 r_idx + 1);
2147 /* EIAM disabled interrupts (on this vector) for us */
2148 napi_schedule(&q_vector->napi);
2150 return IRQ_HANDLED;
2154 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
2155 * @napi: napi struct with our devices info in it
2156 * @budget: amount of work driver is allowed to do this pass, in packets
2158 * This function is optimized for cleaning one queue only on a single
2159 * q_vector!!!
2161 static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
2163 struct ixgbe_q_vector *q_vector =
2164 container_of(napi, struct ixgbe_q_vector, napi);
2165 struct ixgbe_adapter *adapter = q_vector->adapter;
2166 struct ixgbe_ring *rx_ring = NULL;
2167 int work_done = 0;
2168 long r_idx;
2170 #ifdef CONFIG_IXGBE_DCA
2171 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2172 ixgbe_update_dca(q_vector);
2173 #endif
2175 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
2176 rx_ring = adapter->rx_ring[r_idx];
2178 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
2180 /* If all Rx work done, exit the polling mode */
2181 if (work_done < budget) {
2182 napi_complete(napi);
2183 if (adapter->rx_itr_setting & 1)
2184 ixgbe_set_itr_msix(q_vector);
2185 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2186 ixgbe_irq_enable_queues(adapter,
2187 ((u64)1 << q_vector->v_idx));
2190 return work_done;
2194 * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
2195 * @napi: napi struct with our devices info in it
2196 * @budget: amount of work driver is allowed to do this pass, in packets
2198 * This function will clean more than one rx queue associated with a
2199 * q_vector.
2201 static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget)
2203 struct ixgbe_q_vector *q_vector =
2204 container_of(napi, struct ixgbe_q_vector, napi);
2205 struct ixgbe_adapter *adapter = q_vector->adapter;
2206 struct ixgbe_ring *ring = NULL;
2207 int work_done = 0, i;
2208 long r_idx;
2209 bool tx_clean_complete = true;
2211 #ifdef CONFIG_IXGBE_DCA
2212 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2213 ixgbe_update_dca(q_vector);
2214 #endif
2216 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2217 for (i = 0; i < q_vector->txr_count; i++) {
2218 ring = adapter->tx_ring[r_idx];
2219 tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring);
2220 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
2221 r_idx + 1);
2224 /* attempt to distribute budget to each queue fairly, but don't allow
2225 * the budget to go below 1 because we'll exit polling */
2226 budget /= (q_vector->rxr_count ?: 1);
2227 budget = max(budget, 1);
2228 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
2229 for (i = 0; i < q_vector->rxr_count; i++) {
2230 ring = adapter->rx_ring[r_idx];
2231 ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget);
2232 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
2233 r_idx + 1);
2236 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
2237 ring = adapter->rx_ring[r_idx];
2238 /* If all Rx work done, exit the polling mode */
2239 if (work_done < budget) {
2240 napi_complete(napi);
2241 if (adapter->rx_itr_setting & 1)
2242 ixgbe_set_itr_msix(q_vector);
2243 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2244 ixgbe_irq_enable_queues(adapter,
2245 ((u64)1 << q_vector->v_idx));
2246 return 0;
2249 return work_done;
2253 * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
2254 * @napi: napi struct with our devices info in it
2255 * @budget: amount of work driver is allowed to do this pass, in packets
2257 * This function is optimized for cleaning one queue only on a single
2258 * q_vector!!!
2260 static int ixgbe_clean_txonly(struct napi_struct *napi, int budget)
2262 struct ixgbe_q_vector *q_vector =
2263 container_of(napi, struct ixgbe_q_vector, napi);
2264 struct ixgbe_adapter *adapter = q_vector->adapter;
2265 struct ixgbe_ring *tx_ring = NULL;
2266 int work_done = 0;
2267 long r_idx;
2269 #ifdef CONFIG_IXGBE_DCA
2270 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2271 ixgbe_update_dca(q_vector);
2272 #endif
2274 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2275 tx_ring = adapter->tx_ring[r_idx];
2277 if (!ixgbe_clean_tx_irq(q_vector, tx_ring))
2278 work_done = budget;
2280 /* If all Tx work done, exit the polling mode */
2281 if (work_done < budget) {
2282 napi_complete(napi);
2283 if (adapter->tx_itr_setting & 1)
2284 ixgbe_set_itr_msix(q_vector);
2285 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2286 ixgbe_irq_enable_queues(adapter,
2287 ((u64)1 << q_vector->v_idx));
2290 return work_done;
2293 static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
2294 int r_idx)
2296 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
2297 struct ixgbe_ring *rx_ring = a->rx_ring[r_idx];
2299 set_bit(r_idx, q_vector->rxr_idx);
2300 q_vector->rxr_count++;
2301 rx_ring->q_vector = q_vector;
2304 static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
2305 int t_idx)
2307 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
2308 struct ixgbe_ring *tx_ring = a->tx_ring[t_idx];
2310 set_bit(t_idx, q_vector->txr_idx);
2311 q_vector->txr_count++;
2312 tx_ring->q_vector = q_vector;
2316 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
2317 * @adapter: board private structure to initialize
2319 * This function maps descriptor rings to the queue-specific vectors
2320 * we were allotted through the MSI-X enabling code. Ideally, we'd have
2321 * one vector per ring/queue, but on a constrained vector budget, we
2322 * group the rings as "efficiently" as possible. You would add new
2323 * mapping configurations in here.
2325 static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter)
2327 int q_vectors;
2328 int v_start = 0;
2329 int rxr_idx = 0, txr_idx = 0;
2330 int rxr_remaining = adapter->num_rx_queues;
2331 int txr_remaining = adapter->num_tx_queues;
2332 int i, j;
2333 int rqpv, tqpv;
2334 int err = 0;
2336 /* No mapping required if MSI-X is disabled. */
2337 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2338 goto out;
2340 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2343 * The ideal configuration...
2344 * We have enough vectors to map one per queue.
2346 if (q_vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
2347 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
2348 map_vector_to_rxq(adapter, v_start, rxr_idx);
2350 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
2351 map_vector_to_txq(adapter, v_start, txr_idx);
2353 goto out;
2357 * If we don't have enough vectors for a 1-to-1
2358 * mapping, we'll have to group them so there are
2359 * multiple queues per vector.
2361 /* Re-adjusting *qpv takes care of the remainder. */
2362 for (i = v_start; i < q_vectors; i++) {
2363 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
2364 for (j = 0; j < rqpv; j++) {
2365 map_vector_to_rxq(adapter, i, rxr_idx);
2366 rxr_idx++;
2367 rxr_remaining--;
2369 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
2370 for (j = 0; j < tqpv; j++) {
2371 map_vector_to_txq(adapter, i, txr_idx);
2372 txr_idx++;
2373 txr_remaining--;
2376 out:
2377 return err;
2381 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2382 * @adapter: board private structure
2384 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2385 * interrupts from the kernel.
2387 static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2389 struct net_device *netdev = adapter->netdev;
2390 irqreturn_t (*handler)(int, void *);
2391 int i, vector, q_vectors, err;
2392 int ri = 0, ti = 0;
2394 /* Decrement for Other and TCP Timer vectors */
2395 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2397 err = ixgbe_map_rings_to_vectors(adapter);
2398 if (err)
2399 return err;
2401 #define SET_HANDLER(_v) (((_v)->rxr_count && (_v)->txr_count) \
2402 ? &ixgbe_msix_clean_many : \
2403 (_v)->rxr_count ? &ixgbe_msix_clean_rx : \
2404 (_v)->txr_count ? &ixgbe_msix_clean_tx : \
2405 NULL)
2406 for (vector = 0; vector < q_vectors; vector++) {
2407 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2408 handler = SET_HANDLER(q_vector);
2410 if (handler == &ixgbe_msix_clean_rx) {
2411 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2412 "%s-%s-%d", netdev->name, "rx", ri++);
2413 } else if (handler == &ixgbe_msix_clean_tx) {
2414 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2415 "%s-%s-%d", netdev->name, "tx", ti++);
2416 } else if (handler == &ixgbe_msix_clean_many) {
2417 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2418 "%s-%s-%d", netdev->name, "TxRx", ri++);
2419 ti++;
2420 } else {
2421 /* skip this unused q_vector */
2422 continue;
2424 err = request_irq(adapter->msix_entries[vector].vector,
2425 handler, 0, q_vector->name,
2426 q_vector);
2427 if (err) {
2428 e_err(probe, "request_irq failed for MSIX interrupt "
2429 "Error: %d\n", err);
2430 goto free_queue_irqs;
2434 sprintf(adapter->lsc_int_name, "%s:lsc", netdev->name);
2435 err = request_irq(adapter->msix_entries[vector].vector,
2436 ixgbe_msix_lsc, 0, adapter->lsc_int_name, netdev);
2437 if (err) {
2438 e_err(probe, "request_irq for msix_lsc failed: %d\n", err);
2439 goto free_queue_irqs;
2442 return 0;
2444 free_queue_irqs:
2445 for (i = vector - 1; i >= 0; i--)
2446 free_irq(adapter->msix_entries[--vector].vector,
2447 adapter->q_vector[i]);
2448 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2449 pci_disable_msix(adapter->pdev);
2450 kfree(adapter->msix_entries);
2451 adapter->msix_entries = NULL;
2452 return err;
2455 static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
2457 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
2458 struct ixgbe_ring *rx_ring = adapter->rx_ring[0];
2459 struct ixgbe_ring *tx_ring = adapter->tx_ring[0];
2460 u32 new_itr = q_vector->eitr;
2461 u8 current_itr;
2463 q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr,
2464 q_vector->tx_itr,
2465 tx_ring->total_packets,
2466 tx_ring->total_bytes);
2467 q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr,
2468 q_vector->rx_itr,
2469 rx_ring->total_packets,
2470 rx_ring->total_bytes);
2472 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
2474 switch (current_itr) {
2475 /* counts and packets in update_itr are dependent on these numbers */
2476 case lowest_latency:
2477 new_itr = 100000;
2478 break;
2479 case low_latency:
2480 new_itr = 20000; /* aka hwitr = ~200 */
2481 break;
2482 case bulk_latency:
2483 new_itr = 8000;
2484 break;
2485 default:
2486 break;
2489 if (new_itr != q_vector->eitr) {
2490 /* do an exponential smoothing */
2491 new_itr = ((q_vector->eitr * 9) + new_itr)/10;
2493 /* save the algorithm value here */
2494 q_vector->eitr = new_itr;
2496 ixgbe_write_eitr(q_vector);
2501 * ixgbe_irq_enable - Enable default interrupt generation settings
2502 * @adapter: board private structure
2504 static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2505 bool flush)
2507 u32 mask;
2509 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
2510 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
2511 mask |= IXGBE_EIMS_GPI_SDP0;
2512 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2513 mask |= IXGBE_EIMS_GPI_SDP1;
2514 switch (adapter->hw.mac.type) {
2515 case ixgbe_mac_82599EB:
2516 case ixgbe_mac_X540:
2517 mask |= IXGBE_EIMS_ECC;
2518 mask |= IXGBE_EIMS_GPI_SDP1;
2519 mask |= IXGBE_EIMS_GPI_SDP2;
2520 if (adapter->num_vfs)
2521 mask |= IXGBE_EIMS_MAILBOX;
2522 break;
2523 default:
2524 break;
2526 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
2527 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
2528 mask |= IXGBE_EIMS_FLOW_DIR;
2530 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2531 if (queues)
2532 ixgbe_irq_enable_queues(adapter, ~0);
2533 if (flush)
2534 IXGBE_WRITE_FLUSH(&adapter->hw);
2536 if (adapter->num_vfs > 32) {
2537 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
2538 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2543 * ixgbe_intr - legacy mode Interrupt Handler
2544 * @irq: interrupt number
2545 * @data: pointer to a network interface device structure
2547 static irqreturn_t ixgbe_intr(int irq, void *data)
2549 struct net_device *netdev = data;
2550 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2551 struct ixgbe_hw *hw = &adapter->hw;
2552 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
2553 u32 eicr;
2556 * Workaround for silicon errata on 82598. Mask the interrupts
2557 * before the read of EICR.
2559 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2561 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
2562 * therefore no explict interrupt disable is necessary */
2563 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
2564 if (!eicr) {
2566 * shared interrupt alert!
2567 * make sure interrupts are enabled because the read will
2568 * have disabled interrupts due to EIAM
2569 * finish the workaround of silicon errata on 82598. Unmask
2570 * the interrupt that we masked before the EICR read.
2572 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2573 ixgbe_irq_enable(adapter, true, true);
2574 return IRQ_NONE; /* Not our interrupt */
2577 if (eicr & IXGBE_EICR_LSC)
2578 ixgbe_check_lsc(adapter);
2580 switch (hw->mac.type) {
2581 case ixgbe_mac_82599EB:
2582 ixgbe_check_sfp_event(adapter, eicr);
2583 if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2584 ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) {
2585 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2586 adapter->interrupt_event = eicr;
2587 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2588 ixgbe_service_event_schedule(adapter);
2591 break;
2592 default:
2593 break;
2596 ixgbe_check_fan_failure(adapter, eicr);
2598 if (napi_schedule_prep(&(q_vector->napi))) {
2599 adapter->tx_ring[0]->total_packets = 0;
2600 adapter->tx_ring[0]->total_bytes = 0;
2601 adapter->rx_ring[0]->total_packets = 0;
2602 adapter->rx_ring[0]->total_bytes = 0;
2603 /* would disable interrupts here but EIAM disabled it */
2604 __napi_schedule(&(q_vector->napi));
2608 * re-enable link(maybe) and non-queue interrupts, no flush.
2609 * ixgbe_poll will re-enable the queue interrupts
2612 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2613 ixgbe_irq_enable(adapter, false, false);
2615 return IRQ_HANDLED;
2618 static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
2620 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2622 for (i = 0; i < q_vectors; i++) {
2623 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
2624 bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
2625 bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
2626 q_vector->rxr_count = 0;
2627 q_vector->txr_count = 0;
2632 * ixgbe_request_irq - initialize interrupts
2633 * @adapter: board private structure
2635 * Attempts to configure interrupts using the best available
2636 * capabilities of the hardware and kernel.
2638 static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
2640 struct net_device *netdev = adapter->netdev;
2641 int err;
2643 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2644 err = ixgbe_request_msix_irqs(adapter);
2645 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
2646 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
2647 netdev->name, netdev);
2648 } else {
2649 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
2650 netdev->name, netdev);
2653 if (err)
2654 e_err(probe, "request_irq failed, Error %d\n", err);
2656 return err;
2659 static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2661 struct net_device *netdev = adapter->netdev;
2663 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2664 int i, q_vectors;
2666 q_vectors = adapter->num_msix_vectors;
2668 i = q_vectors - 1;
2669 free_irq(adapter->msix_entries[i].vector, netdev);
2671 i--;
2672 for (; i >= 0; i--) {
2673 /* free only the irqs that were actually requested */
2674 if (!adapter->q_vector[i]->rxr_count &&
2675 !adapter->q_vector[i]->txr_count)
2676 continue;
2678 free_irq(adapter->msix_entries[i].vector,
2679 adapter->q_vector[i]);
2682 ixgbe_reset_q_vectors(adapter);
2683 } else {
2684 free_irq(adapter->pdev->irq, netdev);
2689 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2690 * @adapter: board private structure
2692 static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2694 switch (adapter->hw.mac.type) {
2695 case ixgbe_mac_82598EB:
2696 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
2697 break;
2698 case ixgbe_mac_82599EB:
2699 case ixgbe_mac_X540:
2700 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2701 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
2702 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
2703 if (adapter->num_vfs > 32)
2704 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
2705 break;
2706 default:
2707 break;
2709 IXGBE_WRITE_FLUSH(&adapter->hw);
2710 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2711 int i;
2712 for (i = 0; i < adapter->num_msix_vectors; i++)
2713 synchronize_irq(adapter->msix_entries[i].vector);
2714 } else {
2715 synchronize_irq(adapter->pdev->irq);
2720 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2723 static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2725 struct ixgbe_hw *hw = &adapter->hw;
2727 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
2728 EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param));
2730 ixgbe_set_ivar(adapter, 0, 0, 0);
2731 ixgbe_set_ivar(adapter, 1, 0, 0);
2733 map_vector_to_rxq(adapter, 0, 0);
2734 map_vector_to_txq(adapter, 0, 0);
2736 e_info(hw, "Legacy interrupt IVAR setup done\n");
2740 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2741 * @adapter: board private structure
2742 * @ring: structure containing ring specific data
2744 * Configure the Tx descriptor ring after a reset.
2746 void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2747 struct ixgbe_ring *ring)
2749 struct ixgbe_hw *hw = &adapter->hw;
2750 u64 tdba = ring->dma;
2751 int wait_loop = 10;
2752 u32 txdctl;
2753 u8 reg_idx = ring->reg_idx;
2755 /* disable queue to avoid issues while updating state */
2756 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2757 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx),
2758 txdctl & ~IXGBE_TXDCTL_ENABLE);
2759 IXGBE_WRITE_FLUSH(hw);
2761 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
2762 (tdba & DMA_BIT_MASK(32)));
2763 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2764 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2765 ring->count * sizeof(union ixgbe_adv_tx_desc));
2766 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2767 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
2768 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
2770 /* configure fetching thresholds */
2771 if (adapter->rx_itr_setting == 0) {
2772 /* cannot set wthresh when itr==0 */
2773 txdctl &= ~0x007F0000;
2774 } else {
2775 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2776 txdctl |= (8 << 16);
2778 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2779 /* PThresh workaround for Tx hang with DFP enabled. */
2780 txdctl |= 32;
2783 /* reinitialize flowdirector state */
2784 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2785 adapter->atr_sample_rate) {
2786 ring->atr_sample_rate = adapter->atr_sample_rate;
2787 ring->atr_count = 0;
2788 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2789 } else {
2790 ring->atr_sample_rate = 0;
2793 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2795 /* enable queue */
2796 txdctl |= IXGBE_TXDCTL_ENABLE;
2797 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2799 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2800 if (hw->mac.type == ixgbe_mac_82598EB &&
2801 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2802 return;
2804 /* poll to verify queue is enabled */
2805 do {
2806 usleep_range(1000, 2000);
2807 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2808 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2809 if (!wait_loop)
2810 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
2813 static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2815 struct ixgbe_hw *hw = &adapter->hw;
2816 u32 rttdcs;
2817 u32 mask;
2819 if (hw->mac.type == ixgbe_mac_82598EB)
2820 return;
2822 /* disable the arbiter while setting MTQC */
2823 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2824 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2825 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2827 /* set transmit pool layout */
2828 mask = (IXGBE_FLAG_SRIOV_ENABLED | IXGBE_FLAG_DCB_ENABLED);
2829 switch (adapter->flags & mask) {
2831 case (IXGBE_FLAG_SRIOV_ENABLED):
2832 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2833 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2834 break;
2836 case (IXGBE_FLAG_DCB_ENABLED):
2837 /* We enable 8 traffic classes, DCB only */
2838 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2839 (IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ));
2840 break;
2842 default:
2843 IXGBE_WRITE_REG(hw, IXGBE_MTQC, IXGBE_MTQC_64Q_1PB);
2844 break;
2847 /* re-enable the arbiter */
2848 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2849 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2853 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
2854 * @adapter: board private structure
2856 * Configure the Tx unit of the MAC after a reset.
2858 static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2860 struct ixgbe_hw *hw = &adapter->hw;
2861 u32 dmatxctl;
2862 u32 i;
2864 ixgbe_setup_mtqc(adapter);
2866 if (hw->mac.type != ixgbe_mac_82598EB) {
2867 /* DMATXCTL.EN must be before Tx queues are enabled */
2868 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2869 dmatxctl |= IXGBE_DMATXCTL_TE;
2870 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2873 /* Setup the HW Tx Head and Tail descriptor pointers */
2874 for (i = 0; i < adapter->num_tx_queues; i++)
2875 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
2878 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
2880 static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
2881 struct ixgbe_ring *rx_ring)
2883 u32 srrctl;
2884 u8 reg_idx = rx_ring->reg_idx;
2886 switch (adapter->hw.mac.type) {
2887 case ixgbe_mac_82598EB: {
2888 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2889 const int mask = feature[RING_F_RSS].mask;
2890 reg_idx = reg_idx & mask;
2892 break;
2893 case ixgbe_mac_82599EB:
2894 case ixgbe_mac_X540:
2895 default:
2896 break;
2899 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
2901 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2902 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
2903 if (adapter->num_vfs)
2904 srrctl |= IXGBE_SRRCTL_DROP_EN;
2906 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2907 IXGBE_SRRCTL_BSIZEHDR_MASK;
2909 if (ring_is_ps_enabled(rx_ring)) {
2910 #if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
2911 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2912 #else
2913 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2914 #endif
2915 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
2916 } else {
2917 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
2918 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2919 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
2922 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
2925 static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
2927 struct ixgbe_hw *hw = &adapter->hw;
2928 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
2929 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2930 0x6A3E67EA, 0x14364D17, 0x3BED200D};
2931 u32 mrqc = 0, reta = 0;
2932 u32 rxcsum;
2933 int i, j;
2934 int mask;
2936 /* Fill out hash function seeds */
2937 for (i = 0; i < 10; i++)
2938 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
2940 /* Fill out redirection table */
2941 for (i = 0, j = 0; i < 128; i++, j++) {
2942 if (j == adapter->ring_feature[RING_F_RSS].indices)
2943 j = 0;
2944 /* reta = 4-byte sliding window of
2945 * 0x00..(indices-1)(indices-1)00..etc. */
2946 reta = (reta << 8) | (j * 0x11);
2947 if ((i & 3) == 3)
2948 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2951 /* Disable indicating checksum in descriptor, enables RSS hash */
2952 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2953 rxcsum |= IXGBE_RXCSUM_PCSD;
2954 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2956 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
2957 mask = adapter->flags & IXGBE_FLAG_RSS_ENABLED;
2958 else
2959 mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
2960 #ifdef CONFIG_IXGBE_DCB
2961 | IXGBE_FLAG_DCB_ENABLED
2962 #endif
2963 | IXGBE_FLAG_SRIOV_ENABLED
2966 switch (mask) {
2967 #ifdef CONFIG_IXGBE_DCB
2968 case (IXGBE_FLAG_DCB_ENABLED | IXGBE_FLAG_RSS_ENABLED):
2969 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2970 break;
2971 case (IXGBE_FLAG_DCB_ENABLED):
2972 mrqc = IXGBE_MRQC_RT8TCEN;
2973 break;
2974 #endif /* CONFIG_IXGBE_DCB */
2975 case (IXGBE_FLAG_RSS_ENABLED):
2976 mrqc = IXGBE_MRQC_RSSEN;
2977 break;
2978 case (IXGBE_FLAG_SRIOV_ENABLED):
2979 mrqc = IXGBE_MRQC_VMDQEN;
2980 break;
2981 default:
2982 break;
2985 /* Perform hash on these packet types */
2986 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2987 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2988 | IXGBE_MRQC_RSS_FIELD_IPV6
2989 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2991 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
2995 * ixgbe_clear_rscctl - disable RSC for the indicated ring
2996 * @adapter: address of board private structure
2997 * @ring: structure containing ring specific data
2999 void ixgbe_clear_rscctl(struct ixgbe_adapter *adapter,
3000 struct ixgbe_ring *ring)
3002 struct ixgbe_hw *hw = &adapter->hw;
3003 u32 rscctrl;
3004 u8 reg_idx = ring->reg_idx;
3006 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
3007 rscctrl &= ~IXGBE_RSCCTL_RSCEN;
3008 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
3012 * ixgbe_configure_rscctl - enable RSC for the indicated ring
3013 * @adapter: address of board private structure
3014 * @index: index of ring to set
3016 void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
3017 struct ixgbe_ring *ring)
3019 struct ixgbe_hw *hw = &adapter->hw;
3020 u32 rscctrl;
3021 int rx_buf_len;
3022 u8 reg_idx = ring->reg_idx;
3024 if (!ring_is_rsc_enabled(ring))
3025 return;
3027 rx_buf_len = ring->rx_buf_len;
3028 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
3029 rscctrl |= IXGBE_RSCCTL_RSCEN;
3031 * we must limit the number of descriptors so that the
3032 * total size of max desc * buf_len is not greater
3033 * than 65535
3035 if (ring_is_ps_enabled(ring)) {
3036 #if (MAX_SKB_FRAGS > 16)
3037 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
3038 #elif (MAX_SKB_FRAGS > 8)
3039 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
3040 #elif (MAX_SKB_FRAGS > 4)
3041 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
3042 #else
3043 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
3044 #endif
3045 } else {
3046 if (rx_buf_len < IXGBE_RXBUFFER_4096)
3047 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
3048 else if (rx_buf_len < IXGBE_RXBUFFER_8192)
3049 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
3050 else
3051 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
3053 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
3057 * ixgbe_set_uta - Set unicast filter table address
3058 * @adapter: board private structure
3060 * The unicast table address is a register array of 32-bit registers.
3061 * The table is meant to be used in a way similar to how the MTA is used
3062 * however due to certain limitations in the hardware it is necessary to
3063 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
3064 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
3066 static void ixgbe_set_uta(struct ixgbe_adapter *adapter)
3068 struct ixgbe_hw *hw = &adapter->hw;
3069 int i;
3071 /* The UTA table only exists on 82599 hardware and newer */
3072 if (hw->mac.type < ixgbe_mac_82599EB)
3073 return;
3075 /* we only need to do this if VMDq is enabled */
3076 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3077 return;
3079 for (i = 0; i < 128; i++)
3080 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
3083 #define IXGBE_MAX_RX_DESC_POLL 10
3084 static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
3085 struct ixgbe_ring *ring)
3087 struct ixgbe_hw *hw = &adapter->hw;
3088 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3089 u32 rxdctl;
3090 u8 reg_idx = ring->reg_idx;
3092 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3093 if (hw->mac.type == ixgbe_mac_82598EB &&
3094 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3095 return;
3097 do {
3098 usleep_range(1000, 2000);
3099 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3100 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
3102 if (!wait_loop) {
3103 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
3104 "the polling period\n", reg_idx);
3108 void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
3109 struct ixgbe_ring *ring)
3111 struct ixgbe_hw *hw = &adapter->hw;
3112 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3113 u32 rxdctl;
3114 u8 reg_idx = ring->reg_idx;
3116 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3117 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
3119 /* write value back with RXDCTL.ENABLE bit cleared */
3120 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3122 if (hw->mac.type == ixgbe_mac_82598EB &&
3123 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3124 return;
3126 /* the hardware may take up to 100us to really disable the rx queue */
3127 do {
3128 udelay(10);
3129 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3130 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3132 if (!wait_loop) {
3133 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3134 "the polling period\n", reg_idx);
3138 void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3139 struct ixgbe_ring *ring)
3141 struct ixgbe_hw *hw = &adapter->hw;
3142 u64 rdba = ring->dma;
3143 u32 rxdctl;
3144 u8 reg_idx = ring->reg_idx;
3146 /* disable queue to avoid issues while updating state */
3147 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3148 ixgbe_disable_rx_queue(adapter, ring);
3150 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3151 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3152 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3153 ring->count * sizeof(union ixgbe_adv_rx_desc));
3154 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3155 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
3156 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
3158 ixgbe_configure_srrctl(adapter, ring);
3159 ixgbe_configure_rscctl(adapter, ring);
3161 /* If operating in IOV mode set RLPML for X540 */
3162 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
3163 hw->mac.type == ixgbe_mac_X540) {
3164 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
3165 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
3166 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
3169 if (hw->mac.type == ixgbe_mac_82598EB) {
3171 * enable cache line friendly hardware writes:
3172 * PTHRESH=32 descriptors (half the internal cache),
3173 * this also removes ugly rx_no_buffer_count increment
3174 * HTHRESH=4 descriptors (to minimize latency on fetch)
3175 * WTHRESH=8 burst writeback up to two cache lines
3177 rxdctl &= ~0x3FFFFF;
3178 rxdctl |= 0x080420;
3181 /* enable receive descriptor ring */
3182 rxdctl |= IXGBE_RXDCTL_ENABLE;
3183 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3185 ixgbe_rx_desc_queue_enable(adapter, ring);
3186 ixgbe_alloc_rx_buffers(ring, IXGBE_DESC_UNUSED(ring));
3189 static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3191 struct ixgbe_hw *hw = &adapter->hw;
3192 int p;
3194 /* PSRTYPE must be initialized in non 82598 adapters */
3195 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
3196 IXGBE_PSRTYPE_UDPHDR |
3197 IXGBE_PSRTYPE_IPV4HDR |
3198 IXGBE_PSRTYPE_L2HDR |
3199 IXGBE_PSRTYPE_IPV6HDR;
3201 if (hw->mac.type == ixgbe_mac_82598EB)
3202 return;
3204 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
3205 psrtype |= (adapter->num_rx_queues_per_pool << 29);
3207 for (p = 0; p < adapter->num_rx_pools; p++)
3208 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
3209 psrtype);
3212 static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3214 struct ixgbe_hw *hw = &adapter->hw;
3215 u32 gcr_ext;
3216 u32 vt_reg_bits;
3217 u32 reg_offset, vf_shift;
3218 u32 vmdctl;
3220 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3221 return;
3223 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
3224 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
3225 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
3226 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
3228 vf_shift = adapter->num_vfs % 32;
3229 reg_offset = (adapter->num_vfs > 32) ? 1 : 0;
3231 /* Enable only the PF's pool for Tx/Rx */
3232 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
3233 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
3234 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
3235 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
3236 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
3238 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3239 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
3242 * Set up VF register offsets for selected VT Mode,
3243 * i.e. 32 or 64 VFs for SR-IOV
3245 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
3246 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
3247 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
3248 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3250 /* enable Tx loopback for VF/PF communication */
3251 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
3252 /* Enable MAC Anti-Spoofing */
3253 hw->mac.ops.set_mac_anti_spoofing(hw,
3254 (adapter->antispoofing_enabled =
3255 (adapter->num_vfs != 0)),
3256 adapter->num_vfs);
3259 static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
3261 struct ixgbe_hw *hw = &adapter->hw;
3262 struct net_device *netdev = adapter->netdev;
3263 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3264 int rx_buf_len;
3265 struct ixgbe_ring *rx_ring;
3266 int i;
3267 u32 mhadd, hlreg0;
3269 /* Decide whether to use packet split mode or not */
3270 /* On by default */
3271 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
3273 /* Do not use packet split if we're in SR-IOV Mode */
3274 if (adapter->num_vfs)
3275 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
3277 /* Disable packet split due to 82599 erratum #45 */
3278 if (hw->mac.type == ixgbe_mac_82599EB)
3279 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
3281 /* Set the RX buffer length according to the mode */
3282 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
3283 rx_buf_len = IXGBE_RX_HDR_SIZE;
3284 } else {
3285 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
3286 (netdev->mtu <= ETH_DATA_LEN))
3287 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
3288 else
3289 rx_buf_len = ALIGN(max_frame + VLAN_HLEN, 1024);
3292 #ifdef IXGBE_FCOE
3293 /* adjust max frame to be able to do baby jumbo for FCoE */
3294 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3295 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3296 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3298 #endif /* IXGBE_FCOE */
3299 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3300 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3301 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3302 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3304 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
3307 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
3308 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3309 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
3310 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3313 * Setup the HW Rx Head and Tail Descriptor Pointers and
3314 * the Base and Length of the Rx Descriptor Ring
3316 for (i = 0; i < adapter->num_rx_queues; i++) {
3317 rx_ring = adapter->rx_ring[i];
3318 rx_ring->rx_buf_len = rx_buf_len;
3320 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
3321 set_ring_ps_enabled(rx_ring);
3322 else
3323 clear_ring_ps_enabled(rx_ring);
3325 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3326 set_ring_rsc_enabled(rx_ring);
3327 else
3328 clear_ring_rsc_enabled(rx_ring);
3330 #ifdef IXGBE_FCOE
3331 if (netdev->features & NETIF_F_FCOE_MTU) {
3332 struct ixgbe_ring_feature *f;
3333 f = &adapter->ring_feature[RING_F_FCOE];
3334 if ((i >= f->mask) && (i < f->mask + f->indices)) {
3335 clear_ring_ps_enabled(rx_ring);
3336 if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3337 rx_ring->rx_buf_len =
3338 IXGBE_FCOE_JUMBO_FRAME_SIZE;
3339 } else if (!ring_is_rsc_enabled(rx_ring) &&
3340 !ring_is_ps_enabled(rx_ring)) {
3341 rx_ring->rx_buf_len =
3342 IXGBE_FCOE_JUMBO_FRAME_SIZE;
3345 #endif /* IXGBE_FCOE */
3349 static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3351 struct ixgbe_hw *hw = &adapter->hw;
3352 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3354 switch (hw->mac.type) {
3355 case ixgbe_mac_82598EB:
3357 * For VMDq support of different descriptor types or
3358 * buffer sizes through the use of multiple SRRCTL
3359 * registers, RDRXCTL.MVMEN must be set to 1
3361 * also, the manual doesn't mention it clearly but DCA hints
3362 * will only use queue 0's tags unless this bit is set. Side
3363 * effects of setting this bit are only that SRRCTL must be
3364 * fully programmed [0..15]
3366 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3367 break;
3368 case ixgbe_mac_82599EB:
3369 case ixgbe_mac_X540:
3370 /* Disable RSC for ACK packets */
3371 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3372 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3373 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3374 /* hardware requires some bits to be set by default */
3375 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3376 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3377 break;
3378 default:
3379 /* We should do nothing since we don't know this hardware */
3380 return;
3383 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3387 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3388 * @adapter: board private structure
3390 * Configure the Rx unit of the MAC after a reset.
3392 static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3394 struct ixgbe_hw *hw = &adapter->hw;
3395 int i;
3396 u32 rxctrl;
3398 /* disable receives while setting up the descriptors */
3399 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3400 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3402 ixgbe_setup_psrtype(adapter);
3403 ixgbe_setup_rdrxctl(adapter);
3405 /* Program registers for the distribution of queues */
3406 ixgbe_setup_mrqc(adapter);
3408 ixgbe_set_uta(adapter);
3410 /* set_rx_buffer_len must be called before ring initialization */
3411 ixgbe_set_rx_buffer_len(adapter);
3414 * Setup the HW Rx Head and Tail Descriptor Pointers and
3415 * the Base and Length of the Rx Descriptor Ring
3417 for (i = 0; i < adapter->num_rx_queues; i++)
3418 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
3420 /* disable drop enable for 82598 parts */
3421 if (hw->mac.type == ixgbe_mac_82598EB)
3422 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3424 /* enable all receives */
3425 rxctrl |= IXGBE_RXCTRL_RXEN;
3426 hw->mac.ops.enable_rx_dma(hw, rxctrl);
3429 static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
3431 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3432 struct ixgbe_hw *hw = &adapter->hw;
3433 int pool_ndx = adapter->num_vfs;
3435 /* add VID to filter table */
3436 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
3437 set_bit(vid, adapter->active_vlans);
3440 static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
3442 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3443 struct ixgbe_hw *hw = &adapter->hw;
3444 int pool_ndx = adapter->num_vfs;
3446 /* remove VID from filter table */
3447 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
3448 clear_bit(vid, adapter->active_vlans);
3452 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3453 * @adapter: driver data
3455 static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3457 struct ixgbe_hw *hw = &adapter->hw;
3458 u32 vlnctrl;
3460 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3461 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3462 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3466 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3467 * @adapter: driver data
3469 static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3471 struct ixgbe_hw *hw = &adapter->hw;
3472 u32 vlnctrl;
3474 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3475 vlnctrl |= IXGBE_VLNCTRL_VFE;
3476 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3477 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3481 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3482 * @adapter: driver data
3484 static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3486 struct ixgbe_hw *hw = &adapter->hw;
3487 u32 vlnctrl;
3488 int i, j;
3490 switch (hw->mac.type) {
3491 case ixgbe_mac_82598EB:
3492 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3493 vlnctrl &= ~IXGBE_VLNCTRL_VME;
3494 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3495 break;
3496 case ixgbe_mac_82599EB:
3497 case ixgbe_mac_X540:
3498 for (i = 0; i < adapter->num_rx_queues; i++) {
3499 j = adapter->rx_ring[i]->reg_idx;
3500 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3501 vlnctrl &= ~IXGBE_RXDCTL_VME;
3502 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3504 break;
3505 default:
3506 break;
3511 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
3512 * @adapter: driver data
3514 static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
3516 struct ixgbe_hw *hw = &adapter->hw;
3517 u32 vlnctrl;
3518 int i, j;
3520 switch (hw->mac.type) {
3521 case ixgbe_mac_82598EB:
3522 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3523 vlnctrl |= IXGBE_VLNCTRL_VME;
3524 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3525 break;
3526 case ixgbe_mac_82599EB:
3527 case ixgbe_mac_X540:
3528 for (i = 0; i < adapter->num_rx_queues; i++) {
3529 j = adapter->rx_ring[i]->reg_idx;
3530 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3531 vlnctrl |= IXGBE_RXDCTL_VME;
3532 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3534 break;
3535 default:
3536 break;
3540 static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3542 u16 vid;
3544 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3546 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3547 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
3551 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3552 * @netdev: network interface device structure
3554 * Writes unicast address list to the RAR table.
3555 * Returns: -ENOMEM on failure/insufficient address space
3556 * 0 on no addresses written
3557 * X on writing X addresses to the RAR table
3559 static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3561 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3562 struct ixgbe_hw *hw = &adapter->hw;
3563 unsigned int vfn = adapter->num_vfs;
3564 unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS;
3565 int count = 0;
3567 /* return ENOMEM indicating insufficient memory for addresses */
3568 if (netdev_uc_count(netdev) > rar_entries)
3569 return -ENOMEM;
3571 if (!netdev_uc_empty(netdev) && rar_entries) {
3572 struct netdev_hw_addr *ha;
3573 /* return error if we do not support writing to RAR table */
3574 if (!hw->mac.ops.set_rar)
3575 return -ENOMEM;
3577 netdev_for_each_uc_addr(ha, netdev) {
3578 if (!rar_entries)
3579 break;
3580 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3581 vfn, IXGBE_RAH_AV);
3582 count++;
3585 /* write the addresses in reverse order to avoid write combining */
3586 for (; rar_entries > 0 ; rar_entries--)
3587 hw->mac.ops.clear_rar(hw, rar_entries);
3589 return count;
3593 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
3594 * @netdev: network interface device structure
3596 * The set_rx_method entry point is called whenever the unicast/multicast
3597 * address list or the network interface flags are updated. This routine is
3598 * responsible for configuring the hardware for proper unicast, multicast and
3599 * promiscuous mode.
3601 void ixgbe_set_rx_mode(struct net_device *netdev)
3603 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3604 struct ixgbe_hw *hw = &adapter->hw;
3605 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3606 int count;
3608 /* Check for Promiscuous and All Multicast modes */
3610 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3612 /* set all bits that we expect to always be set */
3613 fctrl |= IXGBE_FCTRL_BAM;
3614 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3615 fctrl |= IXGBE_FCTRL_PMCF;
3617 /* clear the bits we are changing the status of */
3618 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3620 if (netdev->flags & IFF_PROMISC) {
3621 hw->addr_ctrl.user_set_promisc = true;
3622 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3623 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
3624 /* don't hardware filter vlans in promisc mode */
3625 ixgbe_vlan_filter_disable(adapter);
3626 } else {
3627 if (netdev->flags & IFF_ALLMULTI) {
3628 fctrl |= IXGBE_FCTRL_MPE;
3629 vmolr |= IXGBE_VMOLR_MPE;
3630 } else {
3632 * Write addresses to the MTA, if the attempt fails
3633 * then we should just turn on promiscuous mode so
3634 * that we can at least receive multicast traffic
3636 hw->mac.ops.update_mc_addr_list(hw, netdev);
3637 vmolr |= IXGBE_VMOLR_ROMPE;
3639 ixgbe_vlan_filter_enable(adapter);
3640 hw->addr_ctrl.user_set_promisc = false;
3642 * Write addresses to available RAR registers, if there is not
3643 * sufficient space to store all the addresses then enable
3644 * unicast promiscuous mode
3646 count = ixgbe_write_uc_addr_list(netdev);
3647 if (count < 0) {
3648 fctrl |= IXGBE_FCTRL_UPE;
3649 vmolr |= IXGBE_VMOLR_ROPE;
3653 if (adapter->num_vfs) {
3654 ixgbe_restore_vf_multicasts(adapter);
3655 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3656 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3657 IXGBE_VMOLR_ROPE);
3658 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
3661 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
3663 if (netdev->features & NETIF_F_HW_VLAN_RX)
3664 ixgbe_vlan_strip_enable(adapter);
3665 else
3666 ixgbe_vlan_strip_disable(adapter);
3669 static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3671 int q_idx;
3672 struct ixgbe_q_vector *q_vector;
3673 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3675 /* legacy and MSI only use one vector */
3676 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3677 q_vectors = 1;
3679 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
3680 struct napi_struct *napi;
3681 q_vector = adapter->q_vector[q_idx];
3682 napi = &q_vector->napi;
3683 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3684 if (!q_vector->rxr_count || !q_vector->txr_count) {
3685 if (q_vector->txr_count == 1)
3686 napi->poll = &ixgbe_clean_txonly;
3687 else if (q_vector->rxr_count == 1)
3688 napi->poll = &ixgbe_clean_rxonly;
3692 napi_enable(napi);
3696 static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3698 int q_idx;
3699 struct ixgbe_q_vector *q_vector;
3700 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3702 /* legacy and MSI only use one vector */
3703 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3704 q_vectors = 1;
3706 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
3707 q_vector = adapter->q_vector[q_idx];
3708 napi_disable(&q_vector->napi);
3712 #ifdef CONFIG_IXGBE_DCB
3714 * ixgbe_configure_dcb - Configure DCB hardware
3715 * @adapter: ixgbe adapter struct
3717 * This is called by the driver on open to configure the DCB hardware.
3718 * This is also called by the gennetlink interface when reconfiguring
3719 * the DCB state.
3721 static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3723 struct ixgbe_hw *hw = &adapter->hw;
3724 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3726 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3727 if (hw->mac.type == ixgbe_mac_82598EB)
3728 netif_set_gso_max_size(adapter->netdev, 65536);
3729 return;
3732 if (hw->mac.type == ixgbe_mac_82598EB)
3733 netif_set_gso_max_size(adapter->netdev, 32768);
3736 /* Enable VLAN tag insert/strip */
3737 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
3739 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
3741 /* reconfigure the hardware */
3742 if (adapter->dcbx_cap & (DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE)) {
3743 #ifdef CONFIG_FCOE
3744 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3745 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3746 #endif
3747 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3748 DCB_TX_CONFIG);
3749 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3750 DCB_RX_CONFIG);
3751 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
3752 } else {
3753 struct net_device *dev = adapter->netdev;
3755 if (adapter->ixgbe_ieee_ets)
3756 dev->dcbnl_ops->ieee_setets(dev,
3757 adapter->ixgbe_ieee_ets);
3758 if (adapter->ixgbe_ieee_pfc)
3759 dev->dcbnl_ops->ieee_setpfc(dev,
3760 adapter->ixgbe_ieee_pfc);
3763 /* Enable RSS Hash per TC */
3764 if (hw->mac.type != ixgbe_mac_82598EB) {
3765 int i;
3766 u32 reg = 0;
3768 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3769 u8 msb = 0;
3770 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3772 while (cnt >>= 1)
3773 msb++;
3775 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3777 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3781 #endif
3782 static void ixgbe_configure(struct ixgbe_adapter *adapter)
3784 struct net_device *netdev = adapter->netdev;
3785 struct ixgbe_hw *hw = &adapter->hw;
3786 int i;
3788 #ifdef CONFIG_IXGBE_DCB
3789 ixgbe_configure_dcb(adapter);
3790 #endif
3792 ixgbe_set_rx_mode(netdev);
3793 ixgbe_restore_vlan(adapter);
3795 #ifdef IXGBE_FCOE
3796 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3797 ixgbe_configure_fcoe(adapter);
3799 #endif /* IXGBE_FCOE */
3800 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
3801 for (i = 0; i < adapter->num_tx_queues; i++)
3802 adapter->tx_ring[i]->atr_sample_rate =
3803 adapter->atr_sample_rate;
3804 ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc);
3805 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3806 ixgbe_init_fdir_perfect_82599(hw, adapter->fdir_pballoc);
3808 ixgbe_configure_virtualization(adapter);
3810 ixgbe_configure_tx(adapter);
3811 ixgbe_configure_rx(adapter);
3814 static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3816 switch (hw->phy.type) {
3817 case ixgbe_phy_sfp_avago:
3818 case ixgbe_phy_sfp_ftl:
3819 case ixgbe_phy_sfp_intel:
3820 case ixgbe_phy_sfp_unknown:
3821 case ixgbe_phy_sfp_passive_tyco:
3822 case ixgbe_phy_sfp_passive_unknown:
3823 case ixgbe_phy_sfp_active_unknown:
3824 case ixgbe_phy_sfp_ftl_active:
3825 return true;
3826 default:
3827 return false;
3832 * ixgbe_sfp_link_config - set up SFP+ link
3833 * @adapter: pointer to private adapter struct
3835 static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3838 * We are assuming the worst case scenerio here, and that
3839 * is that an SFP was inserted/removed after the reset
3840 * but before SFP detection was enabled. As such the best
3841 * solution is to just start searching as soon as we start
3843 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3844 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
3846 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
3850 * ixgbe_non_sfp_link_config - set up non-SFP+ link
3851 * @hw: pointer to private hardware struct
3853 * Returns 0 on success, negative on failure
3855 static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
3857 u32 autoneg;
3858 bool negotiation, link_up = false;
3859 u32 ret = IXGBE_ERR_LINK_SETUP;
3861 if (hw->mac.ops.check_link)
3862 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3864 if (ret)
3865 goto link_cfg_out;
3867 autoneg = hw->phy.autoneg_advertised;
3868 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
3869 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3870 &negotiation);
3871 if (ret)
3872 goto link_cfg_out;
3874 if (hw->mac.ops.setup_link)
3875 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
3876 link_cfg_out:
3877 return ret;
3880 static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
3882 struct ixgbe_hw *hw = &adapter->hw;
3883 u32 gpie = 0;
3885 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3886 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3887 IXGBE_GPIE_OCD;
3888 gpie |= IXGBE_GPIE_EIAME;
3890 * use EIAM to auto-mask when MSI-X interrupt is asserted
3891 * this saves a register write for every interrupt
3893 switch (hw->mac.type) {
3894 case ixgbe_mac_82598EB:
3895 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3896 break;
3897 case ixgbe_mac_82599EB:
3898 case ixgbe_mac_X540:
3899 default:
3900 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3901 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3902 break;
3904 } else {
3905 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3906 * specifically only auto mask tx and rx interrupts */
3907 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3910 /* XXX: to interrupt immediately for EICS writes, enable this */
3911 /* gpie |= IXGBE_GPIE_EIMEN; */
3913 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3914 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3915 gpie |= IXGBE_GPIE_VTMODE_64;
3918 /* Enable fan failure interrupt */
3919 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
3920 gpie |= IXGBE_SDP1_GPIEN;
3922 if (hw->mac.type == ixgbe_mac_82599EB) {
3923 gpie |= IXGBE_SDP1_GPIEN;
3924 gpie |= IXGBE_SDP2_GPIEN;
3927 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3930 static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
3932 struct ixgbe_hw *hw = &adapter->hw;
3933 int err;
3934 u32 ctrl_ext;
3936 ixgbe_get_hw_control(adapter);
3937 ixgbe_setup_gpie(adapter);
3939 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3940 ixgbe_configure_msix(adapter);
3941 else
3942 ixgbe_configure_msi_and_legacy(adapter);
3944 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3945 if (hw->mac.ops.enable_tx_laser &&
3946 ((hw->phy.multispeed_fiber) ||
3947 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
3948 (hw->mac.type == ixgbe_mac_82599EB))))
3949 hw->mac.ops.enable_tx_laser(hw);
3951 clear_bit(__IXGBE_DOWN, &adapter->state);
3952 ixgbe_napi_enable_all(adapter);
3954 if (ixgbe_is_sfp(hw)) {
3955 ixgbe_sfp_link_config(adapter);
3956 } else {
3957 err = ixgbe_non_sfp_link_config(hw);
3958 if (err)
3959 e_err(probe, "link_config FAILED %d\n", err);
3962 /* clear any pending interrupts, may auto mask */
3963 IXGBE_READ_REG(hw, IXGBE_EICR);
3964 ixgbe_irq_enable(adapter, true, true);
3967 * If this adapter has a fan, check to see if we had a failure
3968 * before we enabled the interrupt.
3970 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
3971 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3972 if (esdp & IXGBE_ESDP_SDP1)
3973 e_crit(drv, "Fan has stopped, replace the adapter\n");
3976 /* enable transmits */
3977 netif_tx_start_all_queues(adapter->netdev);
3979 /* bring the link up in the watchdog, this could race with our first
3980 * link up interrupt but shouldn't be a problem */
3981 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3982 adapter->link_check_timeout = jiffies;
3983 mod_timer(&adapter->service_timer, jiffies);
3985 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3986 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
3987 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
3988 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
3990 return 0;
3993 void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
3995 WARN_ON(in_interrupt());
3996 /* put off any impending NetWatchDogTimeout */
3997 adapter->netdev->trans_start = jiffies;
3999 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
4000 usleep_range(1000, 2000);
4001 ixgbe_down(adapter);
4003 * If SR-IOV enabled then wait a bit before bringing the adapter
4004 * back up to give the VFs time to respond to the reset. The
4005 * two second wait is based upon the watchdog timer cycle in
4006 * the VF driver.
4008 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4009 msleep(2000);
4010 ixgbe_up(adapter);
4011 clear_bit(__IXGBE_RESETTING, &adapter->state);
4014 int ixgbe_up(struct ixgbe_adapter *adapter)
4016 /* hardware has been reset, we need to reload some things */
4017 ixgbe_configure(adapter);
4019 return ixgbe_up_complete(adapter);
4022 void ixgbe_reset(struct ixgbe_adapter *adapter)
4024 struct ixgbe_hw *hw = &adapter->hw;
4025 int err;
4027 /* lock SFP init bit to prevent race conditions with the watchdog */
4028 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
4029 usleep_range(1000, 2000);
4031 /* clear all SFP and link config related flags while holding SFP_INIT */
4032 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
4033 IXGBE_FLAG2_SFP_NEEDS_RESET);
4034 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
4036 err = hw->mac.ops.init_hw(hw);
4037 switch (err) {
4038 case 0:
4039 case IXGBE_ERR_SFP_NOT_PRESENT:
4040 case IXGBE_ERR_SFP_NOT_SUPPORTED:
4041 break;
4042 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
4043 e_dev_err("master disable timed out\n");
4044 break;
4045 case IXGBE_ERR_EEPROM_VERSION:
4046 /* We are running on a pre-production device, log a warning */
4047 e_dev_warn("This device is a pre-production adapter/LOM. "
4048 "Please be aware there may be issuesassociated with "
4049 "your hardware. If you are experiencing problems "
4050 "please contact your Intel or hardware "
4051 "representative who provided you with this "
4052 "hardware.\n");
4053 break;
4054 default:
4055 e_dev_err("Hardware Error: %d\n", err);
4058 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
4060 /* reprogram the RAR[0] in case user changed it. */
4061 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
4062 IXGBE_RAH_AV);
4066 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
4067 * @rx_ring: ring to free buffers from
4069 static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
4071 struct device *dev = rx_ring->dev;
4072 unsigned long size;
4073 u16 i;
4075 /* ring already cleared, nothing to do */
4076 if (!rx_ring->rx_buffer_info)
4077 return;
4079 /* Free all the Rx ring sk_buffs */
4080 for (i = 0; i < rx_ring->count; i++) {
4081 struct ixgbe_rx_buffer *rx_buffer_info;
4083 rx_buffer_info = &rx_ring->rx_buffer_info[i];
4084 if (rx_buffer_info->dma) {
4085 dma_unmap_single(rx_ring->dev, rx_buffer_info->dma,
4086 rx_ring->rx_buf_len,
4087 DMA_FROM_DEVICE);
4088 rx_buffer_info->dma = 0;
4090 if (rx_buffer_info->skb) {
4091 struct sk_buff *skb = rx_buffer_info->skb;
4092 rx_buffer_info->skb = NULL;
4093 do {
4094 struct sk_buff *this = skb;
4095 if (IXGBE_RSC_CB(this)->delay_unmap) {
4096 dma_unmap_single(dev,
4097 IXGBE_RSC_CB(this)->dma,
4098 rx_ring->rx_buf_len,
4099 DMA_FROM_DEVICE);
4100 IXGBE_RSC_CB(this)->dma = 0;
4101 IXGBE_RSC_CB(skb)->delay_unmap = false;
4103 skb = skb->prev;
4104 dev_kfree_skb(this);
4105 } while (skb);
4107 if (!rx_buffer_info->page)
4108 continue;
4109 if (rx_buffer_info->page_dma) {
4110 dma_unmap_page(dev, rx_buffer_info->page_dma,
4111 PAGE_SIZE / 2, DMA_FROM_DEVICE);
4112 rx_buffer_info->page_dma = 0;
4114 put_page(rx_buffer_info->page);
4115 rx_buffer_info->page = NULL;
4116 rx_buffer_info->page_offset = 0;
4119 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4120 memset(rx_ring->rx_buffer_info, 0, size);
4122 /* Zero out the descriptor ring */
4123 memset(rx_ring->desc, 0, rx_ring->size);
4125 rx_ring->next_to_clean = 0;
4126 rx_ring->next_to_use = 0;
4130 * ixgbe_clean_tx_ring - Free Tx Buffers
4131 * @tx_ring: ring to be cleaned
4133 static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
4135 struct ixgbe_tx_buffer *tx_buffer_info;
4136 unsigned long size;
4137 u16 i;
4139 /* ring already cleared, nothing to do */
4140 if (!tx_ring->tx_buffer_info)
4141 return;
4143 /* Free all the Tx ring sk_buffs */
4144 for (i = 0; i < tx_ring->count; i++) {
4145 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4146 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
4149 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4150 memset(tx_ring->tx_buffer_info, 0, size);
4152 /* Zero out the descriptor ring */
4153 memset(tx_ring->desc, 0, tx_ring->size);
4155 tx_ring->next_to_use = 0;
4156 tx_ring->next_to_clean = 0;
4160 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4161 * @adapter: board private structure
4163 static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4165 int i;
4167 for (i = 0; i < adapter->num_rx_queues; i++)
4168 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
4172 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4173 * @adapter: board private structure
4175 static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4177 int i;
4179 for (i = 0; i < adapter->num_tx_queues; i++)
4180 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
4183 void ixgbe_down(struct ixgbe_adapter *adapter)
4185 struct net_device *netdev = adapter->netdev;
4186 struct ixgbe_hw *hw = &adapter->hw;
4187 u32 rxctrl;
4188 int i;
4189 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
4191 /* signal that we are down to the interrupt handler */
4192 set_bit(__IXGBE_DOWN, &adapter->state);
4194 /* disable receives */
4195 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4196 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
4198 /* disable all enabled rx queues */
4199 for (i = 0; i < adapter->num_rx_queues; i++)
4200 /* this call also flushes the previous write */
4201 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4203 usleep_range(10000, 20000);
4205 netif_tx_stop_all_queues(netdev);
4207 /* call carrier off first to avoid false dev_watchdog timeouts */
4208 netif_carrier_off(netdev);
4209 netif_tx_disable(netdev);
4211 ixgbe_irq_disable(adapter);
4213 ixgbe_napi_disable_all(adapter);
4215 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4216 IXGBE_FLAG2_RESET_REQUESTED);
4217 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4219 del_timer_sync(&adapter->service_timer);
4221 /* disable receive for all VFs and wait one second */
4222 if (adapter->num_vfs) {
4223 /* ping all the active vfs to let them know we are going down */
4224 ixgbe_ping_all_vfs(adapter);
4226 /* Disable all VFTE/VFRE TX/RX */
4227 ixgbe_disable_tx_rx(adapter);
4229 /* Mark all the VFs as inactive */
4230 for (i = 0 ; i < adapter->num_vfs; i++)
4231 adapter->vfinfo[i].clear_to_send = 0;
4234 /* Cleanup the affinity_hint CPU mask memory and callback */
4235 for (i = 0; i < num_q_vectors; i++) {
4236 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
4237 /* clear the affinity_mask in the IRQ descriptor */
4238 irq_set_affinity_hint(adapter->msix_entries[i]. vector, NULL);
4239 /* release the CPU mask memory */
4240 free_cpumask_var(q_vector->affinity_mask);
4243 /* disable transmits in the hardware now that interrupts are off */
4244 for (i = 0; i < adapter->num_tx_queues; i++) {
4245 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
4246 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
4249 /* Disable the Tx DMA engine on 82599 and X540 */
4250 switch (hw->mac.type) {
4251 case ixgbe_mac_82599EB:
4252 case ixgbe_mac_X540:
4253 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
4254 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4255 ~IXGBE_DMATXCTL_TE));
4256 break;
4257 default:
4258 break;
4261 if (!pci_channel_offline(adapter->pdev))
4262 ixgbe_reset(adapter);
4264 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4265 if (hw->mac.ops.disable_tx_laser &&
4266 ((hw->phy.multispeed_fiber) ||
4267 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
4268 (hw->mac.type == ixgbe_mac_82599EB))))
4269 hw->mac.ops.disable_tx_laser(hw);
4271 ixgbe_clean_all_tx_rings(adapter);
4272 ixgbe_clean_all_rx_rings(adapter);
4274 #ifdef CONFIG_IXGBE_DCA
4275 /* since we reset the hardware DCA settings were cleared */
4276 ixgbe_setup_dca(adapter);
4277 #endif
4281 * ixgbe_poll - NAPI Rx polling callback
4282 * @napi: structure for representing this polling device
4283 * @budget: how many packets driver is allowed to clean
4285 * This function is used for legacy and MSI, NAPI mode
4287 static int ixgbe_poll(struct napi_struct *napi, int budget)
4289 struct ixgbe_q_vector *q_vector =
4290 container_of(napi, struct ixgbe_q_vector, napi);
4291 struct ixgbe_adapter *adapter = q_vector->adapter;
4292 int tx_clean_complete, work_done = 0;
4294 #ifdef CONFIG_IXGBE_DCA
4295 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
4296 ixgbe_update_dca(q_vector);
4297 #endif
4299 tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring[0]);
4300 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring[0], &work_done, budget);
4302 if (!tx_clean_complete)
4303 work_done = budget;
4305 /* If budget not fully consumed, exit the polling mode */
4306 if (work_done < budget) {
4307 napi_complete(napi);
4308 if (adapter->rx_itr_setting & 1)
4309 ixgbe_set_itr(adapter);
4310 if (!test_bit(__IXGBE_DOWN, &adapter->state))
4311 ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE);
4313 return work_done;
4317 * ixgbe_tx_timeout - Respond to a Tx Hang
4318 * @netdev: network interface device structure
4320 static void ixgbe_tx_timeout(struct net_device *netdev)
4322 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4324 /* Do the reset outside of interrupt context */
4325 ixgbe_tx_timeout_reset(adapter);
4329 * ixgbe_set_rss_queues: Allocate queues for RSS
4330 * @adapter: board private structure to initialize
4332 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
4333 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
4336 static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
4338 bool ret = false;
4339 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
4341 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4342 f->mask = 0xF;
4343 adapter->num_rx_queues = f->indices;
4344 adapter->num_tx_queues = f->indices;
4345 ret = true;
4346 } else {
4347 ret = false;
4350 return ret;
4354 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
4355 * @adapter: board private structure to initialize
4357 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
4358 * to the original CPU that initiated the Tx session. This runs in addition
4359 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
4360 * Rx load across CPUs using RSS.
4363 static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
4365 bool ret = false;
4366 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
4368 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
4369 f_fdir->mask = 0;
4371 /* Flow Director must have RSS enabled */
4372 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
4373 ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
4374 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)))) {
4375 adapter->num_tx_queues = f_fdir->indices;
4376 adapter->num_rx_queues = f_fdir->indices;
4377 ret = true;
4378 } else {
4379 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
4380 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
4382 return ret;
4385 #ifdef IXGBE_FCOE
4387 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
4388 * @adapter: board private structure to initialize
4390 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
4391 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
4392 * rx queues out of the max number of rx queues, instead, it is used as the
4393 * index of the first rx queue used by FCoE.
4396 static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
4398 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4400 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4401 return false;
4403 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
4404 #ifdef CONFIG_IXGBE_DCB
4405 int tc;
4406 struct net_device *dev = adapter->netdev;
4408 tc = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
4409 f->indices = dev->tc_to_txq[tc].count;
4410 f->mask = dev->tc_to_txq[tc].offset;
4411 #endif
4412 } else {
4413 f->indices = min((int)num_online_cpus(), f->indices);
4415 adapter->num_rx_queues = 1;
4416 adapter->num_tx_queues = 1;
4418 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4419 e_info(probe, "FCoE enabled with RSS\n");
4420 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
4421 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
4422 ixgbe_set_fdir_queues(adapter);
4423 else
4424 ixgbe_set_rss_queues(adapter);
4426 /* adding FCoE rx rings to the end */
4427 f->mask = adapter->num_rx_queues;
4428 adapter->num_rx_queues += f->indices;
4429 adapter->num_tx_queues += f->indices;
4432 return true;
4434 #endif /* IXGBE_FCOE */
4436 #ifdef CONFIG_IXGBE_DCB
4437 static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
4439 bool ret = false;
4440 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_DCB];
4441 int i, q;
4443 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
4444 return ret;
4446 f->indices = 0;
4447 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
4448 q = min((int)num_online_cpus(), MAX_TRAFFIC_CLASS);
4449 f->indices += q;
4452 f->mask = 0x7 << 3;
4453 adapter->num_rx_queues = f->indices;
4454 adapter->num_tx_queues = f->indices;
4455 ret = true;
4457 #ifdef IXGBE_FCOE
4458 /* FCoE enabled queues require special configuration done through
4459 * configure_fcoe() and others. Here we map FCoE indices onto the
4460 * DCB queue pairs allowing FCoE to own configuration later.
4462 ixgbe_set_fcoe_queues(adapter);
4463 #endif
4465 return ret;
4467 #endif
4470 * ixgbe_set_sriov_queues: Allocate queues for IOV use
4471 * @adapter: board private structure to initialize
4473 * IOV doesn't actually use anything, so just NAK the
4474 * request for now and let the other queue routines
4475 * figure out what to do.
4477 static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
4479 return false;
4483 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
4484 * @adapter: board private structure to initialize
4486 * This is the top level queue allocation routine. The order here is very
4487 * important, starting with the "most" number of features turned on at once,
4488 * and ending with the smallest set of features. This way large combinations
4489 * can be allocated if they're turned on, and smaller combinations are the
4490 * fallthrough conditions.
4493 static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
4495 /* Start with base case */
4496 adapter->num_rx_queues = 1;
4497 adapter->num_tx_queues = 1;
4498 adapter->num_rx_pools = adapter->num_rx_queues;
4499 adapter->num_rx_queues_per_pool = 1;
4501 if (ixgbe_set_sriov_queues(adapter))
4502 goto done;
4504 #ifdef CONFIG_IXGBE_DCB
4505 if (ixgbe_set_dcb_queues(adapter))
4506 goto done;
4508 #endif
4509 #ifdef IXGBE_FCOE
4510 if (ixgbe_set_fcoe_queues(adapter))
4511 goto done;
4513 #endif /* IXGBE_FCOE */
4514 if (ixgbe_set_fdir_queues(adapter))
4515 goto done;
4517 if (ixgbe_set_rss_queues(adapter))
4518 goto done;
4520 /* fallback to base case */
4521 adapter->num_rx_queues = 1;
4522 adapter->num_tx_queues = 1;
4524 done:
4525 /* Notify the stack of the (possibly) reduced queue counts. */
4526 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
4527 return netif_set_real_num_rx_queues(adapter->netdev,
4528 adapter->num_rx_queues);
4531 static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
4532 int vectors)
4534 int err, vector_threshold;
4536 /* We'll want at least 3 (vector_threshold):
4537 * 1) TxQ[0] Cleanup
4538 * 2) RxQ[0] Cleanup
4539 * 3) Other (Link Status Change, etc.)
4540 * 4) TCP Timer (optional)
4542 vector_threshold = MIN_MSIX_COUNT;
4544 /* The more we get, the more we will assign to Tx/Rx Cleanup
4545 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
4546 * Right now, we simply care about how many we'll get; we'll
4547 * set them up later while requesting irq's.
4549 while (vectors >= vector_threshold) {
4550 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
4551 vectors);
4552 if (!err) /* Success in acquiring all requested vectors. */
4553 break;
4554 else if (err < 0)
4555 vectors = 0; /* Nasty failure, quit now */
4556 else /* err == number of vectors we should try again with */
4557 vectors = err;
4560 if (vectors < vector_threshold) {
4561 /* Can't allocate enough MSI-X interrupts? Oh well.
4562 * This just means we'll go with either a single MSI
4563 * vector or fall back to legacy interrupts.
4565 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4566 "Unable to allocate MSI-X interrupts\n");
4567 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4568 kfree(adapter->msix_entries);
4569 adapter->msix_entries = NULL;
4570 } else {
4571 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
4573 * Adjust for only the vectors we'll use, which is minimum
4574 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
4575 * vectors we were allocated.
4577 adapter->num_msix_vectors = min(vectors,
4578 adapter->max_msix_q_vectors + NON_Q_VECTORS);
4583 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
4584 * @adapter: board private structure to initialize
4586 * Cache the descriptor ring offsets for RSS to the assigned rings.
4589 static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
4591 int i;
4593 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
4594 return false;
4596 for (i = 0; i < adapter->num_rx_queues; i++)
4597 adapter->rx_ring[i]->reg_idx = i;
4598 for (i = 0; i < adapter->num_tx_queues; i++)
4599 adapter->tx_ring[i]->reg_idx = i;
4601 return true;
4604 #ifdef CONFIG_IXGBE_DCB
4606 /* ixgbe_get_first_reg_idx - Return first register index associated with ring */
4607 static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc,
4608 unsigned int *tx, unsigned int *rx)
4610 struct net_device *dev = adapter->netdev;
4611 struct ixgbe_hw *hw = &adapter->hw;
4612 u8 num_tcs = netdev_get_num_tc(dev);
4614 *tx = 0;
4615 *rx = 0;
4617 switch (hw->mac.type) {
4618 case ixgbe_mac_82598EB:
4619 *tx = tc << 3;
4620 *rx = tc << 2;
4621 break;
4622 case ixgbe_mac_82599EB:
4623 case ixgbe_mac_X540:
4624 if (num_tcs == 8) {
4625 if (tc < 3) {
4626 *tx = tc << 5;
4627 *rx = tc << 4;
4628 } else if (tc < 5) {
4629 *tx = ((tc + 2) << 4);
4630 *rx = tc << 4;
4631 } else if (tc < num_tcs) {
4632 *tx = ((tc + 8) << 3);
4633 *rx = tc << 4;
4635 } else if (num_tcs == 4) {
4636 *rx = tc << 5;
4637 switch (tc) {
4638 case 0:
4639 *tx = 0;
4640 break;
4641 case 1:
4642 *tx = 64;
4643 break;
4644 case 2:
4645 *tx = 96;
4646 break;
4647 case 3:
4648 *tx = 112;
4649 break;
4650 default:
4651 break;
4654 break;
4655 default:
4656 break;
4660 #define IXGBE_MAX_Q_PER_TC (IXGBE_MAX_DCB_INDICES / MAX_TRAFFIC_CLASS)
4662 /* ixgbe_setup_tc - routine to configure net_device for multiple traffic
4663 * classes.
4665 * @netdev: net device to configure
4666 * @tc: number of traffic classes to enable
4668 int ixgbe_setup_tc(struct net_device *dev, u8 tc)
4670 int i;
4671 unsigned int q, offset = 0;
4673 if (!tc) {
4674 netdev_reset_tc(dev);
4675 } else {
4676 struct ixgbe_adapter *adapter = netdev_priv(dev);
4678 /* Hardware supports up to 8 traffic classes */
4679 if (tc > MAX_TRAFFIC_CLASS || netdev_set_num_tc(dev, tc))
4680 return -EINVAL;
4682 /* Partition Tx queues evenly amongst traffic classes */
4683 for (i = 0; i < tc; i++) {
4684 q = min((int)num_online_cpus(), IXGBE_MAX_Q_PER_TC);
4685 netdev_set_prio_tc_map(dev, i, i);
4686 netdev_set_tc_queue(dev, i, q, offset);
4687 offset += q;
4690 /* This enables multiple traffic class support in the hardware
4691 * which defaults to strict priority transmission by default.
4692 * If traffic classes are already enabled perhaps through DCB
4693 * code path then existing configuration will be used.
4695 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
4696 dev->dcbnl_ops && dev->dcbnl_ops->setdcbx) {
4697 struct ieee_ets ets = {
4698 .prio_tc = {0, 1, 2, 3, 4, 5, 6, 7},
4700 u8 mode = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_IEEE;
4702 dev->dcbnl_ops->setdcbx(dev, mode);
4703 dev->dcbnl_ops->ieee_setets(dev, &ets);
4706 return 0;
4710 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
4711 * @adapter: board private structure to initialize
4713 * Cache the descriptor ring offsets for DCB to the assigned rings.
4716 static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
4718 struct net_device *dev = adapter->netdev;
4719 int i, j, k;
4720 u8 num_tcs = netdev_get_num_tc(dev);
4722 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
4723 return false;
4725 for (i = 0, k = 0; i < num_tcs; i++) {
4726 unsigned int tx_s, rx_s;
4727 u16 count = dev->tc_to_txq[i].count;
4729 ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s);
4730 for (j = 0; j < count; j++, k++) {
4731 adapter->tx_ring[k]->reg_idx = tx_s + j;
4732 adapter->rx_ring[k]->reg_idx = rx_s + j;
4733 adapter->tx_ring[k]->dcb_tc = i;
4734 adapter->rx_ring[k]->dcb_tc = i;
4738 return true;
4740 #endif
4743 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
4744 * @adapter: board private structure to initialize
4746 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
4749 static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
4751 int i;
4752 bool ret = false;
4754 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
4755 ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
4756 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))) {
4757 for (i = 0; i < adapter->num_rx_queues; i++)
4758 adapter->rx_ring[i]->reg_idx = i;
4759 for (i = 0; i < adapter->num_tx_queues; i++)
4760 adapter->tx_ring[i]->reg_idx = i;
4761 ret = true;
4764 return ret;
4767 #ifdef IXGBE_FCOE
4769 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
4770 * @adapter: board private structure to initialize
4772 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
4775 static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
4777 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4778 int i;
4779 u8 fcoe_rx_i = 0, fcoe_tx_i = 0;
4781 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4782 return false;
4784 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4785 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
4786 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
4787 ixgbe_cache_ring_fdir(adapter);
4788 else
4789 ixgbe_cache_ring_rss(adapter);
4791 fcoe_rx_i = f->mask;
4792 fcoe_tx_i = f->mask;
4794 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
4795 adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
4796 adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
4798 return true;
4801 #endif /* IXGBE_FCOE */
4803 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
4804 * @adapter: board private structure to initialize
4806 * SR-IOV doesn't use any descriptor rings but changes the default if
4807 * no other mapping is used.
4810 static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
4812 adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
4813 adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
4814 if (adapter->num_vfs)
4815 return true;
4816 else
4817 return false;
4821 * ixgbe_cache_ring_register - Descriptor ring to register mapping
4822 * @adapter: board private structure to initialize
4824 * Once we know the feature-set enabled for the device, we'll cache
4825 * the register offset the descriptor ring is assigned to.
4827 * Note, the order the various feature calls is important. It must start with
4828 * the "most" features enabled at the same time, then trickle down to the
4829 * least amount of features turned on at once.
4831 static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
4833 /* start with default case */
4834 adapter->rx_ring[0]->reg_idx = 0;
4835 adapter->tx_ring[0]->reg_idx = 0;
4837 if (ixgbe_cache_ring_sriov(adapter))
4838 return;
4840 #ifdef CONFIG_IXGBE_DCB
4841 if (ixgbe_cache_ring_dcb(adapter))
4842 return;
4843 #endif
4845 #ifdef IXGBE_FCOE
4846 if (ixgbe_cache_ring_fcoe(adapter))
4847 return;
4848 #endif /* IXGBE_FCOE */
4850 if (ixgbe_cache_ring_fdir(adapter))
4851 return;
4853 if (ixgbe_cache_ring_rss(adapter))
4854 return;
4858 * ixgbe_alloc_queues - Allocate memory for all rings
4859 * @adapter: board private structure to initialize
4861 * We allocate one ring per queue at run-time since we don't know the
4862 * number of queues at compile-time. The polling_netdev array is
4863 * intended for Multiqueue, but should work fine with a single queue.
4865 static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
4867 int rx = 0, tx = 0, nid = adapter->node;
4869 if (nid < 0 || !node_online(nid))
4870 nid = first_online_node;
4872 for (; tx < adapter->num_tx_queues; tx++) {
4873 struct ixgbe_ring *ring;
4875 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
4876 if (!ring)
4877 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
4878 if (!ring)
4879 goto err_allocation;
4880 ring->count = adapter->tx_ring_count;
4881 ring->queue_index = tx;
4882 ring->numa_node = nid;
4883 ring->dev = &adapter->pdev->dev;
4884 ring->netdev = adapter->netdev;
4886 adapter->tx_ring[tx] = ring;
4889 for (; rx < adapter->num_rx_queues; rx++) {
4890 struct ixgbe_ring *ring;
4892 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
4893 if (!ring)
4894 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
4895 if (!ring)
4896 goto err_allocation;
4897 ring->count = adapter->rx_ring_count;
4898 ring->queue_index = rx;
4899 ring->numa_node = nid;
4900 ring->dev = &adapter->pdev->dev;
4901 ring->netdev = adapter->netdev;
4903 adapter->rx_ring[rx] = ring;
4906 ixgbe_cache_ring_register(adapter);
4908 return 0;
4910 err_allocation:
4911 while (tx)
4912 kfree(adapter->tx_ring[--tx]);
4914 while (rx)
4915 kfree(adapter->rx_ring[--rx]);
4916 return -ENOMEM;
4920 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
4921 * @adapter: board private structure to initialize
4923 * Attempt to configure the interrupts using the best available
4924 * capabilities of the hardware and the kernel.
4926 static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
4928 struct ixgbe_hw *hw = &adapter->hw;
4929 int err = 0;
4930 int vector, v_budget;
4933 * It's easy to be greedy for MSI-X vectors, but it really
4934 * doesn't do us much good if we have a lot more vectors
4935 * than CPU's. So let's be conservative and only ask for
4936 * (roughly) the same number of vectors as there are CPU's.
4938 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
4939 (int)num_online_cpus()) + NON_Q_VECTORS;
4942 * At the same time, hardware can only support a maximum of
4943 * hw.mac->max_msix_vectors vectors. With features
4944 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
4945 * descriptor queues supported by our device. Thus, we cap it off in
4946 * those rare cases where the cpu count also exceeds our vector limit.
4948 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
4950 /* A failure in MSI-X entry allocation isn't fatal, but it does
4951 * mean we disable MSI-X capabilities of the adapter. */
4952 adapter->msix_entries = kcalloc(v_budget,
4953 sizeof(struct msix_entry), GFP_KERNEL);
4954 if (adapter->msix_entries) {
4955 for (vector = 0; vector < v_budget; vector++)
4956 adapter->msix_entries[vector].entry = vector;
4958 ixgbe_acquire_msix_vectors(adapter, v_budget);
4960 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4961 goto out;
4964 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
4965 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
4966 if (adapter->flags & (IXGBE_FLAG_FDIR_HASH_CAPABLE |
4967 IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
4968 e_err(probe,
4969 "Flow Director is not supported while multiple "
4970 "queues are disabled. Disabling Flow Director\n");
4972 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
4973 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
4974 adapter->atr_sample_rate = 0;
4975 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4976 ixgbe_disable_sriov(adapter);
4978 err = ixgbe_set_num_queues(adapter);
4979 if (err)
4980 return err;
4982 err = pci_enable_msi(adapter->pdev);
4983 if (!err) {
4984 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
4985 } else {
4986 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4987 "Unable to allocate MSI interrupt, "
4988 "falling back to legacy. Error: %d\n", err);
4989 /* reset err */
4990 err = 0;
4993 out:
4994 return err;
4998 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
4999 * @adapter: board private structure to initialize
5001 * We allocate one q_vector per queue interrupt. If allocation fails we
5002 * return -ENOMEM.
5004 static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
5006 int q_idx, num_q_vectors;
5007 struct ixgbe_q_vector *q_vector;
5008 int (*poll)(struct napi_struct *, int);
5010 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
5011 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
5012 poll = &ixgbe_clean_rxtx_many;
5013 } else {
5014 num_q_vectors = 1;
5015 poll = &ixgbe_poll;
5018 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
5019 q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector),
5020 GFP_KERNEL, adapter->node);
5021 if (!q_vector)
5022 q_vector = kzalloc(sizeof(struct ixgbe_q_vector),
5023 GFP_KERNEL);
5024 if (!q_vector)
5025 goto err_out;
5026 q_vector->adapter = adapter;
5027 if (q_vector->txr_count && !q_vector->rxr_count)
5028 q_vector->eitr = adapter->tx_eitr_param;
5029 else
5030 q_vector->eitr = adapter->rx_eitr_param;
5031 q_vector->v_idx = q_idx;
5032 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
5033 adapter->q_vector[q_idx] = q_vector;
5036 return 0;
5038 err_out:
5039 while (q_idx) {
5040 q_idx--;
5041 q_vector = adapter->q_vector[q_idx];
5042 netif_napi_del(&q_vector->napi);
5043 kfree(q_vector);
5044 adapter->q_vector[q_idx] = NULL;
5046 return -ENOMEM;
5050 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
5051 * @adapter: board private structure to initialize
5053 * This function frees the memory allocated to the q_vectors. In addition if
5054 * NAPI is enabled it will delete any references to the NAPI struct prior
5055 * to freeing the q_vector.
5057 static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
5059 int q_idx, num_q_vectors;
5061 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
5062 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
5063 else
5064 num_q_vectors = 1;
5066 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
5067 struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx];
5068 adapter->q_vector[q_idx] = NULL;
5069 netif_napi_del(&q_vector->napi);
5070 kfree(q_vector);
5074 static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
5076 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
5077 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
5078 pci_disable_msix(adapter->pdev);
5079 kfree(adapter->msix_entries);
5080 adapter->msix_entries = NULL;
5081 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
5082 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
5083 pci_disable_msi(adapter->pdev);
5088 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
5089 * @adapter: board private structure to initialize
5091 * We determine which interrupt scheme to use based on...
5092 * - Kernel support (MSI, MSI-X)
5093 * - which can be user-defined (via MODULE_PARAM)
5094 * - Hardware queue count (num_*_queues)
5095 * - defined by miscellaneous hardware support/features (RSS, etc.)
5097 int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
5099 int err;
5101 /* Number of supported queues */
5102 err = ixgbe_set_num_queues(adapter);
5103 if (err)
5104 return err;
5106 err = ixgbe_set_interrupt_capability(adapter);
5107 if (err) {
5108 e_dev_err("Unable to setup interrupt capabilities\n");
5109 goto err_set_interrupt;
5112 err = ixgbe_alloc_q_vectors(adapter);
5113 if (err) {
5114 e_dev_err("Unable to allocate memory for queue vectors\n");
5115 goto err_alloc_q_vectors;
5118 err = ixgbe_alloc_queues(adapter);
5119 if (err) {
5120 e_dev_err("Unable to allocate memory for queues\n");
5121 goto err_alloc_queues;
5124 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
5125 (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
5126 adapter->num_rx_queues, adapter->num_tx_queues);
5128 set_bit(__IXGBE_DOWN, &adapter->state);
5130 return 0;
5132 err_alloc_queues:
5133 ixgbe_free_q_vectors(adapter);
5134 err_alloc_q_vectors:
5135 ixgbe_reset_interrupt_capability(adapter);
5136 err_set_interrupt:
5137 return err;
5141 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
5142 * @adapter: board private structure to clear interrupt scheme on
5144 * We go through and clear interrupt specific resources and reset the structure
5145 * to pre-load conditions
5147 void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
5149 int i;
5151 for (i = 0; i < adapter->num_tx_queues; i++) {
5152 kfree(adapter->tx_ring[i]);
5153 adapter->tx_ring[i] = NULL;
5155 for (i = 0; i < adapter->num_rx_queues; i++) {
5156 struct ixgbe_ring *ring = adapter->rx_ring[i];
5158 /* ixgbe_get_stats64() might access this ring, we must wait
5159 * a grace period before freeing it.
5161 kfree_rcu(ring, rcu);
5162 adapter->rx_ring[i] = NULL;
5165 adapter->num_tx_queues = 0;
5166 adapter->num_rx_queues = 0;
5168 ixgbe_free_q_vectors(adapter);
5169 ixgbe_reset_interrupt_capability(adapter);
5173 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5174 * @adapter: board private structure to initialize
5176 * ixgbe_sw_init initializes the Adapter private data structure.
5177 * Fields are initialized based on PCI device information and
5178 * OS network device settings (MTU size).
5180 static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
5182 struct ixgbe_hw *hw = &adapter->hw;
5183 struct pci_dev *pdev = adapter->pdev;
5184 struct net_device *dev = adapter->netdev;
5185 unsigned int rss;
5186 #ifdef CONFIG_IXGBE_DCB
5187 int j;
5188 struct tc_configuration *tc;
5189 #endif
5190 int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
5192 /* PCI config space info */
5194 hw->vendor_id = pdev->vendor;
5195 hw->device_id = pdev->device;
5196 hw->revision_id = pdev->revision;
5197 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5198 hw->subsystem_device_id = pdev->subsystem_device;
5200 /* Set capability flags */
5201 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
5202 adapter->ring_feature[RING_F_RSS].indices = rss;
5203 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
5204 adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES;
5205 switch (hw->mac.type) {
5206 case ixgbe_mac_82598EB:
5207 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5208 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
5209 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
5210 break;
5211 case ixgbe_mac_82599EB:
5212 case ixgbe_mac_X540:
5213 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
5214 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
5215 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
5216 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5217 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
5218 /* n-tuple support exists, always init our spinlock */
5219 spin_lock_init(&adapter->fdir_perfect_lock);
5220 /* Flow Director hash filters enabled */
5221 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
5222 adapter->atr_sample_rate = 20;
5223 adapter->ring_feature[RING_F_FDIR].indices =
5224 IXGBE_MAX_FDIR_INDICES;
5225 adapter->fdir_pballoc = 0;
5226 #ifdef IXGBE_FCOE
5227 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5228 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5229 adapter->ring_feature[RING_F_FCOE].indices = 0;
5230 #ifdef CONFIG_IXGBE_DCB
5231 /* Default traffic class to use for FCoE */
5232 adapter->fcoe.tc = IXGBE_FCOE_DEFTC;
5233 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
5234 #endif
5235 #endif /* IXGBE_FCOE */
5236 break;
5237 default:
5238 break;
5241 #ifdef CONFIG_IXGBE_DCB
5242 /* Configure DCB traffic classes */
5243 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5244 tc = &adapter->dcb_cfg.tc_config[j];
5245 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5246 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5247 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5248 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5249 tc->dcb_pfc = pfc_disabled;
5251 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5252 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
5253 adapter->dcb_cfg.rx_pba_cfg = pba_equal;
5254 adapter->dcb_cfg.pfc_mode_enable = false;
5255 adapter->dcb_set_bitmap = 0x00;
5256 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
5257 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
5258 MAX_TRAFFIC_CLASS);
5260 #endif
5262 /* default flow control settings */
5263 hw->fc.requested_mode = ixgbe_fc_full;
5264 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
5265 #ifdef CONFIG_DCB
5266 adapter->last_lfc_mode = hw->fc.current_mode;
5267 #endif
5268 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5269 hw->fc.low_water = FC_LOW_WATER(max_frame);
5270 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5271 hw->fc.send_xon = true;
5272 hw->fc.disable_fc_autoneg = false;
5274 /* enable itr by default in dynamic mode */
5275 adapter->rx_itr_setting = 1;
5276 adapter->rx_eitr_param = 20000;
5277 adapter->tx_itr_setting = 1;
5278 adapter->tx_eitr_param = 10000;
5280 /* set defaults for eitr in MegaBytes */
5281 adapter->eitr_low = 10;
5282 adapter->eitr_high = 20;
5284 /* set default ring sizes */
5285 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5286 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5288 /* initialize eeprom parameters */
5289 if (ixgbe_init_eeprom_params_generic(hw)) {
5290 e_dev_err("EEPROM initialization failed\n");
5291 return -EIO;
5294 /* enable rx csum by default */
5295 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
5297 /* get assigned NUMA node */
5298 adapter->node = dev_to_node(&pdev->dev);
5300 set_bit(__IXGBE_DOWN, &adapter->state);
5302 return 0;
5306 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
5307 * @tx_ring: tx descriptor ring (for a specific queue) to setup
5309 * Return 0 on success, negative on failure
5311 int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
5313 struct device *dev = tx_ring->dev;
5314 int size;
5316 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
5317 tx_ring->tx_buffer_info = vzalloc_node(size, tx_ring->numa_node);
5318 if (!tx_ring->tx_buffer_info)
5319 tx_ring->tx_buffer_info = vzalloc(size);
5320 if (!tx_ring->tx_buffer_info)
5321 goto err;
5323 /* round up to nearest 4K */
5324 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
5325 tx_ring->size = ALIGN(tx_ring->size, 4096);
5327 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
5328 &tx_ring->dma, GFP_KERNEL);
5329 if (!tx_ring->desc)
5330 goto err;
5332 tx_ring->next_to_use = 0;
5333 tx_ring->next_to_clean = 0;
5334 tx_ring->work_limit = tx_ring->count;
5335 return 0;
5337 err:
5338 vfree(tx_ring->tx_buffer_info);
5339 tx_ring->tx_buffer_info = NULL;
5340 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
5341 return -ENOMEM;
5345 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5346 * @adapter: board private structure
5348 * If this function returns with an error, then it's possible one or
5349 * more of the rings is populated (while the rest are not). It is the
5350 * callers duty to clean those orphaned rings.
5352 * Return 0 on success, negative on failure
5354 static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5356 int i, err = 0;
5358 for (i = 0; i < adapter->num_tx_queues; i++) {
5359 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
5360 if (!err)
5361 continue;
5362 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
5363 break;
5366 return err;
5370 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
5371 * @rx_ring: rx descriptor ring (for a specific queue) to setup
5373 * Returns 0 on success, negative on failure
5375 int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
5377 struct device *dev = rx_ring->dev;
5378 int size;
5380 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
5381 rx_ring->rx_buffer_info = vzalloc_node(size, rx_ring->numa_node);
5382 if (!rx_ring->rx_buffer_info)
5383 rx_ring->rx_buffer_info = vzalloc(size);
5384 if (!rx_ring->rx_buffer_info)
5385 goto err;
5387 /* Round up to nearest 4K */
5388 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5389 rx_ring->size = ALIGN(rx_ring->size, 4096);
5391 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
5392 &rx_ring->dma, GFP_KERNEL);
5394 if (!rx_ring->desc)
5395 goto err;
5397 rx_ring->next_to_clean = 0;
5398 rx_ring->next_to_use = 0;
5400 return 0;
5401 err:
5402 vfree(rx_ring->rx_buffer_info);
5403 rx_ring->rx_buffer_info = NULL;
5404 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
5405 return -ENOMEM;
5409 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5410 * @adapter: board private structure
5412 * If this function returns with an error, then it's possible one or
5413 * more of the rings is populated (while the rest are not). It is the
5414 * callers duty to clean those orphaned rings.
5416 * Return 0 on success, negative on failure
5418 static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5420 int i, err = 0;
5422 for (i = 0; i < adapter->num_rx_queues; i++) {
5423 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
5424 if (!err)
5425 continue;
5426 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
5427 break;
5430 return err;
5434 * ixgbe_free_tx_resources - Free Tx Resources per Queue
5435 * @tx_ring: Tx descriptor ring for a specific queue
5437 * Free all transmit software resources
5439 void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
5441 ixgbe_clean_tx_ring(tx_ring);
5443 vfree(tx_ring->tx_buffer_info);
5444 tx_ring->tx_buffer_info = NULL;
5446 /* if not set, then don't free */
5447 if (!tx_ring->desc)
5448 return;
5450 dma_free_coherent(tx_ring->dev, tx_ring->size,
5451 tx_ring->desc, tx_ring->dma);
5453 tx_ring->desc = NULL;
5457 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5458 * @adapter: board private structure
5460 * Free all transmit software resources
5462 static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5464 int i;
5466 for (i = 0; i < adapter->num_tx_queues; i++)
5467 if (adapter->tx_ring[i]->desc)
5468 ixgbe_free_tx_resources(adapter->tx_ring[i]);
5472 * ixgbe_free_rx_resources - Free Rx Resources
5473 * @rx_ring: ring to clean the resources from
5475 * Free all receive software resources
5477 void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
5479 ixgbe_clean_rx_ring(rx_ring);
5481 vfree(rx_ring->rx_buffer_info);
5482 rx_ring->rx_buffer_info = NULL;
5484 /* if not set, then don't free */
5485 if (!rx_ring->desc)
5486 return;
5488 dma_free_coherent(rx_ring->dev, rx_ring->size,
5489 rx_ring->desc, rx_ring->dma);
5491 rx_ring->desc = NULL;
5495 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5496 * @adapter: board private structure
5498 * Free all receive software resources
5500 static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5502 int i;
5504 for (i = 0; i < adapter->num_rx_queues; i++)
5505 if (adapter->rx_ring[i]->desc)
5506 ixgbe_free_rx_resources(adapter->rx_ring[i]);
5510 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5511 * @netdev: network interface device structure
5512 * @new_mtu: new value for maximum frame size
5514 * Returns 0 on success, negative on failure
5516 static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5518 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5519 struct ixgbe_hw *hw = &adapter->hw;
5520 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5522 /* MTU < 68 is an error and causes problems on some kernels */
5523 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED &&
5524 hw->mac.type != ixgbe_mac_X540) {
5525 if ((new_mtu < 68) || (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
5526 return -EINVAL;
5527 } else {
5528 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5529 return -EINVAL;
5532 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5533 /* must set new MTU before calling down or up */
5534 netdev->mtu = new_mtu;
5536 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5537 hw->fc.low_water = FC_LOW_WATER(max_frame);
5539 if (netif_running(netdev))
5540 ixgbe_reinit_locked(adapter);
5542 return 0;
5546 * ixgbe_open - Called when a network interface is made active
5547 * @netdev: network interface device structure
5549 * Returns 0 on success, negative value on failure
5551 * The open entry point is called when a network interface is made
5552 * active by the system (IFF_UP). At this point all resources needed
5553 * for transmit and receive operations are allocated, the interrupt
5554 * handler is registered with the OS, the watchdog timer is started,
5555 * and the stack is notified that the interface is ready.
5557 static int ixgbe_open(struct net_device *netdev)
5559 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5560 int err;
5562 /* disallow open during test */
5563 if (test_bit(__IXGBE_TESTING, &adapter->state))
5564 return -EBUSY;
5566 netif_carrier_off(netdev);
5568 /* allocate transmit descriptors */
5569 err = ixgbe_setup_all_tx_resources(adapter);
5570 if (err)
5571 goto err_setup_tx;
5573 /* allocate receive descriptors */
5574 err = ixgbe_setup_all_rx_resources(adapter);
5575 if (err)
5576 goto err_setup_rx;
5578 ixgbe_configure(adapter);
5580 err = ixgbe_request_irq(adapter);
5581 if (err)
5582 goto err_req_irq;
5584 err = ixgbe_up_complete(adapter);
5585 if (err)
5586 goto err_up;
5588 netif_tx_start_all_queues(netdev);
5590 return 0;
5592 err_up:
5593 ixgbe_release_hw_control(adapter);
5594 ixgbe_free_irq(adapter);
5595 err_req_irq:
5596 err_setup_rx:
5597 ixgbe_free_all_rx_resources(adapter);
5598 err_setup_tx:
5599 ixgbe_free_all_tx_resources(adapter);
5600 ixgbe_reset(adapter);
5602 return err;
5606 * ixgbe_close - Disables a network interface
5607 * @netdev: network interface device structure
5609 * Returns 0, this is not allowed to fail
5611 * The close entry point is called when an interface is de-activated
5612 * by the OS. The hardware is still under the drivers control, but
5613 * needs to be disabled. A global MAC reset is issued to stop the
5614 * hardware, and all transmit and receive resources are freed.
5616 static int ixgbe_close(struct net_device *netdev)
5618 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5620 ixgbe_down(adapter);
5621 ixgbe_free_irq(adapter);
5623 ixgbe_free_all_tx_resources(adapter);
5624 ixgbe_free_all_rx_resources(adapter);
5626 ixgbe_release_hw_control(adapter);
5628 return 0;
5631 #ifdef CONFIG_PM
5632 static int ixgbe_resume(struct pci_dev *pdev)
5634 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5635 struct net_device *netdev = adapter->netdev;
5636 u32 err;
5638 pci_set_power_state(pdev, PCI_D0);
5639 pci_restore_state(pdev);
5641 * pci_restore_state clears dev->state_saved so call
5642 * pci_save_state to restore it.
5644 pci_save_state(pdev);
5646 err = pci_enable_device_mem(pdev);
5647 if (err) {
5648 e_dev_err("Cannot enable PCI device from suspend\n");
5649 return err;
5651 pci_set_master(pdev);
5653 pci_wake_from_d3(pdev, false);
5655 err = ixgbe_init_interrupt_scheme(adapter);
5656 if (err) {
5657 e_dev_err("Cannot initialize interrupts for device\n");
5658 return err;
5661 ixgbe_reset(adapter);
5663 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5665 if (netif_running(netdev)) {
5666 err = ixgbe_open(netdev);
5667 if (err)
5668 return err;
5671 netif_device_attach(netdev);
5673 return 0;
5675 #endif /* CONFIG_PM */
5677 static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
5679 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5680 struct net_device *netdev = adapter->netdev;
5681 struct ixgbe_hw *hw = &adapter->hw;
5682 u32 ctrl, fctrl;
5683 u32 wufc = adapter->wol;
5684 #ifdef CONFIG_PM
5685 int retval = 0;
5686 #endif
5688 netif_device_detach(netdev);
5690 if (netif_running(netdev)) {
5691 ixgbe_down(adapter);
5692 ixgbe_free_irq(adapter);
5693 ixgbe_free_all_tx_resources(adapter);
5694 ixgbe_free_all_rx_resources(adapter);
5697 ixgbe_clear_interrupt_scheme(adapter);
5698 #ifdef CONFIG_DCB
5699 kfree(adapter->ixgbe_ieee_pfc);
5700 kfree(adapter->ixgbe_ieee_ets);
5701 #endif
5703 #ifdef CONFIG_PM
5704 retval = pci_save_state(pdev);
5705 if (retval)
5706 return retval;
5708 #endif
5709 if (wufc) {
5710 ixgbe_set_rx_mode(netdev);
5712 /* turn on all-multi mode if wake on multicast is enabled */
5713 if (wufc & IXGBE_WUFC_MC) {
5714 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5715 fctrl |= IXGBE_FCTRL_MPE;
5716 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5719 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5720 ctrl |= IXGBE_CTRL_GIO_DIS;
5721 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5723 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5724 } else {
5725 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5726 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5729 switch (hw->mac.type) {
5730 case ixgbe_mac_82598EB:
5731 pci_wake_from_d3(pdev, false);
5732 break;
5733 case ixgbe_mac_82599EB:
5734 case ixgbe_mac_X540:
5735 pci_wake_from_d3(pdev, !!wufc);
5736 break;
5737 default:
5738 break;
5741 *enable_wake = !!wufc;
5743 ixgbe_release_hw_control(adapter);
5745 pci_disable_device(pdev);
5747 return 0;
5750 #ifdef CONFIG_PM
5751 static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5753 int retval;
5754 bool wake;
5756 retval = __ixgbe_shutdown(pdev, &wake);
5757 if (retval)
5758 return retval;
5760 if (wake) {
5761 pci_prepare_to_sleep(pdev);
5762 } else {
5763 pci_wake_from_d3(pdev, false);
5764 pci_set_power_state(pdev, PCI_D3hot);
5767 return 0;
5769 #endif /* CONFIG_PM */
5771 static void ixgbe_shutdown(struct pci_dev *pdev)
5773 bool wake;
5775 __ixgbe_shutdown(pdev, &wake);
5777 if (system_state == SYSTEM_POWER_OFF) {
5778 pci_wake_from_d3(pdev, wake);
5779 pci_set_power_state(pdev, PCI_D3hot);
5784 * ixgbe_update_stats - Update the board statistics counters.
5785 * @adapter: board private structure
5787 void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5789 struct net_device *netdev = adapter->netdev;
5790 struct ixgbe_hw *hw = &adapter->hw;
5791 struct ixgbe_hw_stats *hwstats = &adapter->stats;
5792 u64 total_mpc = 0;
5793 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
5794 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5795 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
5796 u64 bytes = 0, packets = 0;
5798 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5799 test_bit(__IXGBE_RESETTING, &adapter->state))
5800 return;
5802 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
5803 u64 rsc_count = 0;
5804 u64 rsc_flush = 0;
5805 for (i = 0; i < 16; i++)
5806 adapter->hw_rx_no_dma_resources +=
5807 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
5808 for (i = 0; i < adapter->num_rx_queues; i++) {
5809 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5810 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
5812 adapter->rsc_total_count = rsc_count;
5813 adapter->rsc_total_flush = rsc_flush;
5816 for (i = 0; i < adapter->num_rx_queues; i++) {
5817 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5818 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5819 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5820 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
5821 bytes += rx_ring->stats.bytes;
5822 packets += rx_ring->stats.packets;
5824 adapter->non_eop_descs = non_eop_descs;
5825 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5826 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
5827 netdev->stats.rx_bytes = bytes;
5828 netdev->stats.rx_packets = packets;
5830 bytes = 0;
5831 packets = 0;
5832 /* gather some stats to the adapter struct that are per queue */
5833 for (i = 0; i < adapter->num_tx_queues; i++) {
5834 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5835 restart_queue += tx_ring->tx_stats.restart_queue;
5836 tx_busy += tx_ring->tx_stats.tx_busy;
5837 bytes += tx_ring->stats.bytes;
5838 packets += tx_ring->stats.packets;
5840 adapter->restart_queue = restart_queue;
5841 adapter->tx_busy = tx_busy;
5842 netdev->stats.tx_bytes = bytes;
5843 netdev->stats.tx_packets = packets;
5845 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
5846 for (i = 0; i < 8; i++) {
5847 /* for packet buffers not used, the register should read 0 */
5848 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5849 missed_rx += mpc;
5850 hwstats->mpc[i] += mpc;
5851 total_mpc += hwstats->mpc[i];
5852 if (hw->mac.type == ixgbe_mac_82598EB)
5853 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5854 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5855 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5856 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5857 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
5858 switch (hw->mac.type) {
5859 case ixgbe_mac_82598EB:
5860 hwstats->pxonrxc[i] +=
5861 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
5862 break;
5863 case ixgbe_mac_82599EB:
5864 case ixgbe_mac_X540:
5865 hwstats->pxonrxc[i] +=
5866 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
5867 break;
5868 default:
5869 break;
5871 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5872 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
5874 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
5875 /* work around hardware counting issue */
5876 hwstats->gprc -= missed_rx;
5878 ixgbe_update_xoff_received(adapter);
5880 /* 82598 hardware only has a 32 bit counter in the high register */
5881 switch (hw->mac.type) {
5882 case ixgbe_mac_82598EB:
5883 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
5884 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5885 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5886 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5887 break;
5888 case ixgbe_mac_X540:
5889 /* OS2BMC stats are X540 only*/
5890 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5891 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5892 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5893 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5894 case ixgbe_mac_82599EB:
5895 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
5896 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
5897 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
5898 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
5899 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
5900 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
5901 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
5902 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5903 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
5904 #ifdef IXGBE_FCOE
5905 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5906 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5907 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5908 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5909 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5910 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
5911 #endif /* IXGBE_FCOE */
5912 break;
5913 default:
5914 break;
5916 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
5917 hwstats->bprc += bprc;
5918 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
5919 if (hw->mac.type == ixgbe_mac_82598EB)
5920 hwstats->mprc -= bprc;
5921 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5922 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5923 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5924 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5925 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5926 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5927 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5928 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
5929 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
5930 hwstats->lxontxc += lxon;
5931 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
5932 hwstats->lxofftxc += lxoff;
5933 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5934 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5935 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
5937 * 82598 errata - tx of flow control packets is included in tx counters
5939 xon_off_tot = lxon + lxoff;
5940 hwstats->gptc -= xon_off_tot;
5941 hwstats->mptc -= xon_off_tot;
5942 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5943 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5944 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5945 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5946 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5947 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5948 hwstats->ptc64 -= xon_off_tot;
5949 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5950 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5951 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5952 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5953 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5954 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
5956 /* Fill out the OS statistics structure */
5957 netdev->stats.multicast = hwstats->mprc;
5959 /* Rx Errors */
5960 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
5961 netdev->stats.rx_dropped = 0;
5962 netdev->stats.rx_length_errors = hwstats->rlec;
5963 netdev->stats.rx_crc_errors = hwstats->crcerrs;
5964 netdev->stats.rx_missed_errors = total_mpc;
5968 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
5969 * @adapter - pointer to the device adapter structure
5971 static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
5973 struct ixgbe_hw *hw = &adapter->hw;
5974 int i;
5976 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5977 return;
5979 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5981 /* if interface is down do nothing */
5982 if (test_bit(__IXGBE_DOWN, &adapter->state))
5983 return;
5985 /* do nothing if we are not using signature filters */
5986 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5987 return;
5989 adapter->fdir_overflow++;
5991 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5992 for (i = 0; i < adapter->num_tx_queues; i++)
5993 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
5994 &(adapter->tx_ring[i]->state));
5995 /* re-enable flow director interrupts */
5996 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
5997 } else {
5998 e_err(probe, "failed to finish FDIR re-initialization, "
5999 "ignored adding FDIR ATR filters\n");
6004 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
6005 * @adapter - pointer to the device adapter structure
6007 * This function serves two purposes. First it strobes the interrupt lines
6008 * in order to make certain interrupts are occuring. Secondly it sets the
6009 * bits needed to check for TX hangs. As a result we should immediately
6010 * determine if a hang has occured.
6012 static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
6014 struct ixgbe_hw *hw = &adapter->hw;
6015 u64 eics = 0;
6016 int i;
6018 /* If we're down or resetting, just bail */
6019 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6020 test_bit(__IXGBE_RESETTING, &adapter->state))
6021 return;
6023 /* Force detection of hung controller */
6024 if (netif_carrier_ok(adapter->netdev)) {
6025 for (i = 0; i < adapter->num_tx_queues; i++)
6026 set_check_for_tx_hang(adapter->tx_ring[i]);
6029 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
6031 * for legacy and MSI interrupts don't set any bits
6032 * that are enabled for EIAM, because this operation
6033 * would set *both* EIMS and EICS for any bit in EIAM
6035 IXGBE_WRITE_REG(hw, IXGBE_EICS,
6036 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
6037 } else {
6038 /* get one bit for every active tx/rx interrupt vector */
6039 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
6040 struct ixgbe_q_vector *qv = adapter->q_vector[i];
6041 if (qv->rxr_count || qv->txr_count)
6042 eics |= ((u64)1 << i);
6046 /* Cause software interrupt to ensure rings are cleaned */
6047 ixgbe_irq_rearm_queues(adapter, eics);
6052 * ixgbe_watchdog_update_link - update the link status
6053 * @adapter - pointer to the device adapter structure
6054 * @link_speed - pointer to a u32 to store the link_speed
6056 static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
6058 struct ixgbe_hw *hw = &adapter->hw;
6059 u32 link_speed = adapter->link_speed;
6060 bool link_up = adapter->link_up;
6061 int i;
6063 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
6064 return;
6066 if (hw->mac.ops.check_link) {
6067 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
6068 } else {
6069 /* always assume link is up, if no check link function */
6070 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
6071 link_up = true;
6073 if (link_up) {
6074 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6075 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
6076 hw->mac.ops.fc_enable(hw, i);
6077 } else {
6078 hw->mac.ops.fc_enable(hw, 0);
6082 if (link_up ||
6083 time_after(jiffies, (adapter->link_check_timeout +
6084 IXGBE_TRY_LINK_TIMEOUT))) {
6085 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
6086 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
6087 IXGBE_WRITE_FLUSH(hw);
6090 adapter->link_up = link_up;
6091 adapter->link_speed = link_speed;
6095 * ixgbe_watchdog_link_is_up - update netif_carrier status and
6096 * print link up message
6097 * @adapter - pointer to the device adapter structure
6099 static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
6101 struct net_device *netdev = adapter->netdev;
6102 struct ixgbe_hw *hw = &adapter->hw;
6103 u32 link_speed = adapter->link_speed;
6104 bool flow_rx, flow_tx;
6106 /* only continue if link was previously down */
6107 if (netif_carrier_ok(netdev))
6108 return;
6110 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
6112 switch (hw->mac.type) {
6113 case ixgbe_mac_82598EB: {
6114 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6115 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
6116 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6117 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
6119 break;
6120 case ixgbe_mac_X540:
6121 case ixgbe_mac_82599EB: {
6122 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6123 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6124 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6125 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6127 break;
6128 default:
6129 flow_tx = false;
6130 flow_rx = false;
6131 break;
6133 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
6134 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
6135 "10 Gbps" :
6136 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
6137 "1 Gbps" :
6138 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
6139 "100 Mbps" :
6140 "unknown speed"))),
6141 ((flow_rx && flow_tx) ? "RX/TX" :
6142 (flow_rx ? "RX" :
6143 (flow_tx ? "TX" : "None"))));
6145 netif_carrier_on(netdev);
6146 #ifdef HAVE_IPLINK_VF_CONFIG
6147 ixgbe_check_vf_rate_limit(adapter);
6148 #endif /* HAVE_IPLINK_VF_CONFIG */
6152 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6153 * print link down message
6154 * @adapter - pointer to the adapter structure
6156 static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter)
6158 struct net_device *netdev = adapter->netdev;
6159 struct ixgbe_hw *hw = &adapter->hw;
6161 adapter->link_up = false;
6162 adapter->link_speed = 0;
6164 /* only continue if link was up previously */
6165 if (!netif_carrier_ok(netdev))
6166 return;
6168 /* poll for SFP+ cable when link is down */
6169 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
6170 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
6172 e_info(drv, "NIC Link is Down\n");
6173 netif_carrier_off(netdev);
6177 * ixgbe_watchdog_flush_tx - flush queues on link down
6178 * @adapter - pointer to the device adapter structure
6180 static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
6182 int i;
6183 int some_tx_pending = 0;
6185 if (!netif_carrier_ok(adapter->netdev)) {
6186 for (i = 0; i < adapter->num_tx_queues; i++) {
6187 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6188 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
6189 some_tx_pending = 1;
6190 break;
6194 if (some_tx_pending) {
6195 /* We've lost link, so the controller stops DMA,
6196 * but we've got queued Tx work that's never going
6197 * to get done, so reset controller to flush Tx.
6198 * (Do the reset outside of interrupt context).
6200 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
6205 static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6207 u32 ssvpc;
6209 /* Do not perform spoof check for 82598 */
6210 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6211 return;
6213 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6216 * ssvpc register is cleared on read, if zero then no
6217 * spoofed packets in the last interval.
6219 if (!ssvpc)
6220 return;
6222 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
6226 * ixgbe_watchdog_subtask - check and bring link up
6227 * @adapter - pointer to the device adapter structure
6229 static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
6231 /* if interface is down do nothing */
6232 if (test_bit(__IXGBE_DOWN, &adapter->state))
6233 return;
6235 ixgbe_watchdog_update_link(adapter);
6237 if (adapter->link_up)
6238 ixgbe_watchdog_link_is_up(adapter);
6239 else
6240 ixgbe_watchdog_link_is_down(adapter);
6242 ixgbe_spoof_check(adapter);
6243 ixgbe_update_stats(adapter);
6245 ixgbe_watchdog_flush_tx(adapter);
6249 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
6250 * @adapter - the ixgbe adapter structure
6252 static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
6254 struct ixgbe_hw *hw = &adapter->hw;
6255 s32 err;
6257 /* not searching for SFP so there is nothing to do here */
6258 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
6259 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6260 return;
6262 /* someone else is in init, wait until next service event */
6263 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6264 return;
6266 err = hw->phy.ops.identify_sfp(hw);
6267 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6268 goto sfp_out;
6270 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6271 /* If no cable is present, then we need to reset
6272 * the next time we find a good cable. */
6273 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6276 /* exit on error */
6277 if (err)
6278 goto sfp_out;
6280 /* exit if reset not needed */
6281 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6282 goto sfp_out;
6284 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6287 * A module may be identified correctly, but the EEPROM may not have
6288 * support for that module. setup_sfp() will fail in that case, so
6289 * we should not allow that module to load.
6291 if (hw->mac.type == ixgbe_mac_82598EB)
6292 err = hw->phy.ops.reset(hw);
6293 else
6294 err = hw->mac.ops.setup_sfp(hw);
6296 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6297 goto sfp_out;
6299 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6300 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6302 sfp_out:
6303 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6305 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6306 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6307 e_dev_err("failed to initialize because an unsupported "
6308 "SFP+ module type was detected.\n");
6309 e_dev_err("Reload the driver after installing a "
6310 "supported module.\n");
6311 unregister_netdev(adapter->netdev);
6316 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
6317 * @adapter - the ixgbe adapter structure
6319 static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6321 struct ixgbe_hw *hw = &adapter->hw;
6322 u32 autoneg;
6323 bool negotiation;
6325 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6326 return;
6328 /* someone else is in init, wait until next service event */
6329 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6330 return;
6332 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6334 autoneg = hw->phy.autoneg_advertised;
6335 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
6336 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
6337 hw->mac.autotry_restart = false;
6338 if (hw->mac.ops.setup_link)
6339 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
6341 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6342 adapter->link_check_timeout = jiffies;
6343 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6347 * ixgbe_service_timer - Timer Call-back
6348 * @data: pointer to adapter cast into an unsigned long
6350 static void ixgbe_service_timer(unsigned long data)
6352 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6353 unsigned long next_event_offset;
6355 /* poll faster when waiting for link */
6356 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6357 next_event_offset = HZ / 10;
6358 else
6359 next_event_offset = HZ * 2;
6361 /* Reset the timer */
6362 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6364 ixgbe_service_event_schedule(adapter);
6367 static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6369 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6370 return;
6372 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6374 /* If we're already down or resetting, just bail */
6375 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6376 test_bit(__IXGBE_RESETTING, &adapter->state))
6377 return;
6379 ixgbe_dump(adapter);
6380 netdev_err(adapter->netdev, "Reset adapter\n");
6381 adapter->tx_timeout_count++;
6383 ixgbe_reinit_locked(adapter);
6387 * ixgbe_service_task - manages and runs subtasks
6388 * @work: pointer to work_struct containing our data
6390 static void ixgbe_service_task(struct work_struct *work)
6392 struct ixgbe_adapter *adapter = container_of(work,
6393 struct ixgbe_adapter,
6394 service_task);
6396 ixgbe_reset_subtask(adapter);
6397 ixgbe_sfp_detection_subtask(adapter);
6398 ixgbe_sfp_link_config_subtask(adapter);
6399 ixgbe_check_overtemp_subtask(adapter);
6400 ixgbe_watchdog_subtask(adapter);
6401 ixgbe_fdir_reinit_subtask(adapter);
6402 ixgbe_check_hang_subtask(adapter);
6404 ixgbe_service_event_complete(adapter);
6407 static int ixgbe_tso(struct ixgbe_adapter *adapter,
6408 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
6409 u32 tx_flags, u8 *hdr_len, __be16 protocol)
6411 struct ixgbe_adv_tx_context_desc *context_desc;
6412 unsigned int i;
6413 int err;
6414 struct ixgbe_tx_buffer *tx_buffer_info;
6415 u32 vlan_macip_lens = 0, type_tucmd_mlhl;
6416 u32 mss_l4len_idx, l4len;
6418 if (skb_is_gso(skb)) {
6419 if (skb_header_cloned(skb)) {
6420 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
6421 if (err)
6422 return err;
6424 l4len = tcp_hdrlen(skb);
6425 *hdr_len += l4len;
6427 if (protocol == htons(ETH_P_IP)) {
6428 struct iphdr *iph = ip_hdr(skb);
6429 iph->tot_len = 0;
6430 iph->check = 0;
6431 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
6432 iph->daddr, 0,
6433 IPPROTO_TCP,
6435 } else if (skb_is_gso_v6(skb)) {
6436 ipv6_hdr(skb)->payload_len = 0;
6437 tcp_hdr(skb)->check =
6438 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
6439 &ipv6_hdr(skb)->daddr,
6440 0, IPPROTO_TCP, 0);
6443 i = tx_ring->next_to_use;
6445 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6446 context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
6448 /* VLAN MACLEN IPLEN */
6449 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
6450 vlan_macip_lens |=
6451 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
6452 vlan_macip_lens |= ((skb_network_offset(skb)) <<
6453 IXGBE_ADVTXD_MACLEN_SHIFT);
6454 *hdr_len += skb_network_offset(skb);
6455 vlan_macip_lens |=
6456 (skb_transport_header(skb) - skb_network_header(skb));
6457 *hdr_len +=
6458 (skb_transport_header(skb) - skb_network_header(skb));
6459 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6460 context_desc->seqnum_seed = 0;
6462 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
6463 type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
6464 IXGBE_ADVTXD_DTYP_CTXT);
6466 if (protocol == htons(ETH_P_IP))
6467 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
6468 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6469 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
6471 /* MSS L4LEN IDX */
6472 mss_l4len_idx =
6473 (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
6474 mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
6475 /* use index 1 for TSO */
6476 mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
6477 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
6479 tx_buffer_info->time_stamp = jiffies;
6480 tx_buffer_info->next_to_watch = i;
6482 i++;
6483 if (i == tx_ring->count)
6484 i = 0;
6485 tx_ring->next_to_use = i;
6487 return true;
6489 return false;
6492 static u32 ixgbe_psum(struct ixgbe_adapter *adapter, struct sk_buff *skb,
6493 __be16 protocol)
6495 u32 rtn = 0;
6497 switch (protocol) {
6498 case cpu_to_be16(ETH_P_IP):
6499 rtn |= IXGBE_ADVTXD_TUCMD_IPV4;
6500 switch (ip_hdr(skb)->protocol) {
6501 case IPPROTO_TCP:
6502 rtn |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6503 break;
6504 case IPPROTO_SCTP:
6505 rtn |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6506 break;
6508 break;
6509 case cpu_to_be16(ETH_P_IPV6):
6510 /* XXX what about other V6 headers?? */
6511 switch (ipv6_hdr(skb)->nexthdr) {
6512 case IPPROTO_TCP:
6513 rtn |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6514 break;
6515 case IPPROTO_SCTP:
6516 rtn |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6517 break;
6519 break;
6520 default:
6521 if (unlikely(net_ratelimit()))
6522 e_warn(probe, "partial checksum but proto=%x!\n",
6523 protocol);
6524 break;
6527 return rtn;
6530 static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
6531 struct ixgbe_ring *tx_ring,
6532 struct sk_buff *skb, u32 tx_flags,
6533 __be16 protocol)
6535 struct ixgbe_adv_tx_context_desc *context_desc;
6536 unsigned int i;
6537 struct ixgbe_tx_buffer *tx_buffer_info;
6538 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
6540 if (skb->ip_summed == CHECKSUM_PARTIAL ||
6541 (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
6542 i = tx_ring->next_to_use;
6543 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6544 context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
6546 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
6547 vlan_macip_lens |=
6548 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
6549 vlan_macip_lens |= (skb_network_offset(skb) <<
6550 IXGBE_ADVTXD_MACLEN_SHIFT);
6551 if (skb->ip_summed == CHECKSUM_PARTIAL)
6552 vlan_macip_lens |= (skb_transport_header(skb) -
6553 skb_network_header(skb));
6555 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6556 context_desc->seqnum_seed = 0;
6558 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
6559 IXGBE_ADVTXD_DTYP_CTXT);
6561 if (skb->ip_summed == CHECKSUM_PARTIAL)
6562 type_tucmd_mlhl |= ixgbe_psum(adapter, skb, protocol);
6564 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
6565 /* use index zero for tx checksum offload */
6566 context_desc->mss_l4len_idx = 0;
6568 tx_buffer_info->time_stamp = jiffies;
6569 tx_buffer_info->next_to_watch = i;
6571 i++;
6572 if (i == tx_ring->count)
6573 i = 0;
6574 tx_ring->next_to_use = i;
6576 return true;
6579 return false;
6582 static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
6583 struct ixgbe_ring *tx_ring,
6584 struct sk_buff *skb, u32 tx_flags,
6585 unsigned int first, const u8 hdr_len)
6587 struct device *dev = tx_ring->dev;
6588 struct ixgbe_tx_buffer *tx_buffer_info;
6589 unsigned int len;
6590 unsigned int total = skb->len;
6591 unsigned int offset = 0, size, count = 0, i;
6592 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
6593 unsigned int f;
6594 unsigned int bytecount = skb->len;
6595 u16 gso_segs = 1;
6597 i = tx_ring->next_to_use;
6599 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
6600 /* excluding fcoe_crc_eof for FCoE */
6601 total -= sizeof(struct fcoe_crc_eof);
6603 len = min(skb_headlen(skb), total);
6604 while (len) {
6605 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6606 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
6608 tx_buffer_info->length = size;
6609 tx_buffer_info->mapped_as_page = false;
6610 tx_buffer_info->dma = dma_map_single(dev,
6611 skb->data + offset,
6612 size, DMA_TO_DEVICE);
6613 if (dma_mapping_error(dev, tx_buffer_info->dma))
6614 goto dma_error;
6615 tx_buffer_info->time_stamp = jiffies;
6616 tx_buffer_info->next_to_watch = i;
6618 len -= size;
6619 total -= size;
6620 offset += size;
6621 count++;
6623 if (len) {
6624 i++;
6625 if (i == tx_ring->count)
6626 i = 0;
6630 for (f = 0; f < nr_frags; f++) {
6631 struct skb_frag_struct *frag;
6633 frag = &skb_shinfo(skb)->frags[f];
6634 len = min((unsigned int)frag->size, total);
6635 offset = frag->page_offset;
6637 while (len) {
6638 i++;
6639 if (i == tx_ring->count)
6640 i = 0;
6642 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6643 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
6645 tx_buffer_info->length = size;
6646 tx_buffer_info->dma = dma_map_page(dev,
6647 frag->page,
6648 offset, size,
6649 DMA_TO_DEVICE);
6650 tx_buffer_info->mapped_as_page = true;
6651 if (dma_mapping_error(dev, tx_buffer_info->dma))
6652 goto dma_error;
6653 tx_buffer_info->time_stamp = jiffies;
6654 tx_buffer_info->next_to_watch = i;
6656 len -= size;
6657 total -= size;
6658 offset += size;
6659 count++;
6661 if (total == 0)
6662 break;
6665 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6666 gso_segs = skb_shinfo(skb)->gso_segs;
6667 #ifdef IXGBE_FCOE
6668 /* adjust for FCoE Sequence Offload */
6669 else if (tx_flags & IXGBE_TX_FLAGS_FSO)
6670 gso_segs = DIV_ROUND_UP(skb->len - hdr_len,
6671 skb_shinfo(skb)->gso_size);
6672 #endif /* IXGBE_FCOE */
6673 bytecount += (gso_segs - 1) * hdr_len;
6675 /* multiply data chunks by size of headers */
6676 tx_ring->tx_buffer_info[i].bytecount = bytecount;
6677 tx_ring->tx_buffer_info[i].gso_segs = gso_segs;
6678 tx_ring->tx_buffer_info[i].skb = skb;
6679 tx_ring->tx_buffer_info[first].next_to_watch = i;
6681 return count;
6683 dma_error:
6684 e_dev_err("TX DMA map failed\n");
6686 /* clear timestamp and dma mappings for failed tx_buffer_info map */
6687 tx_buffer_info->dma = 0;
6688 tx_buffer_info->time_stamp = 0;
6689 tx_buffer_info->next_to_watch = 0;
6690 if (count)
6691 count--;
6693 /* clear timestamp and dma mappings for remaining portion of packet */
6694 while (count--) {
6695 if (i == 0)
6696 i += tx_ring->count;
6697 i--;
6698 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6699 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
6702 return 0;
6705 static void ixgbe_tx_queue(struct ixgbe_ring *tx_ring,
6706 int tx_flags, int count, u32 paylen, u8 hdr_len)
6708 union ixgbe_adv_tx_desc *tx_desc = NULL;
6709 struct ixgbe_tx_buffer *tx_buffer_info;
6710 u32 olinfo_status = 0, cmd_type_len = 0;
6711 unsigned int i;
6712 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
6714 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
6716 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
6718 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
6719 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
6721 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
6722 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
6724 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
6725 IXGBE_ADVTXD_POPTS_SHIFT;
6727 /* use index 1 context for tso */
6728 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
6729 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6730 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
6731 IXGBE_ADVTXD_POPTS_SHIFT;
6733 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6734 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
6735 IXGBE_ADVTXD_POPTS_SHIFT;
6737 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6738 olinfo_status |= IXGBE_ADVTXD_CC;
6739 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
6740 if (tx_flags & IXGBE_TX_FLAGS_FSO)
6741 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
6744 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
6746 i = tx_ring->next_to_use;
6747 while (count--) {
6748 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6749 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
6750 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
6751 tx_desc->read.cmd_type_len =
6752 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
6753 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
6754 i++;
6755 if (i == tx_ring->count)
6756 i = 0;
6759 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
6762 * Force memory writes to complete before letting h/w
6763 * know there are new descriptors to fetch. (Only
6764 * applicable for weak-ordered memory model archs,
6765 * such as IA-64).
6767 wmb();
6769 tx_ring->next_to_use = i;
6770 writel(i, tx_ring->tail);
6773 static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb,
6774 u32 tx_flags, __be16 protocol)
6776 struct ixgbe_q_vector *q_vector = ring->q_vector;
6777 union ixgbe_atr_hash_dword input = { .dword = 0 };
6778 union ixgbe_atr_hash_dword common = { .dword = 0 };
6779 union {
6780 unsigned char *network;
6781 struct iphdr *ipv4;
6782 struct ipv6hdr *ipv6;
6783 } hdr;
6784 struct tcphdr *th;
6785 __be16 vlan_id;
6787 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6788 if (!q_vector)
6789 return;
6791 /* do nothing if sampling is disabled */
6792 if (!ring->atr_sample_rate)
6793 return;
6795 ring->atr_count++;
6797 /* snag network header to get L4 type and address */
6798 hdr.network = skb_network_header(skb);
6800 /* Currently only IPv4/IPv6 with TCP is supported */
6801 if ((protocol != __constant_htons(ETH_P_IPV6) ||
6802 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
6803 (protocol != __constant_htons(ETH_P_IP) ||
6804 hdr.ipv4->protocol != IPPROTO_TCP))
6805 return;
6807 th = tcp_hdr(skb);
6809 /* skip this packet since the socket is closing */
6810 if (th->fin)
6811 return;
6813 /* sample on all syn packets or once every atr sample count */
6814 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6815 return;
6817 /* reset sample count */
6818 ring->atr_count = 0;
6820 vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
6823 * src and dst are inverted, think how the receiver sees them
6825 * The input is broken into two sections, a non-compressed section
6826 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6827 * is XORed together and stored in the compressed dword.
6829 input.formatted.vlan_id = vlan_id;
6832 * since src port and flex bytes occupy the same word XOR them together
6833 * and write the value to source port portion of compressed dword
6835 if (vlan_id)
6836 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6837 else
6838 common.port.src ^= th->dest ^ protocol;
6839 common.port.dst ^= th->source;
6841 if (protocol == __constant_htons(ETH_P_IP)) {
6842 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6843 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6844 } else {
6845 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6846 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6847 hdr.ipv6->saddr.s6_addr32[1] ^
6848 hdr.ipv6->saddr.s6_addr32[2] ^
6849 hdr.ipv6->saddr.s6_addr32[3] ^
6850 hdr.ipv6->daddr.s6_addr32[0] ^
6851 hdr.ipv6->daddr.s6_addr32[1] ^
6852 hdr.ipv6->daddr.s6_addr32[2] ^
6853 hdr.ipv6->daddr.s6_addr32[3];
6856 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
6857 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6858 input, common, ring->queue_index);
6861 static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, int size)
6863 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
6864 /* Herbert's original patch had:
6865 * smp_mb__after_netif_stop_queue();
6866 * but since that doesn't exist yet, just open code it. */
6867 smp_mb();
6869 /* We need to check again in a case another CPU has just
6870 * made room available. */
6871 if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
6872 return -EBUSY;
6874 /* A reprieve! - use start_queue because it doesn't call schedule */
6875 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
6876 ++tx_ring->tx_stats.restart_queue;
6877 return 0;
6880 static int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, int size)
6882 if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
6883 return 0;
6884 return __ixgbe_maybe_stop_tx(tx_ring, size);
6887 static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6889 struct ixgbe_adapter *adapter = netdev_priv(dev);
6890 int txq = smp_processor_id();
6891 #ifdef IXGBE_FCOE
6892 __be16 protocol;
6894 protocol = vlan_get_protocol(skb);
6896 if (((protocol == htons(ETH_P_FCOE)) ||
6897 (protocol == htons(ETH_P_FIP))) &&
6898 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6899 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
6900 txq += adapter->ring_feature[RING_F_FCOE].mask;
6901 return txq;
6903 #endif
6905 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6906 while (unlikely(txq >= dev->real_num_tx_queues))
6907 txq -= dev->real_num_tx_queues;
6908 return txq;
6911 return skb_tx_hash(dev, skb);
6914 netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
6915 struct ixgbe_adapter *adapter,
6916 struct ixgbe_ring *tx_ring)
6918 unsigned int first;
6919 unsigned int tx_flags = 0;
6920 u8 hdr_len = 0;
6921 int tso;
6922 int count = 0;
6923 unsigned int f;
6924 __be16 protocol;
6926 protocol = vlan_get_protocol(skb);
6928 if (vlan_tx_tag_present(skb)) {
6929 tx_flags |= vlan_tx_tag_get(skb);
6930 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6931 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
6932 tx_flags |= tx_ring->dcb_tc << 13;
6934 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
6935 tx_flags |= IXGBE_TX_FLAGS_VLAN;
6936 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED &&
6937 skb->priority != TC_PRIO_CONTROL) {
6938 tx_flags |= tx_ring->dcb_tc << 13;
6939 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
6940 tx_flags |= IXGBE_TX_FLAGS_VLAN;
6943 #ifdef IXGBE_FCOE
6944 /* for FCoE with DCB, we force the priority to what
6945 * was specified by the switch */
6946 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED &&
6947 (protocol == htons(ETH_P_FCOE)))
6948 tx_flags |= IXGBE_TX_FLAGS_FCOE;
6949 #endif
6951 /* four things can cause us to need a context descriptor */
6952 if (skb_is_gso(skb) ||
6953 (skb->ip_summed == CHECKSUM_PARTIAL) ||
6954 (tx_flags & IXGBE_TX_FLAGS_VLAN) ||
6955 (tx_flags & IXGBE_TX_FLAGS_FCOE))
6956 count++;
6958 count += TXD_USE_COUNT(skb_headlen(skb));
6959 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
6960 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6962 if (ixgbe_maybe_stop_tx(tx_ring, count)) {
6963 tx_ring->tx_stats.tx_busy++;
6964 return NETDEV_TX_BUSY;
6967 first = tx_ring->next_to_use;
6968 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6969 #ifdef IXGBE_FCOE
6970 /* setup tx offload for FCoE */
6971 tso = ixgbe_fso(adapter, tx_ring, skb, tx_flags, &hdr_len);
6972 if (tso < 0) {
6973 dev_kfree_skb_any(skb);
6974 return NETDEV_TX_OK;
6976 if (tso)
6977 tx_flags |= IXGBE_TX_FLAGS_FSO;
6978 #endif /* IXGBE_FCOE */
6979 } else {
6980 if (protocol == htons(ETH_P_IP))
6981 tx_flags |= IXGBE_TX_FLAGS_IPV4;
6982 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len,
6983 protocol);
6984 if (tso < 0) {
6985 dev_kfree_skb_any(skb);
6986 return NETDEV_TX_OK;
6989 if (tso)
6990 tx_flags |= IXGBE_TX_FLAGS_TSO;
6991 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags,
6992 protocol) &&
6993 (skb->ip_summed == CHECKSUM_PARTIAL))
6994 tx_flags |= IXGBE_TX_FLAGS_CSUM;
6997 count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first, hdr_len);
6998 if (count) {
6999 /* add the ATR filter if ATR is on */
7000 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
7001 ixgbe_atr(tx_ring, skb, tx_flags, protocol);
7002 ixgbe_tx_queue(tx_ring, tx_flags, count, skb->len, hdr_len);
7003 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
7005 } else {
7006 dev_kfree_skb_any(skb);
7007 tx_ring->tx_buffer_info[first].time_stamp = 0;
7008 tx_ring->next_to_use = first;
7011 return NETDEV_TX_OK;
7014 static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
7016 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7017 struct ixgbe_ring *tx_ring;
7019 tx_ring = adapter->tx_ring[skb->queue_mapping];
7020 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
7024 * ixgbe_set_mac - Change the Ethernet Address of the NIC
7025 * @netdev: network interface device structure
7026 * @p: pointer to an address structure
7028 * Returns 0 on success, negative on failure
7030 static int ixgbe_set_mac(struct net_device *netdev, void *p)
7032 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7033 struct ixgbe_hw *hw = &adapter->hw;
7034 struct sockaddr *addr = p;
7036 if (!is_valid_ether_addr(addr->sa_data))
7037 return -EADDRNOTAVAIL;
7039 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
7040 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
7042 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
7043 IXGBE_RAH_AV);
7045 return 0;
7048 static int
7049 ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
7051 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7052 struct ixgbe_hw *hw = &adapter->hw;
7053 u16 value;
7054 int rc;
7056 if (prtad != hw->phy.mdio.prtad)
7057 return -EINVAL;
7058 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
7059 if (!rc)
7060 rc = value;
7061 return rc;
7064 static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
7065 u16 addr, u16 value)
7067 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7068 struct ixgbe_hw *hw = &adapter->hw;
7070 if (prtad != hw->phy.mdio.prtad)
7071 return -EINVAL;
7072 return hw->phy.ops.write_reg(hw, addr, devad, value);
7075 static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
7077 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7079 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
7083 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
7084 * netdev->dev_addrs
7085 * @netdev: network interface device structure
7087 * Returns non-zero on failure
7089 static int ixgbe_add_sanmac_netdev(struct net_device *dev)
7091 int err = 0;
7092 struct ixgbe_adapter *adapter = netdev_priv(dev);
7093 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7095 if (is_valid_ether_addr(mac->san_addr)) {
7096 rtnl_lock();
7097 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
7098 rtnl_unlock();
7100 return err;
7104 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
7105 * netdev->dev_addrs
7106 * @netdev: network interface device structure
7108 * Returns non-zero on failure
7110 static int ixgbe_del_sanmac_netdev(struct net_device *dev)
7112 int err = 0;
7113 struct ixgbe_adapter *adapter = netdev_priv(dev);
7114 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7116 if (is_valid_ether_addr(mac->san_addr)) {
7117 rtnl_lock();
7118 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
7119 rtnl_unlock();
7121 return err;
7124 #ifdef CONFIG_NET_POLL_CONTROLLER
7126 * Polling 'interrupt' - used by things like netconsole to send skbs
7127 * without having to re-enable interrupts. It's not called while
7128 * the interrupt routine is executing.
7130 static void ixgbe_netpoll(struct net_device *netdev)
7132 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7133 int i;
7135 /* if interface is down do nothing */
7136 if (test_bit(__IXGBE_DOWN, &adapter->state))
7137 return;
7139 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
7140 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
7141 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
7142 for (i = 0; i < num_q_vectors; i++) {
7143 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
7144 ixgbe_msix_clean_many(0, q_vector);
7146 } else {
7147 ixgbe_intr(adapter->pdev->irq, netdev);
7149 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
7151 #endif
7153 static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
7154 struct rtnl_link_stats64 *stats)
7156 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7157 int i;
7159 rcu_read_lock();
7160 for (i = 0; i < adapter->num_rx_queues; i++) {
7161 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
7162 u64 bytes, packets;
7163 unsigned int start;
7165 if (ring) {
7166 do {
7167 start = u64_stats_fetch_begin_bh(&ring->syncp);
7168 packets = ring->stats.packets;
7169 bytes = ring->stats.bytes;
7170 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7171 stats->rx_packets += packets;
7172 stats->rx_bytes += bytes;
7176 for (i = 0; i < adapter->num_tx_queues; i++) {
7177 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7178 u64 bytes, packets;
7179 unsigned int start;
7181 if (ring) {
7182 do {
7183 start = u64_stats_fetch_begin_bh(&ring->syncp);
7184 packets = ring->stats.packets;
7185 bytes = ring->stats.bytes;
7186 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7187 stats->tx_packets += packets;
7188 stats->tx_bytes += bytes;
7191 rcu_read_unlock();
7192 /* following stats updated by ixgbe_watchdog_task() */
7193 stats->multicast = netdev->stats.multicast;
7194 stats->rx_errors = netdev->stats.rx_errors;
7195 stats->rx_length_errors = netdev->stats.rx_length_errors;
7196 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7197 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7198 return stats;
7202 static const struct net_device_ops ixgbe_netdev_ops = {
7203 .ndo_open = ixgbe_open,
7204 .ndo_stop = ixgbe_close,
7205 .ndo_start_xmit = ixgbe_xmit_frame,
7206 .ndo_select_queue = ixgbe_select_queue,
7207 .ndo_set_rx_mode = ixgbe_set_rx_mode,
7208 .ndo_set_multicast_list = ixgbe_set_rx_mode,
7209 .ndo_validate_addr = eth_validate_addr,
7210 .ndo_set_mac_address = ixgbe_set_mac,
7211 .ndo_change_mtu = ixgbe_change_mtu,
7212 .ndo_tx_timeout = ixgbe_tx_timeout,
7213 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7214 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
7215 .ndo_do_ioctl = ixgbe_ioctl,
7216 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7217 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7218 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
7219 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
7220 .ndo_get_stats64 = ixgbe_get_stats64,
7221 #ifdef CONFIG_IXGBE_DCB
7222 .ndo_setup_tc = ixgbe_setup_tc,
7223 #endif
7224 #ifdef CONFIG_NET_POLL_CONTROLLER
7225 .ndo_poll_controller = ixgbe_netpoll,
7226 #endif
7227 #ifdef IXGBE_FCOE
7228 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
7229 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
7230 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
7231 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7232 .ndo_fcoe_disable = ixgbe_fcoe_disable,
7233 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
7234 #endif /* IXGBE_FCOE */
7237 static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
7238 const struct ixgbe_info *ii)
7240 #ifdef CONFIG_PCI_IOV
7241 struct ixgbe_hw *hw = &adapter->hw;
7242 int err;
7243 int num_vf_macvlans, i;
7244 struct vf_macvlans *mv_list;
7246 if (hw->mac.type == ixgbe_mac_82598EB || !max_vfs)
7247 return;
7249 /* The 82599 supports up to 64 VFs per physical function
7250 * but this implementation limits allocation to 63 so that
7251 * basic networking resources are still available to the
7252 * physical function
7254 adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
7255 adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED;
7256 err = pci_enable_sriov(adapter->pdev, adapter->num_vfs);
7257 if (err) {
7258 e_err(probe, "Failed to enable PCI sriov: %d\n", err);
7259 goto err_novfs;
7262 num_vf_macvlans = hw->mac.num_rar_entries -
7263 (IXGBE_MAX_PF_MACVLANS + 1 + adapter->num_vfs);
7265 adapter->mv_list = mv_list = kcalloc(num_vf_macvlans,
7266 sizeof(struct vf_macvlans),
7267 GFP_KERNEL);
7268 if (mv_list) {
7269 /* Initialize list of VF macvlans */
7270 INIT_LIST_HEAD(&adapter->vf_mvs.l);
7271 for (i = 0; i < num_vf_macvlans; i++) {
7272 mv_list->vf = -1;
7273 mv_list->free = true;
7274 mv_list->rar_entry = hw->mac.num_rar_entries -
7275 (i + adapter->num_vfs + 1);
7276 list_add(&mv_list->l, &adapter->vf_mvs.l);
7277 mv_list++;
7281 /* If call to enable VFs succeeded then allocate memory
7282 * for per VF control structures.
7284 adapter->vfinfo =
7285 kcalloc(adapter->num_vfs,
7286 sizeof(struct vf_data_storage), GFP_KERNEL);
7287 if (adapter->vfinfo) {
7288 /* Now that we're sure SR-IOV is enabled
7289 * and memory allocated set up the mailbox parameters
7291 ixgbe_init_mbx_params_pf(hw);
7292 memcpy(&hw->mbx.ops, ii->mbx_ops,
7293 sizeof(hw->mbx.ops));
7295 /* Disable RSC when in SR-IOV mode */
7296 adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE |
7297 IXGBE_FLAG2_RSC_ENABLED);
7298 return;
7301 /* Oh oh */
7302 e_err(probe, "Unable to allocate memory for VF Data Storage - "
7303 "SRIOV disabled\n");
7304 pci_disable_sriov(adapter->pdev);
7306 err_novfs:
7307 adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
7308 adapter->num_vfs = 0;
7309 #endif /* CONFIG_PCI_IOV */
7313 * ixgbe_probe - Device Initialization Routine
7314 * @pdev: PCI device information struct
7315 * @ent: entry in ixgbe_pci_tbl
7317 * Returns 0 on success, negative on failure
7319 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7320 * The OS initialization, configuring of the adapter private structure,
7321 * and a hardware reset occur.
7323 static int __devinit ixgbe_probe(struct pci_dev *pdev,
7324 const struct pci_device_id *ent)
7326 struct net_device *netdev;
7327 struct ixgbe_adapter *adapter = NULL;
7328 struct ixgbe_hw *hw;
7329 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
7330 static int cards_found;
7331 int i, err, pci_using_dac;
7332 u8 part_str[IXGBE_PBANUM_LENGTH];
7333 unsigned int indices = num_possible_cpus();
7334 #ifdef IXGBE_FCOE
7335 u16 device_caps;
7336 #endif
7337 u32 eec;
7339 /* Catch broken hardware that put the wrong VF device ID in
7340 * the PCIe SR-IOV capability.
7342 if (pdev->is_virtfn) {
7343 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7344 pci_name(pdev), pdev->vendor, pdev->device);
7345 return -EINVAL;
7348 err = pci_enable_device_mem(pdev);
7349 if (err)
7350 return err;
7352 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7353 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
7354 pci_using_dac = 1;
7355 } else {
7356 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
7357 if (err) {
7358 err = dma_set_coherent_mask(&pdev->dev,
7359 DMA_BIT_MASK(32));
7360 if (err) {
7361 dev_err(&pdev->dev,
7362 "No usable DMA configuration, aborting\n");
7363 goto err_dma;
7366 pci_using_dac = 0;
7369 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
7370 IORESOURCE_MEM), ixgbe_driver_name);
7371 if (err) {
7372 dev_err(&pdev->dev,
7373 "pci_request_selected_regions failed 0x%x\n", err);
7374 goto err_pci_reg;
7377 pci_enable_pcie_error_reporting(pdev);
7379 pci_set_master(pdev);
7380 pci_save_state(pdev);
7382 if (ii->mac == ixgbe_mac_82598EB)
7383 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7384 else
7385 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7387 #if defined(CONFIG_DCB)
7388 indices = max_t(unsigned int, indices, IXGBE_MAX_DCB_INDICES);
7389 #elif defined(IXGBE_FCOE)
7390 indices += min_t(unsigned int, num_possible_cpus(),
7391 IXGBE_MAX_FCOE_INDICES);
7392 #endif
7393 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
7394 if (!netdev) {
7395 err = -ENOMEM;
7396 goto err_alloc_etherdev;
7399 SET_NETDEV_DEV(netdev, &pdev->dev);
7401 adapter = netdev_priv(netdev);
7402 pci_set_drvdata(pdev, adapter);
7404 adapter->netdev = netdev;
7405 adapter->pdev = pdev;
7406 hw = &adapter->hw;
7407 hw->back = adapter;
7408 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
7410 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
7411 pci_resource_len(pdev, 0));
7412 if (!hw->hw_addr) {
7413 err = -EIO;
7414 goto err_ioremap;
7417 for (i = 1; i <= 5; i++) {
7418 if (pci_resource_len(pdev, i) == 0)
7419 continue;
7422 netdev->netdev_ops = &ixgbe_netdev_ops;
7423 ixgbe_set_ethtool_ops(netdev);
7424 netdev->watchdog_timeo = 5 * HZ;
7425 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
7427 adapter->bd_number = cards_found;
7429 /* Setup hw api */
7430 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
7431 hw->mac.type = ii->mac;
7433 /* EEPROM */
7434 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7435 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7436 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7437 if (!(eec & (1 << 8)))
7438 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7440 /* PHY */
7441 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
7442 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
7443 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7444 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7445 hw->phy.mdio.mmds = 0;
7446 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7447 hw->phy.mdio.dev = netdev;
7448 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7449 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
7451 ii->get_invariants(hw);
7453 /* setup the private structure */
7454 err = ixgbe_sw_init(adapter);
7455 if (err)
7456 goto err_sw_init;
7458 /* Make it possible the adapter to be woken up via WOL */
7459 switch (adapter->hw.mac.type) {
7460 case ixgbe_mac_82599EB:
7461 case ixgbe_mac_X540:
7462 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
7463 break;
7464 default:
7465 break;
7469 * If there is a fan on this device and it has failed log the
7470 * failure.
7472 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7473 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7474 if (esdp & IXGBE_ESDP_SDP1)
7475 e_crit(probe, "Fan has stopped, replace the adapter\n");
7478 /* reset_hw fills in the perm_addr as well */
7479 hw->phy.reset_if_overtemp = true;
7480 err = hw->mac.ops.reset_hw(hw);
7481 hw->phy.reset_if_overtemp = false;
7482 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7483 hw->mac.type == ixgbe_mac_82598EB) {
7484 err = 0;
7485 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
7486 e_dev_err("failed to load because an unsupported SFP+ "
7487 "module type was detected.\n");
7488 e_dev_err("Reload the driver after installing a supported "
7489 "module.\n");
7490 goto err_sw_init;
7491 } else if (err) {
7492 e_dev_err("HW Init failed: %d\n", err);
7493 goto err_sw_init;
7496 ixgbe_probe_vf(adapter, ii);
7498 netdev->features = NETIF_F_SG |
7499 NETIF_F_IP_CSUM |
7500 NETIF_F_HW_VLAN_TX |
7501 NETIF_F_HW_VLAN_RX |
7502 NETIF_F_HW_VLAN_FILTER;
7504 netdev->features |= NETIF_F_IPV6_CSUM;
7505 netdev->features |= NETIF_F_TSO;
7506 netdev->features |= NETIF_F_TSO6;
7507 netdev->features |= NETIF_F_GRO;
7508 netdev->features |= NETIF_F_RXHASH;
7510 switch (adapter->hw.mac.type) {
7511 case ixgbe_mac_82599EB:
7512 case ixgbe_mac_X540:
7513 netdev->features |= NETIF_F_SCTP_CSUM;
7514 break;
7515 default:
7516 break;
7519 netdev->vlan_features |= NETIF_F_TSO;
7520 netdev->vlan_features |= NETIF_F_TSO6;
7521 netdev->vlan_features |= NETIF_F_IP_CSUM;
7522 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
7523 netdev->vlan_features |= NETIF_F_SG;
7525 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7526 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
7527 IXGBE_FLAG_DCB_ENABLED);
7529 #ifdef CONFIG_IXGBE_DCB
7530 netdev->dcbnl_ops = &dcbnl_ops;
7531 #endif
7533 #ifdef IXGBE_FCOE
7534 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7535 if (hw->mac.ops.get_device_caps) {
7536 hw->mac.ops.get_device_caps(hw, &device_caps);
7537 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7538 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
7541 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7542 netdev->vlan_features |= NETIF_F_FCOE_CRC;
7543 netdev->vlan_features |= NETIF_F_FSO;
7544 netdev->vlan_features |= NETIF_F_FCOE_MTU;
7546 #endif /* IXGBE_FCOE */
7547 if (pci_using_dac) {
7548 netdev->features |= NETIF_F_HIGHDMA;
7549 netdev->vlan_features |= NETIF_F_HIGHDMA;
7552 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
7553 netdev->features |= NETIF_F_LRO;
7555 /* make sure the EEPROM is good */
7556 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
7557 e_dev_err("The EEPROM Checksum Is Not Valid\n");
7558 err = -EIO;
7559 goto err_eeprom;
7562 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7563 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7565 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
7566 e_dev_err("invalid MAC address\n");
7567 err = -EIO;
7568 goto err_eeprom;
7571 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7572 if (hw->mac.ops.disable_tx_laser &&
7573 ((hw->phy.multispeed_fiber) ||
7574 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
7575 (hw->mac.type == ixgbe_mac_82599EB))))
7576 hw->mac.ops.disable_tx_laser(hw);
7578 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
7579 (unsigned long) adapter);
7581 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7582 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
7584 err = ixgbe_init_interrupt_scheme(adapter);
7585 if (err)
7586 goto err_sw_init;
7588 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
7589 netdev->features &= ~NETIF_F_RXHASH;
7591 switch (pdev->device) {
7592 case IXGBE_DEV_ID_82599_SFP:
7593 /* Only this subdevice supports WOL */
7594 if (pdev->subsystem_device == IXGBE_SUBDEV_ID_82599_SFP)
7595 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
7596 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
7597 break;
7598 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7599 /* All except this subdevice support WOL */
7600 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
7601 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
7602 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
7603 break;
7604 case IXGBE_DEV_ID_82599_KX4:
7605 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
7606 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
7607 break;
7608 default:
7609 adapter->wol = 0;
7610 break;
7612 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7614 /* pick up the PCI bus settings for reporting later */
7615 hw->mac.ops.get_bus_info(hw);
7617 /* print bus type/speed/width info */
7618 e_dev_info("(PCI Express:%s:%s) %pM\n",
7619 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7620 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
7621 "Unknown"),
7622 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7623 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7624 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7625 "Unknown"),
7626 netdev->dev_addr);
7628 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7629 if (err)
7630 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
7631 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
7632 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
7633 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
7634 part_str);
7635 else
7636 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7637 hw->mac.type, hw->phy.type, part_str);
7639 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
7640 e_dev_warn("PCI-Express bandwidth available for this card is "
7641 "not sufficient for optimal performance.\n");
7642 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7643 "is required.\n");
7646 /* save off EEPROM version number */
7647 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
7649 /* reset the hardware with the new settings */
7650 err = hw->mac.ops.start_hw(hw);
7652 if (err == IXGBE_ERR_EEPROM_VERSION) {
7653 /* We are running on a pre-production device, log a warning */
7654 e_dev_warn("This device is a pre-production adapter/LOM. "
7655 "Please be aware there may be issues associated "
7656 "with your hardware. If you are experiencing "
7657 "problems please contact your Intel or hardware "
7658 "representative who provided you with this "
7659 "hardware.\n");
7661 strcpy(netdev->name, "eth%d");
7662 err = register_netdev(netdev);
7663 if (err)
7664 goto err_register;
7666 /* carrier off reporting is important to ethtool even BEFORE open */
7667 netif_carrier_off(netdev);
7669 #ifdef CONFIG_IXGBE_DCA
7670 if (dca_add_requester(&pdev->dev) == 0) {
7671 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
7672 ixgbe_setup_dca(adapter);
7674 #endif
7675 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
7676 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
7677 for (i = 0; i < adapter->num_vfs; i++)
7678 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7681 /* add san mac addr to netdev */
7682 ixgbe_add_sanmac_netdev(netdev);
7684 e_dev_info("Intel(R) 10 Gigabit Network Connection\n");
7685 cards_found++;
7686 return 0;
7688 err_register:
7689 ixgbe_release_hw_control(adapter);
7690 ixgbe_clear_interrupt_scheme(adapter);
7691 err_sw_init:
7692 err_eeprom:
7693 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7694 ixgbe_disable_sriov(adapter);
7695 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
7696 iounmap(hw->hw_addr);
7697 err_ioremap:
7698 free_netdev(netdev);
7699 err_alloc_etherdev:
7700 pci_release_selected_regions(pdev,
7701 pci_select_bars(pdev, IORESOURCE_MEM));
7702 err_pci_reg:
7703 err_dma:
7704 pci_disable_device(pdev);
7705 return err;
7709 * ixgbe_remove - Device Removal Routine
7710 * @pdev: PCI device information struct
7712 * ixgbe_remove is called by the PCI subsystem to alert the driver
7713 * that it should release a PCI device. The could be caused by a
7714 * Hot-Plug event, or because the driver is going to be removed from
7715 * memory.
7717 static void __devexit ixgbe_remove(struct pci_dev *pdev)
7719 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7720 struct net_device *netdev = adapter->netdev;
7722 set_bit(__IXGBE_DOWN, &adapter->state);
7723 cancel_work_sync(&adapter->service_task);
7725 #ifdef CONFIG_IXGBE_DCA
7726 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7727 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7728 dca_remove_requester(&pdev->dev);
7729 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7732 #endif
7733 #ifdef IXGBE_FCOE
7734 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7735 ixgbe_cleanup_fcoe(adapter);
7737 #endif /* IXGBE_FCOE */
7739 /* remove the added san mac */
7740 ixgbe_del_sanmac_netdev(netdev);
7742 if (netdev->reg_state == NETREG_REGISTERED)
7743 unregister_netdev(netdev);
7745 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7746 ixgbe_disable_sriov(adapter);
7748 ixgbe_clear_interrupt_scheme(adapter);
7750 ixgbe_release_hw_control(adapter);
7752 iounmap(adapter->hw.hw_addr);
7753 pci_release_selected_regions(pdev, pci_select_bars(pdev,
7754 IORESOURCE_MEM));
7756 e_dev_info("complete\n");
7758 free_netdev(netdev);
7760 pci_disable_pcie_error_reporting(pdev);
7762 pci_disable_device(pdev);
7766 * ixgbe_io_error_detected - called when PCI error is detected
7767 * @pdev: Pointer to PCI device
7768 * @state: The current pci connection state
7770 * This function is called after a PCI bus error affecting
7771 * this device has been detected.
7773 static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
7774 pci_channel_state_t state)
7776 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7777 struct net_device *netdev = adapter->netdev;
7779 netif_device_detach(netdev);
7781 if (state == pci_channel_io_perm_failure)
7782 return PCI_ERS_RESULT_DISCONNECT;
7784 if (netif_running(netdev))
7785 ixgbe_down(adapter);
7786 pci_disable_device(pdev);
7788 /* Request a slot reset. */
7789 return PCI_ERS_RESULT_NEED_RESET;
7793 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7794 * @pdev: Pointer to PCI device
7796 * Restart the card from scratch, as if from a cold-boot.
7798 static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
7800 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7801 pci_ers_result_t result;
7802 int err;
7804 if (pci_enable_device_mem(pdev)) {
7805 e_err(probe, "Cannot re-enable PCI device after reset.\n");
7806 result = PCI_ERS_RESULT_DISCONNECT;
7807 } else {
7808 pci_set_master(pdev);
7809 pci_restore_state(pdev);
7810 pci_save_state(pdev);
7812 pci_wake_from_d3(pdev, false);
7814 ixgbe_reset(adapter);
7815 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
7816 result = PCI_ERS_RESULT_RECOVERED;
7819 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7820 if (err) {
7821 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7822 "failed 0x%0x\n", err);
7823 /* non-fatal, continue */
7826 return result;
7830 * ixgbe_io_resume - called when traffic can start flowing again.
7831 * @pdev: Pointer to PCI device
7833 * This callback is called when the error recovery driver tells us that
7834 * its OK to resume normal operation.
7836 static void ixgbe_io_resume(struct pci_dev *pdev)
7838 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7839 struct net_device *netdev = adapter->netdev;
7841 if (netif_running(netdev)) {
7842 if (ixgbe_up(adapter)) {
7843 e_info(probe, "ixgbe_up failed after reset\n");
7844 return;
7848 netif_device_attach(netdev);
7851 static struct pci_error_handlers ixgbe_err_handler = {
7852 .error_detected = ixgbe_io_error_detected,
7853 .slot_reset = ixgbe_io_slot_reset,
7854 .resume = ixgbe_io_resume,
7857 static struct pci_driver ixgbe_driver = {
7858 .name = ixgbe_driver_name,
7859 .id_table = ixgbe_pci_tbl,
7860 .probe = ixgbe_probe,
7861 .remove = __devexit_p(ixgbe_remove),
7862 #ifdef CONFIG_PM
7863 .suspend = ixgbe_suspend,
7864 .resume = ixgbe_resume,
7865 #endif
7866 .shutdown = ixgbe_shutdown,
7867 .err_handler = &ixgbe_err_handler
7871 * ixgbe_init_module - Driver Registration Routine
7873 * ixgbe_init_module is the first routine called when the driver is
7874 * loaded. All it does is register with the PCI subsystem.
7876 static int __init ixgbe_init_module(void)
7878 int ret;
7879 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
7880 pr_info("%s\n", ixgbe_copyright);
7882 #ifdef CONFIG_IXGBE_DCA
7883 dca_register_notify(&dca_notifier);
7884 #endif
7886 ret = pci_register_driver(&ixgbe_driver);
7887 return ret;
7890 module_init(ixgbe_init_module);
7893 * ixgbe_exit_module - Driver Exit Cleanup Routine
7895 * ixgbe_exit_module is called just before the driver is removed
7896 * from memory.
7898 static void __exit ixgbe_exit_module(void)
7900 #ifdef CONFIG_IXGBE_DCA
7901 dca_unregister_notify(&dca_notifier);
7902 #endif
7903 pci_unregister_driver(&ixgbe_driver);
7904 rcu_barrier(); /* Wait for completion of call_rcu()'s */
7907 #ifdef CONFIG_IXGBE_DCA
7908 static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
7909 void *p)
7911 int ret_val;
7913 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
7914 __ixgbe_notify_dca);
7916 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
7919 #endif /* CONFIG_IXGBE_DCA */
7921 module_exit(ixgbe_exit_module);
7923 /* ixgbe_main.c */