1 /*******************************************************************************
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2012 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
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".
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 /******************************************************************************
29 Copyright (c)2006 - 2007 Myricom, Inc. for some LRO specific code
30 ******************************************************************************/
31 #include <linux/types.h>
32 #include <linux/module.h>
33 #include <linux/pci.h>
34 #include <linux/netdevice.h>
35 #include <linux/vmalloc.h>
36 #include <linux/highmem.h>
37 #include <linux/string.h>
40 #include <linux/tcp.h>
42 #include <linux/sctp.h>
44 #include <linux/pkt_sched.h>
45 #include <linux/ipv6.h>
47 #include <net/checksum.h>
49 #include <net/ip6_checksum.h>
53 #include <linux/ethtool.h>
59 #undef CONFIG_DCA_MODULE
61 char ixgbe_driver_name[] = "ixgbe";
62 static const char ixgbe_driver_string[] =
63 "Intel(R) 10 Gigabit PCI Express Network Driver";
66 #ifndef CONFIG_IXGBE_NAPI
69 #define DRIVERNAPI "-NAPI"
79 #define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
80 __stringify(BUILD) DRIVERNAPI DRV_HW_PERF FPGA VMDQ_TAG
81 const char ixgbe_driver_version[] = DRV_VERSION;
82 static const char ixgbe_copyright[] =
83 "Copyright (c) 1999-2012 Intel Corporation.";
85 /* ixgbe_pci_tbl - PCI Device ID Table
87 * Wildcard entries (PCI_ANY_ID) should come last
88 * Last entry must be all 0s
90 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
91 * Class, Class Mask, private data (not used) }
93 DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
94 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598)},
95 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT)},
96 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT)},
97 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT)},
98 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2)},
99 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4)},
100 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT)},
101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT)},
102 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM)},
103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR)},
104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM)},
105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX)},
106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4)},
107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM)},
108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR)},
109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP)},
110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM)},
111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ)},
112 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4)},
113 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE)},
114 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE)},
115 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM)},
116 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE)},
117 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T)},
118 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2)},
119 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS)},
120 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP)},
121 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_QSFP_SF_QP)},
122 /* required last entry */
126 #if defined(CONFIG_DCA) || defined(CONFIG_DCA_MODULE)
127 static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
129 static struct notifier_block dca_notifier = {
130 .notifier_call = ixgbe_notify_dca,
136 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
137 MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
138 MODULE_LICENSE("GPL");
139 MODULE_VERSION(DRV_VERSION);
141 #define DEFAULT_DEBUG_LEVEL_SHIFT 3
144 static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
148 /* Let firmware take over control of h/w */
149 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
150 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
151 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
155 static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
159 /* Let firmware know the driver has taken over */
160 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
161 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
162 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
167 static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
169 struct ixgbe_hw *hw = &adapter->hw;
170 struct ixgbe_hw_stats *hwstats = &adapter->stats;
174 if ((hw->fc.current_mode != ixgbe_fc_full) &&
175 (hw->fc.current_mode != ixgbe_fc_rx_pause))
178 switch (hw->mac.type) {
179 case ixgbe_mac_82598EB:
180 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
183 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
185 hwstats->lxoffrxc += data;
187 /* refill credits (no tx hang) if we received xoff */
191 for (i = 0; i < adapter->num_tx_queues; i++)
192 clear_bit(__IXGBE_HANG_CHECK_ARMED,
193 &adapter->tx_ring[i]->state);
196 static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
198 struct ixgbe_hw *hw = &adapter->hw;
199 struct ixgbe_hw_stats *hwstats = &adapter->stats;
202 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
204 #ifdef HAVE_DCBNL_IEEE
205 if (adapter->ixgbe_ieee_pfc)
206 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
209 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
210 ixgbe_update_xoff_rx_lfc(adapter);
214 /* update stats for each tc, only valid with PFC enabled */
215 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
216 switch (hw->mac.type) {
217 case ixgbe_mac_82598EB:
218 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
221 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
223 hwstats->pxoffrxc[i] += xoff[i];
226 /* disarm tx queues that have received xoff frames */
227 for (i = 0; i < adapter->num_tx_queues; i++) {
228 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
229 u8 tc = tx_ring->dcb_tc;
231 if ((tc <= 7) && (xoff[tc]))
232 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
239 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
244 #ifdef HAVE_8021P_SUPPORT
246 * ixgbe_vlan_stripping_disable - helper to disable vlan tag stripping
247 * @adapter: driver data
249 void ixgbe_vlan_stripping_disable(struct ixgbe_adapter *adapter)
251 struct ixgbe_hw *hw = &adapter->hw;
255 /* leave vlan tag stripping enabled for DCB */
256 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
259 switch (hw->mac.type) {
260 case ixgbe_mac_82598EB:
261 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
262 vlnctrl &= ~IXGBE_VLNCTRL_VME;
263 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
265 case ixgbe_mac_82599EB:
267 for (i = 0; i < adapter->num_rx_queues; i++) {
268 u8 reg_idx = adapter->rx_ring[i]->reg_idx;
269 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
270 vlnctrl &= ~IXGBE_RXDCTL_VME;
271 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), vlnctrl);
281 * ixgbe_vlan_stripping_enable - helper to enable vlan tag stripping
282 * @adapter: driver data
284 void ixgbe_vlan_stripping_enable(struct ixgbe_adapter *adapter)
286 struct ixgbe_hw *hw = &adapter->hw;
290 switch (hw->mac.type) {
291 case ixgbe_mac_82598EB:
292 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
293 vlnctrl |= IXGBE_VLNCTRL_VME;
294 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
296 case ixgbe_mac_82599EB:
298 for (i = 0; i < adapter->num_rx_queues; i++) {
299 u8 reg_idx = adapter->rx_ring[i]->reg_idx;
300 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
301 vlnctrl |= IXGBE_RXDCTL_VME;
302 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), vlnctrl);
310 #ifdef HAVE_VLAN_RX_REGISTER
311 void ixgbe_vlan_mode(struct net_device *netdev, struct vlan_group *grp)
313 void ixgbe_vlan_mode(struct net_device *netdev, u32 features)
316 struct ixgbe_adapter *adapter = netdev_priv(netdev);
317 #ifdef HAVE_8021P_SUPPORT
320 #ifdef HAVE_VLAN_RX_REGISTER
322 //if (!test_bit(__IXGBE_DOWN, &adapter->state))
323 // ixgbe_irq_disable(adapter);
325 adapter->vlgrp = grp;
327 //if (!test_bit(__IXGBE_DOWN, &adapter->state))
328 // ixgbe_irq_enable(adapter, true, true);
330 #ifdef HAVE_8021P_SUPPORT
331 #ifdef HAVE_VLAN_RX_REGISTER
332 enable = (grp || (adapter->flags & IXGBE_FLAG_DCB_ENABLED));
334 enable = !!(features & NETIF_F_HW_VLAN_RX);
337 /* enable VLAN tag insert/strip */
338 ixgbe_vlan_stripping_enable(adapter);
340 /* disable VLAN tag insert/strip */
341 ixgbe_vlan_stripping_disable(adapter);
346 static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq)
348 #ifdef NETDEV_HW_ADDR_T_MULTICAST
349 struct netdev_hw_addr *mc_ptr;
351 struct dev_mc_list *mc_ptr;
353 struct ixgbe_adapter *adapter = hw->back;
354 u8 *addr = *mc_addr_ptr;
356 *vmdq = adapter->num_vfs;
358 #ifdef NETDEV_HW_ADDR_T_MULTICAST
359 mc_ptr = container_of(addr, struct netdev_hw_addr, addr[0]);
360 if (mc_ptr->list.next) {
361 struct netdev_hw_addr *ha;
363 ha = list_entry(mc_ptr->list.next, struct netdev_hw_addr, list);
364 *mc_addr_ptr = ha->addr;
367 mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]);
369 *mc_addr_ptr = mc_ptr->next->dmi_addr;
378 * ixgbe_write_mc_addr_list - write multicast addresses to MTA
379 * @netdev: network interface device structure
381 * Writes multicast address list to the MTA hash table.
382 * Returns: -ENOMEM on failure
383 * 0 on no addresses written
384 * X on writing X addresses to MTA
386 int ixgbe_write_mc_addr_list(struct net_device *netdev)
388 struct ixgbe_adapter *adapter = netdev_priv(netdev);
389 struct ixgbe_hw *hw = &adapter->hw;
390 #ifdef NETDEV_HW_ADDR_T_MULTICAST
391 struct netdev_hw_addr *ha;
393 u8 *addr_list = NULL;
396 if (!hw->mac.ops.update_mc_addr_list)
399 if (!netif_running(netdev))
403 hw->mac.ops.update_mc_addr_list(hw, NULL, 0,
404 ixgbe_addr_list_itr, true);
406 if (!netdev_mc_empty(netdev)) {
407 #ifdef NETDEV_HW_ADDR_T_MULTICAST
408 ha = list_first_entry(&netdev->mc.list,
409 struct netdev_hw_addr, list);
410 addr_list = ha->addr;
412 addr_list = netdev->mc_list->dmi_addr;
414 addr_count = netdev_mc_count(netdev);
416 hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count,
417 ixgbe_addr_list_itr, false);
420 #ifdef CONFIG_PCI_IOV
421 //ixgbe_restore_vf_multicasts(adapter);
427 void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter)
429 struct ixgbe_hw *hw = &adapter->hw;
431 for (i = 0; i < hw->mac.num_rar_entries; i++) {
432 if (adapter->mac_table[i].state & IXGBE_MAC_STATE_IN_USE) {
433 hw->mac.ops.set_rar(hw, i, adapter->mac_table[i].addr,
434 adapter->mac_table[i].queue,
437 hw->mac.ops.clear_rar(hw, i);
442 void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter)
444 struct ixgbe_hw *hw = &adapter->hw;
446 for (i = 0; i < hw->mac.num_rar_entries; i++) {
447 if (adapter->mac_table[i].state & IXGBE_MAC_STATE_MODIFIED) {
448 if (adapter->mac_table[i].state &
449 IXGBE_MAC_STATE_IN_USE) {
450 hw->mac.ops.set_rar(hw, i,
451 adapter->mac_table[i].addr,
452 adapter->mac_table[i].queue,
455 hw->mac.ops.clear_rar(hw, i);
457 adapter->mac_table[i].state &=
458 ~(IXGBE_MAC_STATE_MODIFIED);
463 int ixgbe_available_rars(struct ixgbe_adapter *adapter)
465 struct ixgbe_hw *hw = &adapter->hw;
468 for (i = 0; i < hw->mac.num_rar_entries; i++) {
469 if (adapter->mac_table[i].state == 0)
475 int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter, u8 *addr, u16 queue)
477 struct ixgbe_hw *hw = &adapter->hw;
480 if (is_zero_ether_addr(addr))
483 for (i = 0; i < hw->mac.num_rar_entries; i++) {
484 if (adapter->mac_table[i].state & IXGBE_MAC_STATE_IN_USE)
486 adapter->mac_table[i].state |= (IXGBE_MAC_STATE_MODIFIED |
487 IXGBE_MAC_STATE_IN_USE);
488 memcpy(adapter->mac_table[i].addr, addr, ETH_ALEN);
489 adapter->mac_table[i].queue = queue;
490 ixgbe_sync_mac_table(adapter);
496 void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter)
499 struct ixgbe_hw *hw = &adapter->hw;
501 for (i = 0; i < hw->mac.num_rar_entries; i++) {
502 adapter->mac_table[i].state |= IXGBE_MAC_STATE_MODIFIED;
503 adapter->mac_table[i].state &= ~IXGBE_MAC_STATE_IN_USE;
504 memset(adapter->mac_table[i].addr, 0, ETH_ALEN);
505 adapter->mac_table[i].queue = 0;
507 ixgbe_sync_mac_table(adapter);
510 void ixgbe_del_mac_filter_by_index(struct ixgbe_adapter *adapter, int index)
512 adapter->mac_table[index].state |= IXGBE_MAC_STATE_MODIFIED;
513 adapter->mac_table[index].state &= ~IXGBE_MAC_STATE_IN_USE;
514 memset(adapter->mac_table[index].addr, 0, ETH_ALEN);
515 adapter->mac_table[index].queue = 0;
516 ixgbe_sync_mac_table(adapter);
519 int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter, u8* addr, u16 queue)
521 /* search table for addr, if found, set to 0 and sync */
523 struct ixgbe_hw *hw = &adapter->hw;
525 if (is_zero_ether_addr(addr))
527 for (i = 0; i < hw->mac.num_rar_entries; i++) {
528 if (!compare_ether_addr(addr, adapter->mac_table[i].addr) &&
529 adapter->mac_table[i].queue == queue) {
530 adapter->mac_table[i].state |= IXGBE_MAC_STATE_MODIFIED;
531 adapter->mac_table[i].state &= ~IXGBE_MAC_STATE_IN_USE;
532 memset(adapter->mac_table[i].addr, 0, ETH_ALEN);
533 adapter->mac_table[i].queue = 0;
534 ixgbe_sync_mac_table(adapter);
540 #ifdef HAVE_SET_RX_MODE
542 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
543 * @netdev: network interface device structure
545 * Writes unicast address list to the RAR table.
546 * Returns: -ENOMEM on failure/insufficient address space
547 * 0 on no addresses written
548 * X on writing X addresses to the RAR table
550 int ixgbe_write_uc_addr_list(struct ixgbe_adapter *adapter,
551 struct net_device *netdev, unsigned int vfn)
555 /* return ENOMEM indicating insufficient memory for addresses */
556 if (netdev_uc_count(netdev) > ixgbe_available_rars(adapter))
559 if (!netdev_uc_empty(netdev)) {
560 #ifdef NETDEV_HW_ADDR_T_UNICAST
561 struct netdev_hw_addr *ha;
563 struct dev_mc_list *ha;
565 netdev_for_each_uc_addr(ha, netdev) {
566 #ifdef NETDEV_HW_ADDR_T_UNICAST
567 ixgbe_del_mac_filter(adapter, ha->addr, (u16)vfn);
568 ixgbe_add_mac_filter(adapter, ha->addr, (u16)vfn);
570 ixgbe_del_mac_filter(adapter, ha->da_addr, (u16)vfn);
571 ixgbe_add_mac_filter(adapter, ha->da_addr, (u16)vfn);
581 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
582 * @netdev: network interface device structure
584 * The set_rx_method entry point is called whenever the unicast/multicast
585 * address list or the network interface flags are updated. This routine is
586 * responsible for configuring the hardware for proper unicast, multicast and
589 void ixgbe_set_rx_mode(struct net_device *netdev)
591 struct ixgbe_adapter *adapter = netdev_priv(netdev);
592 struct ixgbe_hw *hw = &adapter->hw;
593 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
597 /* Check for Promiscuous and All Multicast modes */
598 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
599 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
601 /* set all bits that we expect to always be set */
602 fctrl |= IXGBE_FCTRL_BAM;
603 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
604 fctrl |= IXGBE_FCTRL_PMCF;
606 /* clear the bits we are changing the status of */
607 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
608 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
610 if (netdev->flags & IFF_PROMISC) {
611 hw->addr_ctrl.user_set_promisc = true;
612 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
613 vmolr |= IXGBE_VMOLR_MPE;
615 if (netdev->flags & IFF_ALLMULTI) {
616 fctrl |= IXGBE_FCTRL_MPE;
617 vmolr |= IXGBE_VMOLR_MPE;
620 * Write addresses to the MTA, if the attempt fails
621 * then we should just turn on promiscuous mode so
622 * that we can at least receive multicast traffic
624 count = ixgbe_write_mc_addr_list(netdev);
626 fctrl |= IXGBE_FCTRL_MPE;
627 vmolr |= IXGBE_VMOLR_MPE;
629 vmolr |= IXGBE_VMOLR_ROMPE;
632 #ifdef NETIF_F_HW_VLAN_TX
633 /* enable hardware vlan filtering */
634 vlnctrl |= IXGBE_VLNCTRL_VFE;
636 hw->addr_ctrl.user_set_promisc = false;
637 #ifdef HAVE_SET_RX_MODE
639 * Write addresses to available RAR registers, if there is not
640 * sufficient space to store all the addresses then enable
641 * unicast promiscuous mode
643 count = ixgbe_write_uc_addr_list(adapter, netdev,
646 fctrl |= IXGBE_FCTRL_UPE;
647 vmolr |= IXGBE_VMOLR_ROPE;
652 if (hw->mac.type != ixgbe_mac_82598EB) {
653 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
654 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
656 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
659 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
660 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
670 /* Additional bittime to account for IXGBE framing */
671 #define IXGBE_ETH_FRAMING 20
674 * ixgbe_hpbthresh - calculate high water mark for flow control
676 * @adapter: board private structure to calculate for
677 * @pb - packet buffer to calculate
679 static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
681 struct ixgbe_hw *hw = &adapter->hw;
682 struct net_device *dev = adapter->netdev;
683 int link, tc, kb, marker;
686 /* Calculate max LAN frame size */
687 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
690 /* FCoE traffic class uses FCOE jumbo frames */
691 if (dev->features & NETIF_F_FCOE_MTU) {
694 fcoe_pb = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
696 if (fcoe_pb == pb && tc < IXGBE_FCOE_JUMBO_FRAME_SIZE)
697 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
701 /* Calculate delay value for device */
702 switch (hw->mac.type) {
704 dv_id = IXGBE_DV_X540(link, tc);
707 dv_id = IXGBE_DV(link, tc);
711 /* Loopback switch introduces additional latency */
712 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
713 dv_id += IXGBE_B2BT(tc);
715 /* Delay value is calculated in bit times convert to KB */
716 kb = IXGBE_BT2KB(dv_id);
717 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
719 marker = rx_pba - kb;
721 /* It is possible that the packet buffer is not large enough
722 * to provide required headroom. In this case throw an error
723 * to user and a do the best we can.
726 e_warn(drv, "Packet Buffer(%i) can not provide enough"
727 "headroom to suppport flow control."
728 "Decrease MTU or number of traffic classes\n", pb);
736 * ixgbe_lpbthresh - calculate low water mark for for flow control
738 * @adapter: board private structure to calculate for
739 * @pb - packet buffer to calculate
741 static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb)
743 struct ixgbe_hw *hw = &adapter->hw;
744 struct net_device *dev = adapter->netdev;
748 /* Calculate max LAN frame size */
749 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
752 /* FCoE traffic class uses FCOE jumbo frames */
753 if (dev->features & NETIF_F_FCOE_MTU) {
756 fcoe_pb = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
758 if (fcoe_pb == pb && tc < IXGBE_FCOE_JUMBO_FRAME_SIZE)
759 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
763 /* Calculate delay value for device */
764 switch (hw->mac.type) {
766 dv_id = IXGBE_LOW_DV_X540(tc);
769 dv_id = IXGBE_LOW_DV(tc);
773 /* Delay value is calculated in bit times convert to KB */
774 return IXGBE_BT2KB(dv_id);
778 * ixgbe_pbthresh_setup - calculate and setup high low water marks
780 static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
782 struct ixgbe_hw *hw = &adapter->hw;
783 int num_tc = netdev_get_num_tc(adapter->netdev);
788 if (num_tc > IXGBE_DCB_MAX_TRAFFIC_CLASS)
789 num_tc = IXGBE_DCB_MAX_TRAFFIC_CLASS;
791 for (i = 0; i < num_tc; i++) {
792 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
793 hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i);
795 /* Low water marks must not be larger than high water marks */
796 if (hw->fc.low_water[i] > hw->fc.high_water[i])
797 hw->fc.low_water[i] = 0;
800 for (; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++)
801 hw->fc.high_water[i] = 0;
807 static void ixgbe_configure(struct ixgbe_adapter *adapter)
809 struct ixgbe_hw *hw = &adapter->hw;
811 ixgbe_configure_pb(adapter);
812 ixgbe_configure_dcb(adapter);
814 ixgbe_set_rx_mode(adapter->netdev);
815 #ifdef NETIF_F_HW_VLAN_TX
816 ixgbe_restore_vlan(adapter);
820 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
821 ixgbe_configure_fcoe(adapter);
823 #endif /* IXGBE_FCOE */
825 if (adapter->hw.mac.type != ixgbe_mac_82598EB)
826 hw->mac.ops.disable_sec_rx_path(hw);
828 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
829 ixgbe_init_fdir_signature_82599(&adapter->hw,
830 adapter->fdir_pballoc);
831 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
832 ixgbe_init_fdir_perfect_82599(&adapter->hw,
833 adapter->fdir_pballoc);
834 ixgbe_fdir_filter_restore(adapter);
837 if (adapter->hw.mac.type != ixgbe_mac_82598EB)
838 hw->mac.ops.enable_sec_rx_path(hw);
840 ixgbe_configure_virtualization(adapter);
842 ixgbe_configure_tx(adapter);
843 ixgbe_configure_rx(adapter);
847 static bool ixgbe_is_sfp(struct ixgbe_hw *hw)
849 switch (hw->phy.type) {
850 case ixgbe_phy_sfp_avago:
851 case ixgbe_phy_sfp_ftl:
852 case ixgbe_phy_sfp_intel:
853 case ixgbe_phy_sfp_unknown:
854 case ixgbe_phy_sfp_passive_tyco:
855 case ixgbe_phy_sfp_passive_unknown:
856 case ixgbe_phy_sfp_active_unknown:
857 case ixgbe_phy_sfp_ftl_active:
860 if (hw->mac.type == ixgbe_mac_82598EB)
869 * ixgbe_clear_vf_stats_counters - Clear out VF stats after reset
870 * @adapter: board private structure
872 * On a reset we need to clear out the VF stats or accounting gets
873 * messed up because they're not clear on read.
875 void ixgbe_clear_vf_stats_counters(struct ixgbe_adapter *adapter)
877 struct ixgbe_hw *hw = &adapter->hw;
880 for (i = 0; i < adapter->num_vfs; i++) {
881 adapter->vfinfo[i].last_vfstats.gprc =
882 IXGBE_READ_REG(hw, IXGBE_PVFGPRC(i));
883 adapter->vfinfo[i].saved_rst_vfstats.gprc +=
884 adapter->vfinfo[i].vfstats.gprc;
885 adapter->vfinfo[i].vfstats.gprc = 0;
886 adapter->vfinfo[i].last_vfstats.gptc =
887 IXGBE_READ_REG(hw, IXGBE_PVFGPTC(i));
888 adapter->vfinfo[i].saved_rst_vfstats.gptc +=
889 adapter->vfinfo[i].vfstats.gptc;
890 adapter->vfinfo[i].vfstats.gptc = 0;
891 adapter->vfinfo[i].last_vfstats.gorc =
892 IXGBE_READ_REG(hw, IXGBE_PVFGORC_LSB(i));
893 adapter->vfinfo[i].saved_rst_vfstats.gorc +=
894 adapter->vfinfo[i].vfstats.gorc;
895 adapter->vfinfo[i].vfstats.gorc = 0;
896 adapter->vfinfo[i].last_vfstats.gotc =
897 IXGBE_READ_REG(hw, IXGBE_PVFGOTC_LSB(i));
898 adapter->vfinfo[i].saved_rst_vfstats.gotc +=
899 adapter->vfinfo[i].vfstats.gotc;
900 adapter->vfinfo[i].vfstats.gotc = 0;
901 adapter->vfinfo[i].last_vfstats.mprc =
902 IXGBE_READ_REG(hw, IXGBE_PVFMPRC(i));
903 adapter->vfinfo[i].saved_rst_vfstats.mprc +=
904 adapter->vfinfo[i].vfstats.mprc;
905 adapter->vfinfo[i].vfstats.mprc = 0;
911 void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
914 WARN_ON(in_interrupt());
915 /* put off any impending NetWatchDogTimeout */
916 adapter->netdev->trans_start = jiffies;
918 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
919 usleep_range(1000, 2000);
922 * If SR-IOV enabled then wait a bit before bringing the adapter
923 * back up to give the VFs time to respond to the reset. The
924 * two second wait is based upon the watchdog timer cycle in
927 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
930 clear_bit(__IXGBE_RESETTING, &adapter->state);
934 void ixgbe_up(struct ixgbe_adapter *adapter)
936 /* hardware has been reset, we need to reload some things */
937 //ixgbe_configure(adapter);
939 //ixgbe_up_complete(adapter);
942 void ixgbe_reset(struct ixgbe_adapter *adapter)
944 struct ixgbe_hw *hw = &adapter->hw;
945 struct net_device *netdev = adapter->netdev;
948 /* lock SFP init bit to prevent race conditions with the watchdog */
949 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
950 usleep_range(1000, 2000);
952 /* clear all SFP and link config related flags while holding SFP_INIT */
953 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
954 IXGBE_FLAG2_SFP_NEEDS_RESET);
955 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
957 err = hw->mac.ops.init_hw(hw);
960 case IXGBE_ERR_SFP_NOT_PRESENT:
961 case IXGBE_ERR_SFP_NOT_SUPPORTED:
963 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
964 e_dev_err("master disable timed out\n");
966 case IXGBE_ERR_EEPROM_VERSION:
967 /* We are running on a pre-production device, log a warning */
968 e_dev_warn("This device is a pre-production adapter/LOM. "
969 "Please be aware there may be issues associated "
970 "with your hardware. If you are experiencing "
971 "problems please contact your Intel or hardware "
972 "representative who provided you with this "
976 e_dev_err("Hardware Error: %d\n", err);
979 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
981 ixgbe_flush_sw_mac_table(adapter);
982 memcpy(&adapter->mac_table[0].addr, hw->mac.perm_addr,
984 adapter->mac_table[0].queue = adapter->num_vfs;
985 adapter->mac_table[0].state = (IXGBE_MAC_STATE_DEFAULT |
986 IXGBE_MAC_STATE_IN_USE);
987 hw->mac.ops.set_rar(hw, 0, adapter->mac_table[0].addr,
988 adapter->mac_table[0].queue,
997 void ixgbe_down(struct ixgbe_adapter *adapter)
1000 struct net_device *netdev = adapter->netdev;
1001 struct ixgbe_hw *hw = &adapter->hw;
1005 /* signal that we are down to the interrupt handler */
1006 set_bit(__IXGBE_DOWN, &adapter->state);
1008 /* disable receives */
1009 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
1010 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
1012 /* disable all enabled rx queues */
1013 for (i = 0; i < adapter->num_rx_queues; i++)
1014 /* this call also flushes the previous write */
1015 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
1017 usleep_range(10000, 20000);
1019 netif_tx_stop_all_queues(netdev);
1021 /* call carrier off first to avoid false dev_watchdog timeouts */
1022 netif_carrier_off(netdev);
1023 netif_tx_disable(netdev);
1025 ixgbe_irq_disable(adapter);
1027 ixgbe_napi_disable_all(adapter);
1029 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
1030 IXGBE_FLAG2_RESET_REQUESTED);
1031 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
1033 del_timer_sync(&adapter->service_timer);
1035 if (adapter->num_vfs) {
1036 /* Clear EITR Select mapping */
1037 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
1039 /* Mark all the VFs as inactive */
1040 for (i = 0 ; i < adapter->num_vfs; i++)
1041 adapter->vfinfo[i].clear_to_send = 0;
1043 /* ping all the active vfs to let them know we are going down */
1044 ixgbe_ping_all_vfs(adapter);
1046 /* Disable all VFTE/VFRE TX/RX */
1047 ixgbe_disable_tx_rx(adapter);
1050 /* disable transmits in the hardware now that interrupts are off */
1051 for (i = 0; i < adapter->num_tx_queues; i++) {
1052 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
1053 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
1056 /* Disable the Tx DMA engine on 82599 and X540 */
1057 switch (hw->mac.type) {
1058 case ixgbe_mac_82599EB:
1059 case ixgbe_mac_X540:
1060 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
1061 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
1062 ~IXGBE_DMATXCTL_TE));
1069 if (!pci_channel_offline(adapter->pdev))
1071 ixgbe_reset(adapter);
1072 /* power down the optics */
1073 if ((hw->phy.multispeed_fiber) ||
1074 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
1075 (hw->mac.type == ixgbe_mac_82599EB)))
1076 ixgbe_disable_tx_laser(hw);
1078 ixgbe_clean_all_tx_rings(adapter);
1079 ixgbe_clean_all_rx_rings(adapter);
1081 #if defined(CONFIG_DCA) || defined(CONFIG_DCA_MODULE)
1082 /* since we reset the hardware DCA settings were cleared */
1083 ixgbe_setup_dca(adapter);
1086 #endif /* NO_VNIC */
1093 /* Artificial max queue cap per traffic class in DCB mode */
1094 #define DCB_QUEUE_CAP 8
1097 * ixgbe_set_dcb_queues: Allocate queues for a DCB-enabled device
1098 * @adapter: board private structure to initialize
1100 * When DCB (Data Center Bridging) is enabled, allocate queues for
1101 * each traffic class. If multiqueue isn't available,then abort DCB
1104 * This function handles all combinations of DCB, RSS, and FCoE.
1107 static bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
1111 int rss_i, i, offset = 0;
1112 struct net_device *dev = adapter->netdev;
1114 /* Map queue offset and counts onto allocated tx queues */
1115 tcs = netdev_get_num_tc(dev);
1120 rss_i = min_t(int, dev->num_tx_queues / tcs, num_online_cpus());
1122 if (rss_i > DCB_QUEUE_CAP)
1123 rss_i = DCB_QUEUE_CAP;
1125 for (i = 0; i < tcs; i++) {
1126 netdev_set_tc_queue(dev, i, rss_i, offset);
1130 adapter->num_tx_queues = rss_i * tcs;
1131 adapter->num_rx_queues = rss_i * tcs;
1134 /* FCoE enabled queues require special configuration indexed
1135 * by feature specific indices and mask. Here we map FCoE
1136 * indices onto the DCB queue pairs allowing FCoE to own
1137 * configuration later.
1140 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
1141 struct ixgbe_ring_feature *f;
1143 u8 prio_tc[IXGBE_DCB_MAX_USER_PRIORITY] = {0};
1145 ixgbe_dcb_unpack_map_cee(&adapter->dcb_cfg,
1146 IXGBE_DCB_TX_CONFIG,
1148 tc = prio_tc[adapter->fcoe.up];
1150 f = &adapter->ring_feature[RING_F_FCOE];
1151 f->indices = min_t(int, rss_i, f->indices);
1152 f->mask = rss_i * tc;
1154 #endif /* IXGBE_FCOE */
1156 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
1159 /* Enable one Queue per traffic class */
1165 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
1166 struct ixgbe_ring_feature *f;
1167 int tc = netdev_get_prio_tc_map(adapter->netdev,
1170 f = &adapter->ring_feature[RING_F_FCOE];
1173 * We have max 8 queues for FCoE, where 8 the is
1174 * FCoE redirection table size. We must also share
1175 * ring resources with network traffic so if FCoE TC is
1176 * 4 or greater and we are in 8 TC mode we can only use
1179 if ((tcs > 4) && (tc >= 4) && (f->indices > 7))
1182 f->indices = min_t(int, num_online_cpus(), f->indices);
1185 adapter->num_rx_queues = f->indices + tcs;
1186 adapter->num_tx_queues = f->indices + tcs;
1191 #endif /* IXGBE_FCOE */
1192 adapter->num_rx_queues = tcs;
1193 adapter->num_tx_queues = tcs;
1194 #endif /* HAVE_MQ */
1200 * ixgbe_set_vmdq_queues: Allocate queues for VMDq devices
1201 * @adapter: board private structure to initialize
1203 * When VMDq (Virtual Machine Devices queue) is enabled, allocate queues
1204 * and VM pools where appropriate. If RSS is available, then also try and
1205 * enable RSS and map accordingly.
1208 static bool ixgbe_set_vmdq_queues(struct ixgbe_adapter *adapter)
1210 int vmdq_i = adapter->ring_feature[RING_F_VMDQ].indices;
1212 int rss_i = adapter->ring_feature[RING_F_RSS].indices;
1218 switch (adapter->flags & (IXGBE_FLAG_RSS_ENABLED
1219 | IXGBE_FLAG_DCB_ENABLED
1220 | IXGBE_FLAG_VMDQ_ENABLED)) {
1222 case (IXGBE_FLAG_RSS_ENABLED | IXGBE_FLAG_VMDQ_ENABLED):
1223 switch (adapter->hw.mac.type) {
1224 case ixgbe_mac_82599EB:
1225 case ixgbe_mac_X540:
1226 vmdq_i = min((int)IXGBE_MAX_VMDQ_INDICES, vmdq_i);
1232 rss_shift = find_first_bit(&i, sizeof(i) * 8);
1233 vmdq_m = ((IXGBE_MAX_VMDQ_INDICES - 1) <<
1234 rss_shift) & (MAX_RX_QUEUES - 1);
1239 adapter->num_rx_queues = vmdq_i * rss_i;
1240 adapter->num_tx_queues = min((int)MAX_TX_QUEUES, vmdq_i * rss_i);
1244 case (IXGBE_FLAG_VMDQ_ENABLED):
1245 switch (adapter->hw.mac.type) {
1246 case ixgbe_mac_82598EB:
1247 vmdq_m = (IXGBE_MAX_VMDQ_INDICES - 1);
1249 case ixgbe_mac_82599EB:
1250 case ixgbe_mac_X540:
1251 vmdq_m = (IXGBE_MAX_VMDQ_INDICES - 1) << 1;
1256 adapter->num_rx_queues = vmdq_i;
1257 adapter->num_tx_queues = vmdq_i;
1263 goto vmdq_queues_out;
1266 if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) {
1267 adapter->num_rx_pools = vmdq_i;
1268 adapter->num_rx_queues_per_pool = adapter->num_rx_queues /
1271 adapter->num_rx_pools = adapter->num_rx_queues;
1272 adapter->num_rx_queues_per_pool = 1;
1274 /* save the mask for later use */
1275 adapter->ring_feature[RING_F_VMDQ].mask = vmdq_m;
1281 * ixgbe_set_rss_queues: Allocate queues for RSS
1282 * @adapter: board private structure to initialize
1284 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
1285 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
1288 static bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
1290 struct ixgbe_ring_feature *f;
1292 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
1293 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
1297 /* set mask for 16 queue limit of RSS */
1298 f = &adapter->ring_feature[RING_F_RSS];
1302 * Use Flow Director in addition to RSS to ensure the best
1303 * distribution of flows across cores, even when an FDIR flow
1306 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
1307 f = &adapter->ring_feature[RING_F_FDIR];
1309 f->indices = min_t(int, num_online_cpus(), f->indices);
1313 adapter->num_rx_queues = f->indices;
1315 adapter->num_tx_queues = f->indices;
1323 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
1324 * @adapter: board private structure to initialize
1326 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
1327 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
1328 * rx queues out of the max number of rx queues, instead, it is used as the
1329 * index of the first rx queue used by FCoE.
1332 static bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
1334 struct ixgbe_ring_feature *f;
1336 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
1339 ixgbe_set_rss_queues(adapter);
1341 f = &adapter->ring_feature[RING_F_FCOE];
1342 f->indices = min_t(int, num_online_cpus(), f->indices);
1344 /* adding FCoE queues */
1345 f->mask = adapter->num_rx_queues;
1346 adapter->num_rx_queues += f->indices;
1347 adapter->num_tx_queues += f->indices;
1352 #endif /* IXGBE_FCOE */
1354 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
1355 * @adapter: board private structure to initialize
1357 * This is the top level queue allocation routine. The order here is very
1358 * important, starting with the "most" number of features turned on at once,
1359 * and ending with the smallest set of features. This way large combinations
1360 * can be allocated if they're turned on, and smaller combinations are the
1361 * fallthrough conditions.
1364 static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
1366 /* Start with base case */
1367 adapter->num_rx_queues = 1;
1368 adapter->num_tx_queues = 1;
1369 adapter->num_rx_pools = adapter->num_rx_queues;
1370 adapter->num_rx_queues_per_pool = 1;
1372 if (ixgbe_set_vmdq_queues(adapter))
1375 if (ixgbe_set_dcb_queues(adapter))
1379 if (ixgbe_set_fcoe_queues(adapter))
1382 #endif /* IXGBE_FCOE */
1383 ixgbe_set_rss_queues(adapter);
1390 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
1391 * @adapter: board private structure to initialize
1393 * ixgbe_sw_init initializes the Adapter private data structure.
1394 * Fields are initialized based on PCI device information and
1395 * OS network device settings (MTU size).
1397 static int ixgbe_sw_init(struct ixgbe_adapter *adapter)
1399 struct ixgbe_hw *hw = &adapter->hw;
1400 struct pci_dev *pdev = adapter->pdev;
1403 /* PCI config space info */
1405 hw->vendor_id = pdev->vendor;
1406 hw->device_id = pdev->device;
1407 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
1408 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1409 hw->subsystem_device_id = pdev->subsystem_device;
1411 err = ixgbe_init_shared_code(hw);
1413 e_err(probe, "init_shared_code failed: %d\n", err);
1416 adapter->mac_table = kzalloc(sizeof(struct ixgbe_mac_addr) *
1417 hw->mac.num_rar_entries,
1419 /* Set capability flags */
1420 switch (hw->mac.type) {
1421 case ixgbe_mac_82598EB:
1422 adapter->flags |= IXGBE_FLAG_MSI_CAPABLE |
1423 IXGBE_FLAG_MSIX_CAPABLE |
1424 IXGBE_FLAG_MQ_CAPABLE |
1425 IXGBE_FLAG_RSS_CAPABLE;
1426 adapter->flags |= IXGBE_FLAG_DCB_CAPABLE;
1427 #if defined(CONFIG_DCA) || defined(CONFIG_DCA_MODULE)
1428 adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
1430 adapter->flags &= ~IXGBE_FLAG_SRIOV_CAPABLE;
1431 adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE;
1433 if (hw->device_id == IXGBE_DEV_ID_82598AT)
1434 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
1436 adapter->max_msix_q_vectors = IXGBE_MAX_MSIX_Q_VECTORS_82598;
1438 case ixgbe_mac_X540:
1439 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
1440 case ixgbe_mac_82599EB:
1441 adapter->flags |= IXGBE_FLAG_MSI_CAPABLE |
1442 IXGBE_FLAG_MSIX_CAPABLE |
1443 IXGBE_FLAG_MQ_CAPABLE |
1444 IXGBE_FLAG_RSS_CAPABLE;
1445 adapter->flags |= IXGBE_FLAG_DCB_CAPABLE;
1446 #if defined(CONFIG_DCA) || defined(CONFIG_DCA_MODULE)
1447 adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
1449 adapter->flags |= IXGBE_FLAG_SRIOV_CAPABLE;
1450 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
1452 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
1453 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
1454 adapter->ring_feature[RING_F_FCOE].indices = 0;
1456 /* Default traffic class to use for FCoE */
1457 adapter->fcoe.tc = IXGBE_FCOE_DEFTC;
1458 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
1459 adapter->fcoe.up_set = IXGBE_FCOE_DEFTC;
1462 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
1463 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
1464 #ifndef IXGBE_NO_SMART_SPEED
1465 hw->phy.smart_speed = ixgbe_smart_speed_on;
1467 hw->phy.smart_speed = ixgbe_smart_speed_off;
1469 adapter->max_msix_q_vectors = IXGBE_MAX_MSIX_Q_VECTORS_82599;
1474 /* n-tuple support exists, always init our spinlock */
1475 //spin_lock_init(&adapter->fdir_perfect_lock);
1477 if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE) {
1479 struct ixgbe_dcb_tc_config *tc;
1480 int dcb_i = IXGBE_DCB_MAX_TRAFFIC_CLASS;
1483 adapter->dcb_cfg.num_tcs.pg_tcs = dcb_i;
1484 adapter->dcb_cfg.num_tcs.pfc_tcs = dcb_i;
1485 for (j = 0; j < dcb_i; j++) {
1486 tc = &adapter->dcb_cfg.tc_config[j];
1487 tc->path[IXGBE_DCB_TX_CONFIG].bwg_id = 0;
1488 tc->path[IXGBE_DCB_TX_CONFIG].bwg_percent = 100 / dcb_i;
1489 tc->path[IXGBE_DCB_RX_CONFIG].bwg_id = 0;
1490 tc->path[IXGBE_DCB_RX_CONFIG].bwg_percent = 100 / dcb_i;
1491 tc->pfc = ixgbe_dcb_pfc_disabled;
1493 /* total of all TCs bandwidth needs to be 100 */
1494 tc->path[IXGBE_DCB_TX_CONFIG].bwg_percent +=
1496 tc->path[IXGBE_DCB_RX_CONFIG].bwg_percent +=
1501 /* Initialize default user to priority mapping, UPx->TC0 */
1502 tc = &adapter->dcb_cfg.tc_config[0];
1503 tc->path[IXGBE_DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
1504 tc->path[IXGBE_DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
1506 adapter->dcb_cfg.bw_percentage[IXGBE_DCB_TX_CONFIG][0] = 100;
1507 adapter->dcb_cfg.bw_percentage[IXGBE_DCB_RX_CONFIG][0] = 100;
1508 adapter->dcb_cfg.rx_pba_cfg = ixgbe_dcb_pba_equal;
1509 adapter->dcb_cfg.pfc_mode_enable = false;
1510 adapter->dcb_cfg.round_robin_enable = false;
1511 adapter->dcb_set_bitmap = 0x00;
1513 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
1514 #endif /* CONFIG_DCB */
1516 if (hw->mac.type == ixgbe_mac_X540) {
1517 adapter->dcb_cfg.num_tcs.pg_tcs = 4;
1518 adapter->dcb_cfg.num_tcs.pfc_tcs = 4;
1522 /* XXX does this need to be initialized even w/o DCB? */
1523 //memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
1524 // sizeof(adapter->temp_dcb_cfg));
1527 //if (hw->mac.type == ixgbe_mac_82599EB ||
1528 // hw->mac.type == ixgbe_mac_X540)
1529 // hw->mbx.ops.init_params(hw);
1531 /* default flow control settings */
1532 hw->fc.requested_mode = ixgbe_fc_full;
1533 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
1535 adapter->last_lfc_mode = hw->fc.current_mode;
1536 ixgbe_pbthresh_setup(adapter);
1537 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
1538 hw->fc.send_xon = true;
1539 hw->fc.disable_fc_autoneg = false;
1541 /* set default ring sizes */
1542 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
1543 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
1545 /* set default work limits */
1546 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
1547 adapter->rx_work_limit = IXGBE_DEFAULT_RX_WORK;
1549 set_bit(__IXGBE_DOWN, &adapter->state);
1555 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
1556 * @tx_ring: tx descriptor ring (for a specific queue) to setup
1558 * Return 0 on success, negative on failure
1560 int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
1562 struct device *dev = tx_ring->dev;
1563 //int orig_node = dev_to_node(dev);
1567 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
1569 if (tx_ring->q_vector)
1570 numa_node = tx_ring->q_vector->numa_node;
1572 tx_ring->tx_buffer_info = vzalloc_node(size, numa_node);
1573 if (!tx_ring->tx_buffer_info)
1574 tx_ring->tx_buffer_info = vzalloc(size);
1575 if (!tx_ring->tx_buffer_info)
1578 /* round up to nearest 4K */
1579 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
1580 tx_ring->size = ALIGN(tx_ring->size, 4096);
1582 //set_dev_node(dev, numa_node);
1583 //tx_ring->desc = dma_alloc_coherent(dev,
1587 //set_dev_node(dev, orig_node);
1588 //if (!tx_ring->desc)
1589 // tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
1590 // &tx_ring->dma, GFP_KERNEL);
1591 //if (!tx_ring->desc)
1597 vfree(tx_ring->tx_buffer_info);
1598 tx_ring->tx_buffer_info = NULL;
1599 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
1604 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
1605 * @adapter: board private structure
1607 * If this function returns with an error, then it's possible one or
1608 * more of the rings is populated (while the rest are not). It is the
1609 * callers duty to clean those orphaned rings.
1611 * Return 0 on success, negative on failure
1613 static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
1617 for (i = 0; i < adapter->num_tx_queues; i++) {
1618 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
1621 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
1629 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
1630 * @rx_ring: rx descriptor ring (for a specific queue) to setup
1632 * Returns 0 on success, negative on failure
1634 int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
1636 struct device *dev = rx_ring->dev;
1637 //int orig_node = dev_to_node(dev);
1641 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
1643 if (rx_ring->q_vector)
1644 numa_node = rx_ring->q_vector->numa_node;
1646 rx_ring->rx_buffer_info = vzalloc_node(size, numa_node);
1647 if (!rx_ring->rx_buffer_info)
1648 rx_ring->rx_buffer_info = vzalloc(size);
1649 if (!rx_ring->rx_buffer_info)
1652 /* Round up to nearest 4K */
1653 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
1654 rx_ring->size = ALIGN(rx_ring->size, 4096);
1657 set_dev_node(dev, numa_node);
1658 rx_ring->desc = dma_alloc_coherent(dev,
1662 set_dev_node(dev, orig_node);
1664 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
1665 &rx_ring->dma, GFP_KERNEL);
1669 #ifndef CONFIG_IXGBE_DISABLE_PACKET_SPLIT
1670 ixgbe_init_rx_page_offset(rx_ring);
1674 #endif /* NO_VNIC */
1677 vfree(rx_ring->rx_buffer_info);
1678 rx_ring->rx_buffer_info = NULL;
1679 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
1684 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
1685 * @adapter: board private structure
1687 * If this function returns with an error, then it's possible one or
1688 * more of the rings is populated (while the rest are not). It is the
1689 * callers duty to clean those orphaned rings.
1691 * Return 0 on success, negative on failure
1693 static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
1697 for (i = 0; i < adapter->num_rx_queues; i++) {
1698 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
1701 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
1709 * ixgbe_free_tx_resources - Free Tx Resources per Queue
1710 * @tx_ring: Tx descriptor ring for a specific queue
1712 * Free all transmit software resources
1714 void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
1716 //ixgbe_clean_tx_ring(tx_ring);
1718 vfree(tx_ring->tx_buffer_info);
1719 tx_ring->tx_buffer_info = NULL;
1721 /* if not set, then don't free */
1725 //dma_free_coherent(tx_ring->dev, tx_ring->size,
1726 // tx_ring->desc, tx_ring->dma);
1728 tx_ring->desc = NULL;
1732 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
1733 * @adapter: board private structure
1735 * Free all transmit software resources
1737 static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
1741 for (i = 0; i < adapter->num_tx_queues; i++)
1742 if (adapter->tx_ring[i]->desc)
1743 ixgbe_free_tx_resources(adapter->tx_ring[i]);
1747 * ixgbe_free_rx_resources - Free Rx Resources
1748 * @rx_ring: ring to clean the resources from
1750 * Free all receive software resources
1752 void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
1754 //ixgbe_clean_rx_ring(rx_ring);
1756 vfree(rx_ring->rx_buffer_info);
1757 rx_ring->rx_buffer_info = NULL;
1759 /* if not set, then don't free */
1763 //dma_free_coherent(rx_ring->dev, rx_ring->size,
1764 // rx_ring->desc, rx_ring->dma);
1766 rx_ring->desc = NULL;
1770 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
1771 * @adapter: board private structure
1773 * Free all receive software resources
1775 static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
1779 for (i = 0; i < adapter->num_rx_queues; i++)
1780 if (adapter->rx_ring[i]->desc)
1781 ixgbe_free_rx_resources(adapter->rx_ring[i]);
1786 * ixgbe_open - Called when a network interface is made active
1787 * @netdev: network interface device structure
1789 * Returns 0 on success, negative value on failure
1791 * The open entry point is called when a network interface is made
1792 * active by the system (IFF_UP). At this point all resources needed
1793 * for transmit and receive operations are allocated, the interrupt
1794 * handler is registered with the OS, the watchdog timer is started,
1795 * and the stack is notified that the interface is ready.
1798 int ixgbe_open(struct net_device *netdev)
1800 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1803 /* disallow open during test */
1804 if (test_bit(__IXGBE_TESTING, &adapter->state))
1807 netif_carrier_off(netdev);
1809 /* allocate transmit descriptors */
1810 err = ixgbe_setup_all_tx_resources(adapter);
1814 /* allocate receive descriptors */
1815 err = ixgbe_setup_all_rx_resources(adapter);
1820 ixgbe_configure(adapter);
1822 err = ixgbe_request_irq(adapter);
1826 ixgbe_up_complete(adapter);
1833 ixgbe_free_all_rx_resources(adapter);
1835 ixgbe_free_all_tx_resources(adapter);
1836 ixgbe_reset(adapter);
1842 * ixgbe_close - Disables a network interface
1843 * @netdev: network interface device structure
1845 * Returns 0, this is not allowed to fail
1847 * The close entry point is called when an interface is de-activated
1848 * by the OS. The hardware is still under the drivers control, but
1849 * needs to be disabled. A global MAC reset is issued to stop the
1850 * hardware, and all transmit and receive resources are freed.
1853 int ixgbe_close(struct net_device *netdev)
1855 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1857 //ixgbe_down(adapter);
1858 //ixgbe_free_irq(adapter);
1860 //ixgbe_fdir_filter_exit(adapter);
1862 //ixgbe_free_all_tx_resources(adapter);
1863 //ixgbe_free_all_rx_resources(adapter);
1865 ixgbe_release_hw_control(adapter);
1875 * ixgbe_get_stats - Get System Network Statistics
1876 * @netdev: network interface device structure
1878 * Returns the address of the device statistics structure.
1879 * The statistics are actually updated from the timer callback.
1882 struct net_device_stats *ixgbe_get_stats(struct net_device *netdev)
1884 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1886 /* update the stats data */
1887 ixgbe_update_stats(adapter);
1889 #ifdef HAVE_NETDEV_STATS_IN_NETDEV
1890 /* only return the current stats */
1891 return &netdev->stats;
1893 /* only return the current stats */
1894 return &adapter->net_stats;
1895 #endif /* HAVE_NETDEV_STATS_IN_NETDEV */
1899 * ixgbe_update_stats - Update the board statistics counters.
1900 * @adapter: board private structure
1902 void ixgbe_update_stats(struct ixgbe_adapter *adapter)
1904 #ifdef HAVE_NETDEV_STATS_IN_NETDEV
1905 struct net_device_stats *net_stats = &adapter->netdev->stats;
1907 struct net_device_stats *net_stats = &adapter->net_stats;
1908 #endif /* HAVE_NETDEV_STATS_IN_NETDEV */
1909 struct ixgbe_hw *hw = &adapter->hw;
1910 struct ixgbe_hw_stats *hwstats = &adapter->stats;
1912 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
1913 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
1914 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
1915 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
1916 #ifndef IXGBE_NO_LRO
1917 u32 flushed = 0, coal = 0;
1918 int num_q_vectors = 1;
1921 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
1923 u64 fcoe_noddp_counts_sum = 0, fcoe_noddp_ext_buff_counts_sum = 0;
1924 #endif /* IXGBE_FCOE */
1926 printk(KERN_DEBUG "ixgbe_update_stats, tx_queues=%d, rx_queues=%d\n",
1927 adapter->num_tx_queues, adapter->num_rx_queues);
1929 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
1930 test_bit(__IXGBE_RESETTING, &adapter->state))
1933 #ifndef IXGBE_NO_LRO
1934 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
1935 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1938 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
1941 for (i = 0; i < adapter->num_rx_queues; i++) {
1942 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
1943 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
1945 adapter->rsc_total_count = rsc_count;
1946 adapter->rsc_total_flush = rsc_flush;
1949 #ifndef IXGBE_NO_LRO
1950 for (i = 0; i < num_q_vectors; i++) {
1951 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
1954 flushed += q_vector->lrolist.stats.flushed;
1955 coal += q_vector->lrolist.stats.coal;
1957 adapter->lro_stats.flushed = flushed;
1958 adapter->lro_stats.coal = coal;
1961 for (i = 0; i < adapter->num_rx_queues; i++) {
1962 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
1963 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
1964 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
1965 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
1966 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
1967 bytes += rx_ring->stats.bytes;
1968 packets += rx_ring->stats.packets;
1971 adapter->non_eop_descs = non_eop_descs;
1972 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
1973 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
1974 adapter->hw_csum_rx_error = hw_csum_rx_error;
1975 net_stats->rx_bytes = bytes;
1976 net_stats->rx_packets = packets;
1980 /* gather some stats to the adapter struct that are per queue */
1981 for (i = 0; i < adapter->num_tx_queues; i++) {
1982 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
1983 restart_queue += tx_ring->tx_stats.restart_queue;
1984 tx_busy += tx_ring->tx_stats.tx_busy;
1985 bytes += tx_ring->stats.bytes;
1986 packets += tx_ring->stats.packets;
1988 adapter->restart_queue = restart_queue;
1989 adapter->tx_busy = tx_busy;
1990 net_stats->tx_bytes = bytes;
1991 net_stats->tx_packets = packets;
1993 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
1995 /* 8 register reads */
1996 for (i = 0; i < 8; i++) {
1997 /* for packet buffers not used, the register should read 0 */
1998 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
2000 hwstats->mpc[i] += mpc;
2001 total_mpc += hwstats->mpc[i];
2002 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
2003 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
2004 switch (hw->mac.type) {
2005 case ixgbe_mac_82598EB:
2006 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
2007 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
2008 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
2009 hwstats->pxonrxc[i] +=
2010 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
2012 case ixgbe_mac_82599EB:
2013 case ixgbe_mac_X540:
2014 hwstats->pxonrxc[i] +=
2015 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
2022 /*16 register reads */
2023 for (i = 0; i < 16; i++) {
2024 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
2025 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
2026 if ((hw->mac.type == ixgbe_mac_82599EB) ||
2027 (hw->mac.type == ixgbe_mac_X540)) {
2028 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
2029 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
2030 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
2031 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
2035 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
2036 /* work around hardware counting issue */
2037 hwstats->gprc -= missed_rx;
2039 ixgbe_update_xoff_received(adapter);
2041 /* 82598 hardware only has a 32 bit counter in the high register */
2042 switch (hw->mac.type) {
2043 case ixgbe_mac_82598EB:
2044 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
2045 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
2046 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
2047 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
2049 case ixgbe_mac_X540:
2050 /* OS2BMC stats are X540 only*/
2051 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
2052 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
2053 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
2054 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
2055 case ixgbe_mac_82599EB:
2056 for (i = 0; i < 16; i++)
2057 adapter->hw_rx_no_dma_resources +=
2058 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
2059 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
2060 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
2061 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
2062 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
2063 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
2064 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
2065 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
2067 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
2068 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
2069 #endif /* HAVE_TX_MQ */
2071 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
2072 hwstats->fclast += IXGBE_READ_REG(hw, IXGBE_FCLAST);
2073 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
2074 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
2075 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
2076 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
2077 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
2078 /* Add up per cpu counters for total ddp aloc fail */
2079 if (fcoe && fcoe->pcpu_noddp && fcoe->pcpu_noddp_ext_buff) {
2080 for_each_possible_cpu(cpu) {
2081 fcoe_noddp_counts_sum +=
2082 *per_cpu_ptr(fcoe->pcpu_noddp, cpu);
2083 fcoe_noddp_ext_buff_counts_sum +=
2085 pcpu_noddp_ext_buff, cpu);
2088 hwstats->fcoe_noddp = fcoe_noddp_counts_sum;
2089 hwstats->fcoe_noddp_ext_buff = fcoe_noddp_ext_buff_counts_sum;
2091 #endif /* IXGBE_FCOE */
2096 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
2097 hwstats->bprc += bprc;
2098 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
2099 if (hw->mac.type == ixgbe_mac_82598EB)
2100 hwstats->mprc -= bprc;
2101 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
2102 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
2103 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
2104 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
2105 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
2106 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
2107 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
2108 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
2109 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
2110 hwstats->lxontxc += lxon;
2111 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
2112 hwstats->lxofftxc += lxoff;
2113 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
2114 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
2116 * 82598 errata - tx of flow control packets is included in tx counters
2118 xon_off_tot = lxon + lxoff;
2119 hwstats->gptc -= xon_off_tot;
2120 hwstats->mptc -= xon_off_tot;
2121 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
2122 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
2123 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
2124 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
2125 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
2126 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
2127 hwstats->ptc64 -= xon_off_tot;
2128 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
2129 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
2130 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
2131 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
2132 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
2133 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
2134 /* Fill out the OS statistics structure */
2135 net_stats->multicast = hwstats->mprc;
2138 net_stats->rx_errors = hwstats->crcerrs +
2140 net_stats->rx_dropped = 0;
2141 net_stats->rx_length_errors = hwstats->rlec;
2142 net_stats->rx_crc_errors = hwstats->crcerrs;
2143 net_stats->rx_missed_errors = total_mpc;
2146 * VF Stats Collection - skip while resetting because these
2147 * are not clear on read and otherwise you'll sometimes get
2150 if (!test_bit(__IXGBE_RESETTING, &adapter->state)) {
2151 for (i = 0; i < adapter->num_vfs; i++) {
2152 UPDATE_VF_COUNTER_32bit(IXGBE_PVFGPRC(i), \
2153 adapter->vfinfo[i].last_vfstats.gprc, \
2154 adapter->vfinfo[i].vfstats.gprc);
2155 UPDATE_VF_COUNTER_32bit(IXGBE_PVFGPTC(i), \
2156 adapter->vfinfo[i].last_vfstats.gptc, \
2157 adapter->vfinfo[i].vfstats.gptc);
2158 UPDATE_VF_COUNTER_36bit(IXGBE_PVFGORC_LSB(i), \
2159 IXGBE_PVFGORC_MSB(i), \
2160 adapter->vfinfo[i].last_vfstats.gorc, \
2161 adapter->vfinfo[i].vfstats.gorc);
2162 UPDATE_VF_COUNTER_36bit(IXGBE_PVFGOTC_LSB(i), \
2163 IXGBE_PVFGOTC_MSB(i), \
2164 adapter->vfinfo[i].last_vfstats.gotc, \
2165 adapter->vfinfo[i].vfstats.gotc);
2166 UPDATE_VF_COUNTER_32bit(IXGBE_PVFMPRC(i), \
2167 adapter->vfinfo[i].last_vfstats.mprc, \
2168 adapter->vfinfo[i].vfstats.mprc);
2177 * ixgbe_watchdog_update_link - update the link status
2178 * @adapter - pointer to the device adapter structure
2179 * @link_speed - pointer to a u32 to store the link_speed
2181 static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
2183 struct ixgbe_hw *hw = &adapter->hw;
2184 u32 link_speed = adapter->link_speed;
2185 bool link_up = adapter->link_up;
2186 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
2188 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
2191 if (hw->mac.ops.check_link) {
2192 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
2194 /* always assume link is up, if no check link function */
2195 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
2199 #ifdef HAVE_DCBNL_IEEE
2200 if (adapter->ixgbe_ieee_pfc)
2201 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
2204 if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
2205 hw->mac.ops.fc_enable(hw);
2206 //ixgbe_set_rx_drop_en(adapter);
2210 time_after(jiffies, (adapter->link_check_timeout +
2211 IXGBE_TRY_LINK_TIMEOUT))) {
2212 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
2213 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
2214 IXGBE_WRITE_FLUSH(hw);
2217 adapter->link_up = link_up;
2218 adapter->link_speed = link_speed;
2227 * ixgbe_service_task - manages and runs subtasks
2228 * @work: pointer to work_struct containing our data
2230 static void ixgbe_service_task(struct work_struct *work)
2232 //struct ixgbe_adapter *adapter = container_of(work,
2233 // struct ixgbe_adapter,
2236 //ixgbe_reset_subtask(adapter);
2237 //ixgbe_sfp_detection_subtask(adapter);
2238 //ixgbe_sfp_link_config_subtask(adapter);
2239 //ixgbe_check_overtemp_subtask(adapter);
2240 //ixgbe_watchdog_subtask(adapter);
2242 //ixgbe_fdir_reinit_subtask(adapter);
2244 //ixgbe_check_hang_subtask(adapter);
2246 //ixgbe_service_event_complete(adapter);
2252 #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
2257 * ixgbe_set_mac - Change the Ethernet Address of the NIC
2258 * @netdev: network interface device structure
2259 * @p: pointer to an address structure
2261 * Returns 0 on success, negative on failure
2263 static int ixgbe_set_mac(struct net_device *netdev, void *p)
2265 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2266 struct ixgbe_hw *hw = &adapter->hw;
2267 struct sockaddr *addr = p;
2270 if (!is_valid_ether_addr(addr->sa_data))
2271 return -EADDRNOTAVAIL;
2273 ixgbe_del_mac_filter(adapter, hw->mac.addr,
2275 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2276 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
2279 /* set the correct pool for the new PF MAC address in entry 0 */
2280 ret = ixgbe_add_mac_filter(adapter, hw->mac.addr,
2282 return (ret > 0 ? 0 : ret);
2292 static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
2295 #ifdef ETHTOOL_OPS_COMPAT
2297 return ethtool_ioctl(ifr);
2303 #endif /* NO_VNIC */
2306 void ixgbe_do_reset(struct net_device *netdev)
2308 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2310 if (netif_running(netdev))
2311 ixgbe_reinit_locked(adapter);
2313 ixgbe_reset(adapter);
2322 * ixgbe_probe - Device Initialization Routine
2323 * @pdev: PCI device information struct
2324 * @ent: entry in ixgbe_pci_tbl
2326 * Returns 0 on success, negative on failure
2328 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
2329 * The OS initialization, configuring of the adapter private structure,
2330 * and a hardware reset occur.
2333 int ixgbe_kni_probe(struct pci_dev *pdev,
2334 struct net_device **lad_dev)
2337 struct net_device *netdev;
2338 struct ixgbe_adapter *adapter = NULL;
2339 struct ixgbe_hw *hw = NULL;
2340 static int cards_found;
2343 u16 eeprom_verh, eeprom_verl, eeprom_cfg_blkh, eeprom_cfg_blkl;
2345 u16 build, major, patch;
2346 char *info_string, *i_s_var;
2347 u8 part_str[IXGBE_PBANUM_LENGTH];
2348 enum ixgbe_mac_type mac_type = ixgbe_mac_unknown;
2350 unsigned int indices = num_possible_cpus();
2351 #endif /* HAVE_TX_MQ */
2357 err = pci_enable_device_mem(pdev);
2363 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
2364 IORESOURCE_MEM), ixgbe_driver_name);
2366 dev_err(pci_dev_to_dev(pdev),
2367 "pci_request_selected_regions failed 0x%x\n", err);
2373 * The mac_type is needed before we have the adapter is set up
2374 * so rather than maintain two devID -> MAC tables we dummy up
2375 * an ixgbe_hw stuct and use ixgbe_set_mac_type.
2377 hw = vmalloc(sizeof(struct ixgbe_hw));
2379 pr_info("Unable to allocate memory for early mac "
2382 hw->vendor_id = pdev->vendor;
2383 hw->device_id = pdev->device;
2384 ixgbe_set_mac_type(hw);
2385 mac_type = hw->mac.type;
2391 * Workaround of Silicon errata on 82598. Disable LOs in the PCI switch
2392 * port to which the 82598 is connected to prevent duplicate
2393 * completions caused by LOs. We need the mac type so that we only
2394 * do this on 82598 devices, ixgbe_set_mac_type does this for us if
2395 * we set it's device ID.
2397 if (mac_type == ixgbe_mac_82598EB)
2398 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S);
2400 pci_enable_pcie_error_reporting(pdev);
2402 pci_set_master(pdev);
2408 indices *= IXGBE_DCB_MAX_TRAFFIC_CLASS;
2410 indices = max_t(unsigned int, indices, IXGBE_MAX_DCB_INDICES);
2411 #endif /* HAVE_MQPRIO */
2412 #endif /* CONFIG_DCB */
2414 if (mac_type == ixgbe_mac_82598EB)
2415 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
2417 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
2420 indices += min_t(unsigned int, num_possible_cpus(),
2421 IXGBE_MAX_FCOE_INDICES);
2423 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
2424 #else /* HAVE_TX_MQ */
2425 netdev = alloc_etherdev(sizeof(struct ixgbe_adapter));
2426 #endif /* HAVE_TX_MQ */
2429 goto err_alloc_etherdev;
2432 SET_NETDEV_DEV(netdev, &pdev->dev);
2434 adapter = netdev_priv(netdev);
2435 //pci_set_drvdata(pdev, adapter);
2437 adapter->netdev = netdev;
2438 adapter->pdev = pdev;
2441 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
2445 * call save state here in standalone driver because it relies on
2446 * adapter struct to exist, and needs to call netdev_priv
2448 pci_save_state(pdev);
2451 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
2452 pci_resource_len(pdev, 0));
2457 //ixgbe_assign_netdev_ops(netdev);
2458 ixgbe_set_ethtool_ops(netdev);
2460 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
2462 adapter->bd_number = cards_found;
2464 /* setup the private structure */
2465 err = ixgbe_sw_init(adapter);
2469 /* Make it possible the adapter to be woken up via WOL */
2470 switch (adapter->hw.mac.type) {
2471 case ixgbe_mac_82599EB:
2472 case ixgbe_mac_X540:
2473 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
2480 * check_options must be called before setup_link to set up
2483 //ixgbe_check_options(adapter);
2486 /* reset_hw fills in the perm_addr as well */
2487 hw->phy.reset_if_overtemp = true;
2488 err = hw->mac.ops.reset_hw(hw);
2489 hw->phy.reset_if_overtemp = false;
2490 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
2491 hw->mac.type == ixgbe_mac_82598EB) {
2493 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
2494 e_dev_err("failed to load because an unsupported SFP+ "
2495 "module type was detected.\n");
2496 e_dev_err("Reload the driver after installing a supported "
2500 e_dev_err("HW Init failed: %d\n", err);
2505 //if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
2506 // ixgbe_probe_vf(adapter);
2509 #ifdef MAX_SKB_FRAGS
2510 netdev->features |= NETIF_F_SG |
2513 #ifdef NETIF_F_IPV6_CSUM
2514 netdev->features |= NETIF_F_IPV6_CSUM;
2517 #ifdef NETIF_F_HW_VLAN_TX
2518 netdev->features |= NETIF_F_HW_VLAN_TX |
2522 netdev->features |= NETIF_F_TSO;
2523 #endif /* NETIF_F_TSO */
2525 netdev->features |= NETIF_F_TSO6;
2526 #endif /* NETIF_F_TSO6 */
2527 #ifdef NETIF_F_RXHASH
2528 netdev->features |= NETIF_F_RXHASH;
2529 #endif /* NETIF_F_RXHASH */
2531 #ifdef HAVE_NDO_SET_FEATURES
2532 netdev->features |= NETIF_F_RXCSUM;
2534 /* copy netdev features into list of user selectable features */
2535 netdev->hw_features |= netdev->features;
2537 /* give us the option of enabling RSC/LRO later */
2539 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
2541 netdev->hw_features |= NETIF_F_LRO;
2546 /* this is only needed on kernels prior to 2.6.39 */
2547 netdev->features |= NETIF_F_GRO;
2548 #endif /* NETIF_F_GRO */
2551 #ifdef NETIF_F_HW_VLAN_TX
2552 /* set this bit last since it cannot be part of hw_features */
2553 netdev->features |= NETIF_F_HW_VLAN_FILTER;
2555 switch (adapter->hw.mac.type) {
2556 case ixgbe_mac_82599EB:
2557 case ixgbe_mac_X540:
2558 netdev->features |= NETIF_F_SCTP_CSUM;
2559 #ifdef HAVE_NDO_SET_FEATURES
2560 netdev->hw_features |= NETIF_F_SCTP_CSUM |
2568 #ifdef HAVE_NETDEV_VLAN_FEATURES
2569 netdev->vlan_features |= NETIF_F_SG |
2575 #endif /* HAVE_NETDEV_VLAN_FEATURES */
2577 * If perfect filters were enabled in check_options(), enable them
2578 * on the netdevice too.
2580 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
2581 netdev->features |= NETIF_F_NTUPLE;
2582 if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED)
2583 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
2584 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
2585 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
2586 if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) {
2587 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
2588 /* clear n-tuple support in the netdev unconditionally */
2589 netdev->features &= ~NETIF_F_NTUPLE;
2592 #ifdef NETIF_F_RXHASH
2593 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
2594 netdev->features &= ~NETIF_F_RXHASH;
2596 #endif /* NETIF_F_RXHASH */
2597 if (netdev->features & NETIF_F_LRO) {
2598 if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
2599 ((adapter->rx_itr_setting == 1) ||
2600 (adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR))) {
2601 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
2602 } else if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) {
2604 e_info(probe, "InterruptThrottleRate set too high, "
2607 e_info(probe, "InterruptThrottleRate set too high, "
2608 "falling back to software LRO\n");
2613 //netdev->dcbnl_ops = &dcbnl_ops;
2618 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
2619 ixgbe_get_device_caps(hw, &device_caps);
2620 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS) {
2621 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
2622 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
2623 e_info(probe, "FCoE offload feature is not available. "
2624 "Disabling FCoE offload feature\n");
2626 #ifndef HAVE_NETDEV_OPS_FCOE_ENABLE
2628 adapter->flags |= IXGBE_FLAG_FCOE_ENABLED;
2629 adapter->ring_feature[RING_F_FCOE].indices =
2631 netdev->features |= NETIF_F_FSO |
2634 netdev->fcoe_ddp_xid = IXGBE_FCOE_DDP_MAX - 1;
2636 #endif /* HAVE_NETDEV_OPS_FCOE_ENABLE */
2637 #ifdef HAVE_NETDEV_VLAN_FEATURES
2638 netdev->vlan_features |= NETIF_F_FSO |
2641 #endif /* HAVE_NETDEV_VLAN_FEATURES */
2643 #endif /* NETIF_F_FSO */
2644 #endif /* IXGBE_FCOE */
2646 #endif /* MAX_SKB_FRAGS */
2647 /* make sure the EEPROM is good */
2648 if (hw->eeprom.ops.validate_checksum &&
2649 (hw->eeprom.ops.validate_checksum(hw, NULL) < 0)) {
2650 e_dev_err("The EEPROM Checksum Is Not Valid\n");
2655 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
2656 #ifdef ETHTOOL_GPERMADDR
2657 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
2659 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
2660 e_dev_err("invalid MAC address\n");
2665 if (ixgbe_validate_mac_addr(netdev->dev_addr)) {
2666 e_dev_err("invalid MAC address\n");
2671 memcpy(&adapter->mac_table[0].addr, hw->mac.perm_addr,
2673 adapter->mac_table[0].queue = adapter->num_vfs;
2674 adapter->mac_table[0].state = (IXGBE_MAC_STATE_DEFAULT |
2675 IXGBE_MAC_STATE_IN_USE);
2676 hw->mac.ops.set_rar(hw, 0, adapter->mac_table[0].addr,
2677 adapter->mac_table[0].queue,
2680 //setup_timer(&adapter->service_timer, &ixgbe_service_timer,
2681 // (unsigned long) adapter);
2683 //INIT_WORK(&adapter->service_task, ixgbe_service_task);
2684 //clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
2686 //err = ixgbe_init_interrupt_scheme(adapter);
2688 // goto err_sw_init;
2690 //adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
2691 ixgbe_set_num_queues(adapter);
2694 /* WOL not supported for all but the following */
2695 switch (pdev->device) {
2696 case IXGBE_DEV_ID_82599_SFP:
2697 /* Only these subdevice supports WOL */
2698 switch (pdev->subsystem_device) {
2699 case IXGBE_SUBDEV_ID_82599_560FLR:
2700 /* only support first port */
2701 if (hw->bus.func != 0)
2703 case IXGBE_SUBDEV_ID_82599_SFP:
2704 adapter->wol = IXGBE_WUFC_MAG;
2708 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
2709 /* All except this subdevice support WOL */
2710 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
2711 adapter->wol = IXGBE_WUFC_MAG;
2713 case IXGBE_DEV_ID_82599_KX4:
2714 adapter->wol = IXGBE_WUFC_MAG;
2716 case IXGBE_DEV_ID_X540T:
2717 /* Check eeprom to see if it is enabled */
2718 ixgbe_read_eeprom(hw, 0x2c, &adapter->eeprom_cap);
2719 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
2721 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
2722 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
2723 (hw->bus.func == 0)))
2724 adapter->wol = IXGBE_WUFC_MAG;
2727 //device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
2731 * Save off EEPROM version number and Option Rom version which
2732 * together make a unique identify for the eeprom
2734 ixgbe_read_eeprom(hw, 0x2e, &eeprom_verh);
2735 ixgbe_read_eeprom(hw, 0x2d, &eeprom_verl);
2737 etrack_id = (eeprom_verh << 16) | eeprom_verl;
2739 ixgbe_read_eeprom(hw, 0x17, &offset);
2741 /* Make sure offset to SCSI block is valid */
2742 if (!(offset == 0x0) && !(offset == 0xffff)) {
2743 ixgbe_read_eeprom(hw, offset + 0x84, &eeprom_cfg_blkh);
2744 ixgbe_read_eeprom(hw, offset + 0x83, &eeprom_cfg_blkl);
2746 /* Only display Option Rom if exist */
2747 if (eeprom_cfg_blkl && eeprom_cfg_blkh) {
2748 major = eeprom_cfg_blkl >> 8;
2749 build = (eeprom_cfg_blkl << 8) | (eeprom_cfg_blkh >> 8);
2750 patch = eeprom_cfg_blkh & 0x00ff;
2752 snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
2753 "0x%08x, %d.%d.%d", etrack_id, major, build,
2756 snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
2757 "0x%08x", etrack_id);
2760 snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
2761 "0x%08x", etrack_id);
2764 /* reset the hardware with the new settings */
2765 err = hw->mac.ops.start_hw(hw);
2766 if (err == IXGBE_ERR_EEPROM_VERSION) {
2767 /* We are running on a pre-production device, log a warning */
2768 e_dev_warn("This device is a pre-production adapter/LOM. "
2769 "Please be aware there may be issues associated "
2770 "with your hardware. If you are experiencing "
2771 "problems please contact your Intel or hardware "
2772 "representative who provided you with this "
2775 /* pick up the PCI bus settings for reporting later */
2776 if (hw->mac.ops.get_bus_info)
2777 hw->mac.ops.get_bus_info(hw);
2779 strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
2782 adapter->netdev_registered = true;
2784 /* power down the optics */
2785 if ((hw->phy.multispeed_fiber) ||
2786 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
2787 (hw->mac.type == ixgbe_mac_82599EB)))
2788 ixgbe_disable_tx_laser(hw);
2790 /* carrier off reporting is important to ethtool even BEFORE open */
2791 netif_carrier_off(netdev);
2792 /* keep stopping all the transmit queues for older kernels */
2793 netif_tx_stop_all_queues(netdev);
2796 /* print all messages at the end so that we use our eth%d name */
2797 /* print bus type/speed/width info */
2798 e_dev_info("(PCI Express:%s:%s) ",
2799 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
2800 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
2802 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
2803 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
2804 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
2807 /* print the MAC address */
2808 for (i = 0; i < 6; i++)
2809 pr_cont("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':');
2811 /* First try to read PBA as a string */
2812 err = ixgbe_read_pba_string(hw, part_str, IXGBE_PBANUM_LENGTH);
2814 strlcpy(part_str, "Unknown", sizeof(part_str));
2815 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
2816 e_info(probe, "MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
2817 hw->mac.type, hw->phy.type, hw->phy.sfp_type, part_str);
2819 e_info(probe, "MAC: %d, PHY: %d, PBA No: %s\n",
2820 hw->mac.type, hw->phy.type, part_str);
2822 if (((hw->bus.speed == ixgbe_bus_speed_2500) &&
2823 (hw->bus.width <= ixgbe_bus_width_pcie_x4)) ||
2824 (hw->bus.width <= ixgbe_bus_width_pcie_x2)) {
2825 e_dev_warn("PCI-Express bandwidth available for this "
2826 "card is not sufficient for optimal "
2828 e_dev_warn("For optimal performance a x8 PCI-Express "
2829 "slot is required.\n");
2832 #define INFO_STRING_LEN 255
2833 info_string = kzalloc(INFO_STRING_LEN, GFP_KERNEL);
2835 e_err(probe, "allocation for info string failed\n");
2836 goto no_info_string;
2839 i_s_var = info_string;
2840 count += snprintf(i_s_var, INFO_STRING_LEN, "Enabled Features: ");
2842 i_s_var = info_string + count;
2843 count += snprintf(i_s_var, (INFO_STRING_LEN - count),
2844 "RxQ: %d TxQ: %d ", adapter->num_rx_queues,
2845 adapter->num_tx_queues);
2846 i_s_var = info_string + count;
2848 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
2849 count += snprintf(i_s_var, INFO_STRING_LEN - count, "FCoE ");
2850 i_s_var = info_string + count;
2853 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2854 count += snprintf(i_s_var, INFO_STRING_LEN - count,
2856 i_s_var = info_string + count;
2858 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
2859 count += snprintf(i_s_var, INFO_STRING_LEN - count,
2861 i_s_var = info_string + count;
2863 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2864 count += snprintf(i_s_var, INFO_STRING_LEN - count, "DCB ");
2865 i_s_var = info_string + count;
2867 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
2868 count += snprintf(i_s_var, INFO_STRING_LEN - count, "RSS ");
2869 i_s_var = info_string + count;
2871 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2872 count += snprintf(i_s_var, INFO_STRING_LEN - count, "DCA ");
2873 i_s_var = info_string + count;
2875 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
2876 count += snprintf(i_s_var, INFO_STRING_LEN - count, "RSC ");
2877 i_s_var = info_string + count;
2879 #ifndef IXGBE_NO_LRO
2880 else if (netdev->features & NETIF_F_LRO) {
2881 count += snprintf(i_s_var, INFO_STRING_LEN - count, "LRO ");
2882 i_s_var = info_string + count;
2886 BUG_ON(i_s_var > (info_string + INFO_STRING_LEN));
2887 /* end features printing */
2888 e_info(probe, "%s\n", info_string);
2892 /* firmware requires blank driver version */
2893 ixgbe_set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, 0xFF);
2895 #if defined(HAVE_NETDEV_STORAGE_ADDRESS) && defined(NETDEV_HW_ADDR_T_SAN)
2896 /* add san mac addr to netdev */
2897 //ixgbe_add_sanmac_netdev(netdev);
2899 #endif /* (HAVE_NETDEV_STORAGE_ADDRESS) && (NETDEV_HW_ADDR_T_SAN) */
2900 e_info(probe, "Intel(R) 10 Gigabit Network Connection\n");
2904 //if (ixgbe_sysfs_init(adapter))
2905 // e_err(probe, "failed to allocate sysfs resources\n");
2908 //if (ixgbe_procfs_init(adapter))
2909 // e_err(probe, "failed to allocate procfs resources\n");
2910 #endif /* IXGBE_PROCFS */
2911 #endif /* IXGBE_SYSFS */
2916 //ixgbe_clear_interrupt_scheme(adapter);
2917 //ixgbe_release_hw_control(adapter);
2919 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
2920 if (adapter->mac_table)
2921 kfree(adapter->mac_table);
2922 iounmap(hw->hw_addr);
2924 free_netdev(netdev);
2926 //pci_release_selected_regions(pdev,
2927 // pci_select_bars(pdev, IORESOURCE_MEM));
2930 pci_disable_device(pdev);
2935 * ixgbe_remove - Device Removal Routine
2936 * @pdev: PCI device information struct
2938 * ixgbe_remove is called by the PCI subsystem to alert the driver
2939 * that it should release a PCI device. The could be caused by a
2940 * Hot-Plug event, or because the driver is going to be removed from
2943 void ixgbe_kni_remove(struct pci_dev *pdev)
2945 pci_disable_device(pdev);
2949 u16 ixgbe_read_pci_cfg_word(struct ixgbe_hw *hw, u32 reg)
2952 struct ixgbe_adapter *adapter = hw->back;
2954 pci_read_config_word(adapter->pdev, reg, &value);
2958 void ixgbe_write_pci_cfg_word(struct ixgbe_hw *hw, u32 reg, u16 value)
2960 struct ixgbe_adapter *adapter = hw->back;
2962 pci_write_config_word(adapter->pdev, reg, value);
2965 void ewarn(struct ixgbe_hw *hw, const char *st, u32 status)
2967 struct ixgbe_adapter *adapter = hw->back;
2969 netif_warn(adapter, drv, adapter->netdev, "%s", st);