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_VLAN_RX_REGISTER
319 //if (!test_bit(__IXGBE_DOWN, &adapter->state))
320 // ixgbe_irq_disable(adapter);
322 adapter->vlgrp = grp;
324 //if (!test_bit(__IXGBE_DOWN, &adapter->state))
325 // ixgbe_irq_enable(adapter, true, true);
327 #ifdef HAVE_8021P_SUPPORT
328 #ifdef HAVE_VLAN_RX_REGISTER
329 bool enable = (grp || (adapter->flags & IXGBE_FLAG_DCB_ENABLED));
331 bool enable = !!(features & NETIF_F_HW_VLAN_RX);
334 /* enable VLAN tag insert/strip */
335 ixgbe_vlan_stripping_enable(adapter);
337 /* disable VLAN tag insert/strip */
338 ixgbe_vlan_stripping_disable(adapter);
343 static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq)
345 #ifdef NETDEV_HW_ADDR_T_MULTICAST
346 struct netdev_hw_addr *mc_ptr;
348 struct dev_mc_list *mc_ptr;
350 struct ixgbe_adapter *adapter = hw->back;
351 u8 *addr = *mc_addr_ptr;
353 *vmdq = adapter->num_vfs;
355 #ifdef NETDEV_HW_ADDR_T_MULTICAST
356 mc_ptr = container_of(addr, struct netdev_hw_addr, addr[0]);
357 if (mc_ptr->list.next) {
358 struct netdev_hw_addr *ha;
360 ha = list_entry(mc_ptr->list.next, struct netdev_hw_addr, list);
361 *mc_addr_ptr = ha->addr;
364 mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]);
366 *mc_addr_ptr = mc_ptr->next->dmi_addr;
375 * ixgbe_write_mc_addr_list - write multicast addresses to MTA
376 * @netdev: network interface device structure
378 * Writes multicast address list to the MTA hash table.
379 * Returns: -ENOMEM on failure
380 * 0 on no addresses written
381 * X on writing X addresses to MTA
383 int ixgbe_write_mc_addr_list(struct net_device *netdev)
385 struct ixgbe_adapter *adapter = netdev_priv(netdev);
386 struct ixgbe_hw *hw = &adapter->hw;
387 #ifdef NETDEV_HW_ADDR_T_MULTICAST
388 struct netdev_hw_addr *ha;
390 u8 *addr_list = NULL;
393 if (!hw->mac.ops.update_mc_addr_list)
396 if (!netif_running(netdev))
400 hw->mac.ops.update_mc_addr_list(hw, NULL, 0,
401 ixgbe_addr_list_itr, true);
403 if (!netdev_mc_empty(netdev)) {
404 #ifdef NETDEV_HW_ADDR_T_MULTICAST
405 ha = list_first_entry(&netdev->mc.list,
406 struct netdev_hw_addr, list);
407 addr_list = ha->addr;
409 addr_list = netdev->mc_list->dmi_addr;
411 addr_count = netdev_mc_count(netdev);
413 hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count,
414 ixgbe_addr_list_itr, false);
417 #ifdef CONFIG_PCI_IOV
418 //ixgbe_restore_vf_multicasts(adapter);
424 void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter)
426 struct ixgbe_hw *hw = &adapter->hw;
428 for (i = 0; i < hw->mac.num_rar_entries; i++) {
429 if (adapter->mac_table[i].state & IXGBE_MAC_STATE_IN_USE) {
430 hw->mac.ops.set_rar(hw, i, adapter->mac_table[i].addr,
431 adapter->mac_table[i].queue,
434 hw->mac.ops.clear_rar(hw, i);
439 void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter)
441 struct ixgbe_hw *hw = &adapter->hw;
443 for (i = 0; i < hw->mac.num_rar_entries; i++) {
444 if (adapter->mac_table[i].state & IXGBE_MAC_STATE_MODIFIED) {
445 if (adapter->mac_table[i].state &
446 IXGBE_MAC_STATE_IN_USE) {
447 hw->mac.ops.set_rar(hw, i,
448 adapter->mac_table[i].addr,
449 adapter->mac_table[i].queue,
452 hw->mac.ops.clear_rar(hw, i);
454 adapter->mac_table[i].state &=
455 ~(IXGBE_MAC_STATE_MODIFIED);
460 int ixgbe_available_rars(struct ixgbe_adapter *adapter)
462 struct ixgbe_hw *hw = &adapter->hw;
465 for (i = 0; i < hw->mac.num_rar_entries; i++) {
466 if (adapter->mac_table[i].state == 0)
472 int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter, u8 *addr, u16 queue)
474 struct ixgbe_hw *hw = &adapter->hw;
477 if (is_zero_ether_addr(addr))
480 for (i = 0; i < hw->mac.num_rar_entries; i++) {
481 if (adapter->mac_table[i].state & IXGBE_MAC_STATE_IN_USE)
483 adapter->mac_table[i].state |= (IXGBE_MAC_STATE_MODIFIED |
484 IXGBE_MAC_STATE_IN_USE);
485 memcpy(adapter->mac_table[i].addr, addr, ETH_ALEN);
486 adapter->mac_table[i].queue = queue;
487 ixgbe_sync_mac_table(adapter);
493 void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter)
496 struct ixgbe_hw *hw = &adapter->hw;
498 for (i = 0; i < hw->mac.num_rar_entries; i++) {
499 adapter->mac_table[i].state |= IXGBE_MAC_STATE_MODIFIED;
500 adapter->mac_table[i].state &= ~IXGBE_MAC_STATE_IN_USE;
501 memset(adapter->mac_table[i].addr, 0, ETH_ALEN);
502 adapter->mac_table[i].queue = 0;
504 ixgbe_sync_mac_table(adapter);
507 void ixgbe_del_mac_filter_by_index(struct ixgbe_adapter *adapter, int index)
509 adapter->mac_table[index].state |= IXGBE_MAC_STATE_MODIFIED;
510 adapter->mac_table[index].state &= ~IXGBE_MAC_STATE_IN_USE;
511 memset(adapter->mac_table[index].addr, 0, ETH_ALEN);
512 adapter->mac_table[index].queue = 0;
513 ixgbe_sync_mac_table(adapter);
516 int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter, u8* addr, u16 queue)
518 /* search table for addr, if found, set to 0 and sync */
520 struct ixgbe_hw *hw = &adapter->hw;
522 if (is_zero_ether_addr(addr))
524 for (i = 0; i < hw->mac.num_rar_entries; i++) {
525 if (!compare_ether_addr(addr, adapter->mac_table[i].addr) &&
526 adapter->mac_table[i].queue == queue) {
527 adapter->mac_table[i].state |= IXGBE_MAC_STATE_MODIFIED;
528 adapter->mac_table[i].state &= ~IXGBE_MAC_STATE_IN_USE;
529 memset(adapter->mac_table[i].addr, 0, ETH_ALEN);
530 adapter->mac_table[i].queue = 0;
531 ixgbe_sync_mac_table(adapter);
537 #ifdef HAVE_SET_RX_MODE
539 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
540 * @netdev: network interface device structure
542 * Writes unicast address list to the RAR table.
543 * Returns: -ENOMEM on failure/insufficient address space
544 * 0 on no addresses written
545 * X on writing X addresses to the RAR table
547 int ixgbe_write_uc_addr_list(struct ixgbe_adapter *adapter,
548 struct net_device *netdev, unsigned int vfn)
552 /* return ENOMEM indicating insufficient memory for addresses */
553 if (netdev_uc_count(netdev) > ixgbe_available_rars(adapter))
556 if (!netdev_uc_empty(netdev)) {
557 #ifdef NETDEV_HW_ADDR_T_UNICAST
558 struct netdev_hw_addr *ha;
560 struct dev_mc_list *ha;
562 netdev_for_each_uc_addr(ha, netdev) {
563 #ifdef NETDEV_HW_ADDR_T_UNICAST
564 ixgbe_del_mac_filter(adapter, ha->addr, (u16)vfn);
565 ixgbe_add_mac_filter(adapter, ha->addr, (u16)vfn);
567 ixgbe_del_mac_filter(adapter, ha->da_addr, (u16)vfn);
568 ixgbe_add_mac_filter(adapter, ha->da_addr, (u16)vfn);
578 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
579 * @netdev: network interface device structure
581 * The set_rx_method entry point is called whenever the unicast/multicast
582 * address list or the network interface flags are updated. This routine is
583 * responsible for configuring the hardware for proper unicast, multicast and
586 void ixgbe_set_rx_mode(struct net_device *netdev)
588 struct ixgbe_adapter *adapter = netdev_priv(netdev);
589 struct ixgbe_hw *hw = &adapter->hw;
590 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
594 /* Check for Promiscuous and All Multicast modes */
595 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
596 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
598 /* set all bits that we expect to always be set */
599 fctrl |= IXGBE_FCTRL_BAM;
600 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
601 fctrl |= IXGBE_FCTRL_PMCF;
603 /* clear the bits we are changing the status of */
604 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
605 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
607 if (netdev->flags & IFF_PROMISC) {
608 hw->addr_ctrl.user_set_promisc = true;
609 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
610 vmolr |= IXGBE_VMOLR_MPE;
612 if (netdev->flags & IFF_ALLMULTI) {
613 fctrl |= IXGBE_FCTRL_MPE;
614 vmolr |= IXGBE_VMOLR_MPE;
617 * Write addresses to the MTA, if the attempt fails
618 * then we should just turn on promiscuous mode so
619 * that we can at least receive multicast traffic
621 count = ixgbe_write_mc_addr_list(netdev);
623 fctrl |= IXGBE_FCTRL_MPE;
624 vmolr |= IXGBE_VMOLR_MPE;
626 vmolr |= IXGBE_VMOLR_ROMPE;
629 #ifdef NETIF_F_HW_VLAN_TX
630 /* enable hardware vlan filtering */
631 vlnctrl |= IXGBE_VLNCTRL_VFE;
633 hw->addr_ctrl.user_set_promisc = false;
634 #ifdef HAVE_SET_RX_MODE
636 * Write addresses to available RAR registers, if there is not
637 * sufficient space to store all the addresses then enable
638 * unicast promiscuous mode
640 count = ixgbe_write_uc_addr_list(adapter, netdev,
643 fctrl |= IXGBE_FCTRL_UPE;
644 vmolr |= IXGBE_VMOLR_ROPE;
649 if (hw->mac.type != ixgbe_mac_82598EB) {
650 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
651 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
653 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
656 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
657 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
667 /* Additional bittime to account for IXGBE framing */
668 #define IXGBE_ETH_FRAMING 20
671 * ixgbe_hpbthresh - calculate high water mark for flow control
673 * @adapter: board private structure to calculate for
674 * @pb - packet buffer to calculate
676 static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
678 struct ixgbe_hw *hw = &adapter->hw;
679 struct net_device *dev = adapter->netdev;
680 int link, tc, kb, marker;
683 /* Calculate max LAN frame size */
684 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
687 /* FCoE traffic class uses FCOE jumbo frames */
688 if (dev->features & NETIF_F_FCOE_MTU) {
691 fcoe_pb = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
693 if (fcoe_pb == pb && tc < IXGBE_FCOE_JUMBO_FRAME_SIZE)
694 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
698 /* Calculate delay value for device */
699 switch (hw->mac.type) {
701 dv_id = IXGBE_DV_X540(link, tc);
704 dv_id = IXGBE_DV(link, tc);
708 /* Loopback switch introduces additional latency */
709 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
710 dv_id += IXGBE_B2BT(tc);
712 /* Delay value is calculated in bit times convert to KB */
713 kb = IXGBE_BT2KB(dv_id);
714 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
716 marker = rx_pba - kb;
718 /* It is possible that the packet buffer is not large enough
719 * to provide required headroom. In this case throw an error
720 * to user and a do the best we can.
723 e_warn(drv, "Packet Buffer(%i) can not provide enough"
724 "headroom to suppport flow control."
725 "Decrease MTU or number of traffic classes\n", pb);
733 * ixgbe_lpbthresh - calculate low water mark for for flow control
735 * @adapter: board private structure to calculate for
736 * @pb - packet buffer to calculate
738 static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb)
740 struct ixgbe_hw *hw = &adapter->hw;
741 struct net_device *dev = adapter->netdev;
745 /* Calculate max LAN frame size */
746 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
749 /* FCoE traffic class uses FCOE jumbo frames */
750 if (dev->features & NETIF_F_FCOE_MTU) {
753 fcoe_pb = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
755 if (fcoe_pb == pb && tc < IXGBE_FCOE_JUMBO_FRAME_SIZE)
756 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
760 /* Calculate delay value for device */
761 switch (hw->mac.type) {
763 dv_id = IXGBE_LOW_DV_X540(tc);
766 dv_id = IXGBE_LOW_DV(tc);
770 /* Delay value is calculated in bit times convert to KB */
771 return IXGBE_BT2KB(dv_id);
775 * ixgbe_pbthresh_setup - calculate and setup high low water marks
777 static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
779 struct ixgbe_hw *hw = &adapter->hw;
780 int num_tc = netdev_get_num_tc(adapter->netdev);
785 if (num_tc > IXGBE_DCB_MAX_TRAFFIC_CLASS)
786 num_tc = IXGBE_DCB_MAX_TRAFFIC_CLASS;
788 for (i = 0; i < num_tc; i++) {
789 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
790 hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i);
792 /* Low water marks must not be larger than high water marks */
793 if (hw->fc.low_water[i] > hw->fc.high_water[i])
794 hw->fc.low_water[i] = 0;
797 for (; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++)
798 hw->fc.high_water[i] = 0;
804 static void ixgbe_configure(struct ixgbe_adapter *adapter)
806 struct ixgbe_hw *hw = &adapter->hw;
808 ixgbe_configure_pb(adapter);
809 ixgbe_configure_dcb(adapter);
811 ixgbe_set_rx_mode(adapter->netdev);
812 #ifdef NETIF_F_HW_VLAN_TX
813 ixgbe_restore_vlan(adapter);
817 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
818 ixgbe_configure_fcoe(adapter);
820 #endif /* IXGBE_FCOE */
822 if (adapter->hw.mac.type != ixgbe_mac_82598EB)
823 hw->mac.ops.disable_sec_rx_path(hw);
825 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
826 ixgbe_init_fdir_signature_82599(&adapter->hw,
827 adapter->fdir_pballoc);
828 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
829 ixgbe_init_fdir_perfect_82599(&adapter->hw,
830 adapter->fdir_pballoc);
831 ixgbe_fdir_filter_restore(adapter);
834 if (adapter->hw.mac.type != ixgbe_mac_82598EB)
835 hw->mac.ops.enable_sec_rx_path(hw);
837 ixgbe_configure_virtualization(adapter);
839 ixgbe_configure_tx(adapter);
840 ixgbe_configure_rx(adapter);
844 static bool ixgbe_is_sfp(struct ixgbe_hw *hw)
846 switch (hw->phy.type) {
847 case ixgbe_phy_sfp_avago:
848 case ixgbe_phy_sfp_ftl:
849 case ixgbe_phy_sfp_intel:
850 case ixgbe_phy_sfp_unknown:
851 case ixgbe_phy_sfp_passive_tyco:
852 case ixgbe_phy_sfp_passive_unknown:
853 case ixgbe_phy_sfp_active_unknown:
854 case ixgbe_phy_sfp_ftl_active:
857 if (hw->mac.type == ixgbe_mac_82598EB)
866 * ixgbe_clear_vf_stats_counters - Clear out VF stats after reset
867 * @adapter: board private structure
869 * On a reset we need to clear out the VF stats or accounting gets
870 * messed up because they're not clear on read.
872 void ixgbe_clear_vf_stats_counters(struct ixgbe_adapter *adapter)
874 struct ixgbe_hw *hw = &adapter->hw;
877 for (i = 0; i < adapter->num_vfs; i++) {
878 adapter->vfinfo[i].last_vfstats.gprc =
879 IXGBE_READ_REG(hw, IXGBE_PVFGPRC(i));
880 adapter->vfinfo[i].saved_rst_vfstats.gprc +=
881 adapter->vfinfo[i].vfstats.gprc;
882 adapter->vfinfo[i].vfstats.gprc = 0;
883 adapter->vfinfo[i].last_vfstats.gptc =
884 IXGBE_READ_REG(hw, IXGBE_PVFGPTC(i));
885 adapter->vfinfo[i].saved_rst_vfstats.gptc +=
886 adapter->vfinfo[i].vfstats.gptc;
887 adapter->vfinfo[i].vfstats.gptc = 0;
888 adapter->vfinfo[i].last_vfstats.gorc =
889 IXGBE_READ_REG(hw, IXGBE_PVFGORC_LSB(i));
890 adapter->vfinfo[i].saved_rst_vfstats.gorc +=
891 adapter->vfinfo[i].vfstats.gorc;
892 adapter->vfinfo[i].vfstats.gorc = 0;
893 adapter->vfinfo[i].last_vfstats.gotc =
894 IXGBE_READ_REG(hw, IXGBE_PVFGOTC_LSB(i));
895 adapter->vfinfo[i].saved_rst_vfstats.gotc +=
896 adapter->vfinfo[i].vfstats.gotc;
897 adapter->vfinfo[i].vfstats.gotc = 0;
898 adapter->vfinfo[i].last_vfstats.mprc =
899 IXGBE_READ_REG(hw, IXGBE_PVFMPRC(i));
900 adapter->vfinfo[i].saved_rst_vfstats.mprc +=
901 adapter->vfinfo[i].vfstats.mprc;
902 adapter->vfinfo[i].vfstats.mprc = 0;
908 void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
911 WARN_ON(in_interrupt());
912 /* put off any impending NetWatchDogTimeout */
913 adapter->netdev->trans_start = jiffies;
915 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
916 usleep_range(1000, 2000);
919 * If SR-IOV enabled then wait a bit before bringing the adapter
920 * back up to give the VFs time to respond to the reset. The
921 * two second wait is based upon the watchdog timer cycle in
924 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
927 clear_bit(__IXGBE_RESETTING, &adapter->state);
931 void ixgbe_up(struct ixgbe_adapter *adapter)
933 /* hardware has been reset, we need to reload some things */
934 //ixgbe_configure(adapter);
936 //ixgbe_up_complete(adapter);
939 void ixgbe_reset(struct ixgbe_adapter *adapter)
941 struct ixgbe_hw *hw = &adapter->hw;
942 struct net_device *netdev = adapter->netdev;
945 /* lock SFP init bit to prevent race conditions with the watchdog */
946 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
947 usleep_range(1000, 2000);
949 /* clear all SFP and link config related flags while holding SFP_INIT */
950 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
951 IXGBE_FLAG2_SFP_NEEDS_RESET);
952 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
954 err = hw->mac.ops.init_hw(hw);
957 case IXGBE_ERR_SFP_NOT_PRESENT:
958 case IXGBE_ERR_SFP_NOT_SUPPORTED:
960 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
961 e_dev_err("master disable timed out\n");
963 case IXGBE_ERR_EEPROM_VERSION:
964 /* We are running on a pre-production device, log a warning */
965 e_dev_warn("This device is a pre-production adapter/LOM. "
966 "Please be aware there may be issues associated "
967 "with your hardware. If you are experiencing "
968 "problems please contact your Intel or hardware "
969 "representative who provided you with this "
973 e_dev_err("Hardware Error: %d\n", err);
976 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
978 ixgbe_flush_sw_mac_table(adapter);
979 memcpy(&adapter->mac_table[0].addr, hw->mac.perm_addr,
981 adapter->mac_table[0].queue = adapter->num_vfs;
982 adapter->mac_table[0].state = (IXGBE_MAC_STATE_DEFAULT |
983 IXGBE_MAC_STATE_IN_USE);
984 hw->mac.ops.set_rar(hw, 0, adapter->mac_table[0].addr,
985 adapter->mac_table[0].queue,
994 void ixgbe_down(struct ixgbe_adapter *adapter)
997 struct net_device *netdev = adapter->netdev;
998 struct ixgbe_hw *hw = &adapter->hw;
1002 /* signal that we are down to the interrupt handler */
1003 set_bit(__IXGBE_DOWN, &adapter->state);
1005 /* disable receives */
1006 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
1007 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
1009 /* disable all enabled rx queues */
1010 for (i = 0; i < adapter->num_rx_queues; i++)
1011 /* this call also flushes the previous write */
1012 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
1014 usleep_range(10000, 20000);
1016 netif_tx_stop_all_queues(netdev);
1018 /* call carrier off first to avoid false dev_watchdog timeouts */
1019 netif_carrier_off(netdev);
1020 netif_tx_disable(netdev);
1022 ixgbe_irq_disable(adapter);
1024 ixgbe_napi_disable_all(adapter);
1026 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
1027 IXGBE_FLAG2_RESET_REQUESTED);
1028 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
1030 del_timer_sync(&adapter->service_timer);
1032 if (adapter->num_vfs) {
1033 /* Clear EITR Select mapping */
1034 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
1036 /* Mark all the VFs as inactive */
1037 for (i = 0 ; i < adapter->num_vfs; i++)
1038 adapter->vfinfo[i].clear_to_send = 0;
1040 /* ping all the active vfs to let them know we are going down */
1041 ixgbe_ping_all_vfs(adapter);
1043 /* Disable all VFTE/VFRE TX/RX */
1044 ixgbe_disable_tx_rx(adapter);
1047 /* disable transmits in the hardware now that interrupts are off */
1048 for (i = 0; i < adapter->num_tx_queues; i++) {
1049 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
1050 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
1053 /* Disable the Tx DMA engine on 82599 and X540 */
1054 switch (hw->mac.type) {
1055 case ixgbe_mac_82599EB:
1056 case ixgbe_mac_X540:
1057 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
1058 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
1059 ~IXGBE_DMATXCTL_TE));
1066 if (!pci_channel_offline(adapter->pdev))
1068 ixgbe_reset(adapter);
1069 /* power down the optics */
1070 if ((hw->phy.multispeed_fiber) ||
1071 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
1072 (hw->mac.type == ixgbe_mac_82599EB)))
1073 ixgbe_disable_tx_laser(hw);
1075 ixgbe_clean_all_tx_rings(adapter);
1076 ixgbe_clean_all_rx_rings(adapter);
1078 #if defined(CONFIG_DCA) || defined(CONFIG_DCA_MODULE)
1079 /* since we reset the hardware DCA settings were cleared */
1080 ixgbe_setup_dca(adapter);
1083 #endif /* NO_VNIC */
1090 /* Artificial max queue cap per traffic class in DCB mode */
1091 #define DCB_QUEUE_CAP 8
1094 * ixgbe_set_dcb_queues: Allocate queues for a DCB-enabled device
1095 * @adapter: board private structure to initialize
1097 * When DCB (Data Center Bridging) is enabled, allocate queues for
1098 * each traffic class. If multiqueue isn't available,then abort DCB
1101 * This function handles all combinations of DCB, RSS, and FCoE.
1104 static bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
1108 int rss_i, i, offset = 0;
1109 struct net_device *dev = adapter->netdev;
1111 /* Map queue offset and counts onto allocated tx queues */
1112 tcs = netdev_get_num_tc(dev);
1117 rss_i = min_t(int, dev->num_tx_queues / tcs, num_online_cpus());
1119 if (rss_i > DCB_QUEUE_CAP)
1120 rss_i = DCB_QUEUE_CAP;
1122 for (i = 0; i < tcs; i++) {
1123 netdev_set_tc_queue(dev, i, rss_i, offset);
1127 adapter->num_tx_queues = rss_i * tcs;
1128 adapter->num_rx_queues = rss_i * tcs;
1131 /* FCoE enabled queues require special configuration indexed
1132 * by feature specific indices and mask. Here we map FCoE
1133 * indices onto the DCB queue pairs allowing FCoE to own
1134 * configuration later.
1137 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
1138 struct ixgbe_ring_feature *f;
1140 u8 prio_tc[IXGBE_DCB_MAX_USER_PRIORITY] = {0};
1142 ixgbe_dcb_unpack_map_cee(&adapter->dcb_cfg,
1143 IXGBE_DCB_TX_CONFIG,
1145 tc = prio_tc[adapter->fcoe.up];
1147 f = &adapter->ring_feature[RING_F_FCOE];
1148 f->indices = min_t(int, rss_i, f->indices);
1149 f->mask = rss_i * tc;
1151 #endif /* IXGBE_FCOE */
1153 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
1156 /* Enable one Queue per traffic class */
1162 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
1163 struct ixgbe_ring_feature *f;
1164 int tc = netdev_get_prio_tc_map(adapter->netdev,
1167 f = &adapter->ring_feature[RING_F_FCOE];
1170 * We have max 8 queues for FCoE, where 8 the is
1171 * FCoE redirection table size. We must also share
1172 * ring resources with network traffic so if FCoE TC is
1173 * 4 or greater and we are in 8 TC mode we can only use
1176 if ((tcs > 4) && (tc >= 4) && (f->indices > 7))
1179 f->indices = min_t(int, num_online_cpus(), f->indices);
1182 adapter->num_rx_queues = f->indices + tcs;
1183 adapter->num_tx_queues = f->indices + tcs;
1188 #endif /* IXGBE_FCOE */
1189 adapter->num_rx_queues = tcs;
1190 adapter->num_tx_queues = tcs;
1191 #endif /* HAVE_MQ */
1197 * ixgbe_set_vmdq_queues: Allocate queues for VMDq devices
1198 * @adapter: board private structure to initialize
1200 * When VMDq (Virtual Machine Devices queue) is enabled, allocate queues
1201 * and VM pools where appropriate. If RSS is available, then also try and
1202 * enable RSS and map accordingly.
1205 static bool ixgbe_set_vmdq_queues(struct ixgbe_adapter *adapter)
1207 int vmdq_i = adapter->ring_feature[RING_F_VMDQ].indices;
1209 int rss_i = adapter->ring_feature[RING_F_RSS].indices;
1215 switch (adapter->flags & (IXGBE_FLAG_RSS_ENABLED
1216 | IXGBE_FLAG_DCB_ENABLED
1217 | IXGBE_FLAG_VMDQ_ENABLED)) {
1219 case (IXGBE_FLAG_RSS_ENABLED | IXGBE_FLAG_VMDQ_ENABLED):
1220 switch (adapter->hw.mac.type) {
1221 case ixgbe_mac_82599EB:
1222 case ixgbe_mac_X540:
1223 vmdq_i = min((int)IXGBE_MAX_VMDQ_INDICES, vmdq_i);
1229 rss_shift = find_first_bit(&i, sizeof(i) * 8);
1230 vmdq_m = ((IXGBE_MAX_VMDQ_INDICES - 1) <<
1231 rss_shift) & (MAX_RX_QUEUES - 1);
1236 adapter->num_rx_queues = vmdq_i * rss_i;
1237 adapter->num_tx_queues = min((int)MAX_TX_QUEUES, vmdq_i * rss_i);
1241 case (IXGBE_FLAG_VMDQ_ENABLED):
1242 switch (adapter->hw.mac.type) {
1243 case ixgbe_mac_82598EB:
1244 vmdq_m = (IXGBE_MAX_VMDQ_INDICES - 1);
1246 case ixgbe_mac_82599EB:
1247 case ixgbe_mac_X540:
1248 vmdq_m = (IXGBE_MAX_VMDQ_INDICES - 1) << 1;
1253 adapter->num_rx_queues = vmdq_i;
1254 adapter->num_tx_queues = vmdq_i;
1260 goto vmdq_queues_out;
1263 if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) {
1264 adapter->num_rx_pools = vmdq_i;
1265 adapter->num_rx_queues_per_pool = adapter->num_rx_queues /
1268 adapter->num_rx_pools = adapter->num_rx_queues;
1269 adapter->num_rx_queues_per_pool = 1;
1271 /* save the mask for later use */
1272 adapter->ring_feature[RING_F_VMDQ].mask = vmdq_m;
1278 * ixgbe_set_rss_queues: Allocate queues for RSS
1279 * @adapter: board private structure to initialize
1281 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
1282 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
1285 static bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
1287 struct ixgbe_ring_feature *f;
1289 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
1290 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
1294 /* set mask for 16 queue limit of RSS */
1295 f = &adapter->ring_feature[RING_F_RSS];
1299 * Use Flow Director in addition to RSS to ensure the best
1300 * distribution of flows across cores, even when an FDIR flow
1303 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
1304 f = &adapter->ring_feature[RING_F_FDIR];
1306 f->indices = min_t(int, num_online_cpus(), f->indices);
1310 adapter->num_rx_queues = f->indices;
1312 adapter->num_tx_queues = f->indices;
1320 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
1321 * @adapter: board private structure to initialize
1323 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
1324 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
1325 * rx queues out of the max number of rx queues, instead, it is used as the
1326 * index of the first rx queue used by FCoE.
1329 static bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
1331 struct ixgbe_ring_feature *f;
1333 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
1336 ixgbe_set_rss_queues(adapter);
1338 f = &adapter->ring_feature[RING_F_FCOE];
1339 f->indices = min_t(int, num_online_cpus(), f->indices);
1341 /* adding FCoE queues */
1342 f->mask = adapter->num_rx_queues;
1343 adapter->num_rx_queues += f->indices;
1344 adapter->num_tx_queues += f->indices;
1349 #endif /* IXGBE_FCOE */
1351 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
1352 * @adapter: board private structure to initialize
1354 * This is the top level queue allocation routine. The order here is very
1355 * important, starting with the "most" number of features turned on at once,
1356 * and ending with the smallest set of features. This way large combinations
1357 * can be allocated if they're turned on, and smaller combinations are the
1358 * fallthrough conditions.
1361 static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
1363 /* Start with base case */
1364 adapter->num_rx_queues = 1;
1365 adapter->num_tx_queues = 1;
1366 adapter->num_rx_pools = adapter->num_rx_queues;
1367 adapter->num_rx_queues_per_pool = 1;
1369 if (ixgbe_set_vmdq_queues(adapter))
1372 if (ixgbe_set_dcb_queues(adapter))
1376 if (ixgbe_set_fcoe_queues(adapter))
1379 #endif /* IXGBE_FCOE */
1380 ixgbe_set_rss_queues(adapter);
1387 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
1388 * @adapter: board private structure to initialize
1390 * ixgbe_sw_init initializes the Adapter private data structure.
1391 * Fields are initialized based on PCI device information and
1392 * OS network device settings (MTU size).
1394 static int ixgbe_sw_init(struct ixgbe_adapter *adapter)
1396 struct ixgbe_hw *hw = &adapter->hw;
1397 struct pci_dev *pdev = adapter->pdev;
1400 /* PCI config space info */
1402 hw->vendor_id = pdev->vendor;
1403 hw->device_id = pdev->device;
1404 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
1405 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1406 hw->subsystem_device_id = pdev->subsystem_device;
1408 err = ixgbe_init_shared_code(hw);
1410 e_err(probe, "init_shared_code failed: %d\n", err);
1413 adapter->mac_table = kzalloc(sizeof(struct ixgbe_mac_addr) *
1414 hw->mac.num_rar_entries,
1416 /* Set capability flags */
1417 switch (hw->mac.type) {
1418 case ixgbe_mac_82598EB:
1419 adapter->flags |= IXGBE_FLAG_MSI_CAPABLE |
1420 IXGBE_FLAG_MSIX_CAPABLE |
1421 IXGBE_FLAG_MQ_CAPABLE |
1422 IXGBE_FLAG_RSS_CAPABLE;
1423 adapter->flags |= IXGBE_FLAG_DCB_CAPABLE;
1424 #if defined(CONFIG_DCA) || defined(CONFIG_DCA_MODULE)
1425 adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
1427 adapter->flags &= ~IXGBE_FLAG_SRIOV_CAPABLE;
1428 adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE;
1430 if (hw->device_id == IXGBE_DEV_ID_82598AT)
1431 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
1433 adapter->max_msix_q_vectors = IXGBE_MAX_MSIX_Q_VECTORS_82598;
1435 case ixgbe_mac_X540:
1436 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
1437 case ixgbe_mac_82599EB:
1438 adapter->flags |= IXGBE_FLAG_MSI_CAPABLE |
1439 IXGBE_FLAG_MSIX_CAPABLE |
1440 IXGBE_FLAG_MQ_CAPABLE |
1441 IXGBE_FLAG_RSS_CAPABLE;
1442 adapter->flags |= IXGBE_FLAG_DCB_CAPABLE;
1443 #if defined(CONFIG_DCA) || defined(CONFIG_DCA_MODULE)
1444 adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
1446 adapter->flags |= IXGBE_FLAG_SRIOV_CAPABLE;
1447 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
1449 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
1450 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
1451 adapter->ring_feature[RING_F_FCOE].indices = 0;
1453 /* Default traffic class to use for FCoE */
1454 adapter->fcoe.tc = IXGBE_FCOE_DEFTC;
1455 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
1456 adapter->fcoe.up_set = IXGBE_FCOE_DEFTC;
1459 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
1460 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
1461 #ifndef IXGBE_NO_SMART_SPEED
1462 hw->phy.smart_speed = ixgbe_smart_speed_on;
1464 hw->phy.smart_speed = ixgbe_smart_speed_off;
1466 adapter->max_msix_q_vectors = IXGBE_MAX_MSIX_Q_VECTORS_82599;
1471 /* n-tuple support exists, always init our spinlock */
1472 //spin_lock_init(&adapter->fdir_perfect_lock);
1474 if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE) {
1476 struct ixgbe_dcb_tc_config *tc;
1477 int dcb_i = IXGBE_DCB_MAX_TRAFFIC_CLASS;
1480 adapter->dcb_cfg.num_tcs.pg_tcs = dcb_i;
1481 adapter->dcb_cfg.num_tcs.pfc_tcs = dcb_i;
1482 for (j = 0; j < dcb_i; j++) {
1483 tc = &adapter->dcb_cfg.tc_config[j];
1484 tc->path[IXGBE_DCB_TX_CONFIG].bwg_id = 0;
1485 tc->path[IXGBE_DCB_TX_CONFIG].bwg_percent = 100 / dcb_i;
1486 tc->path[IXGBE_DCB_RX_CONFIG].bwg_id = 0;
1487 tc->path[IXGBE_DCB_RX_CONFIG].bwg_percent = 100 / dcb_i;
1488 tc->pfc = ixgbe_dcb_pfc_disabled;
1490 /* total of all TCs bandwidth needs to be 100 */
1491 tc->path[IXGBE_DCB_TX_CONFIG].bwg_percent +=
1493 tc->path[IXGBE_DCB_RX_CONFIG].bwg_percent +=
1498 /* Initialize default user to priority mapping, UPx->TC0 */
1499 tc = &adapter->dcb_cfg.tc_config[0];
1500 tc->path[IXGBE_DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
1501 tc->path[IXGBE_DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
1503 adapter->dcb_cfg.bw_percentage[IXGBE_DCB_TX_CONFIG][0] = 100;
1504 adapter->dcb_cfg.bw_percentage[IXGBE_DCB_RX_CONFIG][0] = 100;
1505 adapter->dcb_cfg.rx_pba_cfg = ixgbe_dcb_pba_equal;
1506 adapter->dcb_cfg.pfc_mode_enable = false;
1507 adapter->dcb_cfg.round_robin_enable = false;
1508 adapter->dcb_set_bitmap = 0x00;
1510 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
1511 #endif /* CONFIG_DCB */
1513 if (hw->mac.type == ixgbe_mac_X540) {
1514 adapter->dcb_cfg.num_tcs.pg_tcs = 4;
1515 adapter->dcb_cfg.num_tcs.pfc_tcs = 4;
1519 /* XXX does this need to be initialized even w/o DCB? */
1520 //memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
1521 // sizeof(adapter->temp_dcb_cfg));
1524 //if (hw->mac.type == ixgbe_mac_82599EB ||
1525 // hw->mac.type == ixgbe_mac_X540)
1526 // hw->mbx.ops.init_params(hw);
1528 /* default flow control settings */
1529 hw->fc.requested_mode = ixgbe_fc_full;
1530 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
1532 adapter->last_lfc_mode = hw->fc.current_mode;
1533 ixgbe_pbthresh_setup(adapter);
1534 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
1535 hw->fc.send_xon = true;
1536 hw->fc.disable_fc_autoneg = false;
1538 /* set default ring sizes */
1539 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
1540 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
1542 /* set default work limits */
1543 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
1544 adapter->rx_work_limit = IXGBE_DEFAULT_RX_WORK;
1546 set_bit(__IXGBE_DOWN, &adapter->state);
1552 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
1553 * @tx_ring: tx descriptor ring (for a specific queue) to setup
1555 * Return 0 on success, negative on failure
1557 int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
1559 struct device *dev = tx_ring->dev;
1560 //int orig_node = dev_to_node(dev);
1564 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
1566 if (tx_ring->q_vector)
1567 numa_node = tx_ring->q_vector->numa_node;
1569 tx_ring->tx_buffer_info = vzalloc_node(size, numa_node);
1570 if (!tx_ring->tx_buffer_info)
1571 tx_ring->tx_buffer_info = vzalloc(size);
1572 if (!tx_ring->tx_buffer_info)
1575 /* round up to nearest 4K */
1576 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
1577 tx_ring->size = ALIGN(tx_ring->size, 4096);
1579 //set_dev_node(dev, numa_node);
1580 //tx_ring->desc = dma_alloc_coherent(dev,
1584 //set_dev_node(dev, orig_node);
1585 //if (!tx_ring->desc)
1586 // tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
1587 // &tx_ring->dma, GFP_KERNEL);
1588 //if (!tx_ring->desc)
1594 vfree(tx_ring->tx_buffer_info);
1595 tx_ring->tx_buffer_info = NULL;
1596 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
1601 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
1602 * @adapter: board private structure
1604 * If this function returns with an error, then it's possible one or
1605 * more of the rings is populated (while the rest are not). It is the
1606 * callers duty to clean those orphaned rings.
1608 * Return 0 on success, negative on failure
1610 static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
1614 for (i = 0; i < adapter->num_tx_queues; i++) {
1615 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
1618 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
1626 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
1627 * @rx_ring: rx descriptor ring (for a specific queue) to setup
1629 * Returns 0 on success, negative on failure
1631 int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
1633 struct device *dev = rx_ring->dev;
1634 //int orig_node = dev_to_node(dev);
1638 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
1640 if (rx_ring->q_vector)
1641 numa_node = rx_ring->q_vector->numa_node;
1643 rx_ring->rx_buffer_info = vzalloc_node(size, numa_node);
1644 if (!rx_ring->rx_buffer_info)
1645 rx_ring->rx_buffer_info = vzalloc(size);
1646 if (!rx_ring->rx_buffer_info)
1649 /* Round up to nearest 4K */
1650 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
1651 rx_ring->size = ALIGN(rx_ring->size, 4096);
1654 set_dev_node(dev, numa_node);
1655 rx_ring->desc = dma_alloc_coherent(dev,
1659 set_dev_node(dev, orig_node);
1661 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
1662 &rx_ring->dma, GFP_KERNEL);
1666 #ifndef CONFIG_IXGBE_DISABLE_PACKET_SPLIT
1667 ixgbe_init_rx_page_offset(rx_ring);
1671 #endif /* NO_VNIC */
1674 vfree(rx_ring->rx_buffer_info);
1675 rx_ring->rx_buffer_info = NULL;
1676 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
1681 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
1682 * @adapter: board private structure
1684 * If this function returns with an error, then it's possible one or
1685 * more of the rings is populated (while the rest are not). It is the
1686 * callers duty to clean those orphaned rings.
1688 * Return 0 on success, negative on failure
1690 static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
1694 for (i = 0; i < adapter->num_rx_queues; i++) {
1695 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
1698 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
1706 * ixgbe_free_tx_resources - Free Tx Resources per Queue
1707 * @tx_ring: Tx descriptor ring for a specific queue
1709 * Free all transmit software resources
1711 void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
1713 //ixgbe_clean_tx_ring(tx_ring);
1715 vfree(tx_ring->tx_buffer_info);
1716 tx_ring->tx_buffer_info = NULL;
1718 /* if not set, then don't free */
1722 //dma_free_coherent(tx_ring->dev, tx_ring->size,
1723 // tx_ring->desc, tx_ring->dma);
1725 tx_ring->desc = NULL;
1729 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
1730 * @adapter: board private structure
1732 * Free all transmit software resources
1734 static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
1738 for (i = 0; i < adapter->num_tx_queues; i++)
1739 if (adapter->tx_ring[i]->desc)
1740 ixgbe_free_tx_resources(adapter->tx_ring[i]);
1744 * ixgbe_free_rx_resources - Free Rx Resources
1745 * @rx_ring: ring to clean the resources from
1747 * Free all receive software resources
1749 void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
1751 //ixgbe_clean_rx_ring(rx_ring);
1753 vfree(rx_ring->rx_buffer_info);
1754 rx_ring->rx_buffer_info = NULL;
1756 /* if not set, then don't free */
1760 //dma_free_coherent(rx_ring->dev, rx_ring->size,
1761 // rx_ring->desc, rx_ring->dma);
1763 rx_ring->desc = NULL;
1767 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
1768 * @adapter: board private structure
1770 * Free all receive software resources
1772 static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
1776 for (i = 0; i < adapter->num_rx_queues; i++)
1777 if (adapter->rx_ring[i]->desc)
1778 ixgbe_free_rx_resources(adapter->rx_ring[i]);
1783 * ixgbe_open - Called when a network interface is made active
1784 * @netdev: network interface device structure
1786 * Returns 0 on success, negative value on failure
1788 * The open entry point is called when a network interface is made
1789 * active by the system (IFF_UP). At this point all resources needed
1790 * for transmit and receive operations are allocated, the interrupt
1791 * handler is registered with the OS, the watchdog timer is started,
1792 * and the stack is notified that the interface is ready.
1795 int ixgbe_open(struct net_device *netdev)
1797 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1800 /* disallow open during test */
1801 if (test_bit(__IXGBE_TESTING, &adapter->state))
1804 netif_carrier_off(netdev);
1806 /* allocate transmit descriptors */
1807 err = ixgbe_setup_all_tx_resources(adapter);
1811 /* allocate receive descriptors */
1812 err = ixgbe_setup_all_rx_resources(adapter);
1817 ixgbe_configure(adapter);
1819 err = ixgbe_request_irq(adapter);
1823 ixgbe_up_complete(adapter);
1830 ixgbe_free_all_rx_resources(adapter);
1832 ixgbe_free_all_tx_resources(adapter);
1833 ixgbe_reset(adapter);
1839 * ixgbe_close - Disables a network interface
1840 * @netdev: network interface device structure
1842 * Returns 0, this is not allowed to fail
1844 * The close entry point is called when an interface is de-activated
1845 * by the OS. The hardware is still under the drivers control, but
1846 * needs to be disabled. A global MAC reset is issued to stop the
1847 * hardware, and all transmit and receive resources are freed.
1850 int ixgbe_close(struct net_device *netdev)
1852 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1854 //ixgbe_down(adapter);
1855 //ixgbe_free_irq(adapter);
1857 //ixgbe_fdir_filter_exit(adapter);
1859 //ixgbe_free_all_tx_resources(adapter);
1860 //ixgbe_free_all_rx_resources(adapter);
1862 ixgbe_release_hw_control(adapter);
1872 * ixgbe_get_stats - Get System Network Statistics
1873 * @netdev: network interface device structure
1875 * Returns the address of the device statistics structure.
1876 * The statistics are actually updated from the timer callback.
1879 struct net_device_stats *ixgbe_get_stats(struct net_device *netdev)
1881 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1883 /* update the stats data */
1884 ixgbe_update_stats(adapter);
1886 #ifdef HAVE_NETDEV_STATS_IN_NETDEV
1887 /* only return the current stats */
1888 return &netdev->stats;
1890 /* only return the current stats */
1891 return &adapter->net_stats;
1892 #endif /* HAVE_NETDEV_STATS_IN_NETDEV */
1896 * ixgbe_update_stats - Update the board statistics counters.
1897 * @adapter: board private structure
1899 void ixgbe_update_stats(struct ixgbe_adapter *adapter)
1901 #ifdef HAVE_NETDEV_STATS_IN_NETDEV
1902 struct net_device_stats *net_stats = &adapter->netdev->stats;
1904 struct net_device_stats *net_stats = &adapter->net_stats;
1905 #endif /* HAVE_NETDEV_STATS_IN_NETDEV */
1906 struct ixgbe_hw *hw = &adapter->hw;
1907 struct ixgbe_hw_stats *hwstats = &adapter->stats;
1909 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
1910 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
1911 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
1912 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
1913 #ifndef IXGBE_NO_LRO
1914 u32 flushed = 0, coal = 0;
1915 int num_q_vectors = 1;
1918 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
1920 u64 fcoe_noddp_counts_sum = 0, fcoe_noddp_ext_buff_counts_sum = 0;
1921 #endif /* IXGBE_FCOE */
1923 printk(KERN_DEBUG "ixgbe_update_stats, tx_queues=%d, rx_queues=%d\n",
1924 adapter->num_tx_queues, adapter->num_rx_queues);
1926 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
1927 test_bit(__IXGBE_RESETTING, &adapter->state))
1930 #ifndef IXGBE_NO_LRO
1931 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
1932 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1935 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
1938 for (i = 0; i < adapter->num_rx_queues; i++) {
1939 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
1940 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
1942 adapter->rsc_total_count = rsc_count;
1943 adapter->rsc_total_flush = rsc_flush;
1946 #ifndef IXGBE_NO_LRO
1947 for (i = 0; i < num_q_vectors; i++) {
1948 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
1951 flushed += q_vector->lrolist.stats.flushed;
1952 coal += q_vector->lrolist.stats.coal;
1954 adapter->lro_stats.flushed = flushed;
1955 adapter->lro_stats.coal = coal;
1958 for (i = 0; i < adapter->num_rx_queues; i++) {
1959 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
1960 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
1961 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
1962 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
1963 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
1964 bytes += rx_ring->stats.bytes;
1965 packets += rx_ring->stats.packets;
1968 adapter->non_eop_descs = non_eop_descs;
1969 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
1970 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
1971 adapter->hw_csum_rx_error = hw_csum_rx_error;
1972 net_stats->rx_bytes = bytes;
1973 net_stats->rx_packets = packets;
1977 /* gather some stats to the adapter struct that are per queue */
1978 for (i = 0; i < adapter->num_tx_queues; i++) {
1979 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
1980 restart_queue += tx_ring->tx_stats.restart_queue;
1981 tx_busy += tx_ring->tx_stats.tx_busy;
1982 bytes += tx_ring->stats.bytes;
1983 packets += tx_ring->stats.packets;
1985 adapter->restart_queue = restart_queue;
1986 adapter->tx_busy = tx_busy;
1987 net_stats->tx_bytes = bytes;
1988 net_stats->tx_packets = packets;
1990 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
1992 /* 8 register reads */
1993 for (i = 0; i < 8; i++) {
1994 /* for packet buffers not used, the register should read 0 */
1995 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
1997 hwstats->mpc[i] += mpc;
1998 total_mpc += hwstats->mpc[i];
1999 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
2000 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
2001 switch (hw->mac.type) {
2002 case ixgbe_mac_82598EB:
2003 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
2004 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
2005 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
2006 hwstats->pxonrxc[i] +=
2007 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
2009 case ixgbe_mac_82599EB:
2010 case ixgbe_mac_X540:
2011 hwstats->pxonrxc[i] +=
2012 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
2019 /*16 register reads */
2020 for (i = 0; i < 16; i++) {
2021 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
2022 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
2023 if ((hw->mac.type == ixgbe_mac_82599EB) ||
2024 (hw->mac.type == ixgbe_mac_X540)) {
2025 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
2026 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
2027 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
2028 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
2032 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
2033 /* work around hardware counting issue */
2034 hwstats->gprc -= missed_rx;
2036 ixgbe_update_xoff_received(adapter);
2038 /* 82598 hardware only has a 32 bit counter in the high register */
2039 switch (hw->mac.type) {
2040 case ixgbe_mac_82598EB:
2041 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
2042 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
2043 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
2044 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
2046 case ixgbe_mac_X540:
2047 /* OS2BMC stats are X540 only*/
2048 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
2049 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
2050 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
2051 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
2052 case ixgbe_mac_82599EB:
2053 for (i = 0; i < 16; i++)
2054 adapter->hw_rx_no_dma_resources +=
2055 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
2056 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
2057 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
2058 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
2059 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
2060 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
2061 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
2062 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
2064 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
2065 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
2066 #endif /* HAVE_TX_MQ */
2068 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
2069 hwstats->fclast += IXGBE_READ_REG(hw, IXGBE_FCLAST);
2070 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
2071 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
2072 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
2073 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
2074 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
2075 /* Add up per cpu counters for total ddp aloc fail */
2076 if (fcoe && fcoe->pcpu_noddp && fcoe->pcpu_noddp_ext_buff) {
2077 for_each_possible_cpu(cpu) {
2078 fcoe_noddp_counts_sum +=
2079 *per_cpu_ptr(fcoe->pcpu_noddp, cpu);
2080 fcoe_noddp_ext_buff_counts_sum +=
2082 pcpu_noddp_ext_buff, cpu);
2085 hwstats->fcoe_noddp = fcoe_noddp_counts_sum;
2086 hwstats->fcoe_noddp_ext_buff = fcoe_noddp_ext_buff_counts_sum;
2088 #endif /* IXGBE_FCOE */
2093 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
2094 hwstats->bprc += bprc;
2095 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
2096 if (hw->mac.type == ixgbe_mac_82598EB)
2097 hwstats->mprc -= bprc;
2098 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
2099 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
2100 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
2101 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
2102 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
2103 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
2104 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
2105 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
2106 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
2107 hwstats->lxontxc += lxon;
2108 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
2109 hwstats->lxofftxc += lxoff;
2110 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
2111 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
2113 * 82598 errata - tx of flow control packets is included in tx counters
2115 xon_off_tot = lxon + lxoff;
2116 hwstats->gptc -= xon_off_tot;
2117 hwstats->mptc -= xon_off_tot;
2118 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
2119 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
2120 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
2121 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
2122 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
2123 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
2124 hwstats->ptc64 -= xon_off_tot;
2125 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
2126 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
2127 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
2128 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
2129 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
2130 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
2131 /* Fill out the OS statistics structure */
2132 net_stats->multicast = hwstats->mprc;
2135 net_stats->rx_errors = hwstats->crcerrs +
2137 net_stats->rx_dropped = 0;
2138 net_stats->rx_length_errors = hwstats->rlec;
2139 net_stats->rx_crc_errors = hwstats->crcerrs;
2140 net_stats->rx_missed_errors = total_mpc;
2143 * VF Stats Collection - skip while resetting because these
2144 * are not clear on read and otherwise you'll sometimes get
2147 if (!test_bit(__IXGBE_RESETTING, &adapter->state)) {
2148 for (i = 0; i < adapter->num_vfs; i++) {
2149 UPDATE_VF_COUNTER_32bit(IXGBE_PVFGPRC(i), \
2150 adapter->vfinfo[i].last_vfstats.gprc, \
2151 adapter->vfinfo[i].vfstats.gprc);
2152 UPDATE_VF_COUNTER_32bit(IXGBE_PVFGPTC(i), \
2153 adapter->vfinfo[i].last_vfstats.gptc, \
2154 adapter->vfinfo[i].vfstats.gptc);
2155 UPDATE_VF_COUNTER_36bit(IXGBE_PVFGORC_LSB(i), \
2156 IXGBE_PVFGORC_MSB(i), \
2157 adapter->vfinfo[i].last_vfstats.gorc, \
2158 adapter->vfinfo[i].vfstats.gorc);
2159 UPDATE_VF_COUNTER_36bit(IXGBE_PVFGOTC_LSB(i), \
2160 IXGBE_PVFGOTC_MSB(i), \
2161 adapter->vfinfo[i].last_vfstats.gotc, \
2162 adapter->vfinfo[i].vfstats.gotc);
2163 UPDATE_VF_COUNTER_32bit(IXGBE_PVFMPRC(i), \
2164 adapter->vfinfo[i].last_vfstats.mprc, \
2165 adapter->vfinfo[i].vfstats.mprc);
2174 * ixgbe_watchdog_update_link - update the link status
2175 * @adapter - pointer to the device adapter structure
2176 * @link_speed - pointer to a u32 to store the link_speed
2178 static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
2180 struct ixgbe_hw *hw = &adapter->hw;
2181 u32 link_speed = adapter->link_speed;
2182 bool link_up = adapter->link_up;
2183 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
2185 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
2188 if (hw->mac.ops.check_link) {
2189 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
2191 /* always assume link is up, if no check link function */
2192 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
2196 #ifdef HAVE_DCBNL_IEEE
2197 if (adapter->ixgbe_ieee_pfc)
2198 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
2201 if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
2202 hw->mac.ops.fc_enable(hw);
2203 //ixgbe_set_rx_drop_en(adapter);
2207 time_after(jiffies, (adapter->link_check_timeout +
2208 IXGBE_TRY_LINK_TIMEOUT))) {
2209 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
2210 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
2211 IXGBE_WRITE_FLUSH(hw);
2214 adapter->link_up = link_up;
2215 adapter->link_speed = link_speed;
2224 * ixgbe_service_task - manages and runs subtasks
2225 * @work: pointer to work_struct containing our data
2227 static void ixgbe_service_task(struct work_struct *work)
2229 //struct ixgbe_adapter *adapter = container_of(work,
2230 // struct ixgbe_adapter,
2233 //ixgbe_reset_subtask(adapter);
2234 //ixgbe_sfp_detection_subtask(adapter);
2235 //ixgbe_sfp_link_config_subtask(adapter);
2236 //ixgbe_check_overtemp_subtask(adapter);
2237 //ixgbe_watchdog_subtask(adapter);
2239 //ixgbe_fdir_reinit_subtask(adapter);
2241 //ixgbe_check_hang_subtask(adapter);
2243 //ixgbe_service_event_complete(adapter);
2249 #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
2254 * ixgbe_set_mac - Change the Ethernet Address of the NIC
2255 * @netdev: network interface device structure
2256 * @p: pointer to an address structure
2258 * Returns 0 on success, negative on failure
2260 static int ixgbe_set_mac(struct net_device *netdev, void *p)
2262 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2263 struct ixgbe_hw *hw = &adapter->hw;
2264 struct sockaddr *addr = p;
2267 if (!is_valid_ether_addr(addr->sa_data))
2268 return -EADDRNOTAVAIL;
2270 ixgbe_del_mac_filter(adapter, hw->mac.addr,
2272 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2273 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
2276 /* set the correct pool for the new PF MAC address in entry 0 */
2277 ret = ixgbe_add_mac_filter(adapter, hw->mac.addr,
2279 return (ret > 0 ? 0 : ret);
2289 static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
2292 #ifdef ETHTOOL_OPS_COMPAT
2294 return ethtool_ioctl(ifr);
2300 #endif /* NO_VNIC */
2303 void ixgbe_do_reset(struct net_device *netdev)
2305 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2307 if (netif_running(netdev))
2308 ixgbe_reinit_locked(adapter);
2310 ixgbe_reset(adapter);
2319 * ixgbe_probe - Device Initialization Routine
2320 * @pdev: PCI device information struct
2321 * @ent: entry in ixgbe_pci_tbl
2323 * Returns 0 on success, negative on failure
2325 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
2326 * The OS initialization, configuring of the adapter private structure,
2327 * and a hardware reset occur.
2330 int ixgbe_kni_probe(struct pci_dev *pdev,
2331 struct net_device **lad_dev)
2334 struct net_device *netdev;
2335 struct ixgbe_adapter *adapter = NULL;
2336 struct ixgbe_hw *hw = NULL;
2337 static int cards_found;
2340 u16 eeprom_verh, eeprom_verl, eeprom_cfg_blkh, eeprom_cfg_blkl;
2342 u16 build, major, patch;
2343 char *info_string, *i_s_var;
2344 u8 part_str[IXGBE_PBANUM_LENGTH];
2345 enum ixgbe_mac_type mac_type = ixgbe_mac_unknown;
2347 unsigned int indices = num_possible_cpus();
2348 #endif /* HAVE_TX_MQ */
2354 err = pci_enable_device_mem(pdev);
2360 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
2361 IORESOURCE_MEM), ixgbe_driver_name);
2363 dev_err(pci_dev_to_dev(pdev),
2364 "pci_request_selected_regions failed 0x%x\n", err);
2370 * The mac_type is needed before we have the adapter is set up
2371 * so rather than maintain two devID -> MAC tables we dummy up
2372 * an ixgbe_hw stuct and use ixgbe_set_mac_type.
2374 hw = vmalloc(sizeof(struct ixgbe_hw));
2376 pr_info("Unable to allocate memory for early mac "
2379 hw->vendor_id = pdev->vendor;
2380 hw->device_id = pdev->device;
2381 ixgbe_set_mac_type(hw);
2382 mac_type = hw->mac.type;
2388 * Workaround of Silicon errata on 82598. Disable LOs in the PCI switch
2389 * port to which the 82598 is connected to prevent duplicate
2390 * completions caused by LOs. We need the mac type so that we only
2391 * do this on 82598 devices, ixgbe_set_mac_type does this for us if
2392 * we set it's device ID.
2394 if (mac_type == ixgbe_mac_82598EB)
2395 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S);
2397 pci_enable_pcie_error_reporting(pdev);
2399 pci_set_master(pdev);
2405 indices *= IXGBE_DCB_MAX_TRAFFIC_CLASS;
2407 indices = max_t(unsigned int, indices, IXGBE_MAX_DCB_INDICES);
2408 #endif /* HAVE_MQPRIO */
2409 #endif /* CONFIG_DCB */
2411 if (mac_type == ixgbe_mac_82598EB)
2412 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
2414 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
2417 indices += min_t(unsigned int, num_possible_cpus(),
2418 IXGBE_MAX_FCOE_INDICES);
2420 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
2421 #else /* HAVE_TX_MQ */
2422 netdev = alloc_etherdev(sizeof(struct ixgbe_adapter));
2423 #endif /* HAVE_TX_MQ */
2426 goto err_alloc_etherdev;
2429 SET_NETDEV_DEV(netdev, &pdev->dev);
2431 adapter = netdev_priv(netdev);
2432 //pci_set_drvdata(pdev, adapter);
2434 adapter->netdev = netdev;
2435 adapter->pdev = pdev;
2438 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
2442 * call save state here in standalone driver because it relies on
2443 * adapter struct to exist, and needs to call netdev_priv
2445 pci_save_state(pdev);
2448 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
2449 pci_resource_len(pdev, 0));
2454 //ixgbe_assign_netdev_ops(netdev);
2455 ixgbe_set_ethtool_ops(netdev);
2457 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
2459 adapter->bd_number = cards_found;
2461 /* setup the private structure */
2462 err = ixgbe_sw_init(adapter);
2466 /* Make it possible the adapter to be woken up via WOL */
2467 switch (adapter->hw.mac.type) {
2468 case ixgbe_mac_82599EB:
2469 case ixgbe_mac_X540:
2470 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
2477 * check_options must be called before setup_link to set up
2480 //ixgbe_check_options(adapter);
2483 /* reset_hw fills in the perm_addr as well */
2484 hw->phy.reset_if_overtemp = true;
2485 err = hw->mac.ops.reset_hw(hw);
2486 hw->phy.reset_if_overtemp = false;
2487 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
2488 hw->mac.type == ixgbe_mac_82598EB) {
2490 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
2491 e_dev_err("failed to load because an unsupported SFP+ "
2492 "module type was detected.\n");
2493 e_dev_err("Reload the driver after installing a supported "
2497 e_dev_err("HW Init failed: %d\n", err);
2502 //if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
2503 // ixgbe_probe_vf(adapter);
2506 #ifdef MAX_SKB_FRAGS
2507 netdev->features |= NETIF_F_SG |
2510 #ifdef NETIF_F_IPV6_CSUM
2511 netdev->features |= NETIF_F_IPV6_CSUM;
2514 #ifdef NETIF_F_HW_VLAN_TX
2515 netdev->features |= NETIF_F_HW_VLAN_TX |
2519 netdev->features |= NETIF_F_TSO;
2520 #endif /* NETIF_F_TSO */
2522 netdev->features |= NETIF_F_TSO6;
2523 #endif /* NETIF_F_TSO6 */
2524 #ifdef NETIF_F_RXHASH
2525 netdev->features |= NETIF_F_RXHASH;
2526 #endif /* NETIF_F_RXHASH */
2528 #ifdef HAVE_NDO_SET_FEATURES
2529 netdev->features |= NETIF_F_RXCSUM;
2531 /* copy netdev features into list of user selectable features */
2532 netdev->hw_features |= netdev->features;
2534 /* give us the option of enabling RSC/LRO later */
2536 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
2538 netdev->hw_features |= NETIF_F_LRO;
2543 /* this is only needed on kernels prior to 2.6.39 */
2544 netdev->features |= NETIF_F_GRO;
2545 #endif /* NETIF_F_GRO */
2548 #ifdef NETIF_F_HW_VLAN_TX
2549 /* set this bit last since it cannot be part of hw_features */
2550 netdev->features |= NETIF_F_HW_VLAN_FILTER;
2552 switch (adapter->hw.mac.type) {
2553 case ixgbe_mac_82599EB:
2554 case ixgbe_mac_X540:
2555 netdev->features |= NETIF_F_SCTP_CSUM;
2556 #ifdef HAVE_NDO_SET_FEATURES
2557 netdev->hw_features |= NETIF_F_SCTP_CSUM |
2565 #ifdef HAVE_NETDEV_VLAN_FEATURES
2566 netdev->vlan_features |= NETIF_F_SG |
2572 #endif /* HAVE_NETDEV_VLAN_FEATURES */
2574 * If perfect filters were enabled in check_options(), enable them
2575 * on the netdevice too.
2577 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
2578 netdev->features |= NETIF_F_NTUPLE;
2579 if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED)
2580 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
2581 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
2582 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
2583 if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) {
2584 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
2585 /* clear n-tuple support in the netdev unconditionally */
2586 netdev->features &= ~NETIF_F_NTUPLE;
2589 #ifdef NETIF_F_RXHASH
2590 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
2591 netdev->features &= ~NETIF_F_RXHASH;
2593 #endif /* NETIF_F_RXHASH */
2594 if (netdev->features & NETIF_F_LRO) {
2595 if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
2596 ((adapter->rx_itr_setting == 1) ||
2597 (adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR))) {
2598 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
2599 } else if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) {
2601 e_info(probe, "InterruptThrottleRate set too high, "
2604 e_info(probe, "InterruptThrottleRate set too high, "
2605 "falling back to software LRO\n");
2610 //netdev->dcbnl_ops = &dcbnl_ops;
2615 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
2616 ixgbe_get_device_caps(hw, &device_caps);
2617 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS) {
2618 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
2619 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
2620 e_info(probe, "FCoE offload feature is not available. "
2621 "Disabling FCoE offload feature\n");
2623 #ifndef HAVE_NETDEV_OPS_FCOE_ENABLE
2625 adapter->flags |= IXGBE_FLAG_FCOE_ENABLED;
2626 adapter->ring_feature[RING_F_FCOE].indices =
2628 netdev->features |= NETIF_F_FSO |
2631 netdev->fcoe_ddp_xid = IXGBE_FCOE_DDP_MAX - 1;
2633 #endif /* HAVE_NETDEV_OPS_FCOE_ENABLE */
2634 #ifdef HAVE_NETDEV_VLAN_FEATURES
2635 netdev->vlan_features |= NETIF_F_FSO |
2638 #endif /* HAVE_NETDEV_VLAN_FEATURES */
2640 #endif /* NETIF_F_FSO */
2641 #endif /* IXGBE_FCOE */
2643 #endif /* MAX_SKB_FRAGS */
2644 /* make sure the EEPROM is good */
2645 if (hw->eeprom.ops.validate_checksum &&
2646 (hw->eeprom.ops.validate_checksum(hw, NULL) < 0)) {
2647 e_dev_err("The EEPROM Checksum Is Not Valid\n");
2652 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
2653 #ifdef ETHTOOL_GPERMADDR
2654 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
2656 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
2657 e_dev_err("invalid MAC address\n");
2662 if (ixgbe_validate_mac_addr(netdev->dev_addr)) {
2663 e_dev_err("invalid MAC address\n");
2668 memcpy(&adapter->mac_table[0].addr, hw->mac.perm_addr,
2670 adapter->mac_table[0].queue = adapter->num_vfs;
2671 adapter->mac_table[0].state = (IXGBE_MAC_STATE_DEFAULT |
2672 IXGBE_MAC_STATE_IN_USE);
2673 hw->mac.ops.set_rar(hw, 0, adapter->mac_table[0].addr,
2674 adapter->mac_table[0].queue,
2677 //setup_timer(&adapter->service_timer, &ixgbe_service_timer,
2678 // (unsigned long) adapter);
2680 //INIT_WORK(&adapter->service_task, ixgbe_service_task);
2681 //clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
2683 //err = ixgbe_init_interrupt_scheme(adapter);
2685 // goto err_sw_init;
2687 //adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
2688 ixgbe_set_num_queues(adapter);
2691 /* WOL not supported for all but the following */
2692 switch (pdev->device) {
2693 case IXGBE_DEV_ID_82599_SFP:
2694 /* Only these subdevice supports WOL */
2695 switch (pdev->subsystem_device) {
2696 case IXGBE_SUBDEV_ID_82599_560FLR:
2697 /* only support first port */
2698 if (hw->bus.func != 0)
2700 case IXGBE_SUBDEV_ID_82599_SFP:
2701 adapter->wol = IXGBE_WUFC_MAG;
2705 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
2706 /* All except this subdevice support WOL */
2707 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
2708 adapter->wol = IXGBE_WUFC_MAG;
2710 case IXGBE_DEV_ID_82599_KX4:
2711 adapter->wol = IXGBE_WUFC_MAG;
2713 case IXGBE_DEV_ID_X540T:
2714 /* Check eeprom to see if it is enabled */
2715 ixgbe_read_eeprom(hw, 0x2c, &adapter->eeprom_cap);
2716 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
2718 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
2719 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
2720 (hw->bus.func == 0)))
2721 adapter->wol = IXGBE_WUFC_MAG;
2724 //device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
2728 * Save off EEPROM version number and Option Rom version which
2729 * together make a unique identify for the eeprom
2731 ixgbe_read_eeprom(hw, 0x2e, &eeprom_verh);
2732 ixgbe_read_eeprom(hw, 0x2d, &eeprom_verl);
2734 etrack_id = (eeprom_verh << 16) | eeprom_verl;
2736 ixgbe_read_eeprom(hw, 0x17, &offset);
2738 /* Make sure offset to SCSI block is valid */
2739 if (!(offset == 0x0) && !(offset == 0xffff)) {
2740 ixgbe_read_eeprom(hw, offset + 0x84, &eeprom_cfg_blkh);
2741 ixgbe_read_eeprom(hw, offset + 0x83, &eeprom_cfg_blkl);
2743 /* Only display Option Rom if exist */
2744 if (eeprom_cfg_blkl && eeprom_cfg_blkh) {
2745 major = eeprom_cfg_blkl >> 8;
2746 build = (eeprom_cfg_blkl << 8) | (eeprom_cfg_blkh >> 8);
2747 patch = eeprom_cfg_blkh & 0x00ff;
2749 snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
2750 "0x%08x, %d.%d.%d", etrack_id, major, build,
2753 snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
2754 "0x%08x", etrack_id);
2757 snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
2758 "0x%08x", etrack_id);
2761 /* reset the hardware with the new settings */
2762 err = hw->mac.ops.start_hw(hw);
2763 if (err == IXGBE_ERR_EEPROM_VERSION) {
2764 /* We are running on a pre-production device, log a warning */
2765 e_dev_warn("This device is a pre-production adapter/LOM. "
2766 "Please be aware there may be issues associated "
2767 "with your hardware. If you are experiencing "
2768 "problems please contact your Intel or hardware "
2769 "representative who provided you with this "
2772 /* pick up the PCI bus settings for reporting later */
2773 if (hw->mac.ops.get_bus_info)
2774 hw->mac.ops.get_bus_info(hw);
2776 strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
2779 adapter->netdev_registered = true;
2781 /* power down the optics */
2782 if ((hw->phy.multispeed_fiber) ||
2783 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
2784 (hw->mac.type == ixgbe_mac_82599EB)))
2785 ixgbe_disable_tx_laser(hw);
2787 /* carrier off reporting is important to ethtool even BEFORE open */
2788 netif_carrier_off(netdev);
2789 /* keep stopping all the transmit queues for older kernels */
2790 netif_tx_stop_all_queues(netdev);
2793 /* print all messages at the end so that we use our eth%d name */
2794 /* print bus type/speed/width info */
2795 e_dev_info("(PCI Express:%s:%s) ",
2796 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
2797 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
2799 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
2800 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
2801 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
2804 /* print the MAC address */
2805 for (i = 0; i < 6; i++)
2806 pr_cont("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':');
2808 /* First try to read PBA as a string */
2809 err = ixgbe_read_pba_string(hw, part_str, IXGBE_PBANUM_LENGTH);
2811 strlcpy(part_str, "Unknown", sizeof(part_str));
2812 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
2813 e_info(probe, "MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
2814 hw->mac.type, hw->phy.type, hw->phy.sfp_type, part_str);
2816 e_info(probe, "MAC: %d, PHY: %d, PBA No: %s\n",
2817 hw->mac.type, hw->phy.type, part_str);
2819 if (((hw->bus.speed == ixgbe_bus_speed_2500) &&
2820 (hw->bus.width <= ixgbe_bus_width_pcie_x4)) ||
2821 (hw->bus.width <= ixgbe_bus_width_pcie_x2)) {
2822 e_dev_warn("PCI-Express bandwidth available for this "
2823 "card is not sufficient for optimal "
2825 e_dev_warn("For optimal performance a x8 PCI-Express "
2826 "slot is required.\n");
2829 #define INFO_STRING_LEN 255
2830 info_string = kzalloc(INFO_STRING_LEN, GFP_KERNEL);
2832 e_err(probe, "allocation for info string failed\n");
2833 goto no_info_string;
2836 i_s_var = info_string;
2837 count += snprintf(i_s_var, INFO_STRING_LEN, "Enabled Features: ");
2839 i_s_var = info_string + count;
2840 count += snprintf(i_s_var, (INFO_STRING_LEN - count),
2841 "RxQ: %d TxQ: %d ", adapter->num_rx_queues,
2842 adapter->num_tx_queues);
2843 i_s_var = info_string + count;
2845 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
2846 count += snprintf(i_s_var, INFO_STRING_LEN - count, "FCoE ");
2847 i_s_var = info_string + count;
2850 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2851 count += snprintf(i_s_var, INFO_STRING_LEN - count,
2853 i_s_var = info_string + count;
2855 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
2856 count += snprintf(i_s_var, INFO_STRING_LEN - count,
2858 i_s_var = info_string + count;
2860 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2861 count += snprintf(i_s_var, INFO_STRING_LEN - count, "DCB ");
2862 i_s_var = info_string + count;
2864 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
2865 count += snprintf(i_s_var, INFO_STRING_LEN - count, "RSS ");
2866 i_s_var = info_string + count;
2868 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2869 count += snprintf(i_s_var, INFO_STRING_LEN - count, "DCA ");
2870 i_s_var = info_string + count;
2872 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
2873 count += snprintf(i_s_var, INFO_STRING_LEN - count, "RSC ");
2874 i_s_var = info_string + count;
2876 #ifndef IXGBE_NO_LRO
2877 else if (netdev->features & NETIF_F_LRO) {
2878 count += snprintf(i_s_var, INFO_STRING_LEN - count, "LRO ");
2879 i_s_var = info_string + count;
2883 BUG_ON(i_s_var > (info_string + INFO_STRING_LEN));
2884 /* end features printing */
2885 e_info(probe, "%s\n", info_string);
2889 /* firmware requires blank driver version */
2890 ixgbe_set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, 0xFF);
2892 #if defined(HAVE_NETDEV_STORAGE_ADDRESS) && defined(NETDEV_HW_ADDR_T_SAN)
2893 /* add san mac addr to netdev */
2894 //ixgbe_add_sanmac_netdev(netdev);
2896 #endif /* (HAVE_NETDEV_STORAGE_ADDRESS) && (NETDEV_HW_ADDR_T_SAN) */
2897 e_info(probe, "Intel(R) 10 Gigabit Network Connection\n");
2901 //if (ixgbe_sysfs_init(adapter))
2902 // e_err(probe, "failed to allocate sysfs resources\n");
2905 //if (ixgbe_procfs_init(adapter))
2906 // e_err(probe, "failed to allocate procfs resources\n");
2907 #endif /* IXGBE_PROCFS */
2908 #endif /* IXGBE_SYSFS */
2913 //ixgbe_clear_interrupt_scheme(adapter);
2914 //ixgbe_release_hw_control(adapter);
2916 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
2917 if (adapter->mac_table)
2918 kfree(adapter->mac_table);
2919 iounmap(hw->hw_addr);
2921 free_netdev(netdev);
2923 //pci_release_selected_regions(pdev,
2924 // pci_select_bars(pdev, IORESOURCE_MEM));
2927 pci_disable_device(pdev);
2932 * ixgbe_remove - Device Removal Routine
2933 * @pdev: PCI device information struct
2935 * ixgbe_remove is called by the PCI subsystem to alert the driver
2936 * that it should release a PCI device. The could be caused by a
2937 * Hot-Plug event, or because the driver is going to be removed from
2940 void ixgbe_kni_remove(struct pci_dev *pdev)
2942 pci_disable_device(pdev);
2946 u16 ixgbe_read_pci_cfg_word(struct ixgbe_hw *hw, u32 reg)
2949 struct ixgbe_adapter *adapter = hw->back;
2951 pci_read_config_word(adapter->pdev, reg, &value);
2955 void ixgbe_write_pci_cfg_word(struct ixgbe_hw *hw, u32 reg, u16 value)
2957 struct ixgbe_adapter *adapter = hw->back;
2959 pci_write_config_word(adapter->pdev, reg, value);
2962 void ewarn(struct ixgbe_hw *hw, const char *st, u32 status)
2964 struct ixgbe_adapter *adapter = hw->back;
2966 netif_warn(adapter, drv, adapter->netdev, "%s", st);