Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel 10 Gigabit PCI Express Linux driver |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 4 | Copyright(c) 1999 - 2016 Intel Corporation. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms and conditions of the GNU General Public License, |
| 8 | version 2, as published by the Free Software Foundation. |
| 9 | |
| 10 | This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License along with |
| 16 | this program; if not, write to the Free Software Foundation, Inc., |
| 17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | |
| 19 | The full GNU General Public License is included in this distribution in |
| 20 | the file called "COPYING". |
| 21 | |
| 22 | Contact Information: |
Jacob Keller | b89aae7 | 2014-02-22 01:23:50 +0000 | [diff] [blame] | 23 | Linux NICS <linux.nics@intel.com> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 24 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 26 | |
| 27 | *******************************************************************************/ |
| 28 | |
| 29 | #include <linux/types.h> |
| 30 | #include <linux/module.h> |
| 31 | #include <linux/pci.h> |
| 32 | #include <linux/netdevice.h> |
| 33 | #include <linux/vmalloc.h> |
| 34 | #include <linux/string.h> |
| 35 | #include <linux/in.h> |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 36 | #include <linux/interrupt.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 37 | #include <linux/ip.h> |
| 38 | #include <linux/tcp.h> |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 39 | #include <linux/sctp.h> |
Lucy Liu | 6012786 | 2009-07-22 14:07:33 +0000 | [diff] [blame] | 40 | #include <linux/pkt_sched.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 41 | #include <linux/ipv6.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 42 | #include <linux/slab.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 43 | #include <net/checksum.h> |
| 44 | #include <net/ip6_checksum.h> |
Martin K Petersen | c762dff | 2014-11-15 14:24:51 +0000 | [diff] [blame] | 45 | #include <linux/etherdevice.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 46 | #include <linux/ethtool.h> |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 47 | #include <linux/if.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 48 | #include <linux/if_vlan.h> |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 49 | #include <linux/if_macvlan.h> |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 50 | #include <linux/if_bridge.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 51 | #include <linux/prefetch.h> |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 52 | #include <scsi/fc/fc_fcoe.h> |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 53 | #include <net/udp_tunnel.h> |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 54 | #include <net/pkt_cls.h> |
| 55 | #include <net/tc_act/tc_gact.h> |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 56 | #include <net/tc_act/tc_mirred.h> |
Sowmini Varadhan | 9f3c750 | 2016-10-24 15:36:39 -0700 | [diff] [blame] | 57 | #include <net/vxlan.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 58 | |
| 59 | #include "ixgbe.h" |
| 60 | #include "ixgbe_common.h" |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 61 | #include "ixgbe_dcb_82599.h" |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 62 | #include "ixgbe_sriov.h" |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 63 | #include "ixgbe_model.h" |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 64 | |
| 65 | char ixgbe_driver_name[] = "ixgbe"; |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 66 | static const char ixgbe_driver_string[] = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 67 | "Intel(R) 10 Gigabit PCI Express Network Driver"; |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 68 | #ifdef IXGBE_FCOE |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 69 | char ixgbe_default_device_descr[] = |
| 70 | "Intel(R) 10 Gigabit Network Connection"; |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 71 | #else |
| 72 | static char ixgbe_default_device_descr[] = |
| 73 | "Intel(R) 10 Gigabit Network Connection"; |
| 74 | #endif |
Mark Rustad | 1733284 | 2016-12-12 15:08:13 -0800 | [diff] [blame] | 75 | #define DRV_VERSION "5.0.0-k" |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 76 | const char ixgbe_driver_version[] = DRV_VERSION; |
Don Skidmore | a52055e | 2011-02-23 09:58:39 +0000 | [diff] [blame] | 77 | static const char ixgbe_copyright[] = |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 78 | "Copyright (c) 1999-2016 Intel Corporation."; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 79 | |
Don Skidmore | f44e751 | 2015-06-09 16:36:23 -0700 | [diff] [blame] | 80 | static const char ixgbe_overheat_msg[] = "Network adapter has been stopped because it has over heated. Restart the computer. If the problem persists, power off the system and replace the adapter"; |
| 81 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 82 | static const struct ixgbe_info *ixgbe_info_tbl[] = { |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 83 | [board_82598] = &ixgbe_82598_info, |
| 84 | [board_82599] = &ixgbe_82599_info, |
| 85 | [board_X540] = &ixgbe_X540_info, |
| 86 | [board_X550] = &ixgbe_X550_info, |
| 87 | [board_X550EM_x] = &ixgbe_X550EM_x_info, |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 88 | [board_x550em_a] = &ixgbe_x550em_a_info, |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 89 | [board_x550em_a_fw] = &ixgbe_x550em_a_fw_info, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | /* ixgbe_pci_tbl - PCI Device ID Table |
| 93 | * |
| 94 | * Wildcard entries (PCI_ANY_ID) should come last |
| 95 | * Last entry must be all 0s |
| 96 | * |
| 97 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 98 | * Class, Class Mask, private data (not used) } |
| 99 | */ |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 100 | static const struct pci_device_id ixgbe_pci_tbl[] = { |
Alexander Duyck | 54239c6 | 2011-07-15 03:06:06 +0000 | [diff] [blame] | 101 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 }, |
| 102 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 }, |
| 103 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 }, |
| 104 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 }, |
| 105 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 }, |
| 106 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 }, |
| 107 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 }, |
| 108 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 }, |
| 109 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 }, |
| 110 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 }, |
| 111 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 }, |
| 112 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 }, |
| 113 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 }, |
| 114 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 }, |
| 115 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 }, |
| 116 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 }, |
| 117 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 }, |
| 118 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 }, |
| 119 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 }, |
| 120 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 }, |
| 121 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 }, |
| 122 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 }, |
| 123 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 }, |
| 124 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 }, |
| 125 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 }, |
| 126 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 }, |
Don Skidmore | 8f58332 | 2013-07-27 06:25:38 +0000 | [diff] [blame] | 127 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_QSFP_SF_QP), board_82599 }, |
Emil Tantilov | 7d14528 | 2011-09-08 08:30:14 +0000 | [diff] [blame] | 128 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 }, |
Emil Tantilov | 9e791e4 | 2011-11-04 06:43:29 +0000 | [diff] [blame] | 129 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 }, |
joshua.a.hay@intel.com | df376f0 | 2012-09-21 00:08:21 +0000 | [diff] [blame] | 130 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 }, |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 131 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T), board_X550}, |
Mark Rustad | a711ad8 | 2016-03-21 11:21:31 -0700 | [diff] [blame] | 132 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T1), board_X550}, |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 133 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KX4), board_X550EM_x}, |
| 134 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KR), board_X550EM_x}, |
Don Skidmore | deda562 | 2015-06-09 17:39:46 -0700 | [diff] [blame] | 135 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_10G_T), board_X550EM_x}, |
Mark Rustad | 018d714 | 2015-08-08 16:19:19 -0700 | [diff] [blame] | 136 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_SFP), board_X550EM_x}, |
Mark Rustad | f572b2c | 2016-04-01 12:18:46 -0700 | [diff] [blame] | 137 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR), board_x550em_a }, |
| 138 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR_L), board_x550em_a }, |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 139 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP_N), board_x550em_a }, |
Mark Rustad | 200157c | 2016-04-01 12:18:40 -0700 | [diff] [blame] | 140 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII), board_x550em_a }, |
| 141 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII_L), board_x550em_a }, |
Don Skidmore | 92ed843 | 2016-08-17 20:34:40 -0400 | [diff] [blame] | 142 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_10G_T), board_x550em_a}, |
Mark Rustad | 2d40cd1 | 2016-04-01 12:18:35 -0700 | [diff] [blame] | 143 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP), board_x550em_a }, |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 144 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_1G_T), board_x550em_a_fw }, |
| 145 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_1G_T_L), board_x550em_a_fw }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 146 | /* required last entry */ |
| 147 | {0, } |
| 148 | }; |
| 149 | MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl); |
| 150 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 151 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 152 | static int ixgbe_notify_dca(struct notifier_block *, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 153 | void *p); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 154 | static struct notifier_block dca_notifier = { |
| 155 | .notifier_call = ixgbe_notify_dca, |
| 156 | .next = NULL, |
| 157 | .priority = 0 |
| 158 | }; |
| 159 | #endif |
| 160 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 161 | #ifdef CONFIG_PCI_IOV |
| 162 | static unsigned int max_vfs; |
| 163 | module_param(max_vfs, uint, 0); |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 164 | MODULE_PARM_DESC(max_vfs, |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 165 | "Maximum number of virtual functions to allocate per physical function - default is zero and maximum value is 63. (Deprecated)"); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 166 | #endif /* CONFIG_PCI_IOV */ |
| 167 | |
Peter P Waskiewicz Jr | 8ef78ad | 2012-02-01 09:19:21 +0000 | [diff] [blame] | 168 | static unsigned int allow_unsupported_sfp; |
| 169 | module_param(allow_unsupported_sfp, uint, 0); |
| 170 | MODULE_PARM_DESC(allow_unsupported_sfp, |
| 171 | "Allow unsupported and untested SFP+ modules on 82599-based adapters"); |
| 172 | |
stephen hemminger | b3f4d59 | 2012-03-13 06:04:20 +0000 | [diff] [blame] | 173 | #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK) |
| 174 | static int debug = -1; |
| 175 | module_param(debug, int, 0); |
| 176 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 177 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 178 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 179 | MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver"); |
| 180 | MODULE_LICENSE("GPL"); |
| 181 | MODULE_VERSION(DRV_VERSION); |
| 182 | |
Mark Rustad | 780484d | 2015-10-21 17:21:10 -0700 | [diff] [blame] | 183 | static struct workqueue_struct *ixgbe_wq; |
| 184 | |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 185 | static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev); |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 186 | static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *); |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 187 | |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 188 | static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter *adapter, |
| 189 | u32 reg, u16 *value) |
| 190 | { |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 191 | struct pci_dev *parent_dev; |
| 192 | struct pci_bus *parent_bus; |
| 193 | |
| 194 | parent_bus = adapter->pdev->bus->parent; |
| 195 | if (!parent_bus) |
| 196 | return -1; |
| 197 | |
| 198 | parent_dev = parent_bus->self; |
| 199 | if (!parent_dev) |
| 200 | return -1; |
| 201 | |
Yijing Wang | c0798ed | 2013-09-04 17:30:08 +0000 | [diff] [blame] | 202 | if (!pci_is_pcie(parent_dev)) |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 203 | return -1; |
| 204 | |
Yijing Wang | c0798ed | 2013-09-04 17:30:08 +0000 | [diff] [blame] | 205 | pcie_capability_read_word(parent_dev, reg, value); |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 206 | if (*value == IXGBE_FAILED_READ_CFG_WORD && |
| 207 | ixgbe_check_cfg_remove(&adapter->hw, parent_dev)) |
| 208 | return -1; |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | static s32 ixgbe_get_parent_bus_info(struct ixgbe_adapter *adapter) |
| 213 | { |
| 214 | struct ixgbe_hw *hw = &adapter->hw; |
| 215 | u16 link_status = 0; |
| 216 | int err; |
| 217 | |
| 218 | hw->bus.type = ixgbe_bus_type_pci_express; |
| 219 | |
| 220 | /* Get the negotiated link width and speed from PCI config space of the |
| 221 | * parent, as this device is behind a switch |
| 222 | */ |
| 223 | err = ixgbe_read_pci_cfg_word_parent(adapter, 18, &link_status); |
| 224 | |
| 225 | /* assume caller will handle error case */ |
| 226 | if (err) |
| 227 | return err; |
| 228 | |
| 229 | hw->bus.width = ixgbe_convert_bus_width(link_status); |
| 230 | hw->bus.speed = ixgbe_convert_bus_speed(link_status); |
| 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 235 | /** |
| 236 | * ixgbe_check_from_parent - Determine whether PCIe info should come from parent |
| 237 | * @hw: hw specific details |
| 238 | * |
| 239 | * This function is used by probe to determine whether a device's PCI-Express |
| 240 | * bandwidth details should be gathered from the parent bus instead of from the |
| 241 | * device. Used to ensure that various locations all have the correct device ID |
| 242 | * checks. |
| 243 | */ |
| 244 | static inline bool ixgbe_pcie_from_parent(struct ixgbe_hw *hw) |
| 245 | { |
| 246 | switch (hw->device_id) { |
| 247 | case IXGBE_DEV_ID_82599_SFP_SF_QP: |
Don Skidmore | 8f58332 | 2013-07-27 06:25:38 +0000 | [diff] [blame] | 248 | case IXGBE_DEV_ID_82599_QSFP_SF_QP: |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 249 | return true; |
| 250 | default: |
| 251 | return false; |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | static void ixgbe_check_minimum_link(struct ixgbe_adapter *adapter, |
| 256 | int expected_gts) |
| 257 | { |
Don Skidmore | f9328bc | 2015-06-18 13:24:06 -0400 | [diff] [blame] | 258 | struct ixgbe_hw *hw = &adapter->hw; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 259 | int max_gts = 0; |
| 260 | enum pci_bus_speed speed = PCI_SPEED_UNKNOWN; |
| 261 | enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN; |
| 262 | struct pci_dev *pdev; |
| 263 | |
Don Skidmore | f9328bc | 2015-06-18 13:24:06 -0400 | [diff] [blame] | 264 | /* Some devices are not connected over PCIe and thus do not negotiate |
| 265 | * speed. These devices do not have valid bus info, and thus any report |
| 266 | * we generate may not be correct. |
| 267 | */ |
| 268 | if (hw->bus.type == ixgbe_bus_type_internal) |
| 269 | return; |
| 270 | |
Jacob Keller | 56d1392 | 2015-06-10 11:44:45 -0700 | [diff] [blame] | 271 | /* determine whether to use the parent device */ |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 272 | if (ixgbe_pcie_from_parent(&adapter->hw)) |
| 273 | pdev = adapter->pdev->bus->parent->self; |
| 274 | else |
| 275 | pdev = adapter->pdev; |
| 276 | |
| 277 | if (pcie_get_minimum_link(pdev, &speed, &width) || |
| 278 | speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) { |
| 279 | e_dev_warn("Unable to determine PCI Express bandwidth.\n"); |
| 280 | return; |
| 281 | } |
| 282 | |
| 283 | switch (speed) { |
| 284 | case PCIE_SPEED_2_5GT: |
| 285 | /* 8b/10b encoding reduces max throughput by 20% */ |
| 286 | max_gts = 2 * width; |
| 287 | break; |
| 288 | case PCIE_SPEED_5_0GT: |
| 289 | /* 8b/10b encoding reduces max throughput by 20% */ |
| 290 | max_gts = 4 * width; |
| 291 | break; |
| 292 | case PCIE_SPEED_8_0GT: |
Jacob Keller | 9f0a433 | 2013-10-18 05:09:19 +0000 | [diff] [blame] | 293 | /* 128b/130b encoding reduces throughput by less than 2% */ |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 294 | max_gts = 8 * width; |
| 295 | break; |
| 296 | default: |
| 297 | e_dev_warn("Unable to determine PCI Express bandwidth.\n"); |
| 298 | return; |
| 299 | } |
| 300 | |
| 301 | e_dev_info("PCI Express bandwidth of %dGT/s available\n", |
| 302 | max_gts); |
| 303 | e_dev_info("(Speed:%s, Width: x%d, Encoding Loss:%s)\n", |
| 304 | (speed == PCIE_SPEED_8_0GT ? "8.0GT/s" : |
| 305 | speed == PCIE_SPEED_5_0GT ? "5.0GT/s" : |
| 306 | speed == PCIE_SPEED_2_5GT ? "2.5GT/s" : |
| 307 | "Unknown"), |
| 308 | width, |
| 309 | (speed == PCIE_SPEED_2_5GT ? "20%" : |
| 310 | speed == PCIE_SPEED_5_0GT ? "20%" : |
Jacob Keller | 9f0a433 | 2013-10-18 05:09:19 +0000 | [diff] [blame] | 311 | speed == PCIE_SPEED_8_0GT ? "<2%" : |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 312 | "Unknown")); |
| 313 | |
| 314 | if (max_gts < expected_gts) { |
| 315 | e_dev_warn("This is not sufficient for optimal performance of this card.\n"); |
| 316 | e_dev_warn("For optimal performance, at least %dGT/s of bandwidth is required.\n", |
| 317 | expected_gts); |
| 318 | e_dev_warn("A slot with more lanes and/or higher speed is suggested.\n"); |
| 319 | } |
| 320 | } |
| 321 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 322 | static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter) |
| 323 | { |
| 324 | if (!test_bit(__IXGBE_DOWN, &adapter->state) && |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 325 | !test_bit(__IXGBE_REMOVING, &adapter->state) && |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 326 | !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state)) |
Mark Rustad | 780484d | 2015-10-21 17:21:10 -0700 | [diff] [blame] | 327 | queue_work(ixgbe_wq, &adapter->service_task); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 328 | } |
| 329 | |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 330 | static void ixgbe_remove_adapter(struct ixgbe_hw *hw) |
| 331 | { |
| 332 | struct ixgbe_adapter *adapter = hw->back; |
| 333 | |
| 334 | if (!hw->hw_addr) |
| 335 | return; |
| 336 | hw->hw_addr = NULL; |
| 337 | e_dev_err("Adapter removed\n"); |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 338 | if (test_bit(__IXGBE_SERVICE_INITED, &adapter->state)) |
| 339 | ixgbe_service_event_schedule(adapter); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 340 | } |
| 341 | |
Mark Rustad | f8e2472 | 2014-03-18 07:03:40 +0000 | [diff] [blame] | 342 | static void ixgbe_check_remove(struct ixgbe_hw *hw, u32 reg) |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 343 | { |
| 344 | u32 value; |
| 345 | |
| 346 | /* The following check not only optimizes a bit by not |
| 347 | * performing a read on the status register when the |
| 348 | * register just read was a status register read that |
| 349 | * returned IXGBE_FAILED_READ_REG. It also blocks any |
| 350 | * potential recursion. |
| 351 | */ |
| 352 | if (reg == IXGBE_STATUS) { |
| 353 | ixgbe_remove_adapter(hw); |
| 354 | return; |
| 355 | } |
| 356 | value = ixgbe_read_reg(hw, IXGBE_STATUS); |
| 357 | if (value == IXGBE_FAILED_READ_REG) |
| 358 | ixgbe_remove_adapter(hw); |
| 359 | } |
| 360 | |
Mark Rustad | f8e2472 | 2014-03-18 07:03:40 +0000 | [diff] [blame] | 361 | /** |
| 362 | * ixgbe_read_reg - Read from device register |
| 363 | * @hw: hw specific details |
| 364 | * @reg: offset of register to read |
| 365 | * |
| 366 | * Returns : value read or IXGBE_FAILED_READ_REG if removed |
| 367 | * |
| 368 | * This function is used to read device registers. It checks for device |
| 369 | * removal by confirming any read that returns all ones by checking the |
| 370 | * status register value for all ones. This function avoids reading from |
| 371 | * the hardware if a removal was previously detected in which case it |
| 372 | * returns IXGBE_FAILED_READ_REG (all ones). |
| 373 | */ |
| 374 | u32 ixgbe_read_reg(struct ixgbe_hw *hw, u32 reg) |
| 375 | { |
| 376 | u8 __iomem *reg_addr = ACCESS_ONCE(hw->hw_addr); |
| 377 | u32 value; |
| 378 | |
| 379 | if (ixgbe_removed(reg_addr)) |
| 380 | return IXGBE_FAILED_READ_REG; |
Mark Rustad | 2f2219b | 2016-04-07 10:43:50 -0700 | [diff] [blame] | 381 | if (unlikely(hw->phy.nw_mng_if_sel & |
| 382 | IXGBE_NW_MNG_IF_SEL_ENABLE_10_100M)) { |
| 383 | struct ixgbe_adapter *adapter; |
| 384 | int i; |
| 385 | |
| 386 | for (i = 0; i < 200; ++i) { |
| 387 | value = readl(reg_addr + IXGBE_MAC_SGMII_BUSY); |
| 388 | if (likely(!value)) |
| 389 | goto writes_completed; |
| 390 | if (value == IXGBE_FAILED_READ_REG) { |
| 391 | ixgbe_remove_adapter(hw); |
| 392 | return IXGBE_FAILED_READ_REG; |
| 393 | } |
| 394 | udelay(5); |
| 395 | } |
| 396 | |
| 397 | adapter = hw->back; |
| 398 | e_warn(hw, "register writes incomplete %08x\n", value); |
| 399 | } |
| 400 | |
| 401 | writes_completed: |
Mark Rustad | f8e2472 | 2014-03-18 07:03:40 +0000 | [diff] [blame] | 402 | value = readl(reg_addr + reg); |
| 403 | if (unlikely(value == IXGBE_FAILED_READ_REG)) |
| 404 | ixgbe_check_remove(hw, reg); |
| 405 | return value; |
| 406 | } |
| 407 | |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 408 | static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev) |
| 409 | { |
| 410 | u16 value; |
| 411 | |
| 412 | pci_read_config_word(pdev, PCI_VENDOR_ID, &value); |
| 413 | if (value == IXGBE_FAILED_READ_CFG_WORD) { |
| 414 | ixgbe_remove_adapter(hw); |
| 415 | return true; |
| 416 | } |
| 417 | return false; |
| 418 | } |
| 419 | |
| 420 | u16 ixgbe_read_pci_cfg_word(struct ixgbe_hw *hw, u32 reg) |
| 421 | { |
| 422 | struct ixgbe_adapter *adapter = hw->back; |
| 423 | u16 value; |
| 424 | |
| 425 | if (ixgbe_removed(hw->hw_addr)) |
| 426 | return IXGBE_FAILED_READ_CFG_WORD; |
| 427 | pci_read_config_word(adapter->pdev, reg, &value); |
| 428 | if (value == IXGBE_FAILED_READ_CFG_WORD && |
| 429 | ixgbe_check_cfg_remove(hw, adapter->pdev)) |
| 430 | return IXGBE_FAILED_READ_CFG_WORD; |
| 431 | return value; |
| 432 | } |
| 433 | |
| 434 | #ifdef CONFIG_PCI_IOV |
| 435 | static u32 ixgbe_read_pci_cfg_dword(struct ixgbe_hw *hw, u32 reg) |
| 436 | { |
| 437 | struct ixgbe_adapter *adapter = hw->back; |
| 438 | u32 value; |
| 439 | |
| 440 | if (ixgbe_removed(hw->hw_addr)) |
| 441 | return IXGBE_FAILED_READ_CFG_DWORD; |
| 442 | pci_read_config_dword(adapter->pdev, reg, &value); |
| 443 | if (value == IXGBE_FAILED_READ_CFG_DWORD && |
| 444 | ixgbe_check_cfg_remove(hw, adapter->pdev)) |
| 445 | return IXGBE_FAILED_READ_CFG_DWORD; |
| 446 | return value; |
| 447 | } |
| 448 | #endif /* CONFIG_PCI_IOV */ |
| 449 | |
Jacob Keller | ed19231 | 2014-02-22 01:23:53 +0000 | [diff] [blame] | 450 | void ixgbe_write_pci_cfg_word(struct ixgbe_hw *hw, u32 reg, u16 value) |
| 451 | { |
| 452 | struct ixgbe_adapter *adapter = hw->back; |
| 453 | |
| 454 | if (ixgbe_removed(hw->hw_addr)) |
| 455 | return; |
| 456 | pci_write_config_word(adapter->pdev, reg, value); |
| 457 | } |
| 458 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 459 | static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter) |
| 460 | { |
| 461 | BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state)); |
| 462 | |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 463 | /* flush memory to make sure state is correct before next watchdog */ |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 464 | smp_mb__before_atomic(); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 465 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
| 466 | } |
| 467 | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 468 | struct ixgbe_reg_info { |
| 469 | u32 ofs; |
| 470 | char *name; |
| 471 | }; |
| 472 | |
| 473 | static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = { |
| 474 | |
| 475 | /* General Registers */ |
| 476 | {IXGBE_CTRL, "CTRL"}, |
| 477 | {IXGBE_STATUS, "STATUS"}, |
| 478 | {IXGBE_CTRL_EXT, "CTRL_EXT"}, |
| 479 | |
| 480 | /* Interrupt Registers */ |
| 481 | {IXGBE_EICR, "EICR"}, |
| 482 | |
| 483 | /* RX Registers */ |
| 484 | {IXGBE_SRRCTL(0), "SRRCTL"}, |
| 485 | {IXGBE_DCA_RXCTRL(0), "DRXCTL"}, |
| 486 | {IXGBE_RDLEN(0), "RDLEN"}, |
| 487 | {IXGBE_RDH(0), "RDH"}, |
| 488 | {IXGBE_RDT(0), "RDT"}, |
| 489 | {IXGBE_RXDCTL(0), "RXDCTL"}, |
| 490 | {IXGBE_RDBAL(0), "RDBAL"}, |
| 491 | {IXGBE_RDBAH(0), "RDBAH"}, |
| 492 | |
| 493 | /* TX Registers */ |
| 494 | {IXGBE_TDBAL(0), "TDBAL"}, |
| 495 | {IXGBE_TDBAH(0), "TDBAH"}, |
| 496 | {IXGBE_TDLEN(0), "TDLEN"}, |
| 497 | {IXGBE_TDH(0), "TDH"}, |
| 498 | {IXGBE_TDT(0), "TDT"}, |
| 499 | {IXGBE_TXDCTL(0), "TXDCTL"}, |
| 500 | |
| 501 | /* List Terminator */ |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 502 | { .name = NULL } |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 503 | }; |
| 504 | |
| 505 | |
| 506 | /* |
| 507 | * ixgbe_regdump - register printout routine |
| 508 | */ |
| 509 | static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo) |
| 510 | { |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame^] | 511 | int i; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 512 | char rname[16]; |
| 513 | u32 regs[64]; |
| 514 | |
| 515 | switch (reginfo->ofs) { |
| 516 | case IXGBE_SRRCTL(0): |
| 517 | for (i = 0; i < 64; i++) |
| 518 | regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i)); |
| 519 | break; |
| 520 | case IXGBE_DCA_RXCTRL(0): |
| 521 | for (i = 0; i < 64; i++) |
| 522 | regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i)); |
| 523 | break; |
| 524 | case IXGBE_RDLEN(0): |
| 525 | for (i = 0; i < 64; i++) |
| 526 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i)); |
| 527 | break; |
| 528 | case IXGBE_RDH(0): |
| 529 | for (i = 0; i < 64; i++) |
| 530 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i)); |
| 531 | break; |
| 532 | case IXGBE_RDT(0): |
| 533 | for (i = 0; i < 64; i++) |
| 534 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i)); |
| 535 | break; |
| 536 | case IXGBE_RXDCTL(0): |
| 537 | for (i = 0; i < 64; i++) |
| 538 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i)); |
| 539 | break; |
| 540 | case IXGBE_RDBAL(0): |
| 541 | for (i = 0; i < 64; i++) |
| 542 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i)); |
| 543 | break; |
| 544 | case IXGBE_RDBAH(0): |
| 545 | for (i = 0; i < 64; i++) |
| 546 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i)); |
| 547 | break; |
| 548 | case IXGBE_TDBAL(0): |
| 549 | for (i = 0; i < 64; i++) |
| 550 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i)); |
| 551 | break; |
| 552 | case IXGBE_TDBAH(0): |
| 553 | for (i = 0; i < 64; i++) |
| 554 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i)); |
| 555 | break; |
| 556 | case IXGBE_TDLEN(0): |
| 557 | for (i = 0; i < 64; i++) |
| 558 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i)); |
| 559 | break; |
| 560 | case IXGBE_TDH(0): |
| 561 | for (i = 0; i < 64; i++) |
| 562 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i)); |
| 563 | break; |
| 564 | case IXGBE_TDT(0): |
| 565 | for (i = 0; i < 64; i++) |
| 566 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i)); |
| 567 | break; |
| 568 | case IXGBE_TXDCTL(0): |
| 569 | for (i = 0; i < 64; i++) |
| 570 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i)); |
| 571 | break; |
| 572 | default: |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame^] | 573 | pr_info("%-15s %08x\n", |
| 574 | reginfo->name, IXGBE_READ_REG(hw, reginfo->ofs)); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 575 | return; |
| 576 | } |
| 577 | |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame^] | 578 | i = 0; |
| 579 | while (i < 64) { |
| 580 | int j; |
| 581 | char buf[9 * 8 + 1]; |
| 582 | char *p = buf; |
| 583 | |
| 584 | snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i, i + 7); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 585 | for (j = 0; j < 8; j++) |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame^] | 586 | p += sprintf(p, " %08x", regs[i++]); |
| 587 | pr_err("%-15s%s\n", rname, buf); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | } |
| 591 | |
| 592 | /* |
| 593 | * ixgbe_dump - Print registers, tx-rings and rx-rings |
| 594 | */ |
| 595 | static void ixgbe_dump(struct ixgbe_adapter *adapter) |
| 596 | { |
| 597 | struct net_device *netdev = adapter->netdev; |
| 598 | struct ixgbe_hw *hw = &adapter->hw; |
| 599 | struct ixgbe_reg_info *reginfo; |
| 600 | int n = 0; |
| 601 | struct ixgbe_ring *tx_ring; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 602 | struct ixgbe_tx_buffer *tx_buffer; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 603 | union ixgbe_adv_tx_desc *tx_desc; |
| 604 | struct my_u0 { u64 a; u64 b; } *u0; |
| 605 | struct ixgbe_ring *rx_ring; |
| 606 | union ixgbe_adv_rx_desc *rx_desc; |
| 607 | struct ixgbe_rx_buffer *rx_buffer_info; |
| 608 | u32 staterr; |
| 609 | int i = 0; |
| 610 | |
| 611 | if (!netif_msg_hw(adapter)) |
| 612 | return; |
| 613 | |
| 614 | /* Print netdevice Info */ |
| 615 | if (netdev) { |
| 616 | dev_info(&adapter->pdev->dev, "Net device Info\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 617 | pr_info("Device Name state " |
Tobias Klauser | 4a7c972 | 2017-01-18 17:45:01 +0100 | [diff] [blame] | 618 | "trans_start\n"); |
| 619 | pr_info("%-15s %016lX %016lX\n", |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 620 | netdev->name, |
| 621 | netdev->state, |
Tobias Klauser | 4a7c972 | 2017-01-18 17:45:01 +0100 | [diff] [blame] | 622 | dev_trans_start(netdev)); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | /* Print Registers */ |
| 626 | dev_info(&adapter->pdev->dev, "Register Dump\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 627 | pr_info(" Register Name Value\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 628 | for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl; |
| 629 | reginfo->name; reginfo++) { |
| 630 | ixgbe_regdump(hw, reginfo); |
| 631 | } |
| 632 | |
| 633 | /* Print TX Ring Summary */ |
| 634 | if (!netdev || !netif_running(netdev)) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 635 | return; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 636 | |
| 637 | dev_info(&adapter->pdev->dev, "TX Rings Summary\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 638 | pr_info(" %s %s %s %s\n", |
| 639 | "Queue [NTU] [NTC] [bi(ntc)->dma ]", |
| 640 | "leng", "ntw", "timestamp"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 641 | for (n = 0; n < adapter->num_tx_queues; n++) { |
| 642 | tx_ring = adapter->tx_ring[n]; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 643 | tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean]; |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 644 | pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n", |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 645 | n, tx_ring->next_to_use, tx_ring->next_to_clean, |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 646 | (u64)dma_unmap_addr(tx_buffer, dma), |
| 647 | dma_unmap_len(tx_buffer, len), |
| 648 | tx_buffer->next_to_watch, |
| 649 | (u64)tx_buffer->time_stamp); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | /* Print TX Rings */ |
| 653 | if (!netif_msg_tx_done(adapter)) |
| 654 | goto rx_ring_summary; |
| 655 | |
| 656 | dev_info(&adapter->pdev->dev, "TX Rings Dump\n"); |
| 657 | |
| 658 | /* Transmit Descriptor Formats |
| 659 | * |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 660 | * 82598 Advanced Transmit Descriptor |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 661 | * +--------------------------------------------------------------+ |
| 662 | * 0 | Buffer Address [63:0] | |
| 663 | * +--------------------------------------------------------------+ |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 664 | * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 665 | * +--------------------------------------------------------------+ |
| 666 | * 63 46 45 40 39 36 35 32 31 24 23 20 19 0 |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 667 | * |
| 668 | * 82598 Advanced Transmit Descriptor (Write-Back Format) |
| 669 | * +--------------------------------------------------------------+ |
| 670 | * 0 | RSV [63:0] | |
| 671 | * +--------------------------------------------------------------+ |
| 672 | * 8 | RSV | STA | NXTSEQ | |
| 673 | * +--------------------------------------------------------------+ |
| 674 | * 63 36 35 32 31 0 |
| 675 | * |
| 676 | * 82599+ Advanced Transmit Descriptor |
| 677 | * +--------------------------------------------------------------+ |
| 678 | * 0 | Buffer Address [63:0] | |
| 679 | * +--------------------------------------------------------------+ |
| 680 | * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN | |
| 681 | * +--------------------------------------------------------------+ |
| 682 | * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0 |
| 683 | * |
| 684 | * 82599+ Advanced Transmit Descriptor (Write-Back Format) |
| 685 | * +--------------------------------------------------------------+ |
| 686 | * 0 | RSV [63:0] | |
| 687 | * +--------------------------------------------------------------+ |
| 688 | * 8 | RSV | STA | RSV | |
| 689 | * +--------------------------------------------------------------+ |
| 690 | * 63 36 35 32 31 0 |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 691 | */ |
| 692 | |
| 693 | for (n = 0; n < adapter->num_tx_queues; n++) { |
| 694 | tx_ring = adapter->tx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 695 | pr_info("------------------------------------\n"); |
| 696 | pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index); |
| 697 | pr_info("------------------------------------\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 698 | pr_info("%s%s %s %s %s %s\n", |
| 699 | "T [desc] [address 63:0 ] ", |
| 700 | "[PlPOIdStDDt Ln] [bi->dma ] ", |
| 701 | "leng", "ntw", "timestamp", "bi->skb"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 702 | |
| 703 | for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 704 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 705 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 706 | u0 = (struct my_u0 *)tx_desc; |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 707 | if (dma_unmap_len(tx_buffer, len) > 0) { |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame^] | 708 | const char *ring_desc; |
| 709 | |
| 710 | if (i == tx_ring->next_to_use && |
| 711 | i == tx_ring->next_to_clean) |
| 712 | ring_desc = " NTC/U"; |
| 713 | else if (i == tx_ring->next_to_use) |
| 714 | ring_desc = " NTU"; |
| 715 | else if (i == tx_ring->next_to_clean) |
| 716 | ring_desc = " NTC"; |
| 717 | else |
| 718 | ring_desc = ""; |
| 719 | pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p%s", |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 720 | i, |
| 721 | le64_to_cpu(u0->a), |
| 722 | le64_to_cpu(u0->b), |
| 723 | (u64)dma_unmap_addr(tx_buffer, dma), |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 724 | dma_unmap_len(tx_buffer, len), |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 725 | tx_buffer->next_to_watch, |
| 726 | (u64)tx_buffer->time_stamp, |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame^] | 727 | tx_buffer->skb, |
| 728 | ring_desc); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 729 | |
| 730 | if (netif_msg_pktdata(adapter) && |
| 731 | tx_buffer->skb) |
| 732 | print_hex_dump(KERN_INFO, "", |
| 733 | DUMP_PREFIX_ADDRESS, 16, 1, |
| 734 | tx_buffer->skb->data, |
| 735 | dma_unmap_len(tx_buffer, len), |
| 736 | true); |
| 737 | } |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 738 | } |
| 739 | } |
| 740 | |
| 741 | /* Print RX Rings Summary */ |
| 742 | rx_ring_summary: |
| 743 | dev_info(&adapter->pdev->dev, "RX Rings Summary\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 744 | pr_info("Queue [NTU] [NTC]\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 745 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 746 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 747 | pr_info("%5d %5X %5X\n", |
| 748 | n, rx_ring->next_to_use, rx_ring->next_to_clean); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | /* Print RX Rings */ |
| 752 | if (!netif_msg_rx_status(adapter)) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 753 | return; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 754 | |
| 755 | dev_info(&adapter->pdev->dev, "RX Rings Dump\n"); |
| 756 | |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 757 | /* Receive Descriptor Formats |
| 758 | * |
| 759 | * 82598 Advanced Receive Descriptor (Read) Format |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 760 | * 63 1 0 |
| 761 | * +-----------------------------------------------------+ |
| 762 | * 0 | Packet Buffer Address [63:1] |A0/NSE| |
| 763 | * +----------------------------------------------+------+ |
| 764 | * 8 | Header Buffer Address [63:1] | DD | |
| 765 | * +-----------------------------------------------------+ |
| 766 | * |
| 767 | * |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 768 | * 82598 Advanced Receive Descriptor (Write-Back) Format |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 769 | * |
| 770 | * 63 48 47 32 31 30 21 20 16 15 4 3 0 |
| 771 | * +------------------------------------------------------+ |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 772 | * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS | |
| 773 | * | Packet | IP | | | | Type | Type | |
| 774 | * | Checksum | Ident | | | | | | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 775 | * +------------------------------------------------------+ |
| 776 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | |
| 777 | * +------------------------------------------------------+ |
| 778 | * 63 48 47 32 31 20 19 0 |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 779 | * |
| 780 | * 82599+ Advanced Receive Descriptor (Read) Format |
| 781 | * 63 1 0 |
| 782 | * +-----------------------------------------------------+ |
| 783 | * 0 | Packet Buffer Address [63:1] |A0/NSE| |
| 784 | * +----------------------------------------------+------+ |
| 785 | * 8 | Header Buffer Address [63:1] | DD | |
| 786 | * +-----------------------------------------------------+ |
| 787 | * |
| 788 | * |
| 789 | * 82599+ Advanced Receive Descriptor (Write-Back) Format |
| 790 | * |
| 791 | * 63 48 47 32 31 30 21 20 17 16 4 3 0 |
| 792 | * +------------------------------------------------------+ |
| 793 | * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS | |
| 794 | * |/ RTT / PCoE_PARAM | | | CNT | Type | Type | |
| 795 | * |/ Flow Dir Flt ID | | | | | | |
| 796 | * +------------------------------------------------------+ |
| 797 | * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP | |
| 798 | * +------------------------------------------------------+ |
| 799 | * 63 48 47 32 31 20 19 0 |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 800 | */ |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 801 | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 802 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 803 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 804 | pr_info("------------------------------------\n"); |
| 805 | pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index); |
| 806 | pr_info("------------------------------------\n"); |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame^] | 807 | pr_info("%s%s%s\n", |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 808 | "R [desc] [ PktBuf A0] ", |
| 809 | "[ HeadBuf DD] [bi->dma ] [bi->skb ] ", |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame^] | 810 | "<-- Adv Rx Read format"); |
| 811 | pr_info("%s%s%s\n", |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 812 | "RWB[desc] [PcsmIpSHl PtRs] ", |
| 813 | "[vl er S cks ln] ---------------- [bi->skb ] ", |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame^] | 814 | "<-- Adv Rx Write-Back format"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 815 | |
| 816 | for (i = 0; i < rx_ring->count; i++) { |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame^] | 817 | const char *ring_desc; |
| 818 | |
| 819 | if (i == rx_ring->next_to_use) |
| 820 | ring_desc = " NTU"; |
| 821 | else if (i == rx_ring->next_to_clean) |
| 822 | ring_desc = " NTC"; |
| 823 | else |
| 824 | ring_desc = ""; |
| 825 | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 826 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 827 | rx_desc = IXGBE_RX_DESC(rx_ring, i); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 828 | u0 = (struct my_u0 *)rx_desc; |
| 829 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 830 | if (staterr & IXGBE_RXD_STAT_DD) { |
| 831 | /* Descriptor Done */ |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame^] | 832 | pr_info("RWB[0x%03X] %016llX %016llX ---------------- %p%s\n", |
| 833 | i, |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 834 | le64_to_cpu(u0->a), |
| 835 | le64_to_cpu(u0->b), |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame^] | 836 | rx_buffer_info->skb, |
| 837 | ring_desc); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 838 | } else { |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame^] | 839 | pr_info("R [0x%03X] %016llX %016llX %016llX %p%s\n", |
| 840 | i, |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 841 | le64_to_cpu(u0->a), |
| 842 | le64_to_cpu(u0->b), |
| 843 | (u64)rx_buffer_info->dma, |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame^] | 844 | rx_buffer_info->skb, |
| 845 | ring_desc); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 846 | |
Emil Tantilov | 9c50c03 | 2012-07-26 01:21:24 +0000 | [diff] [blame] | 847 | if (netif_msg_pktdata(adapter) && |
| 848 | rx_buffer_info->dma) { |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 849 | print_hex_dump(KERN_INFO, "", |
| 850 | DUMP_PREFIX_ADDRESS, 16, 1, |
Emil Tantilov | 9c50c03 | 2012-07-26 01:21:24 +0000 | [diff] [blame] | 851 | page_address(rx_buffer_info->page) + |
| 852 | rx_buffer_info->page_offset, |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 853 | ixgbe_rx_bufsz(rx_ring), true); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 854 | } |
| 855 | } |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 856 | } |
| 857 | } |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 858 | } |
| 859 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 860 | static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter) |
| 861 | { |
| 862 | u32 ctrl_ext; |
| 863 | |
| 864 | /* Let firmware take over control of h/w */ |
| 865 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 866 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 867 | ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter) |
| 871 | { |
| 872 | u32 ctrl_ext; |
| 873 | |
| 874 | /* Let firmware know the driver has taken over */ |
| 875 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 876 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 877 | ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 878 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 879 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 880 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 881 | * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors |
| 882 | * @adapter: pointer to adapter struct |
| 883 | * @direction: 0 for Rx, 1 for Tx, -1 for other causes |
| 884 | * @queue: queue to map the corresponding interrupt to |
| 885 | * @msix_vector: the vector to map to the corresponding queue |
| 886 | * |
| 887 | */ |
| 888 | static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 889 | u8 queue, u8 msix_vector) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 890 | { |
| 891 | u32 ivar, index; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 892 | struct ixgbe_hw *hw = &adapter->hw; |
| 893 | switch (hw->mac.type) { |
| 894 | case ixgbe_mac_82598EB: |
| 895 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 896 | if (direction == -1) |
| 897 | direction = 0; |
| 898 | index = (((direction * 64) + queue) >> 2) & 0x1F; |
| 899 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index)); |
| 900 | ivar &= ~(0xFF << (8 * (queue & 0x3))); |
| 901 | ivar |= (msix_vector << (8 * (queue & 0x3))); |
| 902 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar); |
| 903 | break; |
| 904 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 905 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 906 | case ixgbe_mac_X550: |
| 907 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 908 | case ixgbe_mac_x550em_a: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 909 | if (direction == -1) { |
| 910 | /* other causes */ |
| 911 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 912 | index = ((queue & 1) * 8); |
| 913 | ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC); |
| 914 | ivar &= ~(0xFF << index); |
| 915 | ivar |= (msix_vector << index); |
| 916 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar); |
| 917 | break; |
| 918 | } else { |
| 919 | /* tx or rx causes */ |
| 920 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 921 | index = ((16 * (queue & 1)) + (8 * direction)); |
| 922 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1)); |
| 923 | ivar &= ~(0xFF << index); |
| 924 | ivar |= (msix_vector << index); |
| 925 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar); |
| 926 | break; |
| 927 | } |
| 928 | default: |
| 929 | break; |
| 930 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 931 | } |
| 932 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 933 | static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 934 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 935 | { |
| 936 | u32 mask; |
| 937 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 938 | switch (adapter->hw.mac.type) { |
| 939 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 940 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 941 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 942 | break; |
| 943 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 944 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 945 | case ixgbe_mac_X550: |
| 946 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 947 | case ixgbe_mac_x550em_a: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 948 | mask = (qmask & 0xFFFFFFFF); |
| 949 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask); |
| 950 | mask = (qmask >> 32); |
| 951 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 952 | break; |
| 953 | default: |
| 954 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 955 | } |
| 956 | } |
| 957 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 958 | static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter) |
| 959 | { |
| 960 | struct ixgbe_hw *hw = &adapter->hw; |
| 961 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
| 962 | int i; |
| 963 | u32 data; |
| 964 | |
| 965 | if ((hw->fc.current_mode != ixgbe_fc_full) && |
| 966 | (hw->fc.current_mode != ixgbe_fc_rx_pause)) |
| 967 | return; |
| 968 | |
| 969 | switch (hw->mac.type) { |
| 970 | case ixgbe_mac_82598EB: |
| 971 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); |
| 972 | break; |
| 973 | default: |
| 974 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); |
| 975 | } |
| 976 | hwstats->lxoffrxc += data; |
| 977 | |
| 978 | /* refill credits (no tx hang) if we received xoff */ |
| 979 | if (!data) |
| 980 | return; |
| 981 | |
| 982 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 983 | clear_bit(__IXGBE_HANG_CHECK_ARMED, |
| 984 | &adapter->tx_ring[i]->state); |
| 985 | } |
| 986 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 987 | static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 988 | { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 989 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 990 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 991 | u32 xoff[8] = {0}; |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 992 | u8 tc; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 993 | int i; |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 994 | bool pfc_en = adapter->dcb_cfg.pfc_mode_enable; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 995 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 996 | if (adapter->ixgbe_ieee_pfc) |
| 997 | pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 998 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 999 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) { |
| 1000 | ixgbe_update_xoff_rx_lfc(adapter); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1001 | return; |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 1002 | } |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1003 | |
| 1004 | /* update stats for each tc, only valid with PFC enabled */ |
| 1005 | for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) { |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 1006 | u32 pxoffrxc; |
| 1007 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1008 | switch (hw->mac.type) { |
| 1009 | case ixgbe_mac_82598EB: |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 1010 | pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i)); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1011 | break; |
| 1012 | default: |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 1013 | pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i)); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1014 | } |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 1015 | hwstats->pxoffrxc[i] += pxoffrxc; |
| 1016 | /* Get the TC for given UP */ |
| 1017 | tc = netdev_get_prio_tc_map(adapter->netdev, i); |
| 1018 | xoff[tc] += pxoffrxc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1019 | } |
| 1020 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1021 | /* disarm tx queues that have received xoff frames */ |
| 1022 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 1023 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1024 | |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 1025 | tc = tx_ring->dcb_tc; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1026 | if (xoff[tc]) |
| 1027 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
| 1028 | } |
| 1029 | } |
| 1030 | |
| 1031 | static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring) |
| 1032 | { |
Alexander Duyck | 7d7ce68 | 2012-02-08 07:50:51 +0000 | [diff] [blame] | 1033 | return ring->stats.packets; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring) |
| 1037 | { |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 1038 | struct ixgbe_adapter *adapter; |
| 1039 | struct ixgbe_hw *hw; |
| 1040 | u32 head, tail; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1041 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 1042 | if (ring->l2_accel_priv) |
| 1043 | adapter = ring->l2_accel_priv->real_adapter; |
| 1044 | else |
| 1045 | adapter = netdev_priv(ring->netdev); |
| 1046 | |
| 1047 | hw = &adapter->hw; |
| 1048 | head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx)); |
| 1049 | tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx)); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1050 | |
| 1051 | if (head != tail) |
| 1052 | return (head < tail) ? |
| 1053 | tail - head : (tail + ring->count - head); |
| 1054 | |
| 1055 | return 0; |
| 1056 | } |
| 1057 | |
| 1058 | static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring) |
| 1059 | { |
| 1060 | u32 tx_done = ixgbe_get_tx_completed(tx_ring); |
| 1061 | u32 tx_done_old = tx_ring->tx_stats.tx_done_old; |
| 1062 | u32 tx_pending = ixgbe_get_tx_pending(tx_ring); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1063 | |
| 1064 | clear_check_for_tx_hang(tx_ring); |
| 1065 | |
| 1066 | /* |
| 1067 | * Check for a hung queue, but be thorough. This verifies |
| 1068 | * that a transmit has been completed since the previous |
| 1069 | * check AND there is at least one packet pending. The |
| 1070 | * ARMED bit is set to indicate a potential hang. The |
| 1071 | * bit is cleared if a pause frame is received to remove |
| 1072 | * false hang detection due to PFC or 802.3x frames. By |
| 1073 | * requiring this to fail twice we avoid races with |
| 1074 | * pfc clearing the ARMED bit and conditions where we |
| 1075 | * run the check_tx_hang logic with a transmit completion |
| 1076 | * pending but without time to complete it yet. |
| 1077 | */ |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 1078 | if (tx_done_old == tx_done && tx_pending) |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1079 | /* make sure it is true for two checks in a row */ |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 1080 | return test_and_set_bit(__IXGBE_HANG_CHECK_ARMED, |
| 1081 | &tx_ring->state); |
| 1082 | /* update completed stats and continue */ |
| 1083 | tx_ring->tx_stats.tx_done_old = tx_done; |
| 1084 | /* reset the countdown */ |
| 1085 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1086 | |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 1087 | return false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1088 | } |
| 1089 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 1090 | /** |
| 1091 | * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout |
| 1092 | * @adapter: driver private struct |
| 1093 | **/ |
| 1094 | static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter) |
| 1095 | { |
| 1096 | |
| 1097 | /* Do the reset outside of interrupt context */ |
| 1098 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
Emil Tantilov | 57ca2a4 | 2016-07-29 14:46:31 -0700 | [diff] [blame] | 1099 | set_bit(__IXGBE_RESET_REQUESTED, &adapter->state); |
Jacob Keller | 12ff3f3 | 2012-12-01 07:57:17 +0000 | [diff] [blame] | 1100 | e_warn(drv, "initiating reset due to tx timeout\n"); |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 1101 | ixgbe_service_event_schedule(adapter); |
| 1102 | } |
| 1103 | } |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1104 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1105 | /** |
Rostislav Pehlivanov | c04f90e | 2016-01-27 18:33:30 +0000 | [diff] [blame] | 1106 | * ixgbe_tx_maxrate - callback to set the maximum per-queue bitrate |
| 1107 | **/ |
| 1108 | static int ixgbe_tx_maxrate(struct net_device *netdev, |
| 1109 | int queue_index, u32 maxrate) |
| 1110 | { |
| 1111 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1112 | struct ixgbe_hw *hw = &adapter->hw; |
| 1113 | u32 bcnrc_val = ixgbe_link_mbps(adapter); |
| 1114 | |
| 1115 | if (!maxrate) |
| 1116 | return 0; |
| 1117 | |
| 1118 | /* Calculate the rate factor values to set */ |
| 1119 | bcnrc_val <<= IXGBE_RTTBCNRC_RF_INT_SHIFT; |
| 1120 | bcnrc_val /= maxrate; |
| 1121 | |
| 1122 | /* clear everything but the rate factor */ |
| 1123 | bcnrc_val &= IXGBE_RTTBCNRC_RF_INT_MASK | |
| 1124 | IXGBE_RTTBCNRC_RF_DEC_MASK; |
| 1125 | |
| 1126 | /* enable the rate scheduler */ |
| 1127 | bcnrc_val |= IXGBE_RTTBCNRC_RS_ENA; |
| 1128 | |
| 1129 | IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, queue_index); |
| 1130 | IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val); |
| 1131 | |
| 1132 | return 0; |
| 1133 | } |
| 1134 | |
| 1135 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1136 | * ixgbe_clean_tx_irq - Reclaim resources after transmit completes |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1137 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1138 | * @tx_ring: tx ring to clean |
Alexander Duyck | 8220bbc | 2016-03-07 09:30:09 -0800 | [diff] [blame] | 1139 | * @napi_budget: Used to determine if we are in netpoll |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1140 | **/ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1141 | static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector, |
Jesper Dangaard Brouer | a3a8749 | 2016-02-08 13:15:09 +0100 | [diff] [blame] | 1142 | struct ixgbe_ring *tx_ring, int napi_budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1143 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1144 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1145 | struct ixgbe_tx_buffer *tx_buffer; |
| 1146 | union ixgbe_adv_tx_desc *tx_desc; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1147 | unsigned int total_bytes = 0, total_packets = 0; |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 1148 | unsigned int budget = q_vector->tx.work_limit; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1149 | unsigned int i = tx_ring->next_to_clean; |
| 1150 | |
| 1151 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1152 | return true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1153 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1154 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1155 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1156 | i -= tx_ring->count; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 1157 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1158 | do { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1159 | union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1160 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1161 | /* if next_to_watch is not set then there is no work pending */ |
| 1162 | if (!eop_desc) |
| 1163 | break; |
| 1164 | |
Alexander Duyck | 7f83a9e | 2012-02-08 07:49:23 +0000 | [diff] [blame] | 1165 | /* prevent any other reads prior to eop_desc */ |
Alexander Duyck | 7e63bf4 | 2013-01-08 07:00:58 +0000 | [diff] [blame] | 1166 | read_barrier_depends(); |
Alexander Duyck | 7f83a9e | 2012-02-08 07:49:23 +0000 | [diff] [blame] | 1167 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1168 | /* if DD is not set pending work has not been completed */ |
| 1169 | if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD))) |
| 1170 | break; |
| 1171 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1172 | /* clear next_to_watch to prevent false hangs */ |
| 1173 | tx_buffer->next_to_watch = NULL; |
| 1174 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 1175 | /* update the statistics for this packet */ |
| 1176 | total_bytes += tx_buffer->bytecount; |
| 1177 | total_packets += tx_buffer->gso_segs; |
| 1178 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1179 | /* free the skb */ |
Jesper Dangaard Brouer | a3a8749 | 2016-02-08 13:15:09 +0100 | [diff] [blame] | 1180 | napi_consume_skb(tx_buffer->skb, napi_budget); |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1181 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1182 | /* unmap skb header data */ |
| 1183 | dma_unmap_single(tx_ring->dev, |
| 1184 | dma_unmap_addr(tx_buffer, dma), |
| 1185 | dma_unmap_len(tx_buffer, len), |
| 1186 | DMA_TO_DEVICE); |
| 1187 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1188 | /* clear tx_buffer data */ |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1189 | dma_unmap_len_set(tx_buffer, len, 0); |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1190 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1191 | /* unmap remaining buffers */ |
| 1192 | while (tx_desc != eop_desc) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1193 | tx_buffer++; |
| 1194 | tx_desc++; |
| 1195 | i++; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1196 | if (unlikely(!i)) { |
| 1197 | i -= tx_ring->count; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1198 | tx_buffer = tx_ring->tx_buffer_info; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1199 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1200 | } |
| 1201 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1202 | /* unmap any remaining paged data */ |
| 1203 | if (dma_unmap_len(tx_buffer, len)) { |
| 1204 | dma_unmap_page(tx_ring->dev, |
| 1205 | dma_unmap_addr(tx_buffer, dma), |
| 1206 | dma_unmap_len(tx_buffer, len), |
| 1207 | DMA_TO_DEVICE); |
| 1208 | dma_unmap_len_set(tx_buffer, len, 0); |
| 1209 | } |
| 1210 | } |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 1211 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1212 | /* move us one more past the eop_desc for start of next pkt */ |
| 1213 | tx_buffer++; |
| 1214 | tx_desc++; |
| 1215 | i++; |
| 1216 | if (unlikely(!i)) { |
| 1217 | i -= tx_ring->count; |
| 1218 | tx_buffer = tx_ring->tx_buffer_info; |
| 1219 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
| 1220 | } |
| 1221 | |
| 1222 | /* issue prefetch for next Tx descriptor */ |
| 1223 | prefetch(tx_desc); |
| 1224 | |
| 1225 | /* update budget accounting */ |
| 1226 | budget--; |
| 1227 | } while (likely(budget)); |
| 1228 | |
| 1229 | i += tx_ring->count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1230 | tx_ring->next_to_clean = i; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1231 | u64_stats_update_begin(&tx_ring->syncp); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1232 | tx_ring->stats.bytes += total_bytes; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1233 | tx_ring->stats.packets += total_packets; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1234 | u64_stats_update_end(&tx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1235 | q_vector->tx.total_bytes += total_bytes; |
| 1236 | q_vector->tx.total_packets += total_packets; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1237 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1238 | if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) { |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1239 | /* schedule immediate reset if we believe we hung */ |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1240 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1241 | e_err(drv, "Detected Tx Unit Hang\n" |
| 1242 | " Tx Queue <%d>\n" |
| 1243 | " TDH, TDT <%x>, <%x>\n" |
| 1244 | " next_to_use <%x>\n" |
| 1245 | " next_to_clean <%x>\n" |
| 1246 | "tx_buffer_info[next_to_clean]\n" |
| 1247 | " time_stamp <%lx>\n" |
| 1248 | " jiffies <%lx>\n", |
| 1249 | tx_ring->queue_index, |
| 1250 | IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)), |
| 1251 | IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)), |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1252 | tx_ring->next_to_use, i, |
| 1253 | tx_ring->tx_buffer_info[i].time_stamp, jiffies); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1254 | |
| 1255 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 1256 | |
| 1257 | e_info(probe, |
| 1258 | "tx hang %d detected on queue %d, resetting adapter\n", |
| 1259 | adapter->tx_timeout_count + 1, tx_ring->queue_index); |
| 1260 | |
| 1261 | /* schedule immediate reset if we believe we hung */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 1262 | ixgbe_tx_timeout_reset(adapter); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1263 | |
| 1264 | /* the adapter is about to reset, no point in enabling stuff */ |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 1265 | return true; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1266 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1267 | |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 1268 | netdev_tx_completed_queue(txring_txq(tx_ring), |
| 1269 | total_packets, total_bytes); |
| 1270 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 1271 | #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) |
Alexander Duyck | 30065e6 | 2011-07-15 03:05:14 +0000 | [diff] [blame] | 1272 | if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) && |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 1273 | (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 1274 | /* Make sure that anybody stopping the queue after this |
| 1275 | * sees the new next_to_clean. |
| 1276 | */ |
| 1277 | smp_mb(); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1278 | if (__netif_subqueue_stopped(tx_ring->netdev, |
| 1279 | tx_ring->queue_index) |
| 1280 | && !test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1281 | netif_wake_subqueue(tx_ring->netdev, |
| 1282 | tx_ring->queue_index); |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 1283 | ++tx_ring->tx_stats.restart_queue; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 1284 | } |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 1285 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1286 | |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 1287 | return !!budget; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1288 | } |
| 1289 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1290 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1291 | static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter, |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1292 | struct ixgbe_ring *tx_ring, |
| 1293 | int cpu) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1294 | { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 1295 | struct ixgbe_hw *hw = &adapter->hw; |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1296 | u32 txctrl = 0; |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1297 | u16 reg_offset; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1298 | |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1299 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1300 | txctrl = dca3_get_tag(tx_ring->dev, cpu); |
| 1301 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1302 | switch (hw->mac.type) { |
| 1303 | case ixgbe_mac_82598EB: |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1304 | reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1305 | break; |
| 1306 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1307 | case ixgbe_mac_X540: |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1308 | reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx); |
| 1309 | txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599; |
| 1310 | break; |
| 1311 | default: |
| 1312 | /* for unknown hardware do not write register */ |
| 1313 | return; |
| 1314 | } |
| 1315 | |
| 1316 | /* |
| 1317 | * We can enable relaxed ordering for reads, but not writes when |
| 1318 | * DCA is enabled. This is due to a known issue in some chipsets |
| 1319 | * which will cause the DCA tag to be cleared. |
| 1320 | */ |
| 1321 | txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN | |
| 1322 | IXGBE_DCA_TXCTRL_DATA_RRO_EN | |
| 1323 | IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
| 1324 | |
| 1325 | IXGBE_WRITE_REG(hw, reg_offset, txctrl); |
| 1326 | } |
| 1327 | |
| 1328 | static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter, |
| 1329 | struct ixgbe_ring *rx_ring, |
| 1330 | int cpu) |
| 1331 | { |
| 1332 | struct ixgbe_hw *hw = &adapter->hw; |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1333 | u32 rxctrl = 0; |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1334 | u8 reg_idx = rx_ring->reg_idx; |
| 1335 | |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1336 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1337 | rxctrl = dca3_get_tag(rx_ring->dev, cpu); |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1338 | |
| 1339 | switch (hw->mac.type) { |
| 1340 | case ixgbe_mac_82599EB: |
| 1341 | case ixgbe_mac_X540: |
| 1342 | rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1343 | break; |
| 1344 | default: |
| 1345 | break; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1346 | } |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1347 | |
| 1348 | /* |
| 1349 | * We can enable relaxed ordering for reads, but not writes when |
| 1350 | * DCA is enabled. This is due to a known issue in some chipsets |
| 1351 | * which will cause the DCA tag to be cleared. |
| 1352 | */ |
| 1353 | rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN | |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1354 | IXGBE_DCA_RXCTRL_DATA_DCA_EN | |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1355 | IXGBE_DCA_RXCTRL_DESC_DCA_EN; |
| 1356 | |
| 1357 | IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1358 | } |
| 1359 | |
| 1360 | static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector) |
| 1361 | { |
| 1362 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1363 | struct ixgbe_ring *ring; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1364 | int cpu = get_cpu(); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1365 | |
| 1366 | if (q_vector->cpu == cpu) |
| 1367 | goto out_no_update; |
| 1368 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 1369 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1370 | ixgbe_update_tx_dca(adapter, ring, cpu); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1371 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 1372 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1373 | ixgbe_update_rx_dca(adapter, ring, cpu); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1374 | |
| 1375 | q_vector->cpu = cpu; |
| 1376 | out_no_update: |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1377 | put_cpu(); |
| 1378 | } |
| 1379 | |
| 1380 | static void ixgbe_setup_dca(struct ixgbe_adapter *adapter) |
| 1381 | { |
| 1382 | int i; |
| 1383 | |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 1384 | /* always use CB2 mode, difference is masked in the CB driver */ |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1385 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1386 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 1387 | IXGBE_DCA_CTRL_DCA_MODE_CB2); |
| 1388 | else |
| 1389 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 1390 | IXGBE_DCA_CTRL_DCA_DISABLE); |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 1391 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 1392 | for (i = 0; i < adapter->num_q_vectors; i++) { |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1393 | adapter->q_vector[i]->cpu = -1; |
| 1394 | ixgbe_update_dca(adapter->q_vector[i]); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1395 | } |
| 1396 | } |
| 1397 | |
| 1398 | static int __ixgbe_notify_dca(struct device *dev, void *data) |
| 1399 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 1400 | struct ixgbe_adapter *adapter = dev_get_drvdata(dev); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1401 | unsigned long event = *(unsigned long *)data; |
| 1402 | |
Don Skidmore | 2a72c31 | 2011-07-20 02:27:05 +0000 | [diff] [blame] | 1403 | if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE)) |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1404 | return 0; |
| 1405 | |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1406 | switch (event) { |
| 1407 | case DCA_PROVIDER_ADD: |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 1408 | /* if we're already enabled, don't do it again */ |
| 1409 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1410 | break; |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 1411 | if (dca_add_requester(dev) == 0) { |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 1412 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1413 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 1414 | IXGBE_DCA_CTRL_DCA_MODE_CB2); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1415 | break; |
| 1416 | } |
| 1417 | /* Fall Through since DCA is disabled. */ |
| 1418 | case DCA_PROVIDER_REMOVE: |
| 1419 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 1420 | dca_remove_requester(dev); |
| 1421 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1422 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 1423 | IXGBE_DCA_CTRL_DCA_DISABLE); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1424 | } |
| 1425 | break; |
| 1426 | } |
| 1427 | |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 1428 | return 0; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1429 | } |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1430 | |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1431 | #endif /* CONFIG_IXGBE_DCA */ |
Fan Du | 7edda4b8 | 2015-04-29 10:57:39 +0800 | [diff] [blame] | 1432 | |
| 1433 | #define IXGBE_RSS_L4_TYPES_MASK \ |
| 1434 | ((1ul << IXGBE_RXDADV_RSSTYPE_IPV4_TCP) | \ |
| 1435 | (1ul << IXGBE_RXDADV_RSSTYPE_IPV4_UDP) | \ |
| 1436 | (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_TCP) | \ |
| 1437 | (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_UDP)) |
| 1438 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1439 | static inline void ixgbe_rx_hash(struct ixgbe_ring *ring, |
| 1440 | union ixgbe_adv_rx_desc *rx_desc, |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1441 | struct sk_buff *skb) |
| 1442 | { |
Fan Du | 7edda4b8 | 2015-04-29 10:57:39 +0800 | [diff] [blame] | 1443 | u16 rss_type; |
| 1444 | |
| 1445 | if (!(ring->netdev->features & NETIF_F_RXHASH)) |
| 1446 | return; |
| 1447 | |
| 1448 | rss_type = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) & |
| 1449 | IXGBE_RXDADV_RSSTYPE_MASK; |
| 1450 | |
| 1451 | if (!rss_type) |
| 1452 | return; |
| 1453 | |
| 1454 | skb_set_hash(skb, le32_to_cpu(rx_desc->wb.lower.hi_dword.rss), |
| 1455 | (IXGBE_RSS_L4_TYPES_MASK & (1ul << rss_type)) ? |
| 1456 | PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3); |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1457 | } |
| 1458 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1459 | #ifdef IXGBE_FCOE |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1460 | /** |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1461 | * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1462 | * @ring: structure containing ring specific data |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1463 | * @rx_desc: advanced rx descriptor |
| 1464 | * |
| 1465 | * Returns : true if it is FCoE pkt |
| 1466 | */ |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1467 | static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring, |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1468 | union ixgbe_adv_rx_desc *rx_desc) |
| 1469 | { |
| 1470 | __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 1471 | |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1472 | return test_bit(__IXGBE_RX_FCOE, &ring->state) && |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1473 | ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) == |
| 1474 | (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE << |
| 1475 | IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT))); |
| 1476 | } |
| 1477 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1478 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1479 | /** |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1480 | * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1481 | * @ring: structure containing ring specific data |
| 1482 | * @rx_desc: current Rx descriptor being processed |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1483 | * @skb: skb currently being received and modified |
| 1484 | **/ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1485 | static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring, |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1486 | union ixgbe_adv_rx_desc *rx_desc, |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1487 | struct sk_buff *skb) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1488 | { |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1489 | __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1490 | bool encap_pkt = false; |
| 1491 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1492 | skb_checksum_none_assert(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1493 | |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 1494 | /* Rx csum disabled */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1495 | if (!(ring->netdev->features & NETIF_F_RXCSUM)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1496 | return; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1497 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 1498 | /* check for VXLAN and Geneve packets */ |
| 1499 | if (pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_VXLAN)) { |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1500 | encap_pkt = true; |
| 1501 | skb->encapsulation = 1; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1502 | } |
| 1503 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1504 | /* if IP and error */ |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1505 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) && |
| 1506 | ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1507 | ring->rx_stats.csum_err++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1508 | return; |
| 1509 | } |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1510 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1511 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS)) |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1512 | return; |
| 1513 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1514 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) { |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1515 | /* |
| 1516 | * 82599 errata, UDP frames with a 0 checksum can be marked as |
| 1517 | * checksum errors. |
| 1518 | */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1519 | if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) && |
| 1520 | test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state)) |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1521 | return; |
| 1522 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1523 | ring->rx_stats.csum_err++; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1524 | return; |
| 1525 | } |
| 1526 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1527 | /* It must be a TCP or UDP packet with a valid checksum */ |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1528 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1529 | if (encap_pkt) { |
| 1530 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_OUTERIPCS)) |
| 1531 | return; |
| 1532 | |
| 1533 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_OUTERIPER)) { |
Mark Rustad | d469251 | 2015-12-04 11:26:43 -0800 | [diff] [blame] | 1534 | skb->ip_summed = CHECKSUM_NONE; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1535 | return; |
| 1536 | } |
| 1537 | /* If we checked the outer header let the stack know */ |
| 1538 | skb->csum_level = 1; |
| 1539 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1540 | } |
| 1541 | |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 1542 | static inline unsigned int ixgbe_rx_offset(struct ixgbe_ring *rx_ring) |
| 1543 | { |
| 1544 | return ring_uses_build_skb(rx_ring) ? IXGBE_SKB_PAD : 0; |
| 1545 | } |
| 1546 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1547 | static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring, |
| 1548 | struct ixgbe_rx_buffer *bi) |
| 1549 | { |
| 1550 | struct page *page = bi->page; |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1551 | dma_addr_t dma; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1552 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1553 | /* since we are recycling buffers we should seldom need to alloc */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1554 | if (likely(page)) |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1555 | return true; |
| 1556 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1557 | /* alloc new page for storage */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1558 | page = dev_alloc_pages(ixgbe_rx_pg_order(rx_ring)); |
| 1559 | if (unlikely(!page)) { |
| 1560 | rx_ring->rx_stats.alloc_rx_page_failed++; |
| 1561 | return false; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1562 | } |
| 1563 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1564 | /* map page for use */ |
Alexander Duyck | f3213d9 | 2017-01-17 08:35:54 -0800 | [diff] [blame] | 1565 | dma = dma_map_page_attrs(rx_ring->dev, page, 0, |
| 1566 | ixgbe_rx_pg_size(rx_ring), |
| 1567 | DMA_FROM_DEVICE, |
| 1568 | IXGBE_RX_DMA_ATTR); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1569 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1570 | /* |
| 1571 | * if mapping failed free memory back to system since |
| 1572 | * there isn't much point in holding memory we can't use |
| 1573 | */ |
| 1574 | if (dma_mapping_error(rx_ring->dev, dma)) { |
Alexander Duyck | dd411ec | 2012-04-06 04:24:50 +0000 | [diff] [blame] | 1575 | __free_pages(page, ixgbe_rx_pg_order(rx_ring)); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1576 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1577 | rx_ring->rx_stats.alloc_rx_page_failed++; |
| 1578 | return false; |
| 1579 | } |
| 1580 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1581 | bi->dma = dma; |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1582 | bi->page = page; |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 1583 | bi->page_offset = ixgbe_rx_offset(rx_ring); |
Alexander Duyck | 1b56cf4 | 2017-01-17 08:36:03 -0800 | [diff] [blame] | 1584 | bi->pagecnt_bias = 1; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1585 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1586 | return true; |
| 1587 | } |
| 1588 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1589 | /** |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1590 | * ixgbe_alloc_rx_buffers - Replace used receive buffers |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1591 | * @rx_ring: ring to place buffers on |
| 1592 | * @cleaned_count: number of buffers to replace |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1593 | **/ |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1594 | void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1595 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1596 | union ixgbe_adv_rx_desc *rx_desc; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1597 | struct ixgbe_rx_buffer *bi; |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1598 | u16 i = rx_ring->next_to_use; |
Alexander Duyck | 4f4542b | 2017-01-17 08:36:14 -0800 | [diff] [blame] | 1599 | u16 bufsz; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1600 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1601 | /* nothing to do */ |
| 1602 | if (!cleaned_count) |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1603 | return; |
| 1604 | |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1605 | rx_desc = IXGBE_RX_DESC(rx_ring, i); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1606 | bi = &rx_ring->rx_buffer_info[i]; |
| 1607 | i -= rx_ring->count; |
| 1608 | |
Alexander Duyck | 4f4542b | 2017-01-17 08:36:14 -0800 | [diff] [blame] | 1609 | bufsz = ixgbe_rx_bufsz(rx_ring); |
| 1610 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1611 | do { |
| 1612 | if (!ixgbe_alloc_mapped_page(rx_ring, bi)) |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1613 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1614 | |
Alexander Duyck | f3213d9 | 2017-01-17 08:35:54 -0800 | [diff] [blame] | 1615 | /* sync the buffer for use by the device */ |
| 1616 | dma_sync_single_range_for_device(rx_ring->dev, bi->dma, |
Alexander Duyck | 4f4542b | 2017-01-17 08:36:14 -0800 | [diff] [blame] | 1617 | bi->page_offset, bufsz, |
Alexander Duyck | f3213d9 | 2017-01-17 08:35:54 -0800 | [diff] [blame] | 1618 | DMA_FROM_DEVICE); |
| 1619 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1620 | /* |
| 1621 | * Refresh the desc even if buffer_addrs didn't change |
| 1622 | * because each write-back erases this info. |
| 1623 | */ |
| 1624 | rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1625 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1626 | rx_desc++; |
| 1627 | bi++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1628 | i++; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1629 | if (unlikely(!i)) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1630 | rx_desc = IXGBE_RX_DESC(rx_ring, 0); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1631 | bi = rx_ring->rx_buffer_info; |
| 1632 | i -= rx_ring->count; |
| 1633 | } |
| 1634 | |
Alexander Duyck | c3630cc | 2017-01-17 08:36:28 -0800 | [diff] [blame] | 1635 | /* clear the length for the next_to_use descriptor */ |
| 1636 | rx_desc->wb.upper.length = 0; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1637 | |
| 1638 | cleaned_count--; |
| 1639 | } while (cleaned_count); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1640 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1641 | i += rx_ring->count; |
| 1642 | |
Alexander Duyck | ad435ec | 2014-11-14 00:56:35 +0000 | [diff] [blame] | 1643 | if (rx_ring->next_to_use != i) { |
| 1644 | rx_ring->next_to_use = i; |
| 1645 | |
| 1646 | /* update next to alloc since we have filled the ring */ |
| 1647 | rx_ring->next_to_alloc = i; |
| 1648 | |
| 1649 | /* Force memory writes to complete before letting h/w |
| 1650 | * know there are new descriptors to fetch. (Only |
| 1651 | * applicable for weak-ordered memory model archs, |
| 1652 | * such as IA-64). |
| 1653 | */ |
| 1654 | wmb(); |
| 1655 | writel(i, rx_ring->tail); |
| 1656 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1657 | } |
| 1658 | |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1659 | static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring, |
| 1660 | struct sk_buff *skb) |
| 1661 | { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1662 | u16 hdr_len = skb_headlen(skb); |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1663 | |
| 1664 | /* set gso_size to avoid messing up TCP MSS */ |
| 1665 | skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len), |
| 1666 | IXGBE_CB(skb)->append_cnt); |
Alexander Duyck | 96be80a | 2013-02-12 09:45:44 +0000 | [diff] [blame] | 1667 | skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4; |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1668 | } |
| 1669 | |
| 1670 | static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring, |
| 1671 | struct sk_buff *skb) |
| 1672 | { |
| 1673 | /* if append_cnt is 0 then frame is not RSC */ |
| 1674 | if (!IXGBE_CB(skb)->append_cnt) |
| 1675 | return; |
| 1676 | |
| 1677 | rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt; |
| 1678 | rx_ring->rx_stats.rsc_flush++; |
| 1679 | |
| 1680 | ixgbe_set_rsc_gso_size(rx_ring, skb); |
| 1681 | |
| 1682 | /* gso_size is computed using append_cnt so always clear it last */ |
| 1683 | IXGBE_CB(skb)->append_cnt = 0; |
| 1684 | } |
| 1685 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1686 | /** |
| 1687 | * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor |
| 1688 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1689 | * @rx_desc: pointer to the EOP Rx descriptor |
| 1690 | * @skb: pointer to current skb being populated |
| 1691 | * |
| 1692 | * This function checks the ring, descriptor, and packet information in |
| 1693 | * order to populate the hash, checksum, VLAN, timestamp, protocol, and |
| 1694 | * other fields within the skb. |
| 1695 | **/ |
| 1696 | static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring, |
| 1697 | union ixgbe_adv_rx_desc *rx_desc, |
| 1698 | struct sk_buff *skb) |
| 1699 | { |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1700 | struct net_device *dev = rx_ring->netdev; |
Mark Rustad | a9763f3 | 2015-10-27 09:58:07 -0700 | [diff] [blame] | 1701 | u32 flags = rx_ring->q_vector->adapter->flags; |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1702 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1703 | ixgbe_update_rsc_stats(rx_ring, skb); |
| 1704 | |
| 1705 | ixgbe_rx_hash(rx_ring, rx_desc, skb); |
| 1706 | |
| 1707 | ixgbe_rx_checksum(rx_ring, rx_desc, skb); |
| 1708 | |
Mark Rustad | a9763f3 | 2015-10-27 09:58:07 -0700 | [diff] [blame] | 1709 | if (unlikely(flags & IXGBE_FLAG_RX_HWTSTAMP_ENABLED)) |
| 1710 | ixgbe_ptp_rx_hwtstamp(rx_ring, rx_desc, skb); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 1711 | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 1712 | if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) && |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1713 | ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1714 | u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan); |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 1715 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid); |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1716 | } |
| 1717 | |
| 1718 | skb_record_rx_queue(skb, rx_ring->queue_index); |
| 1719 | |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1720 | skb->protocol = eth_type_trans(skb, dev); |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1721 | } |
| 1722 | |
| 1723 | static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector, |
| 1724 | struct sk_buff *skb) |
| 1725 | { |
Eric Dumazet | 3ffc1af | 2017-02-02 16:26:39 -0800 | [diff] [blame] | 1726 | napi_gro_receive(&q_vector->napi, skb); |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1727 | } |
Mallikarjuna R Chilakala | 43634e8 | 2010-02-25 23:14:37 +0000 | [diff] [blame] | 1728 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1729 | /** |
| 1730 | * ixgbe_is_non_eop - process handling of non-EOP buffers |
| 1731 | * @rx_ring: Rx ring being processed |
| 1732 | * @rx_desc: Rx descriptor for current buffer |
| 1733 | * @skb: Current socket buffer containing buffer in progress |
| 1734 | * |
| 1735 | * This function updates next to clean. If the buffer is an EOP buffer |
| 1736 | * this function exits returning false, otherwise it will place the |
| 1737 | * sk_buff in the next buffer to be chained and return true indicating |
| 1738 | * that this is in fact a non-EOP buffer. |
| 1739 | **/ |
| 1740 | static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring, |
| 1741 | union ixgbe_adv_rx_desc *rx_desc, |
| 1742 | struct sk_buff *skb) |
| 1743 | { |
| 1744 | u32 ntc = rx_ring->next_to_clean + 1; |
| 1745 | |
| 1746 | /* fetch, update, and store next to clean */ |
| 1747 | ntc = (ntc < rx_ring->count) ? ntc : 0; |
| 1748 | rx_ring->next_to_clean = ntc; |
| 1749 | |
| 1750 | prefetch(IXGBE_RX_DESC(rx_ring, ntc)); |
| 1751 | |
Alexander Duyck | 5a02cbd | 2012-07-20 08:08:51 +0000 | [diff] [blame] | 1752 | /* update RSC append count if present */ |
| 1753 | if (ring_is_rsc_enabled(rx_ring)) { |
| 1754 | __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data & |
| 1755 | cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK); |
| 1756 | |
| 1757 | if (unlikely(rsc_enabled)) { |
| 1758 | u32 rsc_cnt = le32_to_cpu(rsc_enabled); |
| 1759 | |
| 1760 | rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT; |
| 1761 | IXGBE_CB(skb)->append_cnt += rsc_cnt - 1; |
| 1762 | |
| 1763 | /* update ntc based on RSC value */ |
| 1764 | ntc = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 1765 | ntc &= IXGBE_RXDADV_NEXTP_MASK; |
| 1766 | ntc >>= IXGBE_RXDADV_NEXTP_SHIFT; |
| 1767 | } |
| 1768 | } |
| 1769 | |
| 1770 | /* if we are the last buffer then there is nothing else to do */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1771 | if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))) |
| 1772 | return false; |
| 1773 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1774 | /* place skb in next buffer to be received */ |
| 1775 | rx_ring->rx_buffer_info[ntc].skb = skb; |
| 1776 | rx_ring->rx_stats.non_eop_descs++; |
| 1777 | |
| 1778 | return true; |
| 1779 | } |
| 1780 | |
| 1781 | /** |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1782 | * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail |
| 1783 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1784 | * @skb: pointer to current skb being adjusted |
| 1785 | * |
| 1786 | * This function is an ixgbe specific version of __pskb_pull_tail. The |
| 1787 | * main difference between this version and the original function is that |
| 1788 | * this function can make several assumptions about the state of things |
| 1789 | * that allow for significant optimizations versus the standard function. |
| 1790 | * As a result we can do things like drop a frag and maintain an accurate |
| 1791 | * truesize for the skb. |
| 1792 | */ |
| 1793 | static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring, |
| 1794 | struct sk_buff *skb) |
| 1795 | { |
| 1796 | struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0]; |
| 1797 | unsigned char *va; |
| 1798 | unsigned int pull_len; |
| 1799 | |
| 1800 | /* |
| 1801 | * it is valid to use page_address instead of kmap since we are |
| 1802 | * working with pages allocated out of the lomem pool per |
| 1803 | * alloc_page(GFP_ATOMIC) |
| 1804 | */ |
| 1805 | va = skb_frag_address(frag); |
| 1806 | |
| 1807 | /* |
| 1808 | * we need the header to contain the greater of either ETH_HLEN or |
| 1809 | * 60 bytes if the skb->len is less than 60 for skb_pad. |
| 1810 | */ |
Alexander Duyck | 8496e338 | 2014-09-05 19:22:18 -0400 | [diff] [blame] | 1811 | pull_len = eth_get_headlen(va, IXGBE_RX_HDR_SIZE); |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1812 | |
| 1813 | /* align pull length to size of long to optimize memcpy performance */ |
| 1814 | skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long))); |
| 1815 | |
| 1816 | /* update all of the pointers */ |
| 1817 | skb_frag_size_sub(frag, pull_len); |
| 1818 | frag->page_offset += pull_len; |
| 1819 | skb->data_len -= pull_len; |
| 1820 | skb->tail += pull_len; |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1821 | } |
| 1822 | |
| 1823 | /** |
Alexander Duyck | 42073d9 | 2012-07-20 08:08:28 +0000 | [diff] [blame] | 1824 | * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB |
| 1825 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1826 | * @skb: pointer to current skb being updated |
| 1827 | * |
| 1828 | * This function provides a basic DMA sync up for the first fragment of an |
| 1829 | * skb. The reason for doing this is that the first fragment cannot be |
| 1830 | * unmapped until we have reached the end of packet descriptor for a buffer |
| 1831 | * chain. |
| 1832 | */ |
| 1833 | static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring, |
| 1834 | struct sk_buff *skb) |
| 1835 | { |
| 1836 | /* if the page was released unmap it, else just sync our portion */ |
| 1837 | if (unlikely(IXGBE_CB(skb)->page_released)) { |
Alexander Duyck | f3213d9 | 2017-01-17 08:35:54 -0800 | [diff] [blame] | 1838 | dma_unmap_page_attrs(rx_ring->dev, IXGBE_CB(skb)->dma, |
| 1839 | ixgbe_rx_pg_size(rx_ring), |
| 1840 | DMA_FROM_DEVICE, |
| 1841 | IXGBE_RX_DMA_ATTR); |
Alexander Duyck | 42073d9 | 2012-07-20 08:08:28 +0000 | [diff] [blame] | 1842 | } else { |
| 1843 | struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0]; |
| 1844 | |
| 1845 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 1846 | IXGBE_CB(skb)->dma, |
| 1847 | frag->page_offset, |
Alexander Duyck | f215af8 | 2017-01-17 08:35:44 -0800 | [diff] [blame] | 1848 | skb_frag_size(frag), |
Alexander Duyck | 42073d9 | 2012-07-20 08:08:28 +0000 | [diff] [blame] | 1849 | DMA_FROM_DEVICE); |
| 1850 | } |
Alexander Duyck | 42073d9 | 2012-07-20 08:08:28 +0000 | [diff] [blame] | 1851 | } |
| 1852 | |
| 1853 | /** |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1854 | * ixgbe_cleanup_headers - Correct corrupted or empty headers |
| 1855 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1856 | * @rx_desc: pointer to the EOP Rx descriptor |
| 1857 | * @skb: pointer to current skb being fixed |
| 1858 | * |
| 1859 | * Check for corrupted packet headers caused by senders on the local L2 |
| 1860 | * embedded NIC switch not setting up their Tx Descriptors right. These |
| 1861 | * should be very rare. |
| 1862 | * |
| 1863 | * Also address the case where we are pulling data in on pages only |
| 1864 | * and as such no data is present in the skb header. |
| 1865 | * |
| 1866 | * In addition if skb is not at least 60 bytes we need to pad it so that |
| 1867 | * it is large enough to qualify as a valid Ethernet frame. |
| 1868 | * |
| 1869 | * Returns true if an error was encountered and skb was freed. |
| 1870 | **/ |
| 1871 | static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring, |
| 1872 | union ixgbe_adv_rx_desc *rx_desc, |
| 1873 | struct sk_buff *skb) |
| 1874 | { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1875 | struct net_device *netdev = rx_ring->netdev; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1876 | |
| 1877 | /* verify that the packet does not have any known errors */ |
| 1878 | if (unlikely(ixgbe_test_staterr(rx_desc, |
| 1879 | IXGBE_RXDADV_ERR_FRAME_ERR_MASK) && |
| 1880 | !(netdev->features & NETIF_F_RXALL))) { |
| 1881 | dev_kfree_skb_any(skb); |
| 1882 | return true; |
| 1883 | } |
| 1884 | |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1885 | /* place header in linear portion of buffer */ |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 1886 | if (!skb_headlen(skb)) |
Alexander Duyck | cf3fe7a | 2012-07-20 08:08:39 +0000 | [diff] [blame] | 1887 | ixgbe_pull_tail(rx_ring, skb); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1888 | |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1889 | #ifdef IXGBE_FCOE |
| 1890 | /* do not attempt to pad FCoE Frames as this will disrupt DDP */ |
| 1891 | if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) |
| 1892 | return false; |
| 1893 | |
| 1894 | #endif |
Alexander Duyck | a94d9e2 | 2014-12-03 08:17:39 -0800 | [diff] [blame] | 1895 | /* if eth_skb_pad returns an error the skb was freed */ |
| 1896 | if (eth_skb_pad(skb)) |
| 1897 | return true; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1898 | |
| 1899 | return false; |
| 1900 | } |
| 1901 | |
| 1902 | /** |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1903 | * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring |
| 1904 | * @rx_ring: rx descriptor ring to store buffers on |
| 1905 | * @old_buff: donor buffer to have page reused |
| 1906 | * |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1907 | * Synchronizes page for reuse by the adapter |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1908 | **/ |
| 1909 | static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring, |
| 1910 | struct ixgbe_rx_buffer *old_buff) |
| 1911 | { |
| 1912 | struct ixgbe_rx_buffer *new_buff; |
| 1913 | u16 nta = rx_ring->next_to_alloc; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1914 | |
| 1915 | new_buff = &rx_ring->rx_buffer_info[nta]; |
| 1916 | |
| 1917 | /* update, and store next to alloc */ |
| 1918 | nta++; |
| 1919 | rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0; |
| 1920 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 1921 | /* Transfer page from old buffer to new buffer. |
| 1922 | * Move each member individually to avoid possible store |
| 1923 | * forwarding stalls and unnecessary copy of skb. |
| 1924 | */ |
| 1925 | new_buff->dma = old_buff->dma; |
| 1926 | new_buff->page = old_buff->page; |
| 1927 | new_buff->page_offset = old_buff->page_offset; |
| 1928 | new_buff->pagecnt_bias = old_buff->pagecnt_bias; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1929 | } |
| 1930 | |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1931 | static inline bool ixgbe_page_is_reserved(struct page *page) |
| 1932 | { |
Michal Hocko | 2f064f3 | 2015-08-21 14:11:51 -0700 | [diff] [blame] | 1933 | return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page); |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1934 | } |
| 1935 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 1936 | static bool ixgbe_can_reuse_rx_page(struct ixgbe_rx_buffer *rx_buffer) |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1937 | { |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 1938 | unsigned int pagecnt_bias = rx_buffer->pagecnt_bias; |
| 1939 | struct page *page = rx_buffer->page; |
Alexander Duyck | 1b56cf4 | 2017-01-17 08:36:03 -0800 | [diff] [blame] | 1940 | |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1941 | /* avoid re-using remote pages */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1942 | if (unlikely(ixgbe_page_is_reserved(page))) |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1943 | return false; |
| 1944 | |
| 1945 | #if (PAGE_SIZE < 8192) |
| 1946 | /* if we are only owner of page we can reuse it */ |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 1947 | if (unlikely((page_ref_count(page) - pagecnt_bias) > 1)) |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1948 | return false; |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1949 | #else |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 1950 | /* The last offset is a bit aggressive in that we assume the |
| 1951 | * worst case of FCoE being enabled and using a 3K buffer. |
| 1952 | * However this should have minimal impact as the 1K extra is |
| 1953 | * still less than one buffer in size. |
| 1954 | */ |
| 1955 | #define IXGBE_LAST_OFFSET \ |
| 1956 | (SKB_WITH_OVERHEAD(PAGE_SIZE) - IXGBE_RXBUFFER_3K) |
| 1957 | if (rx_buffer->page_offset > IXGBE_LAST_OFFSET) |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1958 | return false; |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1959 | #endif |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1960 | |
Alexander Duyck | 1b56cf4 | 2017-01-17 08:36:03 -0800 | [diff] [blame] | 1961 | /* If we have drained the page fragment pool we need to update |
| 1962 | * the pagecnt_bias and page count so that we fully restock the |
| 1963 | * number of references the driver holds. |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1964 | */ |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 1965 | if (unlikely(!pagecnt_bias)) { |
Alexander Duyck | 1b56cf4 | 2017-01-17 08:36:03 -0800 | [diff] [blame] | 1966 | page_ref_add(page, USHRT_MAX); |
| 1967 | rx_buffer->pagecnt_bias = USHRT_MAX; |
| 1968 | } |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1969 | |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1970 | return true; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1971 | } |
| 1972 | |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 1973 | /** |
| 1974 | * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff |
| 1975 | * @rx_ring: rx descriptor ring to transact packets on |
| 1976 | * @rx_buffer: buffer containing page to add |
| 1977 | * @rx_desc: descriptor containing length of buffer written by hardware |
| 1978 | * @skb: sk_buff to place the data into |
| 1979 | * |
| 1980 | * This function will add the data contained in rx_buffer->page to the skb. |
| 1981 | * This is done either through a direct copy if the data in the buffer is |
| 1982 | * less than the skb header size, otherwise it will just attach the page as |
| 1983 | * a frag to the skb. |
| 1984 | * |
| 1985 | * The function will then update the page offset if necessary and return |
| 1986 | * true if the buffer can be reused by the adapter. |
| 1987 | **/ |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 1988 | static void ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring, |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 1989 | struct ixgbe_rx_buffer *rx_buffer, |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 1990 | struct sk_buff *skb, |
| 1991 | unsigned int size) |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 1992 | { |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 1993 | #if (PAGE_SIZE < 8192) |
Alexander Duyck | 4f4542b | 2017-01-17 08:36:14 -0800 | [diff] [blame] | 1994 | unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2; |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 1995 | #else |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 1996 | unsigned int truesize = ring_uses_build_skb(rx_ring) ? |
| 1997 | SKB_DATA_ALIGN(IXGBE_SKB_PAD + size) : |
| 1998 | SKB_DATA_ALIGN(size); |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 1999 | #endif |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2000 | skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_buffer->page, |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 2001 | rx_buffer->page_offset, size, truesize); |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2002 | #if (PAGE_SIZE < 8192) |
| 2003 | rx_buffer->page_offset ^= truesize; |
| 2004 | #else |
| 2005 | rx_buffer->page_offset += truesize; |
| 2006 | #endif |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 2007 | } |
| 2008 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2009 | static struct ixgbe_rx_buffer *ixgbe_get_rx_buffer(struct ixgbe_ring *rx_ring, |
| 2010 | union ixgbe_adv_rx_desc *rx_desc, |
| 2011 | struct sk_buff **skb, |
| 2012 | const unsigned int size) |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2013 | { |
| 2014 | struct ixgbe_rx_buffer *rx_buffer; |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2015 | |
| 2016 | rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean]; |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2017 | prefetchw(rx_buffer->page); |
| 2018 | *skb = rx_buffer->skb; |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2019 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2020 | /* Delay unmapping of the first packet. It carries the header |
| 2021 | * information, HW may still access the header after the writeback. |
| 2022 | * Only unmap it when EOP is reached |
| 2023 | */ |
| 2024 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)) { |
| 2025 | if (!*skb) |
| 2026 | goto skip_sync; |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2027 | } else { |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2028 | if (*skb) |
| 2029 | ixgbe_dma_sync_frag(rx_ring, *skb); |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2030 | } |
| 2031 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2032 | /* we are reusing so sync this buffer for CPU use */ |
| 2033 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 2034 | rx_buffer->dma, |
| 2035 | rx_buffer->page_offset, |
| 2036 | size, |
| 2037 | DMA_FROM_DEVICE); |
| 2038 | skip_sync: |
| 2039 | rx_buffer->pagecnt_bias--; |
| 2040 | |
| 2041 | return rx_buffer; |
| 2042 | } |
| 2043 | |
| 2044 | static void ixgbe_put_rx_buffer(struct ixgbe_ring *rx_ring, |
| 2045 | struct ixgbe_rx_buffer *rx_buffer, |
| 2046 | struct sk_buff *skb) |
| 2047 | { |
| 2048 | if (ixgbe_can_reuse_rx_page(rx_buffer)) { |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2049 | /* hand second half of page back to the ring */ |
| 2050 | ixgbe_reuse_rx_page(rx_ring, rx_buffer); |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2051 | } else { |
Alexander Duyck | 1b56cf4 | 2017-01-17 08:36:03 -0800 | [diff] [blame] | 2052 | if (IXGBE_CB(skb)->dma == rx_buffer->dma) { |
| 2053 | /* the page has been released from the ring */ |
| 2054 | IXGBE_CB(skb)->page_released = true; |
| 2055 | } else { |
| 2056 | /* we are not reusing the buffer so unmap it */ |
| 2057 | dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma, |
| 2058 | ixgbe_rx_pg_size(rx_ring), |
| 2059 | DMA_FROM_DEVICE, |
| 2060 | IXGBE_RX_DMA_ATTR); |
| 2061 | } |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2062 | __page_frag_cache_drain(rx_buffer->page, |
Alexander Duyck | 1b56cf4 | 2017-01-17 08:36:03 -0800 | [diff] [blame] | 2063 | rx_buffer->pagecnt_bias); |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2064 | } |
| 2065 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2066 | /* clear contents of rx_buffer */ |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2067 | rx_buffer->page = NULL; |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2068 | rx_buffer->skb = NULL; |
| 2069 | } |
| 2070 | |
| 2071 | static struct sk_buff *ixgbe_construct_skb(struct ixgbe_ring *rx_ring, |
| 2072 | struct ixgbe_rx_buffer *rx_buffer, |
| 2073 | union ixgbe_adv_rx_desc *rx_desc, |
| 2074 | unsigned int size) |
| 2075 | { |
| 2076 | void *va = page_address(rx_buffer->page) + rx_buffer->page_offset; |
| 2077 | #if (PAGE_SIZE < 8192) |
| 2078 | unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2; |
| 2079 | #else |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 2080 | unsigned int truesize = SKB_DATA_ALIGN(size); |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2081 | #endif |
| 2082 | struct sk_buff *skb; |
| 2083 | |
| 2084 | /* prefetch first cache line of first page */ |
| 2085 | prefetch(va); |
| 2086 | #if L1_CACHE_BYTES < 128 |
| 2087 | prefetch(va + L1_CACHE_BYTES); |
| 2088 | #endif |
| 2089 | |
| 2090 | /* allocate a skb to store the frags */ |
| 2091 | skb = napi_alloc_skb(&rx_ring->q_vector->napi, IXGBE_RX_HDR_SIZE); |
| 2092 | if (unlikely(!skb)) |
| 2093 | return NULL; |
| 2094 | |
| 2095 | if (size > IXGBE_RX_HDR_SIZE) { |
| 2096 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)) |
| 2097 | IXGBE_CB(skb)->dma = rx_buffer->dma; |
| 2098 | |
| 2099 | skb_add_rx_frag(skb, 0, rx_buffer->page, |
| 2100 | rx_buffer->page_offset, |
| 2101 | size, truesize); |
| 2102 | #if (PAGE_SIZE < 8192) |
| 2103 | rx_buffer->page_offset ^= truesize; |
| 2104 | #else |
| 2105 | rx_buffer->page_offset += truesize; |
| 2106 | #endif |
| 2107 | } else { |
| 2108 | memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long))); |
| 2109 | rx_buffer->pagecnt_bias++; |
| 2110 | } |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2111 | |
| 2112 | return skb; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2113 | } |
| 2114 | |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 2115 | static struct sk_buff *ixgbe_build_skb(struct ixgbe_ring *rx_ring, |
| 2116 | struct ixgbe_rx_buffer *rx_buffer, |
| 2117 | union ixgbe_adv_rx_desc *rx_desc, |
| 2118 | unsigned int size) |
| 2119 | { |
| 2120 | void *va = page_address(rx_buffer->page) + rx_buffer->page_offset; |
| 2121 | #if (PAGE_SIZE < 8192) |
| 2122 | unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2; |
| 2123 | #else |
| 2124 | unsigned int truesize = SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) + |
| 2125 | SKB_DATA_ALIGN(IXGBE_SKB_PAD + size); |
| 2126 | #endif |
| 2127 | struct sk_buff *skb; |
| 2128 | |
| 2129 | /* prefetch first cache line of first page */ |
| 2130 | prefetch(va); |
| 2131 | #if L1_CACHE_BYTES < 128 |
| 2132 | prefetch(va + L1_CACHE_BYTES); |
| 2133 | #endif |
| 2134 | |
Alexander Duyck | 3a1eb6d | 2017-02-15 09:15:59 -0800 | [diff] [blame] | 2135 | /* build an skb around the page buffer */ |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 2136 | skb = build_skb(va - IXGBE_SKB_PAD, truesize); |
| 2137 | if (unlikely(!skb)) |
| 2138 | return NULL; |
| 2139 | |
| 2140 | /* update pointers within the skb to store the data */ |
| 2141 | skb_reserve(skb, IXGBE_SKB_PAD); |
| 2142 | __skb_put(skb, size); |
| 2143 | |
| 2144 | /* record DMA address if this is the start of a chain of buffers */ |
| 2145 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)) |
| 2146 | IXGBE_CB(skb)->dma = rx_buffer->dma; |
| 2147 | |
| 2148 | /* update buffer offset */ |
| 2149 | #if (PAGE_SIZE < 8192) |
| 2150 | rx_buffer->page_offset ^= truesize; |
| 2151 | #else |
| 2152 | rx_buffer->page_offset += truesize; |
| 2153 | #endif |
| 2154 | |
| 2155 | return skb; |
| 2156 | } |
| 2157 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2158 | /** |
| 2159 | * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf |
| 2160 | * @q_vector: structure containing interrupt and ring information |
| 2161 | * @rx_ring: rx descriptor ring to transact packets on |
| 2162 | * @budget: Total limit on number of packets to process |
| 2163 | * |
| 2164 | * This function provides a "bounce buffer" approach to Rx interrupt |
| 2165 | * processing. The advantage to this is that on systems that have |
| 2166 | * expensive overhead for IOMMU access this provides a means of avoiding |
| 2167 | * it by maintaining the mapping of the page to the syste. |
| 2168 | * |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2169 | * Returns amount of work completed |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2170 | **/ |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2171 | static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2172 | struct ixgbe_ring *rx_ring, |
Alexander Duyck | f4de00e | 2012-09-25 00:29:37 +0000 | [diff] [blame] | 2173 | const int budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2174 | { |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 2175 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 2176 | #ifdef IXGBE_FCOE |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2177 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Mark Rustad | 4ffdf91 | 2012-07-18 06:05:50 +0000 | [diff] [blame] | 2178 | int ddp_bytes; |
| 2179 | unsigned int mss = 0; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 2180 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2181 | u16 cleaned_count = ixgbe_desc_unused(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2182 | |
Eric W. Biederman | fdabfc8a | 2014-03-14 18:00:41 -0700 | [diff] [blame] | 2183 | while (likely(total_rx_packets < budget)) { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2184 | union ixgbe_adv_rx_desc *rx_desc; |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2185 | struct ixgbe_rx_buffer *rx_buffer; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2186 | struct sk_buff *skb; |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2187 | unsigned int size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2188 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2189 | /* return some buffers to hardware, one at a time is too slow */ |
| 2190 | if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) { |
| 2191 | ixgbe_alloc_rx_buffers(rx_ring, cleaned_count); |
| 2192 | cleaned_count = 0; |
| 2193 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2194 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2195 | rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean); |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2196 | size = le16_to_cpu(rx_desc->wb.upper.length); |
| 2197 | if (!size) |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2198 | break; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 2199 | |
Alexander Duyck | 124b74c | 2014-12-11 15:02:28 -0800 | [diff] [blame] | 2200 | /* This memory barrier is needed to keep us from reading |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2201 | * any other fields out of the rx_desc until we know the |
Alexander Duyck | 124b74c | 2014-12-11 15:02:28 -0800 | [diff] [blame] | 2202 | * descriptor has been written back |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2203 | */ |
Alexander Duyck | 124b74c | 2014-12-11 15:02:28 -0800 | [diff] [blame] | 2204 | dma_rmb(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2205 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2206 | rx_buffer = ixgbe_get_rx_buffer(rx_ring, rx_desc, &skb, size); |
| 2207 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2208 | /* retrieve a buffer from the ring */ |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2209 | if (skb) |
| 2210 | ixgbe_add_rx_frag(rx_ring, rx_buffer, skb, size); |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 2211 | else if (ring_uses_build_skb(rx_ring)) |
| 2212 | skb = ixgbe_build_skb(rx_ring, rx_buffer, |
| 2213 | rx_desc, size); |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2214 | else |
| 2215 | skb = ixgbe_construct_skb(rx_ring, rx_buffer, |
| 2216 | rx_desc, size); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2217 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2218 | /* exit if we failed to retrieve a buffer */ |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2219 | if (!skb) { |
| 2220 | rx_ring->rx_stats.alloc_rx_buff_failed++; |
| 2221 | rx_buffer->pagecnt_bias++; |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2222 | break; |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2223 | } |
Alexander Duyck | 4c1975d | 2012-01-31 02:59:23 +0000 | [diff] [blame] | 2224 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2225 | ixgbe_put_rx_buffer(rx_ring, rx_buffer, skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2226 | cleaned_count++; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2227 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2228 | /* place incomplete frames back on ring for completion */ |
| 2229 | if (ixgbe_is_non_eop(rx_ring, rx_desc, skb)) |
| 2230 | continue; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2231 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2232 | /* verify the packet layout is correct */ |
| 2233 | if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb)) |
| 2234 | continue; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 2235 | |
| 2236 | /* probably a little skewed due to removing CRC */ |
| 2237 | total_rx_bytes += skb->len; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 2238 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 2239 | /* populate checksum, timestamp, VLAN, and protocol */ |
| 2240 | ixgbe_process_skb_fields(rx_ring, rx_desc, skb); |
| 2241 | |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 2242 | #ifdef IXGBE_FCOE |
| 2243 | /* if ddp, not passing to ULD unless for FCP_RSP or error */ |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 2244 | if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) { |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 2245 | ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb); |
Mark Rustad | 4ffdf91 | 2012-07-18 06:05:50 +0000 | [diff] [blame] | 2246 | /* include DDPed FCoE data */ |
| 2247 | if (ddp_bytes > 0) { |
| 2248 | if (!mss) { |
| 2249 | mss = rx_ring->netdev->mtu - |
| 2250 | sizeof(struct fcoe_hdr) - |
| 2251 | sizeof(struct fc_frame_header) - |
| 2252 | sizeof(struct fcoe_crc_eof); |
| 2253 | if (mss > 512) |
| 2254 | mss &= ~511; |
| 2255 | } |
| 2256 | total_rx_bytes += ddp_bytes; |
| 2257 | total_rx_packets += DIV_ROUND_UP(ddp_bytes, |
| 2258 | mss); |
| 2259 | } |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 2260 | if (!ddp_bytes) { |
| 2261 | dev_kfree_skb_any(skb); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2262 | continue; |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 2263 | } |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 2264 | } |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2265 | |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 2266 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 2267 | ixgbe_rx_skb(q_vector, skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2268 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2269 | /* update budget accounting */ |
Alexander Duyck | f4de00e | 2012-09-25 00:29:37 +0000 | [diff] [blame] | 2270 | total_rx_packets++; |
Eric W. Biederman | fdabfc8a | 2014-03-14 18:00:41 -0700 | [diff] [blame] | 2271 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2272 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 2273 | u64_stats_update_begin(&rx_ring->syncp); |
| 2274 | rx_ring->stats.packets += total_rx_packets; |
| 2275 | rx_ring->stats.bytes += total_rx_bytes; |
| 2276 | u64_stats_update_end(&rx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2277 | q_vector->rx.total_packets += total_rx_packets; |
| 2278 | q_vector->rx.total_bytes += total_rx_bytes; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2279 | |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2280 | return total_rx_packets; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2281 | } |
| 2282 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2283 | /** |
| 2284 | * ixgbe_configure_msix - Configure MSI-X hardware |
| 2285 | * @adapter: board private structure |
| 2286 | * |
| 2287 | * ixgbe_configure_msix sets up the hardware to properly generate MSI-X |
| 2288 | * interrupts. |
| 2289 | **/ |
| 2290 | static void ixgbe_configure_msix(struct ixgbe_adapter *adapter) |
| 2291 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2292 | struct ixgbe_q_vector *q_vector; |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2293 | int v_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2294 | u32 mask; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2295 | |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 2296 | /* Populate MSIX to EITR Select */ |
| 2297 | if (adapter->num_vfs > 32) { |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 2298 | u32 eitrsel = BIT(adapter->num_vfs - 32) - 1; |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 2299 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel); |
| 2300 | } |
| 2301 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 2302 | /* |
| 2303 | * Populate the IVAR table and set the ITR values to the |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2304 | * corresponding register. |
| 2305 | */ |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2306 | for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) { |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2307 | struct ixgbe_ring *ring; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2308 | q_vector = adapter->q_vector[v_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2309 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 2310 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2311 | ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2312 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 2313 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2314 | ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2315 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2316 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2317 | } |
| 2318 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2319 | switch (adapter->hw.mac.type) { |
| 2320 | case ixgbe_mac_82598EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2321 | ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2322 | v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2323 | break; |
| 2324 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2325 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2326 | case ixgbe_mac_X550: |
| 2327 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2328 | case ixgbe_mac_x550em_a: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2329 | ixgbe_set_ivar(adapter, -1, 1, v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2330 | break; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2331 | default: |
| 2332 | break; |
| 2333 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2334 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2335 | |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 2336 | /* set up to autoclear timer, and the vectors */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2337 | mask = IXGBE_EIMS_ENABLE_MASK; |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2338 | mask &= ~(IXGBE_EIMS_OTHER | |
| 2339 | IXGBE_EIMS_MAILBOX | |
| 2340 | IXGBE_EIMS_LSC); |
| 2341 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2342 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2343 | } |
| 2344 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2345 | enum latency_range { |
| 2346 | lowest_latency = 0, |
| 2347 | low_latency = 1, |
| 2348 | bulk_latency = 2, |
| 2349 | latency_invalid = 255 |
| 2350 | }; |
| 2351 | |
| 2352 | /** |
| 2353 | * ixgbe_update_itr - update the dynamic ITR value based on statistics |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2354 | * @q_vector: structure containing interrupt and ring information |
| 2355 | * @ring_container: structure containing ring performance data |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2356 | * |
| 2357 | * Stores a new ITR value based on packets and byte |
| 2358 | * counts during the last interrupt. The advantage of per interrupt |
| 2359 | * computation is faster updates and more accurate ITR for the current |
| 2360 | * traffic pattern. Constants in this function were computed |
| 2361 | * based on theoretical maximum wire speed and thresholds were set based |
| 2362 | * on testing data as well as attempting to minimize response time |
| 2363 | * while increasing bulk throughput. |
| 2364 | * this functionality is controlled by the InterruptThrottleRate module |
| 2365 | * parameter (see ixgbe_param.c) |
| 2366 | **/ |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2367 | static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector, |
| 2368 | struct ixgbe_ring_container *ring_container) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2369 | { |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2370 | int bytes = ring_container->total_bytes; |
| 2371 | int packets = ring_container->total_packets; |
| 2372 | u32 timepassed_us; |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2373 | u64 bytes_perint; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2374 | u8 itr_setting = ring_container->itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2375 | |
| 2376 | if (packets == 0) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2377 | return; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2378 | |
| 2379 | /* simple throttlerate management |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2380 | * 0-10MB/s lowest (100000 ints/s) |
| 2381 | * 10-20MB/s low (20000 ints/s) |
Alexander Duyck | 8ac34f1 | 2015-07-30 15:19:28 -0700 | [diff] [blame] | 2382 | * 20-1249MB/s bulk (12000 ints/s) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2383 | */ |
| 2384 | /* what was last interrupt timeslice? */ |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2385 | timepassed_us = q_vector->itr >> 2; |
Don Skidmore | bdbeefe | 2013-03-02 07:17:37 +0000 | [diff] [blame] | 2386 | if (timepassed_us == 0) |
| 2387 | return; |
| 2388 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2389 | bytes_perint = bytes / timepassed_us; /* bytes/usec */ |
| 2390 | |
| 2391 | switch (itr_setting) { |
| 2392 | case lowest_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2393 | if (bytes_perint > 10) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2394 | itr_setting = low_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2395 | break; |
| 2396 | case low_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2397 | if (bytes_perint > 20) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2398 | itr_setting = bulk_latency; |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2399 | else if (bytes_perint <= 10) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2400 | itr_setting = lowest_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2401 | break; |
| 2402 | case bulk_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2403 | if (bytes_perint <= 20) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2404 | itr_setting = low_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2405 | break; |
| 2406 | } |
| 2407 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2408 | /* clear work counters since we have the values we need */ |
| 2409 | ring_container->total_bytes = 0; |
| 2410 | ring_container->total_packets = 0; |
| 2411 | |
| 2412 | /* write updated itr to ring container */ |
| 2413 | ring_container->itr = itr_setting; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2414 | } |
| 2415 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2416 | /** |
| 2417 | * ixgbe_write_eitr - write EITR register in hardware specific way |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2418 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2419 | * |
| 2420 | * This function is made to be called by ethtool and by the driver |
| 2421 | * when it needs to update EITR registers at runtime. Hardware |
| 2422 | * specific quirks/differences are taken care of here. |
| 2423 | */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2424 | void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector) |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2425 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2426 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2427 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2428 | int v_idx = q_vector->v_idx; |
Alexander Duyck | 5d967eb | 2012-02-08 07:49:43 +0000 | [diff] [blame] | 2429 | u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2430 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2431 | switch (adapter->hw.mac.type) { |
| 2432 | case ixgbe_mac_82598EB: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2433 | /* must write high and low 16 bits to reset counter */ |
| 2434 | itr_reg |= (itr_reg << 16); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2435 | break; |
| 2436 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2437 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2438 | case ixgbe_mac_X550: |
| 2439 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2440 | case ixgbe_mac_x550em_a: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2441 | /* |
| 2442 | * set the WDIS bit to not clear the timer bits and cause an |
| 2443 | * immediate assertion of the interrupt |
| 2444 | */ |
| 2445 | itr_reg |= IXGBE_EITR_CNT_WDIS; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2446 | break; |
| 2447 | default: |
| 2448 | break; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2449 | } |
| 2450 | IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg); |
| 2451 | } |
| 2452 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2453 | static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2454 | { |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2455 | u32 new_itr = q_vector->itr; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2456 | u8 current_itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2457 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2458 | ixgbe_update_itr(q_vector, &q_vector->tx); |
| 2459 | ixgbe_update_itr(q_vector, &q_vector->rx); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2460 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2461 | current_itr = max(q_vector->rx.itr, q_vector->tx.itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2462 | |
| 2463 | switch (current_itr) { |
| 2464 | /* counts and packets in update_itr are dependent on these numbers */ |
| 2465 | case lowest_latency: |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2466 | new_itr = IXGBE_100K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2467 | break; |
| 2468 | case low_latency: |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2469 | new_itr = IXGBE_20K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2470 | break; |
| 2471 | case bulk_latency: |
Alexander Duyck | 8ac34f1 | 2015-07-30 15:19:28 -0700 | [diff] [blame] | 2472 | new_itr = IXGBE_12K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2473 | break; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2474 | default: |
| 2475 | break; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2476 | } |
| 2477 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2478 | if (new_itr != q_vector->itr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2479 | /* do an exponential smoothing */ |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2480 | new_itr = (10 * new_itr * q_vector->itr) / |
| 2481 | ((9 * new_itr) + q_vector->itr); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2482 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2483 | /* save the algorithm value here */ |
Alexander Duyck | 5d967eb | 2012-02-08 07:49:43 +0000 | [diff] [blame] | 2484 | q_vector->itr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2485 | |
| 2486 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2487 | } |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2488 | } |
| 2489 | |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2490 | /** |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2491 | * ixgbe_check_overtemp_subtask - check for over temperature |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2492 | * @adapter: pointer to adapter |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2493 | **/ |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2494 | static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter) |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2495 | { |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2496 | struct ixgbe_hw *hw = &adapter->hw; |
| 2497 | u32 eicr = adapter->interrupt_event; |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 2498 | s32 rc; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2499 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2500 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2501 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2502 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2503 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) && |
| 2504 | !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT)) |
| 2505 | return; |
| 2506 | |
| 2507 | adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2508 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2509 | switch (hw->device_id) { |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2510 | case IXGBE_DEV_ID_82599_T3_LOM: |
| 2511 | /* |
| 2512 | * Since the warning interrupt is for both ports |
| 2513 | * we don't have to check if: |
| 2514 | * - This interrupt wasn't for our port. |
| 2515 | * - We may have missed the interrupt so always have to |
| 2516 | * check if we got a LSC |
| 2517 | */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2518 | if (!(eicr & IXGBE_EICR_GPI_SDP0_8259X) && |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2519 | !(eicr & IXGBE_EICR_LSC)) |
| 2520 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2521 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2522 | if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) { |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 2523 | u32 speed; |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2524 | bool link_up = false; |
| 2525 | |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 2526 | hw->mac.ops.check_link(hw, &speed, &link_up, false); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2527 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2528 | if (link_up) |
| 2529 | return; |
| 2530 | } |
| 2531 | |
| 2532 | /* Check if this is not due to overtemp */ |
| 2533 | if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP) |
| 2534 | return; |
| 2535 | |
| 2536 | break; |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 2537 | case IXGBE_DEV_ID_X550EM_A_1G_T: |
| 2538 | case IXGBE_DEV_ID_X550EM_A_1G_T_L: |
| 2539 | rc = hw->phy.ops.check_overtemp(hw); |
| 2540 | if (rc != IXGBE_ERR_OVERTEMP) |
| 2541 | return; |
| 2542 | break; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2543 | default: |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 2544 | if (adapter->hw.mac.type >= ixgbe_mac_X540) |
| 2545 | return; |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2546 | if (!(eicr & IXGBE_EICR_GPI_SDP0(hw))) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2547 | return; |
| 2548 | break; |
| 2549 | } |
Don Skidmore | f44e751 | 2015-06-09 16:36:23 -0700 | [diff] [blame] | 2550 | e_crit(drv, "%s\n", ixgbe_overheat_msg); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2551 | |
| 2552 | adapter->interrupt_event = 0; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2553 | } |
| 2554 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2555 | static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr) |
| 2556 | { |
| 2557 | struct ixgbe_hw *hw = &adapter->hw; |
| 2558 | |
| 2559 | if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) && |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2560 | (eicr & IXGBE_EICR_GPI_SDP1(hw))) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2561 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2562 | /* write to clear the interrupt */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2563 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw)); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2564 | } |
| 2565 | } |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2566 | |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2567 | static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 2568 | { |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2569 | struct ixgbe_hw *hw = &adapter->hw; |
| 2570 | |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2571 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)) |
| 2572 | return; |
| 2573 | |
| 2574 | switch (adapter->hw.mac.type) { |
| 2575 | case ixgbe_mac_82599EB: |
| 2576 | /* |
| 2577 | * Need to check link state so complete overtemp check |
| 2578 | * on service task |
| 2579 | */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2580 | if (((eicr & IXGBE_EICR_GPI_SDP0(hw)) || |
| 2581 | (eicr & IXGBE_EICR_LSC)) && |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2582 | (!test_bit(__IXGBE_DOWN, &adapter->state))) { |
| 2583 | adapter->interrupt_event = eicr; |
| 2584 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2585 | ixgbe_service_event_schedule(adapter); |
| 2586 | return; |
| 2587 | } |
| 2588 | return; |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 2589 | case ixgbe_mac_x550em_a: |
| 2590 | if (eicr & IXGBE_EICR_GPI_SDP0_X550EM_a) { |
| 2591 | adapter->interrupt_event = eicr; |
| 2592 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2593 | ixgbe_service_event_schedule(adapter); |
| 2594 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, |
| 2595 | IXGBE_EICR_GPI_SDP0_X550EM_a); |
| 2596 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICR, |
| 2597 | IXGBE_EICR_GPI_SDP0_X550EM_a); |
| 2598 | } |
| 2599 | return; |
| 2600 | case ixgbe_mac_X550: |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2601 | case ixgbe_mac_X540: |
| 2602 | if (!(eicr & IXGBE_EICR_TS)) |
| 2603 | return; |
| 2604 | break; |
| 2605 | default: |
| 2606 | return; |
| 2607 | } |
| 2608 | |
Don Skidmore | f44e751 | 2015-06-09 16:36:23 -0700 | [diff] [blame] | 2609 | e_crit(drv, "%s\n", ixgbe_overheat_msg); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2610 | } |
| 2611 | |
Don Skidmore | 45788d2 | 2015-06-09 16:59:04 -0700 | [diff] [blame] | 2612 | static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw) |
| 2613 | { |
| 2614 | switch (hw->mac.type) { |
| 2615 | case ixgbe_mac_82598EB: |
| 2616 | if (hw->phy.type == ixgbe_phy_nl) |
| 2617 | return true; |
| 2618 | return false; |
| 2619 | case ixgbe_mac_82599EB: |
| 2620 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2621 | case ixgbe_mac_x550em_a: |
Don Skidmore | 45788d2 | 2015-06-09 16:59:04 -0700 | [diff] [blame] | 2622 | switch (hw->mac.ops.get_media_type(hw)) { |
| 2623 | case ixgbe_media_type_fiber: |
| 2624 | case ixgbe_media_type_fiber_qsfp: |
| 2625 | return true; |
| 2626 | default: |
| 2627 | return false; |
| 2628 | } |
| 2629 | default: |
| 2630 | return false; |
| 2631 | } |
| 2632 | } |
| 2633 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2634 | static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 2635 | { |
| 2636 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 4ccc650 | 2015-09-02 13:47:54 -0700 | [diff] [blame] | 2637 | u32 eicr_mask = IXGBE_EICR_GPI_SDP2(hw); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2638 | |
Don Skidmore | 4ccc650 | 2015-09-02 13:47:54 -0700 | [diff] [blame] | 2639 | if (!ixgbe_is_sfp(hw)) |
| 2640 | return; |
| 2641 | |
| 2642 | /* Later MAC's use different SDP */ |
| 2643 | if (hw->mac.type >= ixgbe_mac_X540) |
| 2644 | eicr_mask = IXGBE_EICR_GPI_SDP0_X540; |
| 2645 | |
| 2646 | if (eicr & eicr_mask) { |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2647 | /* Clear the interrupt */ |
Don Skidmore | 4ccc650 | 2015-09-02 13:47:54 -0700 | [diff] [blame] | 2648 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr_mask); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2649 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2650 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
Mark Rustad | 58e7cd2 | 2015-08-08 16:18:48 -0700 | [diff] [blame] | 2651 | adapter->sfp_poll_time = 0; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2652 | ixgbe_service_event_schedule(adapter); |
| 2653 | } |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2654 | } |
| 2655 | |
Don Skidmore | 4ccc650 | 2015-09-02 13:47:54 -0700 | [diff] [blame] | 2656 | if (adapter->hw.mac.type == ixgbe_mac_82599EB && |
| 2657 | (eicr & IXGBE_EICR_GPI_SDP1(hw))) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2658 | /* Clear the interrupt */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2659 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw)); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2660 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2661 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 2662 | ixgbe_service_event_schedule(adapter); |
| 2663 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2664 | } |
| 2665 | } |
| 2666 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2667 | static void ixgbe_check_lsc(struct ixgbe_adapter *adapter) |
| 2668 | { |
| 2669 | struct ixgbe_hw *hw = &adapter->hw; |
| 2670 | |
| 2671 | adapter->lsc_int++; |
| 2672 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 2673 | adapter->link_check_timeout = jiffies; |
| 2674 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2675 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC); |
Nelson, Shannon | 8a0717f | 2009-11-12 18:47:11 +0000 | [diff] [blame] | 2676 | IXGBE_WRITE_FLUSH(hw); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 2677 | ixgbe_service_event_schedule(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2678 | } |
| 2679 | } |
| 2680 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2681 | static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter, |
| 2682 | u64 qmask) |
| 2683 | { |
| 2684 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2685 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2686 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2687 | switch (hw->mac.type) { |
| 2688 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2689 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2690 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask); |
| 2691 | break; |
| 2692 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2693 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2694 | case ixgbe_mac_X550: |
| 2695 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2696 | case ixgbe_mac_x550em_a: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2697 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2698 | if (mask) |
| 2699 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2700 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2701 | if (mask) |
| 2702 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask); |
| 2703 | break; |
| 2704 | default: |
| 2705 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2706 | } |
| 2707 | /* skip the flush */ |
| 2708 | } |
| 2709 | |
| 2710 | static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2711 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2712 | { |
| 2713 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2714 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2715 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2716 | switch (hw->mac.type) { |
| 2717 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2718 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2719 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask); |
| 2720 | break; |
| 2721 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2722 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2723 | case ixgbe_mac_X550: |
| 2724 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2725 | case ixgbe_mac_x550em_a: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2726 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2727 | if (mask) |
| 2728 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2729 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2730 | if (mask) |
| 2731 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask); |
| 2732 | break; |
| 2733 | default: |
| 2734 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2735 | } |
| 2736 | /* skip the flush */ |
| 2737 | } |
| 2738 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2739 | /** |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2740 | * ixgbe_irq_enable - Enable default interrupt generation settings |
| 2741 | * @adapter: board private structure |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2742 | **/ |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2743 | static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues, |
| 2744 | bool flush) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2745 | { |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2746 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2747 | u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE); |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 2748 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2749 | /* don't reenable LSC while waiting for link */ |
| 2750 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 2751 | mask &= ~IXGBE_EIMS_LSC; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2752 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2753 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2754 | switch (adapter->hw.mac.type) { |
| 2755 | case ixgbe_mac_82599EB: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2756 | mask |= IXGBE_EIMS_GPI_SDP0(hw); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2757 | break; |
| 2758 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2759 | case ixgbe_mac_X550: |
| 2760 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2761 | case ixgbe_mac_x550em_a: |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2762 | mask |= IXGBE_EIMS_TS; |
| 2763 | break; |
| 2764 | default: |
| 2765 | break; |
| 2766 | } |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2767 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2768 | mask |= IXGBE_EIMS_GPI_SDP1(hw); |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2769 | switch (adapter->hw.mac.type) { |
| 2770 | case ixgbe_mac_82599EB: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2771 | mask |= IXGBE_EIMS_GPI_SDP1(hw); |
| 2772 | mask |= IXGBE_EIMS_GPI_SDP2(hw); |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2773 | /* fall through */ |
Don Skidmore | 858bc08 | 2011-08-04 09:28:30 +0000 | [diff] [blame] | 2774 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2775 | case ixgbe_mac_X550: |
| 2776 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2777 | case ixgbe_mac_x550em_a: |
| 2778 | if (adapter->hw.device_id == IXGBE_DEV_ID_X550EM_X_SFP || |
Mark Rustad | 2d40cd1 | 2016-04-01 12:18:35 -0700 | [diff] [blame] | 2779 | adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP || |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2780 | adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP_N) |
Mark Rustad | cbd45ec | 2015-08-08 16:17:51 -0700 | [diff] [blame] | 2781 | mask |= IXGBE_EIMS_GPI_SDP0(&adapter->hw); |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 2782 | if (adapter->hw.phy.type == ixgbe_phy_x550em_ext_t) |
| 2783 | mask |= IXGBE_EICR_GPI_SDP0_X540; |
Don Skidmore | 858bc08 | 2011-08-04 09:28:30 +0000 | [diff] [blame] | 2784 | mask |= IXGBE_EIMS_ECC; |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2785 | mask |= IXGBE_EIMS_MAILBOX; |
| 2786 | break; |
| 2787 | default: |
| 2788 | break; |
| 2789 | } |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2790 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2791 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) && |
| 2792 | !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 2793 | mask |= IXGBE_EIMS_FLOW_DIR; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2794 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2795 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
| 2796 | if (queues) |
| 2797 | ixgbe_irq_enable_queues(adapter, ~0); |
| 2798 | if (flush) |
| 2799 | IXGBE_WRITE_FLUSH(&adapter->hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2800 | } |
| 2801 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2802 | static irqreturn_t ixgbe_msix_other(int irq, void *data) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2803 | { |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2804 | struct ixgbe_adapter *adapter = data; |
| 2805 | struct ixgbe_hw *hw = &adapter->hw; |
| 2806 | u32 eicr; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2807 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2808 | /* |
| 2809 | * Workaround for Silicon errata. Use clear-by-write instead |
| 2810 | * of clear-by-read. Reading with EICS will return the |
| 2811 | * interrupt causes without clearing, which later be done |
| 2812 | * with the write to EICR. |
| 2813 | */ |
| 2814 | eicr = IXGBE_READ_REG(hw, IXGBE_EICS); |
Jacob Keller | d87d830 | 2013-03-02 07:51:42 +0000 | [diff] [blame] | 2815 | |
| 2816 | /* The lower 16bits of the EICR register are for the queue interrupts |
Joe Perches | dbedd44 | 2015-03-06 20:49:12 -0800 | [diff] [blame] | 2817 | * which should be masked here in order to not accidentally clear them if |
Jacob Keller | d87d830 | 2013-03-02 07:51:42 +0000 | [diff] [blame] | 2818 | * the bits are high when ixgbe_msix_other is called. There is a race |
| 2819 | * condition otherwise which results in possible performance loss |
| 2820 | * especially if the ixgbe_msix_other interrupt is triggering |
| 2821 | * consistently (as it would when PPS is turned on for the X540 device) |
| 2822 | */ |
| 2823 | eicr &= 0xFFFF0000; |
| 2824 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2825 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2826 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2827 | if (eicr & IXGBE_EICR_LSC) |
| 2828 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2829 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2830 | if (eicr & IXGBE_EICR_MAILBOX) |
| 2831 | ixgbe_msg_task(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2832 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2833 | switch (hw->mac.type) { |
| 2834 | case ixgbe_mac_82599EB: |
| 2835 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2836 | case ixgbe_mac_X550: |
| 2837 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2838 | case ixgbe_mac_x550em_a: |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 2839 | if (hw->phy.type == ixgbe_phy_x550em_ext_t && |
| 2840 | (eicr & IXGBE_EICR_GPI_SDP0_X540)) { |
| 2841 | adapter->flags2 |= IXGBE_FLAG2_PHY_INTERRUPT; |
| 2842 | ixgbe_service_event_schedule(adapter); |
| 2843 | IXGBE_WRITE_REG(hw, IXGBE_EICR, |
| 2844 | IXGBE_EICR_GPI_SDP0_X540); |
| 2845 | } |
Don Skidmore | d773ce2 | 2014-02-25 17:58:53 -0800 | [diff] [blame] | 2846 | if (eicr & IXGBE_EICR_ECC) { |
| 2847 | e_info(link, "Received ECC Err, initiating reset\n"); |
Emil Tantilov | 57ca2a4 | 2016-07-29 14:46:31 -0700 | [diff] [blame] | 2848 | set_bit(__IXGBE_RESET_REQUESTED, &adapter->state); |
Don Skidmore | d773ce2 | 2014-02-25 17:58:53 -0800 | [diff] [blame] | 2849 | ixgbe_service_event_schedule(adapter); |
| 2850 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC); |
| 2851 | } |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2852 | /* Handle Flow Director Full threshold interrupt */ |
| 2853 | if (eicr & IXGBE_EICR_FLOW_DIR) { |
| 2854 | int reinit_count = 0; |
| 2855 | int i; |
| 2856 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2857 | struct ixgbe_ring *ring = adapter->tx_ring[i]; |
| 2858 | if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE, |
| 2859 | &ring->state)) |
| 2860 | reinit_count++; |
| 2861 | } |
| 2862 | if (reinit_count) { |
| 2863 | /* no more flow director interrupts until after init */ |
| 2864 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR); |
| 2865 | adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 2866 | ixgbe_service_event_schedule(adapter); |
| 2867 | } |
| 2868 | } |
| 2869 | ixgbe_check_sfp_event(adapter, eicr); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2870 | ixgbe_check_overtemp_event(adapter, eicr); |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2871 | break; |
| 2872 | default: |
| 2873 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2874 | } |
| 2875 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2876 | ixgbe_check_fan_failure(adapter, eicr); |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2877 | |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2878 | if (unlikely(eicr & IXGBE_EICR_TIMESYNC)) |
Mark Rustad | a9763f3 | 2015-10-27 09:58:07 -0700 | [diff] [blame] | 2879 | ixgbe_ptp_check_pps_event(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2880 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2881 | /* re-enable the original interrupt state, no lsc, no queues */ |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2882 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2883 | ixgbe_irq_enable(adapter, false, false); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2884 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2885 | return IRQ_HANDLED; |
| 2886 | } |
| 2887 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2888 | static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2889 | { |
| 2890 | struct ixgbe_q_vector *q_vector = data; |
| 2891 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2892 | /* EIAM disabled interrupts (on this vector) for us */ |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2893 | |
| 2894 | if (q_vector->rx.ring || q_vector->tx.ring) |
Alexander Duyck | ef2662b | 2015-09-29 15:19:43 -0700 | [diff] [blame] | 2895 | napi_schedule_irqoff(&q_vector->napi); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2896 | |
| 2897 | return IRQ_HANDLED; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2898 | } |
| 2899 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2900 | /** |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2901 | * ixgbe_poll - NAPI Rx polling callback |
| 2902 | * @napi: structure for representing this polling device |
| 2903 | * @budget: how many packets driver is allowed to clean |
| 2904 | * |
| 2905 | * This function is used for legacy and MSI, NAPI mode |
| 2906 | **/ |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 2907 | int ixgbe_poll(struct napi_struct *napi, int budget) |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2908 | { |
| 2909 | struct ixgbe_q_vector *q_vector = |
| 2910 | container_of(napi, struct ixgbe_q_vector, napi); |
| 2911 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 2912 | struct ixgbe_ring *ring; |
Jesse Brandeburg | 32b3e08 | 2015-09-24 16:35:47 -0700 | [diff] [blame] | 2913 | int per_ring_budget, work_done = 0; |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2914 | bool clean_complete = true; |
| 2915 | |
| 2916 | #ifdef CONFIG_IXGBE_DCA |
| 2917 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 2918 | ixgbe_update_dca(q_vector); |
| 2919 | #endif |
| 2920 | |
Alexander Duyck | 8220bbc | 2016-03-07 09:30:09 -0800 | [diff] [blame] | 2921 | ixgbe_for_each_ring(ring, q_vector->tx) { |
| 2922 | if (!ixgbe_clean_tx_irq(q_vector, ring, budget)) |
| 2923 | clean_complete = false; |
| 2924 | } |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2925 | |
Eric Dumazet | 3ffc1af | 2017-02-02 16:26:39 -0800 | [diff] [blame] | 2926 | /* Exit if we are called by netpoll */ |
| 2927 | if (budget <= 0) |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2928 | return budget; |
| 2929 | |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2930 | /* attempt to distribute budget to each queue fairly, but don't allow |
| 2931 | * the budget to go below 1 because we'll exit polling */ |
| 2932 | if (q_vector->rx.count > 1) |
| 2933 | per_ring_budget = max(budget/q_vector->rx.count, 1); |
| 2934 | else |
| 2935 | per_ring_budget = budget; |
| 2936 | |
Jesse Brandeburg | 32b3e08 | 2015-09-24 16:35:47 -0700 | [diff] [blame] | 2937 | ixgbe_for_each_ring(ring, q_vector->rx) { |
| 2938 | int cleaned = ixgbe_clean_rx_irq(q_vector, ring, |
| 2939 | per_ring_budget); |
| 2940 | |
| 2941 | work_done += cleaned; |
Alexander Duyck | 8220bbc | 2016-03-07 09:30:09 -0800 | [diff] [blame] | 2942 | if (cleaned >= per_ring_budget) |
| 2943 | clean_complete = false; |
Jesse Brandeburg | 32b3e08 | 2015-09-24 16:35:47 -0700 | [diff] [blame] | 2944 | } |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2945 | |
| 2946 | /* If all work not completed, return budget and keep polling */ |
| 2947 | if (!clean_complete) |
| 2948 | return budget; |
| 2949 | |
| 2950 | /* all work done, exit the polling mode */ |
Jesse Brandeburg | 32b3e08 | 2015-09-24 16:35:47 -0700 | [diff] [blame] | 2951 | napi_complete_done(napi, work_done); |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2952 | if (adapter->rx_itr_setting & 1) |
| 2953 | ixgbe_set_itr(q_vector); |
| 2954 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 2955 | ixgbe_irq_enable_queues(adapter, BIT_ULL(q_vector->v_idx)); |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2956 | |
Paolo Abeni | 4b732cd | 2016-06-15 15:37:59 +0200 | [diff] [blame] | 2957 | return min(work_done, budget - 1); |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2958 | } |
| 2959 | |
| 2960 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2961 | * ixgbe_request_msix_irqs - Initialize MSI-X interrupts |
| 2962 | * @adapter: board private structure |
| 2963 | * |
| 2964 | * ixgbe_request_msix_irqs allocates MSI-X vectors and requests |
| 2965 | * interrupts from the kernel. |
| 2966 | **/ |
| 2967 | static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter) |
| 2968 | { |
| 2969 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2970 | int vector, err; |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2971 | int ri = 0, ti = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2972 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2973 | for (vector = 0; vector < adapter->num_q_vectors; vector++) { |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2974 | struct ixgbe_q_vector *q_vector = adapter->q_vector[vector]; |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2975 | struct msix_entry *entry = &adapter->msix_entries[vector]; |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 2976 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2977 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 2978 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2979 | "%s-%s-%d", netdev->name, "TxRx", ri++); |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2980 | ti++; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2981 | } else if (q_vector->rx.ring) { |
| 2982 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2983 | "%s-%s-%d", netdev->name, "rx", ri++); |
| 2984 | } else if (q_vector->tx.ring) { |
| 2985 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2986 | "%s-%s-%d", netdev->name, "tx", ti++); |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2987 | } else { |
| 2988 | /* skip this unused q_vector */ |
| 2989 | continue; |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2990 | } |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2991 | err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0, |
| 2992 | q_vector->name, q_vector); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2993 | if (err) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2994 | e_err(probe, "request_irq failed for MSIX interrupt " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 2995 | "Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2996 | goto free_queue_irqs; |
| 2997 | } |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2998 | /* If Flow Director is enabled, set interrupt affinity */ |
| 2999 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 3000 | /* assign the mask for this irq */ |
| 3001 | irq_set_affinity_hint(entry->vector, |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 3002 | &q_vector->affinity_mask); |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 3003 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3004 | } |
| 3005 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3006 | err = request_irq(adapter->msix_entries[vector].vector, |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3007 | ixgbe_msix_other, 0, netdev->name, adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3008 | if (err) { |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 3009 | e_err(probe, "request_irq for msix_other failed: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3010 | goto free_queue_irqs; |
| 3011 | } |
| 3012 | |
| 3013 | return 0; |
| 3014 | |
| 3015 | free_queue_irqs: |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 3016 | while (vector) { |
| 3017 | vector--; |
| 3018 | irq_set_affinity_hint(adapter->msix_entries[vector].vector, |
| 3019 | NULL); |
| 3020 | free_irq(adapter->msix_entries[vector].vector, |
| 3021 | adapter->q_vector[vector]); |
| 3022 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3023 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 3024 | pci_disable_msix(adapter->pdev); |
| 3025 | kfree(adapter->msix_entries); |
| 3026 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3027 | return err; |
| 3028 | } |
| 3029 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 3030 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3031 | * ixgbe_intr - legacy mode Interrupt Handler |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3032 | * @irq: interrupt number |
| 3033 | * @data: pointer to a network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3034 | **/ |
| 3035 | static irqreturn_t ixgbe_intr(int irq, void *data) |
| 3036 | { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 3037 | struct ixgbe_adapter *adapter = data; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3038 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3039 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3040 | u32 eicr; |
| 3041 | |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 3042 | /* |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 3043 | * Workaround for silicon errata #26 on 82598. Mask the interrupt |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 3044 | * before the read of EICR. |
| 3045 | */ |
| 3046 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); |
| 3047 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3048 | /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 3049 | * therefore no explicit interrupt disable is necessary */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3050 | eicr = IXGBE_READ_REG(hw, IXGBE_EICR); |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 3051 | if (!eicr) { |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 3052 | /* |
| 3053 | * shared interrupt alert! |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 3054 | * make sure interrupts are enabled because the read will |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 3055 | * have disabled interrupts due to EIAM |
| 3056 | * finish the workaround of silicon errata on 82598. Unmask |
| 3057 | * the interrupt that we masked before the EICR read. |
| 3058 | */ |
| 3059 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 3060 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3061 | return IRQ_NONE; /* Not our interrupt */ |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 3062 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3063 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 3064 | if (eicr & IXGBE_EICR_LSC) |
| 3065 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3066 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3067 | switch (hw->mac.type) { |
| 3068 | case ixgbe_mac_82599EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3069 | ixgbe_check_sfp_event(adapter, eicr); |
Don Skidmore | 0ccb974 | 2011-08-04 02:07:48 +0000 | [diff] [blame] | 3070 | /* Fall through */ |
| 3071 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 3072 | case ixgbe_mac_X550: |
| 3073 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 3074 | case ixgbe_mac_x550em_a: |
Don Skidmore | d773ce2 | 2014-02-25 17:58:53 -0800 | [diff] [blame] | 3075 | if (eicr & IXGBE_EICR_ECC) { |
| 3076 | e_info(link, "Received ECC Err, initiating reset\n"); |
Emil Tantilov | 57ca2a4 | 2016-07-29 14:46:31 -0700 | [diff] [blame] | 3077 | set_bit(__IXGBE_RESET_REQUESTED, &adapter->state); |
Don Skidmore | d773ce2 | 2014-02-25 17:58:53 -0800 | [diff] [blame] | 3078 | ixgbe_service_event_schedule(adapter); |
| 3079 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC); |
| 3080 | } |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 3081 | ixgbe_check_overtemp_event(adapter, eicr); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3082 | break; |
| 3083 | default: |
| 3084 | break; |
| 3085 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3086 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 3087 | ixgbe_check_fan_failure(adapter, eicr); |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 3088 | if (unlikely(eicr & IXGBE_EICR_TIMESYNC)) |
Mark Rustad | a9763f3 | 2015-10-27 09:58:07 -0700 | [diff] [blame] | 3089 | ixgbe_ptp_check_pps_event(adapter); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 3090 | |
Alexander Duyck | b9f6ed2 | 2012-02-08 07:49:54 +0000 | [diff] [blame] | 3091 | /* would disable interrupts here but EIAM disabled it */ |
Alexander Duyck | ef2662b | 2015-09-29 15:19:43 -0700 | [diff] [blame] | 3092 | napi_schedule_irqoff(&q_vector->napi); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3093 | |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 3094 | /* |
| 3095 | * re-enable link(maybe) and non-queue interrupts, no flush. |
| 3096 | * ixgbe_poll will re-enable the queue interrupts |
| 3097 | */ |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 3098 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 3099 | ixgbe_irq_enable(adapter, false, false); |
| 3100 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3101 | return IRQ_HANDLED; |
| 3102 | } |
| 3103 | |
| 3104 | /** |
| 3105 | * ixgbe_request_irq - initialize interrupts |
| 3106 | * @adapter: board private structure |
| 3107 | * |
| 3108 | * Attempts to configure interrupts using the best available |
| 3109 | * capabilities of the hardware and kernel. |
| 3110 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3111 | static int ixgbe_request_irq(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3112 | { |
| 3113 | struct net_device *netdev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3114 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3115 | |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 3116 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3117 | err = ixgbe_request_msix_irqs(adapter); |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 3118 | else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 3119 | err = request_irq(adapter->pdev->irq, ixgbe_intr, 0, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 3120 | netdev->name, adapter); |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 3121 | else |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 3122 | err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 3123 | netdev->name, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3124 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 3125 | if (err) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 3126 | e_err(probe, "request_irq failed, Error %d\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3127 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3128 | return err; |
| 3129 | } |
| 3130 | |
| 3131 | static void ixgbe_free_irq(struct ixgbe_adapter *adapter) |
| 3132 | { |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3133 | int vector; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3134 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3135 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 3136 | free_irq(adapter->pdev->irq, adapter); |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3137 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3138 | } |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3139 | |
Mark Rustad | 1fa7125 | 2016-09-28 15:36:38 -0700 | [diff] [blame] | 3140 | if (!adapter->msix_entries) |
| 3141 | return; |
| 3142 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3143 | for (vector = 0; vector < adapter->num_q_vectors; vector++) { |
| 3144 | struct ixgbe_q_vector *q_vector = adapter->q_vector[vector]; |
| 3145 | struct msix_entry *entry = &adapter->msix_entries[vector]; |
| 3146 | |
| 3147 | /* free only the irqs that were actually requested */ |
| 3148 | if (!q_vector->rx.ring && !q_vector->tx.ring) |
| 3149 | continue; |
| 3150 | |
| 3151 | /* clear the affinity_mask in the IRQ descriptor */ |
| 3152 | irq_set_affinity_hint(entry->vector, NULL); |
| 3153 | |
| 3154 | free_irq(entry->vector, q_vector); |
| 3155 | } |
| 3156 | |
Babu Moger | 90c6f87 | 2016-06-18 17:40:47 -0700 | [diff] [blame] | 3157 | free_irq(adapter->msix_entries[vector].vector, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3158 | } |
| 3159 | |
| 3160 | /** |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3161 | * ixgbe_irq_disable - Mask off interrupt generation on the NIC |
| 3162 | * @adapter: board private structure |
| 3163 | **/ |
| 3164 | static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter) |
| 3165 | { |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3166 | switch (adapter->hw.mac.type) { |
| 3167 | case ixgbe_mac_82598EB: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 3168 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3169 | break; |
| 3170 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3171 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 3172 | case ixgbe_mac_X550: |
| 3173 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 3174 | case ixgbe_mac_x550em_a: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 3175 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000); |
| 3176 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3177 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3178 | break; |
| 3179 | default: |
| 3180 | break; |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3181 | } |
| 3182 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 3183 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3184 | int vector; |
| 3185 | |
| 3186 | for (vector = 0; vector < adapter->num_q_vectors; vector++) |
| 3187 | synchronize_irq(adapter->msix_entries[vector].vector); |
| 3188 | |
| 3189 | synchronize_irq(adapter->msix_entries[vector++].vector); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3190 | } else { |
| 3191 | synchronize_irq(adapter->pdev->irq); |
| 3192 | } |
| 3193 | } |
| 3194 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3195 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3196 | * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts |
| 3197 | * |
| 3198 | **/ |
| 3199 | static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter) |
| 3200 | { |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 3201 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3202 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 3203 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3204 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3205 | ixgbe_set_ivar(adapter, 0, 0, 0); |
| 3206 | ixgbe_set_ivar(adapter, 1, 0, 0); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3207 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 3208 | e_info(hw, "Legacy interrupt IVAR setup done\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3209 | } |
| 3210 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3211 | /** |
| 3212 | * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset |
| 3213 | * @adapter: board private structure |
| 3214 | * @ring: structure containing ring specific data |
| 3215 | * |
| 3216 | * Configure the Tx descriptor ring after a reset. |
| 3217 | **/ |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 3218 | void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter, |
| 3219 | struct ixgbe_ring *ring) |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3220 | { |
| 3221 | struct ixgbe_hw *hw = &adapter->hw; |
| 3222 | u64 tdba = ring->dma; |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3223 | int wait_loop = 10; |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3224 | u32 txdctl = IXGBE_TXDCTL_ENABLE; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3225 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3226 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3227 | /* disable queue to avoid issues while updating state */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3228 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3229 | IXGBE_WRITE_FLUSH(hw); |
| 3230 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3231 | IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3232 | (tdba & DMA_BIT_MASK(32))); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3233 | IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32)); |
| 3234 | IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx), |
| 3235 | ring->count * sizeof(union ixgbe_adv_tx_desc)); |
| 3236 | IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0); |
| 3237 | IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 3238 | ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3239 | |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3240 | /* |
| 3241 | * set WTHRESH to encourage burst writeback, it should not be set |
Emil Tantilov | 67da097 | 2013-01-25 06:19:20 +0000 | [diff] [blame] | 3242 | * higher than 1 when: |
| 3243 | * - ITR is 0 as it could cause false TX hangs |
| 3244 | * - ITR is set to > 100k int/sec and BQL is enabled |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3245 | * |
| 3246 | * In order to avoid issues WTHRESH + PTHRESH should always be equal |
| 3247 | * to or less than the number of on chip descriptors, which is |
| 3248 | * currently 40. |
| 3249 | */ |
Emil Tantilov | 67da097 | 2013-01-25 06:19:20 +0000 | [diff] [blame] | 3250 | if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR)) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 3251 | txdctl |= 1u << 16; /* WTHRESH = 1 */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3252 | else |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 3253 | txdctl |= 8u << 16; /* WTHRESH = 8 */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3254 | |
Alexander Duyck | e954b37 | 2012-02-08 07:49:38 +0000 | [diff] [blame] | 3255 | /* |
| 3256 | * Setting PTHRESH to 32 both improves performance |
| 3257 | * and avoids a TX hang with DFP enabled |
| 3258 | */ |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 3259 | txdctl |= (1u << 8) | /* HTHRESH = 1 */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3260 | 32; /* PTHRESH = 32 */ |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3261 | |
| 3262 | /* reinitialize flowdirector state */ |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 3263 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 3264 | ring->atr_sample_rate = adapter->atr_sample_rate; |
| 3265 | ring->atr_count = 0; |
| 3266 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state); |
| 3267 | } else { |
| 3268 | ring->atr_sample_rate = 0; |
| 3269 | } |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3270 | |
Alexander Duyck | fd786b7 | 2013-01-12 06:33:31 +0000 | [diff] [blame] | 3271 | /* initialize XPS */ |
| 3272 | if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) { |
| 3273 | struct ixgbe_q_vector *q_vector = ring->q_vector; |
| 3274 | |
| 3275 | if (q_vector) |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 3276 | netif_set_xps_queue(ring->netdev, |
Alexander Duyck | fd786b7 | 2013-01-12 06:33:31 +0000 | [diff] [blame] | 3277 | &q_vector->affinity_mask, |
| 3278 | ring->queue_index); |
| 3279 | } |
| 3280 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 3281 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state); |
| 3282 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 3283 | /* reinitialize tx_buffer_info */ |
| 3284 | memset(ring->tx_buffer_info, 0, |
| 3285 | sizeof(struct ixgbe_tx_buffer) * ring->count); |
| 3286 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3287 | /* enable queue */ |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3288 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl); |
| 3289 | |
| 3290 | /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 3291 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 3292 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 3293 | return; |
| 3294 | |
| 3295 | /* poll to verify queue is enabled */ |
| 3296 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 3297 | usleep_range(1000, 2000); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3298 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx)); |
| 3299 | } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE)); |
| 3300 | if (!wait_loop) |
Emil Tantilov | a55defd | 2016-07-29 10:30:06 -0700 | [diff] [blame] | 3301 | hw_dbg(hw, "Could not enable Tx Queue %d\n", reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3302 | } |
| 3303 | |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 3304 | static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter) |
| 3305 | { |
| 3306 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3307 | u32 rttdcs, mtqc; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3308 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 3309 | |
| 3310 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3311 | return; |
| 3312 | |
| 3313 | /* disable the arbiter while setting MTQC */ |
| 3314 | rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS); |
| 3315 | rttdcs |= IXGBE_RTTDCS_ARBDIS; |
| 3316 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 3317 | |
| 3318 | /* set transmit pool layout */ |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3319 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 3320 | mtqc = IXGBE_MTQC_VT_ENA; |
| 3321 | if (tcs > 4) |
| 3322 | mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ; |
| 3323 | else if (tcs > 1) |
| 3324 | mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ; |
Alexander Duyck | e24fcf2 | 2016-09-07 20:28:24 -0700 | [diff] [blame] | 3325 | else if (adapter->ring_feature[RING_F_VMDQ].mask == |
| 3326 | IXGBE_82599_VMDQ_4Q_MASK) |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3327 | mtqc |= IXGBE_MTQC_32VF; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3328 | else |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3329 | mtqc |= IXGBE_MTQC_64VF; |
| 3330 | } else { |
| 3331 | if (tcs > 4) |
| 3332 | mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ; |
| 3333 | else if (tcs > 1) |
| 3334 | mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ; |
| 3335 | else |
| 3336 | mtqc = IXGBE_MTQC_64Q_1PB; |
| 3337 | } |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3338 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3339 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3340 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3341 | /* Enable Security TX Buffer IFG for multiple pb */ |
| 3342 | if (tcs) { |
| 3343 | u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG); |
| 3344 | sectx |= IXGBE_SECTX_DCB; |
| 3345 | IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx); |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 3346 | } |
| 3347 | |
| 3348 | /* re-enable the arbiter */ |
| 3349 | rttdcs &= ~IXGBE_RTTDCS_ARBDIS; |
| 3350 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 3351 | } |
| 3352 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3353 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3354 | * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3355 | * @adapter: board private structure |
| 3356 | * |
| 3357 | * Configure the Tx unit of the MAC after a reset. |
| 3358 | **/ |
| 3359 | static void ixgbe_configure_tx(struct ixgbe_adapter *adapter) |
| 3360 | { |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3361 | struct ixgbe_hw *hw = &adapter->hw; |
| 3362 | u32 dmatxctl; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3363 | u32 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3364 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3365 | ixgbe_setup_mtqc(adapter); |
| 3366 | |
| 3367 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 3368 | /* DMATXCTL.EN must be before Tx queues are enabled */ |
| 3369 | dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); |
| 3370 | dmatxctl |= IXGBE_DMATXCTL_TE; |
| 3371 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl); |
| 3372 | } |
| 3373 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3374 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3375 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 3376 | ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3377 | } |
| 3378 | |
Alexander Duyck | 3ebe8fd | 2012-04-25 04:36:38 +0000 | [diff] [blame] | 3379 | static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter, |
| 3380 | struct ixgbe_ring *ring) |
| 3381 | { |
| 3382 | struct ixgbe_hw *hw = &adapter->hw; |
| 3383 | u8 reg_idx = ring->reg_idx; |
| 3384 | u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx)); |
| 3385 | |
| 3386 | srrctl |= IXGBE_SRRCTL_DROP_EN; |
| 3387 | |
| 3388 | IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl); |
| 3389 | } |
| 3390 | |
| 3391 | static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter, |
| 3392 | struct ixgbe_ring *ring) |
| 3393 | { |
| 3394 | struct ixgbe_hw *hw = &adapter->hw; |
| 3395 | u8 reg_idx = ring->reg_idx; |
| 3396 | u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx)); |
| 3397 | |
| 3398 | srrctl &= ~IXGBE_SRRCTL_DROP_EN; |
| 3399 | |
| 3400 | IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl); |
| 3401 | } |
| 3402 | |
| 3403 | #ifdef CONFIG_IXGBE_DCB |
| 3404 | void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter) |
| 3405 | #else |
| 3406 | static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter) |
| 3407 | #endif |
| 3408 | { |
| 3409 | int i; |
| 3410 | bool pfc_en = adapter->dcb_cfg.pfc_mode_enable; |
| 3411 | |
| 3412 | if (adapter->ixgbe_ieee_pfc) |
| 3413 | pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en); |
| 3414 | |
| 3415 | /* |
| 3416 | * We should set the drop enable bit if: |
| 3417 | * SR-IOV is enabled |
| 3418 | * or |
| 3419 | * Number of Rx queues > 1 and flow control is disabled |
| 3420 | * |
| 3421 | * This allows us to avoid head of line blocking for security |
| 3422 | * and performance reasons. |
| 3423 | */ |
| 3424 | if (adapter->num_vfs || (adapter->num_rx_queues > 1 && |
| 3425 | !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) { |
| 3426 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3427 | ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]); |
| 3428 | } else { |
| 3429 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3430 | ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]); |
| 3431 | } |
| 3432 | } |
| 3433 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3434 | #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3435 | |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 3436 | static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3437 | struct ixgbe_ring *rx_ring) |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3438 | { |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3439 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3440 | u32 srrctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3441 | u8 reg_idx = rx_ring->reg_idx; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3442 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3443 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 3444 | u16 mask = adapter->ring_feature[RING_F_RSS].mask; |
| 3445 | |
| 3446 | /* |
| 3447 | * if VMDq is not active we must program one srrctl register |
| 3448 | * per RSS queue since we have enabled RDRXCTL.MVMEN |
| 3449 | */ |
| 3450 | reg_idx &= mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3451 | } |
| 3452 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3453 | /* configure header buffer length, needed for RSC */ |
| 3454 | srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3455 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3456 | /* configure the packet buffer length */ |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 3457 | if (test_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state)) |
| 3458 | srrctl |= IXGBE_RXBUFFER_3K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 3459 | else |
| 3460 | srrctl |= IXGBE_RXBUFFER_2K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3461 | |
| 3462 | /* configure descriptor type */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 3463 | srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3464 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3465 | IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3466 | } |
| 3467 | |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3468 | /** |
Jean Sacren | a897a2a | 2015-09-19 05:08:44 -0600 | [diff] [blame] | 3469 | * ixgbe_rss_indir_tbl_entries - Return RSS indirection table entries |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3470 | * @adapter: device handle |
| 3471 | * |
| 3472 | * - 82598/82599/X540: 128 |
| 3473 | * - X550(non-SRIOV mode): 512 |
| 3474 | * - X550(SRIOV mode): 64 |
| 3475 | */ |
Vlad Zolotarov | 7f276ef | 2015-03-30 21:18:58 +0300 | [diff] [blame] | 3476 | u32 ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3477 | { |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3478 | if (adapter->hw.mac.type < ixgbe_mac_X550) |
| 3479 | return 128; |
| 3480 | else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 3481 | return 64; |
| 3482 | else |
| 3483 | return 512; |
| 3484 | } |
| 3485 | |
| 3486 | /** |
Paolo Abeni | d3aa9c9 | 2016-12-15 15:20:34 +0100 | [diff] [blame] | 3487 | * ixgbe_store_key - Write the RSS key to HW |
| 3488 | * @adapter: device handle |
| 3489 | * |
| 3490 | * Write the RSS key stored in adapter.rss_key to HW. |
| 3491 | */ |
| 3492 | void ixgbe_store_key(struct ixgbe_adapter *adapter) |
| 3493 | { |
| 3494 | struct ixgbe_hw *hw = &adapter->hw; |
| 3495 | int i; |
| 3496 | |
| 3497 | for (i = 0; i < 10; i++) |
| 3498 | IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), adapter->rss_key[i]); |
| 3499 | } |
| 3500 | |
| 3501 | /** |
Jean Sacren | a897a2a | 2015-09-19 05:08:44 -0600 | [diff] [blame] | 3502 | * ixgbe_store_reta - Write the RETA table to HW |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3503 | * @adapter: device handle |
| 3504 | * |
| 3505 | * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW. |
| 3506 | */ |
Tom Barbette | 1c7cf07 | 2015-06-26 15:40:18 +0200 | [diff] [blame] | 3507 | void ixgbe_store_reta(struct ixgbe_adapter *adapter) |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3508 | { |
| 3509 | u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter); |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3510 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3511 | u32 reta = 0; |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3512 | u32 indices_multi; |
| 3513 | u8 *indir_tbl = adapter->rss_indir_tbl; |
John Fastabend | 86b4db3 | 2011-04-26 07:26:19 +0000 | [diff] [blame] | 3514 | |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3515 | /* Fill out the redirection table as follows: |
| 3516 | * - 82598: 8 bit wide entries containing pair of 4 bit RSS |
| 3517 | * indices. |
| 3518 | * - 82599/X540: 8 bit wide entries containing 4 bit RSS index |
| 3519 | * - X550: 8 bit wide entries containing 6 bit RSS index |
| 3520 | */ |
| 3521 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 3522 | indices_multi = 0x11; |
| 3523 | else |
| 3524 | indices_multi = 0x1; |
| 3525 | |
| 3526 | /* Write redirection table to HW */ |
| 3527 | for (i = 0; i < reta_entries; i++) { |
| 3528 | reta |= indices_multi * indir_tbl[i] << (i & 0x3) * 8; |
| 3529 | if ((i & 3) == 3) { |
| 3530 | if (i < 128) |
| 3531 | IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); |
| 3532 | else |
| 3533 | IXGBE_WRITE_REG(hw, IXGBE_ERETA((i >> 2) - 32), |
| 3534 | reta); |
| 3535 | reta = 0; |
| 3536 | } |
| 3537 | } |
| 3538 | } |
| 3539 | |
| 3540 | /** |
Jean Sacren | a897a2a | 2015-09-19 05:08:44 -0600 | [diff] [blame] | 3541 | * ixgbe_store_vfreta - Write the RETA table to HW (x550 devices in SRIOV mode) |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3542 | * @adapter: device handle |
| 3543 | * |
| 3544 | * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW. |
| 3545 | */ |
| 3546 | static void ixgbe_store_vfreta(struct ixgbe_adapter *adapter) |
| 3547 | { |
| 3548 | u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter); |
| 3549 | struct ixgbe_hw *hw = &adapter->hw; |
| 3550 | u32 vfreta = 0; |
| 3551 | unsigned int pf_pool = adapter->num_vfs; |
| 3552 | |
| 3553 | /* Write redirection table to HW */ |
| 3554 | for (i = 0; i < reta_entries; i++) { |
| 3555 | vfreta |= (u32)adapter->rss_indir_tbl[i] << (i & 0x3) * 8; |
| 3556 | if ((i & 3) == 3) { |
| 3557 | IXGBE_WRITE_REG(hw, IXGBE_PFVFRETA(i >> 2, pf_pool), |
| 3558 | vfreta); |
| 3559 | vfreta = 0; |
| 3560 | } |
| 3561 | } |
| 3562 | } |
| 3563 | |
| 3564 | static void ixgbe_setup_reta(struct ixgbe_adapter *adapter) |
| 3565 | { |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3566 | u32 i, j; |
| 3567 | u32 reta_entries = ixgbe_rss_indir_tbl_entries(adapter); |
| 3568 | u16 rss_i = adapter->ring_feature[RING_F_RSS].indices; |
| 3569 | |
Alexander Duyck | e24fcf2 | 2016-09-07 20:28:24 -0700 | [diff] [blame] | 3570 | /* Program table for at least 4 queues w/ SR-IOV so that VFs can |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3571 | * make full use of any rings they may have. We will use the |
| 3572 | * PSRTYPE register to control how many rings we use within the PF. |
| 3573 | */ |
Alexander Duyck | e24fcf2 | 2016-09-07 20:28:24 -0700 | [diff] [blame] | 3574 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 4)) |
| 3575 | rss_i = 4; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3576 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3577 | /* Fill out hash function seeds */ |
Paolo Abeni | d3aa9c9 | 2016-12-15 15:20:34 +0100 | [diff] [blame] | 3578 | ixgbe_store_key(adapter); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3579 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3580 | /* Fill out redirection table */ |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3581 | memset(adapter->rss_indir_tbl, 0, sizeof(adapter->rss_indir_tbl)); |
| 3582 | |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3583 | for (i = 0, j = 0; i < reta_entries; i++, j++) { |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3584 | if (j == rss_i) |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3585 | j = 0; |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3586 | |
| 3587 | adapter->rss_indir_tbl[i] = j; |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3588 | } |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3589 | |
| 3590 | ixgbe_store_reta(adapter); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3591 | } |
| 3592 | |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3593 | static void ixgbe_setup_vfreta(struct ixgbe_adapter *adapter) |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3594 | { |
| 3595 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3596 | u16 rss_i = adapter->ring_feature[RING_F_RSS].indices; |
| 3597 | unsigned int pf_pool = adapter->num_vfs; |
| 3598 | int i, j; |
| 3599 | |
| 3600 | /* Fill out hash function seeds */ |
| 3601 | for (i = 0; i < 10; i++) |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3602 | IXGBE_WRITE_REG(hw, IXGBE_PFVFRSSRK(i, pf_pool), |
| 3603 | adapter->rss_key[i]); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3604 | |
| 3605 | /* Fill out the redirection table */ |
| 3606 | for (i = 0, j = 0; i < 64; i++, j++) { |
| 3607 | if (j == rss_i) |
| 3608 | j = 0; |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3609 | |
| 3610 | adapter->rss_indir_tbl[i] = j; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3611 | } |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3612 | |
| 3613 | ixgbe_store_vfreta(adapter); |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3614 | } |
| 3615 | |
| 3616 | static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter) |
| 3617 | { |
| 3618 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3619 | u32 mrqc = 0, rss_field = 0, vfmrqc = 0; |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3620 | u32 rxcsum; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3621 | |
| 3622 | /* Disable indicating checksum in descriptor, enables RSS hash */ |
| 3623 | rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); |
| 3624 | rxcsum |= IXGBE_RXCSUM_PCSD; |
| 3625 | IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); |
| 3626 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3627 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 3628 | if (adapter->ring_feature[RING_F_RSS].mask) |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3629 | mrqc = IXGBE_MRQC_RSSEN; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3630 | } else { |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3631 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3632 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3633 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 3634 | if (tcs > 4) |
| 3635 | mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */ |
| 3636 | else if (tcs > 1) |
| 3637 | mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */ |
Alexander Duyck | e24fcf2 | 2016-09-07 20:28:24 -0700 | [diff] [blame] | 3638 | else if (adapter->ring_feature[RING_F_VMDQ].mask == |
| 3639 | IXGBE_82599_VMDQ_4Q_MASK) |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3640 | mrqc = IXGBE_MRQC_VMDQRSS32EN; |
| 3641 | else |
| 3642 | mrqc = IXGBE_MRQC_VMDQRSS64EN; |
| 3643 | } else { |
| 3644 | if (tcs > 4) |
| 3645 | mrqc = IXGBE_MRQC_RTRSS8TCEN; |
| 3646 | else if (tcs > 1) |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3647 | mrqc = IXGBE_MRQC_RTRSS4TCEN; |
| 3648 | else |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3649 | mrqc = IXGBE_MRQC_RSSEN; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3650 | } |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3651 | } |
| 3652 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3653 | /* Perform hash on these packet types */ |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3654 | rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4 | |
| 3655 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP | |
| 3656 | IXGBE_MRQC_RSS_FIELD_IPV6 | |
| 3657 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3658 | |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 3659 | if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP) |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3660 | rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP; |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 3661 | if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP) |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3662 | rss_field |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP; |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 3663 | |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3664 | netdev_rss_key_fill(adapter->rss_key, sizeof(adapter->rss_key)); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3665 | if ((hw->mac.type >= ixgbe_mac_X550) && |
| 3666 | (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) { |
| 3667 | unsigned int pf_pool = adapter->num_vfs; |
| 3668 | |
| 3669 | /* Enable VF RSS mode */ |
| 3670 | mrqc |= IXGBE_MRQC_MULTIPLE_RSS; |
| 3671 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
| 3672 | |
| 3673 | /* Setup RSS through the VF registers */ |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3674 | ixgbe_setup_vfreta(adapter); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3675 | vfmrqc = IXGBE_MRQC_RSSEN; |
| 3676 | vfmrqc |= rss_field; |
| 3677 | IXGBE_WRITE_REG(hw, IXGBE_PFVFMRQC(pf_pool), vfmrqc); |
| 3678 | } else { |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3679 | ixgbe_setup_reta(adapter); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3680 | mrqc |= rss_field; |
| 3681 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
| 3682 | } |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3683 | } |
| 3684 | |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3685 | /** |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3686 | * ixgbe_configure_rscctl - enable RSC for the indicated ring |
| 3687 | * @adapter: address of board private structure |
| 3688 | * @index: index of ring to set |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3689 | **/ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 3690 | static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3691 | struct ixgbe_ring *ring) |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3692 | { |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3693 | struct ixgbe_hw *hw = &adapter->hw; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3694 | u32 rscctrl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3695 | u8 reg_idx = ring->reg_idx; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3696 | |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3697 | if (!ring_is_rsc_enabled(ring)) |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3698 | return; |
| 3699 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3700 | rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx)); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3701 | rscctrl |= IXGBE_RSCCTL_RSCEN; |
| 3702 | /* |
| 3703 | * we must limit the number of descriptors so that the |
| 3704 | * total size of max desc * buf_len is not greater |
Alexander Duyck | 642c680 | 2011-11-10 09:09:17 +0000 | [diff] [blame] | 3705 | * than 65536 |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3706 | */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 3707 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3708 | IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3709 | } |
| 3710 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3711 | #define IXGBE_MAX_RX_DESC_POLL 10 |
| 3712 | static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter, |
| 3713 | struct ixgbe_ring *ring) |
| 3714 | { |
| 3715 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3716 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 3717 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3718 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3719 | |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 3720 | if (ixgbe_removed(hw->hw_addr)) |
| 3721 | return; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3722 | /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 3723 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 3724 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 3725 | return; |
| 3726 | |
| 3727 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 3728 | usleep_range(1000, 2000); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3729 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 3730 | } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 3731 | |
| 3732 | if (!wait_loop) { |
| 3733 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within " |
| 3734 | "the polling period\n", reg_idx); |
| 3735 | } |
| 3736 | } |
| 3737 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 3738 | void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter, |
| 3739 | struct ixgbe_ring *ring) |
| 3740 | { |
| 3741 | struct ixgbe_hw *hw = &adapter->hw; |
| 3742 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 3743 | u32 rxdctl; |
| 3744 | u8 reg_idx = ring->reg_idx; |
| 3745 | |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 3746 | if (ixgbe_removed(hw->hw_addr)) |
| 3747 | return; |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 3748 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 3749 | rxdctl &= ~IXGBE_RXDCTL_ENABLE; |
| 3750 | |
| 3751 | /* write value back with RXDCTL.ENABLE bit cleared */ |
| 3752 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 3753 | |
| 3754 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 3755 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 3756 | return; |
| 3757 | |
| 3758 | /* the hardware may take up to 100us to really disable the rx queue */ |
| 3759 | do { |
| 3760 | udelay(10); |
| 3761 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 3762 | } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 3763 | |
| 3764 | if (!wait_loop) { |
| 3765 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within " |
| 3766 | "the polling period\n", reg_idx); |
| 3767 | } |
| 3768 | } |
| 3769 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 3770 | void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter, |
| 3771 | struct ixgbe_ring *ring) |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3772 | { |
| 3773 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | c3630cc | 2017-01-17 08:36:28 -0800 | [diff] [blame] | 3774 | union ixgbe_adv_rx_desc *rx_desc; |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3775 | u64 rdba = ring->dma; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3776 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3777 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3778 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3779 | /* disable queue to avoid issues while updating state */ |
| 3780 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 3781 | ixgbe_disable_rx_queue(adapter, ring); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3782 | |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3783 | IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32))); |
| 3784 | IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32)); |
| 3785 | IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx), |
| 3786 | ring->count * sizeof(union ixgbe_adv_rx_desc)); |
Neerav Parikh | 8b75451 | 2015-12-08 22:13:58 -0800 | [diff] [blame] | 3787 | /* Force flushing of IXGBE_RDLEN to prevent MDD */ |
| 3788 | IXGBE_WRITE_FLUSH(hw); |
| 3789 | |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3790 | IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0); |
| 3791 | IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 3792 | ring->tail = adapter->io_addr + IXGBE_RDT(reg_idx); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3793 | |
| 3794 | ixgbe_configure_srrctl(adapter, ring); |
| 3795 | ixgbe_configure_rscctl(adapter, ring); |
| 3796 | |
| 3797 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 3798 | /* |
| 3799 | * enable cache line friendly hardware writes: |
| 3800 | * PTHRESH=32 descriptors (half the internal cache), |
| 3801 | * this also removes ugly rx_no_buffer_count increment |
| 3802 | * HTHRESH=4 descriptors (to minimize latency on fetch) |
| 3803 | * WTHRESH=8 burst writeback up to two cache lines |
| 3804 | */ |
| 3805 | rxdctl &= ~0x3FFFFF; |
| 3806 | rxdctl |= 0x080420; |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 3807 | #if (PAGE_SIZE < 8192) |
| 3808 | } else { |
| 3809 | rxdctl &= ~(IXGBE_RXDCTL_RLPMLMASK | |
| 3810 | IXGBE_RXDCTL_RLPML_EN); |
| 3811 | |
| 3812 | /* Limit the maximum frame size so we don't overrun the skb */ |
| 3813 | if (ring_uses_build_skb(ring) && |
| 3814 | !test_bit(__IXGBE_RX_3K_BUFFER, &ring->state)) |
| 3815 | rxdctl |= IXGBE_MAX_FRAME_BUILD_SKB | |
| 3816 | IXGBE_RXDCTL_RLPML_EN; |
| 3817 | #endif |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3818 | } |
| 3819 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 3820 | /* initialize rx_buffer_info */ |
| 3821 | memset(ring->rx_buffer_info, 0, |
| 3822 | sizeof(struct ixgbe_rx_buffer) * ring->count); |
| 3823 | |
Alexander Duyck | c3630cc | 2017-01-17 08:36:28 -0800 | [diff] [blame] | 3824 | /* initialize Rx descriptor 0 */ |
| 3825 | rx_desc = IXGBE_RX_DESC(ring, 0); |
| 3826 | rx_desc->wb.upper.length = 0; |
| 3827 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3828 | /* enable receive descriptor ring */ |
| 3829 | rxdctl |= IXGBE_RXDCTL_ENABLE; |
| 3830 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 3831 | |
| 3832 | ixgbe_rx_desc_queue_enable(adapter, ring); |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 3833 | ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring)); |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3834 | } |
| 3835 | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3836 | static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter) |
| 3837 | { |
| 3838 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 3839 | int rss_i = adapter->ring_feature[RING_F_RSS].indices; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 3840 | u16 pool; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3841 | |
| 3842 | /* PSRTYPE must be initialized in non 82598 adapters */ |
| 3843 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3844 | IXGBE_PSRTYPE_UDPHDR | |
| 3845 | IXGBE_PSRTYPE_IPV4HDR | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3846 | IXGBE_PSRTYPE_L2HDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3847 | IXGBE_PSRTYPE_IPV6HDR; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3848 | |
| 3849 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3850 | return; |
| 3851 | |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 3852 | if (rss_i > 3) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 3853 | psrtype |= 2u << 29; |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 3854 | else if (rss_i > 1) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 3855 | psrtype |= 1u << 29; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3856 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 3857 | for_each_set_bit(pool, &adapter->fwd_bitmask, 32) |
| 3858 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype); |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3859 | } |
| 3860 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3861 | static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter) |
| 3862 | { |
| 3863 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3864 | u32 reg_offset, vf_shift; |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3865 | u32 gcr_ext, vmdctl; |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 3866 | int i; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3867 | |
| 3868 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 3869 | return; |
| 3870 | |
| 3871 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL); |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3872 | vmdctl |= IXGBE_VMD_CTL_VMDQ_EN; |
| 3873 | vmdctl &= ~IXGBE_VT_CTL_POOL_MASK; |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3874 | vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT; |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3875 | vmdctl |= IXGBE_VT_CTL_REPLEN; |
| 3876 | IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3877 | |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3878 | vf_shift = VMDQ_P(0) % 32; |
| 3879 | reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3880 | |
| 3881 | /* Enable only the PF's pool for Tx/Rx */ |
Emil Tantilov | 11f2b49 | 2016-05-04 15:01:27 -0700 | [diff] [blame] | 3882 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), GENMASK(31, vf_shift)); |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3883 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1); |
Emil Tantilov | 11f2b49 | 2016-05-04 15:01:27 -0700 | [diff] [blame] | 3884 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), GENMASK(31, vf_shift)); |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3885 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1); |
Don Skidmore | aa2bacb | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 3886 | if (adapter->bridge_mode == BRIDGE_MODE_VEB) |
Greg Rose | 9b73598 | 2012-11-08 02:41:35 +0000 | [diff] [blame] | 3887 | IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3888 | |
| 3889 | /* Map PF MAC address in RAR Entry 0 to first pool following VFs */ |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3890 | hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0)); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3891 | |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 3892 | /* clear VLAN promisc flag so VFTA will be updated if necessary */ |
| 3893 | adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC; |
| 3894 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3895 | /* |
| 3896 | * Set up VF register offsets for selected VT Mode, |
| 3897 | * i.e. 32 or 64 VFs for SR-IOV |
| 3898 | */ |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 3899 | switch (adapter->ring_feature[RING_F_VMDQ].mask) { |
| 3900 | case IXGBE_82599_VMDQ_8Q_MASK: |
| 3901 | gcr_ext = IXGBE_GCR_EXT_VT_MODE_16; |
| 3902 | break; |
| 3903 | case IXGBE_82599_VMDQ_4Q_MASK: |
| 3904 | gcr_ext = IXGBE_GCR_EXT_VT_MODE_32; |
| 3905 | break; |
| 3906 | default: |
| 3907 | gcr_ext = IXGBE_GCR_EXT_VT_MODE_64; |
| 3908 | break; |
| 3909 | } |
| 3910 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3911 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext); |
| 3912 | |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 3913 | for (i = 0; i < adapter->num_vfs; i++) { |
Emil Tantilov | 77f192a | 2016-03-18 16:11:14 -0700 | [diff] [blame] | 3914 | /* configure spoof checking */ |
| 3915 | ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, |
| 3916 | adapter->vfinfo[i].spoofchk_enabled); |
Vlad Zolotarov | e65ce0d | 2015-03-30 21:35:24 +0300 | [diff] [blame] | 3917 | |
| 3918 | /* Enable/Disable RSS query feature */ |
| 3919 | ixgbe_ndo_set_vf_rss_query_en(adapter->netdev, i, |
| 3920 | adapter->vfinfo[i].rss_query_enabled); |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 3921 | } |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3922 | } |
| 3923 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3924 | static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3925 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3926 | struct ixgbe_hw *hw = &adapter->hw; |
| 3927 | struct net_device *netdev = adapter->netdev; |
| 3928 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3929 | struct ixgbe_ring *rx_ring; |
| 3930 | int i; |
| 3931 | u32 mhadd, hlreg0; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3932 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3933 | #ifdef IXGBE_FCOE |
| 3934 | /* adjust max frame to be able to do baby jumbo for FCoE */ |
| 3935 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 3936 | (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE)) |
| 3937 | max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 3938 | |
| 3939 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 3940 | |
| 3941 | /* adjust max frame to be at least the size of a standard frame */ |
| 3942 | if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN)) |
| 3943 | max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN); |
| 3944 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3945 | mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD); |
| 3946 | if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) { |
| 3947 | mhadd &= ~IXGBE_MHADD_MFS_MASK; |
| 3948 | mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT; |
| 3949 | |
| 3950 | IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3951 | } |
| 3952 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3953 | hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3954 | /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */ |
| 3955 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3956 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0); |
| 3957 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3958 | /* |
| 3959 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3960 | * the Base and Length of the Rx Descriptor Ring |
| 3961 | */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3962 | for (i = 0; i < adapter->num_rx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3963 | rx_ring = adapter->rx_ring[i]; |
Alexander Duyck | 4f4542b | 2017-01-17 08:36:14 -0800 | [diff] [blame] | 3964 | |
| 3965 | clear_ring_rsc_enabled(rx_ring); |
| 3966 | clear_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state); |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 3967 | clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state); |
Alexander Duyck | 4f4542b | 2017-01-17 08:36:14 -0800 | [diff] [blame] | 3968 | |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3969 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
| 3970 | set_ring_rsc_enabled(rx_ring); |
Alexander Duyck | 4f4542b | 2017-01-17 08:36:14 -0800 | [diff] [blame] | 3971 | |
| 3972 | if (test_bit(__IXGBE_RX_FCOE, &rx_ring->state)) |
| 3973 | set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state); |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 3974 | |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 3975 | clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state); |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 3976 | if (adapter->flags2 & IXGBE_FLAG2_RX_LEGACY) |
| 3977 | continue; |
| 3978 | |
| 3979 | set_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state); |
| 3980 | |
| 3981 | #if (PAGE_SIZE < 8192) |
| 3982 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
| 3983 | set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state); |
| 3984 | |
Alexander Duyck | c74042f | 2017-02-03 09:19:40 -0800 | [diff] [blame] | 3985 | if ((max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)) || |
| 3986 | (max_frame > IXGBE_MAX_FRAME_BUILD_SKB)) |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 3987 | set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state); |
| 3988 | #endif |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3989 | } |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3990 | } |
| 3991 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3992 | static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter) |
| 3993 | { |
| 3994 | struct ixgbe_hw *hw = &adapter->hw; |
| 3995 | u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 3996 | |
| 3997 | switch (hw->mac.type) { |
| 3998 | case ixgbe_mac_82598EB: |
| 3999 | /* |
| 4000 | * For VMDq support of different descriptor types or |
| 4001 | * buffer sizes through the use of multiple SRRCTL |
| 4002 | * registers, RDRXCTL.MVMEN must be set to 1 |
| 4003 | * |
| 4004 | * also, the manual doesn't mention it clearly but DCA hints |
| 4005 | * will only use queue 0's tags unless this bit is set. Side |
| 4006 | * effects of setting this bit are only that SRRCTL must be |
| 4007 | * fully programmed [0..15] |
| 4008 | */ |
| 4009 | rdrxctl |= IXGBE_RDRXCTL_MVMEN; |
| 4010 | break; |
Mark Rustad | 052a1a7 | 2015-08-08 16:19:04 -0700 | [diff] [blame] | 4011 | case ixgbe_mac_X550: |
| 4012 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 4013 | case ixgbe_mac_x550em_a: |
Mark Rustad | f961dda | 2015-08-08 16:19:09 -0700 | [diff] [blame] | 4014 | if (adapter->num_vfs) |
| 4015 | rdrxctl |= IXGBE_RDRXCTL_PSP; |
| 4016 | /* fall through for older HW */ |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 4017 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4018 | case ixgbe_mac_X540: |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 4019 | /* Disable RSC for ACK packets */ |
| 4020 | IXGBE_WRITE_REG(hw, IXGBE_RSCDBU, |
| 4021 | (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU))); |
| 4022 | rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE; |
| 4023 | /* hardware requires some bits to be set by default */ |
| 4024 | rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX); |
| 4025 | rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP; |
| 4026 | break; |
| 4027 | default: |
| 4028 | /* We should do nothing since we don't know this hardware */ |
| 4029 | return; |
| 4030 | } |
| 4031 | |
| 4032 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
| 4033 | } |
| 4034 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4035 | /** |
| 4036 | * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset |
| 4037 | * @adapter: board private structure |
| 4038 | * |
| 4039 | * Configure the Rx unit of the MAC after a reset. |
| 4040 | **/ |
| 4041 | static void ixgbe_configure_rx(struct ixgbe_adapter *adapter) |
| 4042 | { |
| 4043 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4044 | int i; |
Jacob Keller | 6dcc28b | 2013-07-17 02:53:23 +0000 | [diff] [blame] | 4045 | u32 rxctrl, rfctl; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4046 | |
| 4047 | /* disable receives while setting up the descriptors */ |
Don Skidmore | 1f9ac57 | 2015-03-13 13:54:30 -0700 | [diff] [blame] | 4048 | hw->mac.ops.disable_rx(hw); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4049 | |
| 4050 | ixgbe_setup_psrtype(adapter); |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 4051 | ixgbe_setup_rdrxctl(adapter); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4052 | |
Jacob Keller | 6dcc28b | 2013-07-17 02:53:23 +0000 | [diff] [blame] | 4053 | /* RSC Setup */ |
| 4054 | rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL); |
| 4055 | rfctl &= ~IXGBE_RFCTL_RSC_DIS; |
| 4056 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) |
| 4057 | rfctl |= IXGBE_RFCTL_RSC_DIS; |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 4058 | |
| 4059 | /* disable NFS filtering */ |
| 4060 | rfctl |= (IXGBE_RFCTL_NFSW_DIS | IXGBE_RFCTL_NFSR_DIS); |
Jacob Keller | 6dcc28b | 2013-07-17 02:53:23 +0000 | [diff] [blame] | 4061 | IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl); |
| 4062 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4063 | /* Program registers for the distribution of queues */ |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 4064 | ixgbe_setup_mrqc(adapter); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 4065 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4066 | /* set_rx_buffer_len must be called before ring initialization */ |
| 4067 | ixgbe_set_rx_buffer_len(adapter); |
| 4068 | |
| 4069 | /* |
| 4070 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 4071 | * the Base and Length of the Rx Descriptor Ring |
| 4072 | */ |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4073 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 4074 | ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 4075 | |
Don Skidmore | 1f9ac57 | 2015-03-13 13:54:30 -0700 | [diff] [blame] | 4076 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4077 | /* disable drop enable for 82598 parts */ |
| 4078 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4079 | rxctrl |= IXGBE_RXCTRL_DMBYPS; |
| 4080 | |
| 4081 | /* enable all receives */ |
| 4082 | rxctrl |= IXGBE_RXCTRL_RXEN; |
| 4083 | hw->mac.ops.enable_rx_dma(hw, rxctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4084 | } |
| 4085 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 4086 | static int ixgbe_vlan_rx_add_vid(struct net_device *netdev, |
| 4087 | __be16 proto, u16 vid) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4088 | { |
| 4089 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4090 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4091 | |
| 4092 | /* add VID to filter table */ |
Alexander Duyck | 18be4fc | 2016-01-06 22:48:44 -0800 | [diff] [blame] | 4093 | if (!vid || !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)) |
| 4094 | hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true, !!vid); |
| 4095 | |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4096 | set_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 4097 | |
| 4098 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4099 | } |
| 4100 | |
Alexander Duyck | e1d0a2a | 2015-11-02 17:10:19 -0800 | [diff] [blame] | 4101 | static int ixgbe_find_vlvf_entry(struct ixgbe_hw *hw, u32 vlan) |
| 4102 | { |
| 4103 | u32 vlvf; |
| 4104 | int idx; |
| 4105 | |
| 4106 | /* short cut the special case */ |
| 4107 | if (vlan == 0) |
| 4108 | return 0; |
| 4109 | |
| 4110 | /* Search for the vlan id in the VLVF entries */ |
| 4111 | for (idx = IXGBE_VLVF_ENTRIES; --idx;) { |
| 4112 | vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(idx)); |
| 4113 | if ((vlvf & VLAN_VID_MASK) == vlan) |
| 4114 | break; |
| 4115 | } |
| 4116 | |
| 4117 | return idx; |
| 4118 | } |
| 4119 | |
| 4120 | void ixgbe_update_pf_promisc_vlvf(struct ixgbe_adapter *adapter, u32 vid) |
| 4121 | { |
| 4122 | struct ixgbe_hw *hw = &adapter->hw; |
| 4123 | u32 bits, word; |
| 4124 | int idx; |
| 4125 | |
| 4126 | idx = ixgbe_find_vlvf_entry(hw, vid); |
| 4127 | if (!idx) |
| 4128 | return; |
| 4129 | |
| 4130 | /* See if any other pools are set for this VLAN filter |
| 4131 | * entry other than the PF. |
| 4132 | */ |
| 4133 | word = idx * 2 + (VMDQ_P(0) / 32); |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 4134 | bits = ~BIT(VMDQ_P(0) % 32); |
Alexander Duyck | e1d0a2a | 2015-11-02 17:10:19 -0800 | [diff] [blame] | 4135 | bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word)); |
| 4136 | |
| 4137 | /* Disable the filter so this falls into the default pool. */ |
| 4138 | if (!bits && !IXGBE_READ_REG(hw, IXGBE_VLVFB(word ^ 1))) { |
| 4139 | if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)) |
| 4140 | IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), 0); |
| 4141 | IXGBE_WRITE_REG(hw, IXGBE_VLVF(idx), 0); |
| 4142 | } |
| 4143 | } |
| 4144 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 4145 | static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev, |
| 4146 | __be16 proto, u16 vid) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4147 | { |
| 4148 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4149 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4150 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4151 | /* remove VID from filter table */ |
Alexander Duyck | 18be4fc | 2016-01-06 22:48:44 -0800 | [diff] [blame] | 4152 | if (vid && !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)) |
Alexander Duyck | e1d0a2a | 2015-11-02 17:10:19 -0800 | [diff] [blame] | 4153 | hw->mac.ops.set_vfta(hw, vid, VMDQ_P(0), false, true); |
| 4154 | |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4155 | clear_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 4156 | |
| 4157 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4158 | } |
| 4159 | |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4160 | /** |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4161 | * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping |
| 4162 | * @adapter: driver data |
| 4163 | */ |
| 4164 | static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter) |
| 4165 | { |
| 4166 | struct ixgbe_hw *hw = &adapter->hw; |
| 4167 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4168 | int i, j; |
| 4169 | |
| 4170 | switch (hw->mac.type) { |
| 4171 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4172 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 4173 | vlnctrl &= ~IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4174 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4175 | break; |
| 4176 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4177 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 4178 | case ixgbe_mac_X550: |
| 4179 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 4180 | case ixgbe_mac_x550em_a: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4181 | for (i = 0; i < adapter->num_rx_queues; i++) { |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4182 | struct ixgbe_ring *ring = adapter->rx_ring[i]; |
| 4183 | |
| 4184 | if (ring->l2_accel_priv) |
| 4185 | continue; |
| 4186 | j = ring->reg_idx; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4187 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 4188 | vlnctrl &= ~IXGBE_RXDCTL_VME; |
| 4189 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 4190 | } |
| 4191 | break; |
| 4192 | default: |
| 4193 | break; |
| 4194 | } |
| 4195 | } |
| 4196 | |
| 4197 | /** |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4198 | * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4199 | * @adapter: driver data |
| 4200 | */ |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4201 | static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4202 | { |
| 4203 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4204 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4205 | int i, j; |
| 4206 | |
| 4207 | switch (hw->mac.type) { |
| 4208 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4209 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 4210 | vlnctrl |= IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4211 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4212 | break; |
| 4213 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4214 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 4215 | case ixgbe_mac_X550: |
| 4216 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 4217 | case ixgbe_mac_x550em_a: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4218 | for (i = 0; i < adapter->num_rx_queues; i++) { |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4219 | struct ixgbe_ring *ring = adapter->rx_ring[i]; |
| 4220 | |
| 4221 | if (ring->l2_accel_priv) |
| 4222 | continue; |
| 4223 | j = ring->reg_idx; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4224 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 4225 | vlnctrl |= IXGBE_RXDCTL_VME; |
| 4226 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 4227 | } |
| 4228 | break; |
| 4229 | default: |
| 4230 | break; |
| 4231 | } |
| 4232 | } |
| 4233 | |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4234 | static void ixgbe_vlan_promisc_enable(struct ixgbe_adapter *adapter) |
| 4235 | { |
| 4236 | struct ixgbe_hw *hw = &adapter->hw; |
| 4237 | u32 vlnctrl, i; |
| 4238 | |
Alexander Duyck | f60439b | 2016-08-11 14:51:56 -0700 | [diff] [blame] | 4239 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 4240 | |
Emil Tantilov | 691e412 | 2016-08-22 16:17:46 -0700 | [diff] [blame] | 4241 | if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) { |
| 4242 | /* For VMDq and SR-IOV we must leave VLAN filtering enabled */ |
| 4243 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
| 4244 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4245 | } else { |
Alexander Duyck | f60439b | 2016-08-11 14:51:56 -0700 | [diff] [blame] | 4246 | vlnctrl &= ~IXGBE_VLNCTRL_VFE; |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4247 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4248 | return; |
| 4249 | } |
| 4250 | |
Emil Tantilov | 691e412 | 2016-08-22 16:17:46 -0700 | [diff] [blame] | 4251 | /* Nothing to do for 82598 */ |
| 4252 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4253 | return; |
| 4254 | |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4255 | /* We are already in VLAN promisc, nothing to do */ |
| 4256 | if (adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC) |
| 4257 | return; |
| 4258 | |
| 4259 | /* Set flag so we don't redo unnecessary work */ |
| 4260 | adapter->flags2 |= IXGBE_FLAG2_VLAN_PROMISC; |
| 4261 | |
| 4262 | /* Add PF to all active pools */ |
| 4263 | for (i = IXGBE_VLVF_ENTRIES; --i;) { |
| 4264 | u32 reg_offset = IXGBE_VLVFB(i * 2 + VMDQ_P(0) / 32); |
| 4265 | u32 vlvfb = IXGBE_READ_REG(hw, reg_offset); |
| 4266 | |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 4267 | vlvfb |= BIT(VMDQ_P(0) % 32); |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4268 | IXGBE_WRITE_REG(hw, reg_offset, vlvfb); |
| 4269 | } |
| 4270 | |
| 4271 | /* Set all bits in the VLAN filter table array */ |
| 4272 | for (i = hw->mac.vft_size; i--;) |
| 4273 | IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), ~0U); |
| 4274 | } |
| 4275 | |
| 4276 | #define VFTA_BLOCK_SIZE 8 |
| 4277 | static void ixgbe_scrub_vfta(struct ixgbe_adapter *adapter, u32 vfta_offset) |
| 4278 | { |
| 4279 | struct ixgbe_hw *hw = &adapter->hw; |
| 4280 | u32 vfta[VFTA_BLOCK_SIZE] = { 0 }; |
| 4281 | u32 vid_start = vfta_offset * 32; |
| 4282 | u32 vid_end = vid_start + (VFTA_BLOCK_SIZE * 32); |
| 4283 | u32 i, vid, word, bits; |
| 4284 | |
| 4285 | for (i = IXGBE_VLVF_ENTRIES; --i;) { |
| 4286 | u32 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(i)); |
| 4287 | |
| 4288 | /* pull VLAN ID from VLVF */ |
| 4289 | vid = vlvf & VLAN_VID_MASK; |
| 4290 | |
| 4291 | /* only concern outselves with a certain range */ |
| 4292 | if (vid < vid_start || vid >= vid_end) |
| 4293 | continue; |
| 4294 | |
| 4295 | if (vlvf) { |
| 4296 | /* record VLAN ID in VFTA */ |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 4297 | vfta[(vid - vid_start) / 32] |= BIT(vid % 32); |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4298 | |
| 4299 | /* if PF is part of this then continue */ |
| 4300 | if (test_bit(vid, adapter->active_vlans)) |
| 4301 | continue; |
| 4302 | } |
| 4303 | |
| 4304 | /* remove PF from the pool */ |
| 4305 | word = i * 2 + VMDQ_P(0) / 32; |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 4306 | bits = ~BIT(VMDQ_P(0) % 32); |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4307 | bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word)); |
| 4308 | IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), bits); |
| 4309 | } |
| 4310 | |
| 4311 | /* extract values from active_vlans and write back to VFTA */ |
| 4312 | for (i = VFTA_BLOCK_SIZE; i--;) { |
| 4313 | vid = (vfta_offset + i) * 32; |
| 4314 | word = vid / BITS_PER_LONG; |
| 4315 | bits = vid % BITS_PER_LONG; |
| 4316 | |
| 4317 | vfta[i] |= adapter->active_vlans[word] >> bits; |
| 4318 | |
| 4319 | IXGBE_WRITE_REG(hw, IXGBE_VFTA(vfta_offset + i), vfta[i]); |
| 4320 | } |
| 4321 | } |
| 4322 | |
| 4323 | static void ixgbe_vlan_promisc_disable(struct ixgbe_adapter *adapter) |
| 4324 | { |
| 4325 | struct ixgbe_hw *hw = &adapter->hw; |
| 4326 | u32 vlnctrl, i; |
| 4327 | |
Alexander Duyck | f60439b | 2016-08-11 14:51:56 -0700 | [diff] [blame] | 4328 | /* Set VLAN filtering to enabled */ |
| 4329 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 4330 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
| 4331 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4332 | |
Emil Tantilov | 691e412 | 2016-08-22 16:17:46 -0700 | [diff] [blame] | 4333 | if (!(adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) || |
| 4334 | hw->mac.type == ixgbe_mac_82598EB) |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4335 | return; |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4336 | |
| 4337 | /* We are not in VLAN promisc, nothing to do */ |
| 4338 | if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)) |
| 4339 | return; |
| 4340 | |
| 4341 | /* Set flag so we don't redo unnecessary work */ |
| 4342 | adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC; |
| 4343 | |
| 4344 | for (i = 0; i < hw->mac.vft_size; i += VFTA_BLOCK_SIZE) |
| 4345 | ixgbe_scrub_vfta(adapter, i); |
| 4346 | } |
| 4347 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4348 | static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter) |
| 4349 | { |
Alexander Duyck | 06bb1c3 | 2016-01-06 22:48:50 -0800 | [diff] [blame] | 4350 | u16 vid = 1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4351 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 4352 | ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4353 | |
Alexander Duyck | 06bb1c3 | 2016-01-06 22:48:50 -0800 | [diff] [blame] | 4354 | for_each_set_bit_from(vid, adapter->active_vlans, VLAN_N_VID) |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 4355 | ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4356 | } |
| 4357 | |
| 4358 | /** |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4359 | * ixgbe_write_mc_addr_list - write multicast addresses to MTA |
| 4360 | * @netdev: network interface device structure |
| 4361 | * |
| 4362 | * Writes multicast address list to the MTA hash table. |
| 4363 | * Returns: -ENOMEM on failure |
| 4364 | * 0 on no addresses written |
| 4365 | * X on writing X addresses to MTA |
| 4366 | **/ |
| 4367 | static int ixgbe_write_mc_addr_list(struct net_device *netdev) |
| 4368 | { |
| 4369 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4370 | struct ixgbe_hw *hw = &adapter->hw; |
| 4371 | |
| 4372 | if (!netif_running(netdev)) |
| 4373 | return 0; |
| 4374 | |
| 4375 | if (hw->mac.ops.update_mc_addr_list) |
| 4376 | hw->mac.ops.update_mc_addr_list(hw, netdev); |
| 4377 | else |
| 4378 | return -ENOMEM; |
| 4379 | |
| 4380 | #ifdef CONFIG_PCI_IOV |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4381 | ixgbe_restore_vf_multicasts(adapter); |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4382 | #endif |
| 4383 | |
| 4384 | return netdev_mc_count(netdev); |
| 4385 | } |
| 4386 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4387 | #ifdef CONFIG_PCI_IOV |
| 4388 | void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter) |
| 4389 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4390 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4391 | struct ixgbe_hw *hw = &adapter->hw; |
| 4392 | int i; |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4393 | |
| 4394 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4395 | mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED; |
| 4396 | |
| 4397 | if (mac_table->state & IXGBE_MAC_STATE_IN_USE) |
| 4398 | hw->mac.ops.set_rar(hw, i, |
| 4399 | mac_table->addr, |
| 4400 | mac_table->pool, |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4401 | IXGBE_RAH_AV); |
| 4402 | else |
| 4403 | hw->mac.ops.clear_rar(hw, i); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4404 | } |
| 4405 | } |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4406 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4407 | #endif |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4408 | static void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter) |
| 4409 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4410 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4411 | struct ixgbe_hw *hw = &adapter->hw; |
| 4412 | int i; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4413 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4414 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4415 | if (!(mac_table->state & IXGBE_MAC_STATE_MODIFIED)) |
| 4416 | continue; |
| 4417 | |
| 4418 | mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED; |
| 4419 | |
| 4420 | if (mac_table->state & IXGBE_MAC_STATE_IN_USE) |
| 4421 | hw->mac.ops.set_rar(hw, i, |
| 4422 | mac_table->addr, |
| 4423 | mac_table->pool, |
| 4424 | IXGBE_RAH_AV); |
| 4425 | else |
| 4426 | hw->mac.ops.clear_rar(hw, i); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4427 | } |
| 4428 | } |
| 4429 | |
| 4430 | static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter) |
| 4431 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4432 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4433 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4434 | int i; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4435 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4436 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4437 | mac_table->state |= IXGBE_MAC_STATE_MODIFIED; |
| 4438 | mac_table->state &= ~IXGBE_MAC_STATE_IN_USE; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4439 | } |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4440 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4441 | ixgbe_sync_mac_table(adapter); |
| 4442 | } |
| 4443 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4444 | static int ixgbe_available_rars(struct ixgbe_adapter *adapter, u16 pool) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4445 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4446 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4447 | struct ixgbe_hw *hw = &adapter->hw; |
| 4448 | int i, count = 0; |
| 4449 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4450 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4451 | /* do not count default RAR as available */ |
| 4452 | if (mac_table->state & IXGBE_MAC_STATE_DEFAULT) |
| 4453 | continue; |
| 4454 | |
| 4455 | /* only count unused and addresses that belong to us */ |
| 4456 | if (mac_table->state & IXGBE_MAC_STATE_IN_USE) { |
| 4457 | if (mac_table->pool != pool) |
| 4458 | continue; |
| 4459 | } |
| 4460 | |
| 4461 | count++; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4462 | } |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4463 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4464 | return count; |
| 4465 | } |
| 4466 | |
| 4467 | /* this function destroys the first RAR entry */ |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4468 | static void ixgbe_mac_set_default_filter(struct ixgbe_adapter *adapter) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4469 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4470 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4471 | struct ixgbe_hw *hw = &adapter->hw; |
| 4472 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4473 | memcpy(&mac_table->addr, hw->mac.addr, ETH_ALEN); |
| 4474 | mac_table->pool = VMDQ_P(0); |
| 4475 | |
| 4476 | mac_table->state = IXGBE_MAC_STATE_DEFAULT | IXGBE_MAC_STATE_IN_USE; |
| 4477 | |
| 4478 | hw->mac.ops.set_rar(hw, 0, mac_table->addr, mac_table->pool, |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4479 | IXGBE_RAH_AV); |
| 4480 | } |
| 4481 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4482 | int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter, |
| 4483 | const u8 *addr, u16 pool) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4484 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4485 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4486 | struct ixgbe_hw *hw = &adapter->hw; |
| 4487 | int i; |
| 4488 | |
| 4489 | if (is_zero_ether_addr(addr)) |
| 4490 | return -EINVAL; |
| 4491 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4492 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4493 | if (mac_table->state & IXGBE_MAC_STATE_IN_USE) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4494 | continue; |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4495 | |
| 4496 | ether_addr_copy(mac_table->addr, addr); |
| 4497 | mac_table->pool = pool; |
| 4498 | |
| 4499 | mac_table->state |= IXGBE_MAC_STATE_MODIFIED | |
| 4500 | IXGBE_MAC_STATE_IN_USE; |
| 4501 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4502 | ixgbe_sync_mac_table(adapter); |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4503 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4504 | return i; |
| 4505 | } |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4506 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4507 | return -ENOMEM; |
| 4508 | } |
| 4509 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4510 | int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter, |
| 4511 | const u8 *addr, u16 pool) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4512 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4513 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4514 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4515 | int i; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4516 | |
| 4517 | if (is_zero_ether_addr(addr)) |
| 4518 | return -EINVAL; |
| 4519 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4520 | /* search table for addr, if found clear IN_USE flag and sync */ |
| 4521 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4522 | /* we can only delete an entry if it is in use */ |
| 4523 | if (!(mac_table->state & IXGBE_MAC_STATE_IN_USE)) |
| 4524 | continue; |
| 4525 | /* we only care about entries that belong to the given pool */ |
| 4526 | if (mac_table->pool != pool) |
| 4527 | continue; |
| 4528 | /* we only care about a specific MAC address */ |
| 4529 | if (!ether_addr_equal(addr, mac_table->addr)) |
| 4530 | continue; |
| 4531 | |
| 4532 | mac_table->state |= IXGBE_MAC_STATE_MODIFIED; |
| 4533 | mac_table->state &= ~IXGBE_MAC_STATE_IN_USE; |
| 4534 | |
| 4535 | ixgbe_sync_mac_table(adapter); |
| 4536 | |
| 4537 | return 0; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4538 | } |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4539 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4540 | return -ENOMEM; |
| 4541 | } |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4542 | /** |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4543 | * ixgbe_write_uc_addr_list - write unicast addresses to RAR table |
| 4544 | * @netdev: network interface device structure |
| 4545 | * |
| 4546 | * Writes unicast address list to the RAR table. |
| 4547 | * Returns: -ENOMEM on failure/insufficient address space |
| 4548 | * 0 on no addresses written |
| 4549 | * X on writing X addresses to the RAR table |
| 4550 | **/ |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4551 | static int ixgbe_write_uc_addr_list(struct net_device *netdev, int vfn) |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4552 | { |
| 4553 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4554 | int count = 0; |
| 4555 | |
| 4556 | /* return ENOMEM indicating insufficient memory for addresses */ |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4557 | if (netdev_uc_count(netdev) > ixgbe_available_rars(adapter, vfn)) |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4558 | return -ENOMEM; |
| 4559 | |
John Fastabend | 9544746 | 2012-05-31 12:42:26 +0000 | [diff] [blame] | 4560 | if (!netdev_uc_empty(netdev)) { |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4561 | struct netdev_hw_addr *ha; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4562 | netdev_for_each_uc_addr(ha, netdev) { |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4563 | ixgbe_del_mac_filter(adapter, ha->addr, vfn); |
| 4564 | ixgbe_add_mac_filter(adapter, ha->addr, vfn); |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4565 | count++; |
| 4566 | } |
| 4567 | } |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4568 | return count; |
| 4569 | } |
| 4570 | |
Alexander Duyck | 0f079d2 | 2015-10-22 16:26:36 -0700 | [diff] [blame] | 4571 | static int ixgbe_uc_sync(struct net_device *netdev, const unsigned char *addr) |
| 4572 | { |
| 4573 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4574 | int ret; |
| 4575 | |
| 4576 | ret = ixgbe_add_mac_filter(adapter, addr, VMDQ_P(0)); |
| 4577 | |
| 4578 | return min_t(int, ret, 0); |
| 4579 | } |
| 4580 | |
| 4581 | static int ixgbe_uc_unsync(struct net_device *netdev, const unsigned char *addr) |
| 4582 | { |
| 4583 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4584 | |
| 4585 | ixgbe_del_mac_filter(adapter, addr, VMDQ_P(0)); |
| 4586 | |
| 4587 | return 0; |
| 4588 | } |
| 4589 | |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4590 | /** |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 4591 | * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4592 | * @netdev: network interface device structure |
| 4593 | * |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 4594 | * The set_rx_method entry point is called whenever the unicast/multicast |
| 4595 | * address list or the network interface flags are updated. This routine is |
| 4596 | * responsible for configuring the hardware for proper unicast, multicast and |
| 4597 | * promiscuous mode. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4598 | **/ |
Greg Rose | 7f87047 | 2010-01-09 02:25:29 +0000 | [diff] [blame] | 4599 | void ixgbe_set_rx_mode(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4600 | { |
| 4601 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4602 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4603 | u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE; |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 4604 | netdev_features_t features = netdev->features; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4605 | int count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4606 | |
| 4607 | /* Check for Promiscuous and All Multicast modes */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4608 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 4609 | |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 4610 | /* set all bits that we expect to always be set */ |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 4611 | fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */ |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 4612 | fctrl |= IXGBE_FCTRL_BAM; |
| 4613 | fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */ |
| 4614 | fctrl |= IXGBE_FCTRL_PMCF; |
| 4615 | |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4616 | /* clear the bits we are changing the status of */ |
| 4617 | fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4618 | if (netdev->flags & IFF_PROMISC) { |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 4619 | hw->addr_ctrl.user_set_promisc = true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4620 | fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4621 | vmolr |= IXGBE_VMOLR_MPE; |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 4622 | features &= ~NETIF_F_HW_VLAN_CTAG_FILTER; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4623 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 4624 | if (netdev->flags & IFF_ALLMULTI) { |
| 4625 | fctrl |= IXGBE_FCTRL_MPE; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4626 | vmolr |= IXGBE_VMOLR_MPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 4627 | } |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 4628 | hw->addr_ctrl.user_set_promisc = false; |
John Fastabend | 9dcb373 | 2012-04-15 06:44:25 +0000 | [diff] [blame] | 4629 | } |
| 4630 | |
| 4631 | /* |
| 4632 | * Write addresses to available RAR registers, if there is not |
| 4633 | * sufficient space to store all the addresses then enable |
| 4634 | * unicast promiscuous mode |
| 4635 | */ |
Alexander Duyck | 0f079d2 | 2015-10-22 16:26:36 -0700 | [diff] [blame] | 4636 | if (__dev_uc_sync(netdev, ixgbe_uc_sync, ixgbe_uc_unsync)) { |
John Fastabend | 9dcb373 | 2012-04-15 06:44:25 +0000 | [diff] [blame] | 4637 | fctrl |= IXGBE_FCTRL_UPE; |
| 4638 | vmolr |= IXGBE_VMOLR_ROPE; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4639 | } |
| 4640 | |
Emil Tantilov | cf78959 | 2013-10-26 08:13:20 +0000 | [diff] [blame] | 4641 | /* Write addresses to the MTA, if the attempt fails |
| 4642 | * then we should just turn on promiscuous mode so |
| 4643 | * that we can at least receive multicast traffic |
| 4644 | */ |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4645 | count = ixgbe_write_mc_addr_list(netdev); |
| 4646 | if (count < 0) { |
| 4647 | fctrl |= IXGBE_FCTRL_MPE; |
| 4648 | vmolr |= IXGBE_VMOLR_MPE; |
| 4649 | } else if (count) { |
| 4650 | vmolr |= IXGBE_VMOLR_ROMPE; |
| 4651 | } |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 4652 | |
| 4653 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 4654 | vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) & |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4655 | ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE | |
| 4656 | IXGBE_VMOLR_ROPE); |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 4657 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4658 | } |
| 4659 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 4660 | /* This is useful for sniffing bad packets. */ |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 4661 | if (features & NETIF_F_RXALL) { |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 4662 | /* UPE and MPE will be handled by normal PROMISC logic |
| 4663 | * in e1000e_set_rx_mode */ |
| 4664 | fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */ |
| 4665 | IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */ |
| 4666 | IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */ |
| 4667 | |
| 4668 | fctrl &= ~(IXGBE_FCTRL_DPF); |
| 4669 | /* NOTE: VLAN filtering is disabled by setting PROMISC */ |
| 4670 | } |
| 4671 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4672 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4673 | |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 4674 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4675 | ixgbe_vlan_strip_enable(adapter); |
| 4676 | else |
| 4677 | ixgbe_vlan_strip_disable(adapter); |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 4678 | |
| 4679 | if (features & NETIF_F_HW_VLAN_CTAG_FILTER) |
| 4680 | ixgbe_vlan_promisc_disable(adapter); |
| 4681 | else |
| 4682 | ixgbe_vlan_promisc_enable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4683 | } |
| 4684 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4685 | static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter) |
| 4686 | { |
| 4687 | int q_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4688 | |
Eric Dumazet | 3ffc1af | 2017-02-02 16:26:39 -0800 | [diff] [blame] | 4689 | for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 4690 | napi_enable(&adapter->q_vector[q_idx]->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4691 | } |
| 4692 | |
| 4693 | static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter) |
| 4694 | { |
| 4695 | int q_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4696 | |
Eric Dumazet | 3ffc1af | 2017-02-02 16:26:39 -0800 | [diff] [blame] | 4697 | for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 4698 | napi_disable(&adapter->q_vector[q_idx]->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4699 | } |
| 4700 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 4701 | static void ixgbe_clear_udp_tunnel_port(struct ixgbe_adapter *adapter, u32 mask) |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 4702 | { |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 4703 | struct ixgbe_hw *hw = &adapter->hw; |
| 4704 | u32 vxlanctrl; |
| 4705 | |
| 4706 | if (!(adapter->flags & (IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE | |
| 4707 | IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))) |
| 4708 | return; |
| 4709 | |
| 4710 | vxlanctrl = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) && ~mask; |
| 4711 | IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, vxlanctrl); |
| 4712 | |
| 4713 | if (mask & IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK) |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 4714 | adapter->vxlan_port = 0; |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 4715 | |
| 4716 | if (mask & IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK) |
| 4717 | adapter->geneve_port = 0; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 4718 | } |
| 4719 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 4720 | #ifdef CONFIG_IXGBE_DCB |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4721 | /** |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4722 | * ixgbe_configure_dcb - Configure DCB hardware |
| 4723 | * @adapter: ixgbe adapter struct |
| 4724 | * |
| 4725 | * This is called by the driver on open to configure the DCB hardware. |
| 4726 | * This is also called by the gennetlink interface when reconfiguring |
| 4727 | * the DCB state. |
| 4728 | */ |
| 4729 | static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter) |
| 4730 | { |
| 4731 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 9806307a | 2010-10-28 00:59:57 +0000 | [diff] [blame] | 4732 | int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4733 | |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 4734 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) { |
| 4735 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4736 | netif_set_gso_max_size(adapter->netdev, 65536); |
| 4737 | return; |
| 4738 | } |
| 4739 | |
| 4740 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4741 | netif_set_gso_max_size(adapter->netdev, 32768); |
| 4742 | |
John Fastabend | b120818 | 2011-10-15 05:00:10 +0000 | [diff] [blame] | 4743 | #ifdef IXGBE_FCOE |
| 4744 | if (adapter->netdev->features & NETIF_F_FCOE_MTU) |
| 4745 | max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE); |
| 4746 | #endif |
| 4747 | |
Alexander Duyck | 01fa7d9 | 2010-11-16 19:26:53 -0800 | [diff] [blame] | 4748 | /* reconfigure the hardware */ |
John Fastabend | 6f70f6a | 2011-04-26 07:26:25 +0000 | [diff] [blame] | 4749 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) { |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 4750 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 4751 | DCB_TX_CONFIG); |
| 4752 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 4753 | DCB_RX_CONFIG); |
| 4754 | ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg); |
John Fastabend | b120818 | 2011-10-15 05:00:10 +0000 | [diff] [blame] | 4755 | } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) { |
| 4756 | ixgbe_dcb_hw_ets(&adapter->hw, |
| 4757 | adapter->ixgbe_ieee_ets, |
| 4758 | max_frame); |
| 4759 | ixgbe_dcb_hw_pfc_config(&adapter->hw, |
| 4760 | adapter->ixgbe_ieee_pfc->pfc_en, |
| 4761 | adapter->ixgbe_ieee_ets->prio_tc); |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 4762 | } |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 4763 | |
| 4764 | /* Enable RSS Hash per TC */ |
| 4765 | if (hw->mac.type != ixgbe_mac_82598EB) { |
Alexander Duyck | 4ae6373 | 2012-06-22 06:46:33 +0000 | [diff] [blame] | 4766 | u32 msb = 0; |
| 4767 | u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1; |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 4768 | |
Alexander Duyck | d411a93 | 2012-06-30 00:14:01 +0000 | [diff] [blame] | 4769 | while (rss_i) { |
| 4770 | msb++; |
| 4771 | rss_i >>= 1; |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 4772 | } |
Alexander Duyck | d411a93 | 2012-06-30 00:14:01 +0000 | [diff] [blame] | 4773 | |
Alexander Duyck | 4ae6373 | 2012-06-22 06:46:33 +0000 | [diff] [blame] | 4774 | /* write msb to all 8 TCs in one write */ |
| 4775 | IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111); |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 4776 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4777 | } |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4778 | #endif |
| 4779 | |
| 4780 | /* Additional bittime to account for IXGBE framing */ |
| 4781 | #define IXGBE_ETH_FRAMING 20 |
| 4782 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4783 | /** |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4784 | * ixgbe_hpbthresh - calculate high water mark for flow control |
| 4785 | * |
| 4786 | * @adapter: board private structure to calculate for |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4787 | * @pb: packet buffer to calculate |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4788 | */ |
| 4789 | static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb) |
| 4790 | { |
| 4791 | struct ixgbe_hw *hw = &adapter->hw; |
| 4792 | struct net_device *dev = adapter->netdev; |
| 4793 | int link, tc, kb, marker; |
| 4794 | u32 dv_id, rx_pba; |
| 4795 | |
| 4796 | /* Calculate max LAN frame size */ |
| 4797 | tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING; |
| 4798 | |
| 4799 | #ifdef IXGBE_FCOE |
| 4800 | /* FCoE traffic class uses FCOE jumbo frames */ |
Alexander Duyck | 800bd60 | 2012-06-02 00:11:02 +0000 | [diff] [blame] | 4801 | if ((dev->features & NETIF_F_FCOE_MTU) && |
| 4802 | (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) && |
| 4803 | (pb == ixgbe_fcoe_get_tc(adapter))) |
| 4804 | tc = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4805 | #endif |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4806 | |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4807 | /* Calculate delay value for device */ |
| 4808 | switch (hw->mac.type) { |
| 4809 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 4810 | case ixgbe_mac_X550: |
| 4811 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 4812 | case ixgbe_mac_x550em_a: |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4813 | dv_id = IXGBE_DV_X540(link, tc); |
| 4814 | break; |
| 4815 | default: |
| 4816 | dv_id = IXGBE_DV(link, tc); |
| 4817 | break; |
| 4818 | } |
| 4819 | |
| 4820 | /* Loopback switch introduces additional latency */ |
| 4821 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 4822 | dv_id += IXGBE_B2BT(tc); |
| 4823 | |
| 4824 | /* Delay value is calculated in bit times convert to KB */ |
| 4825 | kb = IXGBE_BT2KB(dv_id); |
| 4826 | rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10; |
| 4827 | |
| 4828 | marker = rx_pba - kb; |
| 4829 | |
| 4830 | /* It is possible that the packet buffer is not large enough |
| 4831 | * to provide required headroom. In this case throw an error |
| 4832 | * to user and a do the best we can. |
| 4833 | */ |
| 4834 | if (marker < 0) { |
| 4835 | e_warn(drv, "Packet Buffer(%i) can not provide enough" |
| 4836 | "headroom to support flow control." |
| 4837 | "Decrease MTU or number of traffic classes\n", pb); |
| 4838 | marker = tc + 1; |
| 4839 | } |
| 4840 | |
| 4841 | return marker; |
| 4842 | } |
| 4843 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4844 | /** |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4845 | * ixgbe_lpbthresh - calculate low water mark for for flow control |
| 4846 | * |
| 4847 | * @adapter: board private structure to calculate for |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4848 | * @pb: packet buffer to calculate |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4849 | */ |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4850 | static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb) |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4851 | { |
| 4852 | struct ixgbe_hw *hw = &adapter->hw; |
| 4853 | struct net_device *dev = adapter->netdev; |
| 4854 | int tc; |
| 4855 | u32 dv_id; |
| 4856 | |
| 4857 | /* Calculate max LAN frame size */ |
| 4858 | tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN; |
| 4859 | |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4860 | #ifdef IXGBE_FCOE |
| 4861 | /* FCoE traffic class uses FCOE jumbo frames */ |
| 4862 | if ((dev->features & NETIF_F_FCOE_MTU) && |
| 4863 | (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) && |
| 4864 | (pb == netdev_get_prio_tc_map(dev, adapter->fcoe.up))) |
| 4865 | tc = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 4866 | #endif |
| 4867 | |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4868 | /* Calculate delay value for device */ |
| 4869 | switch (hw->mac.type) { |
| 4870 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 4871 | case ixgbe_mac_X550: |
| 4872 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 4873 | case ixgbe_mac_x550em_a: |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4874 | dv_id = IXGBE_LOW_DV_X540(tc); |
| 4875 | break; |
| 4876 | default: |
| 4877 | dv_id = IXGBE_LOW_DV(tc); |
| 4878 | break; |
| 4879 | } |
| 4880 | |
| 4881 | /* Delay value is calculated in bit times convert to KB */ |
| 4882 | return IXGBE_BT2KB(dv_id); |
| 4883 | } |
| 4884 | |
| 4885 | /* |
| 4886 | * ixgbe_pbthresh_setup - calculate and setup high low water marks |
| 4887 | */ |
| 4888 | static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter) |
| 4889 | { |
| 4890 | struct ixgbe_hw *hw = &adapter->hw; |
| 4891 | int num_tc = netdev_get_num_tc(adapter->netdev); |
| 4892 | int i; |
| 4893 | |
| 4894 | if (!num_tc) |
| 4895 | num_tc = 1; |
| 4896 | |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4897 | for (i = 0; i < num_tc; i++) { |
| 4898 | hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i); |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4899 | hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i); |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4900 | |
| 4901 | /* Low water marks must not be larger than high water marks */ |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4902 | if (hw->fc.low_water[i] > hw->fc.high_water[i]) |
| 4903 | hw->fc.low_water[i] = 0; |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4904 | } |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4905 | |
| 4906 | for (; i < MAX_TRAFFIC_CLASS; i++) |
| 4907 | hw->fc.high_water[i] = 0; |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4908 | } |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4909 | |
| 4910 | static void ixgbe_configure_pb(struct ixgbe_adapter *adapter) |
| 4911 | { |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4912 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 4913 | int hdrm; |
| 4914 | u8 tc = netdev_get_num_tc(adapter->netdev); |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4915 | |
| 4916 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 4917 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 4918 | hdrm = 32 << adapter->fdir_pballoc; |
| 4919 | else |
| 4920 | hdrm = 0; |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4921 | |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 4922 | hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL); |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4923 | ixgbe_pbthresh_setup(adapter); |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4924 | } |
| 4925 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4926 | static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter) |
| 4927 | { |
| 4928 | struct ixgbe_hw *hw = &adapter->hw; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 4929 | struct hlist_node *node2; |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4930 | struct ixgbe_fdir_filter *filter; |
| 4931 | |
| 4932 | spin_lock(&adapter->fdir_perfect_lock); |
| 4933 | |
| 4934 | if (!hlist_empty(&adapter->fdir_filter_list)) |
| 4935 | ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask); |
| 4936 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 4937 | hlist_for_each_entry_safe(filter, node2, |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4938 | &adapter->fdir_filter_list, fdir_node) { |
| 4939 | ixgbe_fdir_write_perfect_filter_82599(hw, |
Alexander Duyck | 1f4d518 | 2011-05-14 01:16:02 +0000 | [diff] [blame] | 4940 | &filter->filter, |
| 4941 | filter->sw_idx, |
| 4942 | (filter->action == IXGBE_FDIR_DROP_QUEUE) ? |
| 4943 | IXGBE_FDIR_DROP_QUEUE : |
| 4944 | adapter->rx_ring[filter->action]->reg_idx); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4945 | } |
| 4946 | |
| 4947 | spin_unlock(&adapter->fdir_perfect_lock); |
| 4948 | } |
| 4949 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4950 | static void ixgbe_macvlan_set_rx_mode(struct net_device *dev, unsigned int pool, |
| 4951 | struct ixgbe_adapter *adapter) |
| 4952 | { |
| 4953 | struct ixgbe_hw *hw = &adapter->hw; |
| 4954 | u32 vmolr; |
| 4955 | |
| 4956 | /* No unicast promiscuous support for VMDQ devices. */ |
| 4957 | vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(pool)); |
| 4958 | vmolr |= (IXGBE_VMOLR_ROMPE | IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE); |
| 4959 | |
| 4960 | /* clear the affected bit */ |
| 4961 | vmolr &= ~IXGBE_VMOLR_MPE; |
| 4962 | |
| 4963 | if (dev->flags & IFF_ALLMULTI) { |
| 4964 | vmolr |= IXGBE_VMOLR_MPE; |
| 4965 | } else { |
| 4966 | vmolr |= IXGBE_VMOLR_ROMPE; |
| 4967 | hw->mac.ops.update_mc_addr_list(hw, dev); |
| 4968 | } |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4969 | ixgbe_write_uc_addr_list(adapter->netdev, pool); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4970 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(pool), vmolr); |
| 4971 | } |
| 4972 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4973 | static void ixgbe_fwd_psrtype(struct ixgbe_fwd_adapter *vadapter) |
| 4974 | { |
| 4975 | struct ixgbe_adapter *adapter = vadapter->real_adapter; |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 4976 | int rss_i = adapter->num_rx_queues_per_pool; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4977 | struct ixgbe_hw *hw = &adapter->hw; |
| 4978 | u16 pool = vadapter->pool; |
| 4979 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
| 4980 | IXGBE_PSRTYPE_UDPHDR | |
| 4981 | IXGBE_PSRTYPE_IPV4HDR | |
| 4982 | IXGBE_PSRTYPE_L2HDR | |
| 4983 | IXGBE_PSRTYPE_IPV6HDR; |
| 4984 | |
| 4985 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4986 | return; |
| 4987 | |
| 4988 | if (rss_i > 3) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 4989 | psrtype |= 2u << 29; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4990 | else if (rss_i > 1) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 4991 | psrtype |= 1u << 29; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4992 | |
| 4993 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype); |
| 4994 | } |
| 4995 | |
| 4996 | /** |
| 4997 | * ixgbe_clean_rx_ring - Free Rx Buffers per Queue |
| 4998 | * @rx_ring: ring to free buffers from |
| 4999 | **/ |
| 5000 | static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring) |
| 5001 | { |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5002 | u16 i = rx_ring->next_to_clean; |
| 5003 | struct ixgbe_rx_buffer *rx_buffer = &rx_ring->rx_buffer_info[i]; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5004 | |
| 5005 | /* Free all the Rx ring sk_buffs */ |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5006 | while (i != rx_ring->next_to_alloc) { |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5007 | if (rx_buffer->skb) { |
| 5008 | struct sk_buff *skb = rx_buffer->skb; |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 5009 | if (IXGBE_CB(skb)->page_released) |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5010 | dma_unmap_page_attrs(rx_ring->dev, |
Alexander Duyck | f3213d9 | 2017-01-17 08:35:54 -0800 | [diff] [blame] | 5011 | IXGBE_CB(skb)->dma, |
| 5012 | ixgbe_rx_pg_size(rx_ring), |
| 5013 | DMA_FROM_DEVICE, |
| 5014 | IXGBE_RX_DMA_ATTR); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5015 | dev_kfree_skb(skb); |
| 5016 | } |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 5017 | |
Alexander Duyck | f3213d9 | 2017-01-17 08:35:54 -0800 | [diff] [blame] | 5018 | /* Invalidate cache lines that may have been written to by |
| 5019 | * device so that we avoid corrupting memory. |
| 5020 | */ |
| 5021 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 5022 | rx_buffer->dma, |
| 5023 | rx_buffer->page_offset, |
| 5024 | ixgbe_rx_bufsz(rx_ring), |
| 5025 | DMA_FROM_DEVICE); |
| 5026 | |
| 5027 | /* free resources associated with mapping */ |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5028 | dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma, |
Alexander Duyck | f3213d9 | 2017-01-17 08:35:54 -0800 | [diff] [blame] | 5029 | ixgbe_rx_pg_size(rx_ring), |
| 5030 | DMA_FROM_DEVICE, |
| 5031 | IXGBE_RX_DMA_ATTR); |
Alexander Duyck | 1b56cf4 | 2017-01-17 08:36:03 -0800 | [diff] [blame] | 5032 | __page_frag_cache_drain(rx_buffer->page, |
| 5033 | rx_buffer->pagecnt_bias); |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 5034 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5035 | i++; |
| 5036 | rx_buffer++; |
| 5037 | if (i == rx_ring->count) { |
| 5038 | i = 0; |
| 5039 | rx_buffer = rx_ring->rx_buffer_info; |
| 5040 | } |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5041 | } |
| 5042 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5043 | rx_ring->next_to_alloc = 0; |
| 5044 | rx_ring->next_to_clean = 0; |
| 5045 | rx_ring->next_to_use = 0; |
| 5046 | } |
| 5047 | |
| 5048 | static void ixgbe_disable_fwd_ring(struct ixgbe_fwd_adapter *vadapter, |
| 5049 | struct ixgbe_ring *rx_ring) |
| 5050 | { |
| 5051 | struct ixgbe_adapter *adapter = vadapter->real_adapter; |
| 5052 | int index = rx_ring->queue_index + vadapter->rx_base_queue; |
| 5053 | |
| 5054 | /* shutdown specific queue receive and wait for dma to settle */ |
| 5055 | ixgbe_disable_rx_queue(adapter, rx_ring); |
| 5056 | usleep_range(10000, 20000); |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 5057 | ixgbe_irq_disable_queues(adapter, BIT_ULL(index)); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5058 | ixgbe_clean_rx_ring(rx_ring); |
| 5059 | rx_ring->l2_accel_priv = NULL; |
| 5060 | } |
| 5061 | |
John Fastabend | ae72c8d | 2013-11-09 07:11:26 +0000 | [diff] [blame] | 5062 | static int ixgbe_fwd_ring_down(struct net_device *vdev, |
| 5063 | struct ixgbe_fwd_adapter *accel) |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5064 | { |
| 5065 | struct ixgbe_adapter *adapter = accel->real_adapter; |
| 5066 | unsigned int rxbase = accel->rx_base_queue; |
| 5067 | unsigned int txbase = accel->tx_base_queue; |
| 5068 | int i; |
| 5069 | |
| 5070 | netif_tx_stop_all_queues(vdev); |
| 5071 | |
| 5072 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 5073 | ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]); |
| 5074 | adapter->rx_ring[rxbase + i]->netdev = adapter->netdev; |
| 5075 | } |
| 5076 | |
| 5077 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 5078 | adapter->tx_ring[txbase + i]->l2_accel_priv = NULL; |
| 5079 | adapter->tx_ring[txbase + i]->netdev = adapter->netdev; |
| 5080 | } |
| 5081 | |
| 5082 | |
| 5083 | return 0; |
| 5084 | } |
| 5085 | |
| 5086 | static int ixgbe_fwd_ring_up(struct net_device *vdev, |
| 5087 | struct ixgbe_fwd_adapter *accel) |
| 5088 | { |
| 5089 | struct ixgbe_adapter *adapter = accel->real_adapter; |
| 5090 | unsigned int rxbase, txbase, queues; |
| 5091 | int i, baseq, err = 0; |
| 5092 | |
| 5093 | if (!test_bit(accel->pool, &adapter->fwd_bitmask)) |
| 5094 | return 0; |
| 5095 | |
| 5096 | baseq = accel->pool * adapter->num_rx_queues_per_pool; |
| 5097 | netdev_dbg(vdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n", |
| 5098 | accel->pool, adapter->num_rx_pools, |
| 5099 | baseq, baseq + adapter->num_rx_queues_per_pool, |
| 5100 | adapter->fwd_bitmask); |
| 5101 | |
| 5102 | accel->netdev = vdev; |
| 5103 | accel->rx_base_queue = rxbase = baseq; |
| 5104 | accel->tx_base_queue = txbase = baseq; |
| 5105 | |
| 5106 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) |
| 5107 | ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]); |
| 5108 | |
| 5109 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 5110 | adapter->rx_ring[rxbase + i]->netdev = vdev; |
| 5111 | adapter->rx_ring[rxbase + i]->l2_accel_priv = accel; |
| 5112 | ixgbe_configure_rx_ring(adapter, adapter->rx_ring[rxbase + i]); |
| 5113 | } |
| 5114 | |
| 5115 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 5116 | adapter->tx_ring[txbase + i]->netdev = vdev; |
| 5117 | adapter->tx_ring[txbase + i]->l2_accel_priv = accel; |
| 5118 | } |
| 5119 | |
| 5120 | queues = min_t(unsigned int, |
| 5121 | adapter->num_rx_queues_per_pool, vdev->num_tx_queues); |
| 5122 | err = netif_set_real_num_tx_queues(vdev, queues); |
| 5123 | if (err) |
| 5124 | goto fwd_queue_err; |
| 5125 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5126 | err = netif_set_real_num_rx_queues(vdev, queues); |
| 5127 | if (err) |
| 5128 | goto fwd_queue_err; |
| 5129 | |
| 5130 | if (is_valid_ether_addr(vdev->dev_addr)) |
| 5131 | ixgbe_add_mac_filter(adapter, vdev->dev_addr, accel->pool); |
| 5132 | |
| 5133 | ixgbe_fwd_psrtype(accel); |
| 5134 | ixgbe_macvlan_set_rx_mode(vdev, accel->pool, adapter); |
| 5135 | return err; |
| 5136 | fwd_queue_err: |
| 5137 | ixgbe_fwd_ring_down(vdev, accel); |
| 5138 | return err; |
| 5139 | } |
| 5140 | |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 5141 | static int ixgbe_upper_dev_walk(struct net_device *upper, void *data) |
| 5142 | { |
| 5143 | if (netif_is_macvlan(upper)) { |
| 5144 | struct macvlan_dev *dfwd = netdev_priv(upper); |
| 5145 | struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv; |
| 5146 | |
| 5147 | if (dfwd->fwd_priv) |
| 5148 | ixgbe_fwd_ring_up(upper, vadapter); |
| 5149 | } |
| 5150 | |
| 5151 | return 0; |
| 5152 | } |
| 5153 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5154 | static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter) |
| 5155 | { |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 5156 | netdev_walk_all_upper_dev_rcu(adapter->netdev, |
| 5157 | ixgbe_upper_dev_walk, NULL); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5158 | } |
| 5159 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5160 | static void ixgbe_configure(struct ixgbe_adapter *adapter) |
| 5161 | { |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 5162 | struct ixgbe_hw *hw = &adapter->hw; |
| 5163 | |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 5164 | ixgbe_configure_pb(adapter); |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5165 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 5166 | ixgbe_configure_dcb(adapter); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5167 | #endif |
Alexander Duyck | b35d4d4 | 2012-05-23 05:39:25 +0000 | [diff] [blame] | 5168 | /* |
| 5169 | * We must restore virtualization before VLANs or else |
| 5170 | * the VLVF registers will not be populated |
| 5171 | */ |
| 5172 | ixgbe_configure_virtualization(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5173 | |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 5174 | ixgbe_set_rx_mode(adapter->netdev); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 5175 | ixgbe_restore_vlan(adapter); |
| 5176 | |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 5177 | switch (hw->mac.type) { |
| 5178 | case ixgbe_mac_82599EB: |
| 5179 | case ixgbe_mac_X540: |
| 5180 | hw->mac.ops.disable_rx_buff(hw); |
| 5181 | break; |
| 5182 | default: |
| 5183 | break; |
| 5184 | } |
| 5185 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5186 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 5187 | ixgbe_init_fdir_signature_82599(&adapter->hw, |
| 5188 | adapter->fdir_pballoc); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5189 | } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) { |
| 5190 | ixgbe_init_fdir_perfect_82599(&adapter->hw, |
| 5191 | adapter->fdir_pballoc); |
| 5192 | ixgbe_fdir_filter_restore(adapter); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5193 | } |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 5194 | |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 5195 | switch (hw->mac.type) { |
| 5196 | case ixgbe_mac_82599EB: |
| 5197 | case ixgbe_mac_X540: |
| 5198 | hw->mac.ops.enable_rx_buff(hw); |
| 5199 | break; |
| 5200 | default: |
| 5201 | break; |
| 5202 | } |
| 5203 | |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 5204 | #ifdef CONFIG_IXGBE_DCA |
| 5205 | /* configure DCA */ |
| 5206 | if (adapter->flags & IXGBE_FLAG_DCA_CAPABLE) |
| 5207 | ixgbe_setup_dca(adapter); |
| 5208 | #endif /* CONFIG_IXGBE_DCA */ |
| 5209 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 5210 | #ifdef IXGBE_FCOE |
| 5211 | /* configure FCoE L2 filters, redirection table, and Rx control */ |
| 5212 | ixgbe_configure_fcoe(adapter); |
| 5213 | |
| 5214 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5215 | ixgbe_configure_tx(adapter); |
| 5216 | ixgbe_configure_rx(adapter); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5217 | ixgbe_configure_dfwd(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5218 | } |
| 5219 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5220 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5221 | * ixgbe_sfp_link_config - set up SFP+ link |
| 5222 | * @adapter: pointer to private adapter struct |
| 5223 | **/ |
| 5224 | static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter) |
| 5225 | { |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5226 | /* |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 5227 | * We are assuming the worst case scenario here, and that |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5228 | * is that an SFP was inserted/removed after the reset |
| 5229 | * but before SFP detection was enabled. As such the best |
| 5230 | * solution is to just start searching as soon as we start |
| 5231 | */ |
| 5232 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 5233 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5234 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5235 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
Mark Rustad | 58e7cd2 | 2015-08-08 16:18:48 -0700 | [diff] [blame] | 5236 | adapter->sfp_poll_time = 0; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5237 | } |
| 5238 | |
| 5239 | /** |
| 5240 | * ixgbe_non_sfp_link_config - set up non-SFP+ link |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5241 | * @hw: pointer to private hardware struct |
| 5242 | * |
| 5243 | * Returns 0 on success, negative on failure |
| 5244 | **/ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5245 | static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw) |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5246 | { |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 5247 | u32 speed; |
| 5248 | bool autoneg, link_up = false; |
Mark Rustad | a1e869d | 2015-04-10 10:36:36 -0700 | [diff] [blame] | 5249 | int ret = IXGBE_ERR_LINK_SETUP; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5250 | |
| 5251 | if (hw->mac.ops.check_link) |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 5252 | ret = hw->mac.ops.check_link(hw, &speed, &link_up, false); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5253 | |
| 5254 | if (ret) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 5255 | return ret; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5256 | |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 5257 | speed = hw->phy.autoneg_advertised; |
| 5258 | if ((!speed) && (hw->mac.ops.get_link_capabilities)) |
| 5259 | ret = hw->mac.ops.get_link_capabilities(hw, &speed, |
| 5260 | &autoneg); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5261 | if (ret) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 5262 | return ret; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5263 | |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 5264 | if (hw->mac.ops.setup_link) |
Josh Hay | fd0326f | 2012-12-15 03:28:30 +0000 | [diff] [blame] | 5265 | ret = hw->mac.ops.setup_link(hw, speed, link_up); |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 5266 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5267 | return ret; |
| 5268 | } |
| 5269 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5270 | static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5271 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5272 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5273 | u32 gpie = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5274 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 5275 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5276 | gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT | |
| 5277 | IXGBE_GPIE_OCD; |
| 5278 | gpie |= IXGBE_GPIE_EIAME; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 5279 | /* |
| 5280 | * use EIAM to auto-mask when MSI-X interrupt is asserted |
| 5281 | * this saves a register write for every interrupt |
| 5282 | */ |
| 5283 | switch (hw->mac.type) { |
| 5284 | case ixgbe_mac_82598EB: |
| 5285 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
| 5286 | break; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 5287 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5288 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5289 | case ixgbe_mac_X550: |
| 5290 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 5291 | case ixgbe_mac_x550em_a: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5292 | default: |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 5293 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF); |
| 5294 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF); |
| 5295 | break; |
| 5296 | } |
| 5297 | } else { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5298 | /* legacy interrupts, use EIAM to auto-mask when reading EICR, |
| 5299 | * specifically only auto mask tx and rx interrupts */ |
| 5300 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5301 | } |
| 5302 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5303 | /* XXX: to interrupt immediately for EICS writes, enable this */ |
| 5304 | /* gpie |= IXGBE_GPIE_EIMEN; */ |
| 5305 | |
| 5306 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 5307 | gpie &= ~IXGBE_GPIE_VTMODE_MASK; |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 5308 | |
| 5309 | switch (adapter->ring_feature[RING_F_VMDQ].mask) { |
| 5310 | case IXGBE_82599_VMDQ_8Q_MASK: |
| 5311 | gpie |= IXGBE_GPIE_VTMODE_16; |
| 5312 | break; |
| 5313 | case IXGBE_82599_VMDQ_4Q_MASK: |
| 5314 | gpie |= IXGBE_GPIE_VTMODE_32; |
| 5315 | break; |
| 5316 | default: |
| 5317 | gpie |= IXGBE_GPIE_VTMODE_64; |
| 5318 | break; |
| 5319 | } |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 5320 | } |
| 5321 | |
Alexander Duyck | 5fdd31f | 2011-07-21 00:40:45 +0000 | [diff] [blame] | 5322 | /* Enable Thermal over heat sensor interrupt */ |
Don Skidmore | f3df98e | 2011-08-17 10:15:21 +0000 | [diff] [blame] | 5323 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) { |
| 5324 | switch (adapter->hw.mac.type) { |
| 5325 | case ixgbe_mac_82599EB: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 5326 | gpie |= IXGBE_SDP0_GPIEN_8259X; |
Don Skidmore | f3df98e | 2011-08-17 10:15:21 +0000 | [diff] [blame] | 5327 | break; |
Don Skidmore | f3df98e | 2011-08-17 10:15:21 +0000 | [diff] [blame] | 5328 | default: |
| 5329 | break; |
| 5330 | } |
| 5331 | } |
Alexander Duyck | 5fdd31f | 2011-07-21 00:40:45 +0000 | [diff] [blame] | 5332 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5333 | /* Enable fan failure interrupt */ |
| 5334 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 5335 | gpie |= IXGBE_SDP1_GPIEN(hw); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 5336 | |
Don Skidmore | a023bbd | 2015-06-24 16:38:53 -0400 | [diff] [blame] | 5337 | switch (hw->mac.type) { |
| 5338 | case ixgbe_mac_82599EB: |
| 5339 | gpie |= IXGBE_SDP1_GPIEN_8259X | IXGBE_SDP2_GPIEN_8259X; |
| 5340 | break; |
| 5341 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 5342 | case ixgbe_mac_x550em_a: |
Don Skidmore | a023bbd | 2015-06-24 16:38:53 -0400 | [diff] [blame] | 5343 | gpie |= IXGBE_SDP0_GPIEN_X540; |
| 5344 | break; |
| 5345 | default: |
| 5346 | break; |
Don Skidmore | 2698b20 | 2011-04-13 07:01:52 +0000 | [diff] [blame] | 5347 | } |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5348 | |
| 5349 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 5350 | } |
| 5351 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 5352 | static void ixgbe_up_complete(struct ixgbe_adapter *adapter) |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5353 | { |
| 5354 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5355 | int err; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5356 | u32 ctrl_ext; |
| 5357 | |
| 5358 | ixgbe_get_hw_control(adapter); |
| 5359 | ixgbe_setup_gpie(adapter); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5360 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5361 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 5362 | ixgbe_configure_msix(adapter); |
| 5363 | else |
| 5364 | ixgbe_configure_msi_and_legacy(adapter); |
| 5365 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 5366 | /* enable the optics for 82599 SFP+ fiber */ |
| 5367 | if (hw->mac.ops.enable_tx_laser) |
Peter Waskiewicz | 61fac74 | 2010-04-27 00:38:15 +0000 | [diff] [blame] | 5368 | hw->mac.ops.enable_tx_laser(hw); |
| 5369 | |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 5370 | if (hw->phy.ops.set_phy_power) |
| 5371 | hw->phy.ops.set_phy_power(hw, true); |
| 5372 | |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 5373 | smp_mb__before_atomic(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5374 | clear_bit(__IXGBE_DOWN, &adapter->state); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5375 | ixgbe_napi_enable_all(adapter); |
| 5376 | |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 5377 | if (ixgbe_is_sfp(hw)) { |
| 5378 | ixgbe_sfp_link_config(adapter); |
| 5379 | } else { |
| 5380 | err = ixgbe_non_sfp_link_config(hw); |
| 5381 | if (err) |
| 5382 | e_err(probe, "link_config FAILED %d\n", err); |
| 5383 | } |
| 5384 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5385 | /* clear any pending interrupts, may auto mask */ |
| 5386 | IXGBE_READ_REG(hw, IXGBE_EICR); |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 5387 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5388 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5389 | /* |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5390 | * If this adapter has a fan, check to see if we had a failure |
| 5391 | * before we enabled the interrupt. |
| 5392 | */ |
| 5393 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 5394 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 5395 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5396 | e_crit(drv, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5397 | } |
| 5398 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5399 | /* bring the link up in the watchdog, this could race with our first |
| 5400 | * link up interrupt but shouldn't be a problem */ |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5401 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 5402 | adapter->link_check_timeout = jiffies; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5403 | mod_timer(&adapter->service_timer, jiffies); |
Greg Rose | c920569 | 2010-01-22 22:46:22 +0000 | [diff] [blame] | 5404 | |
| 5405 | /* Set PF Reset Done bit so PF/VF Mail Ops can work */ |
| 5406 | ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); |
| 5407 | ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD; |
| 5408 | IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5409 | } |
| 5410 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5411 | void ixgbe_reinit_locked(struct ixgbe_adapter *adapter) |
| 5412 | { |
| 5413 | WARN_ON(in_interrupt()); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5414 | /* put off any impending NetWatchDogTimeout */ |
Florian Westphal | 860e953 | 2016-05-03 16:33:13 +0200 | [diff] [blame] | 5415 | netif_trans_update(adapter->netdev); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5416 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5417 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 5418 | usleep_range(1000, 2000); |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 5419 | if (adapter->hw.phy.type == ixgbe_phy_fw) |
| 5420 | ixgbe_watchdog_link_is_down(adapter); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5421 | ixgbe_down(adapter); |
Greg Rose | 5809a1a | 2010-03-24 09:36:08 +0000 | [diff] [blame] | 5422 | /* |
| 5423 | * If SR-IOV enabled then wait a bit before bringing the adapter |
| 5424 | * back up to give the VFs time to respond to the reset. The |
| 5425 | * two second wait is based upon the watchdog timer cycle in |
| 5426 | * the VF driver. |
| 5427 | */ |
| 5428 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 5429 | msleep(2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5430 | ixgbe_up(adapter); |
| 5431 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
| 5432 | } |
| 5433 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 5434 | void ixgbe_up(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5435 | { |
| 5436 | /* hardware has been reset, we need to reload some things */ |
| 5437 | ixgbe_configure(adapter); |
| 5438 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 5439 | ixgbe_up_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5440 | } |
| 5441 | |
| 5442 | void ixgbe_reset(struct ixgbe_adapter *adapter) |
| 5443 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5444 | struct ixgbe_hw *hw = &adapter->hw; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 5445 | struct net_device *netdev = adapter->netdev; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 5446 | int err; |
| 5447 | |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 5448 | if (ixgbe_removed(hw->hw_addr)) |
| 5449 | return; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5450 | /* lock SFP init bit to prevent race conditions with the watchdog */ |
| 5451 | while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 5452 | usleep_range(1000, 2000); |
| 5453 | |
| 5454 | /* clear all SFP and link config related flags while holding SFP_INIT */ |
| 5455 | adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP | |
| 5456 | IXGBE_FLAG2_SFP_NEEDS_RESET); |
| 5457 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 5458 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 5459 | err = hw->mac.ops.init_hw(hw); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5460 | switch (err) { |
| 5461 | case 0: |
| 5462 | case IXGBE_ERR_SFP_NOT_PRESENT: |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5463 | case IXGBE_ERR_SFP_NOT_SUPPORTED: |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5464 | break; |
| 5465 | case IXGBE_ERR_MASTER_REQUESTS_PENDING: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5466 | e_dev_err("master disable timed out\n"); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5467 | break; |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 5468 | case IXGBE_ERR_EEPROM_VERSION: |
| 5469 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5470 | e_dev_warn("This device is a pre-production adapter/LOM. " |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 5471 | "Please be aware there may be issues associated with " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5472 | "your hardware. If you are experiencing problems " |
| 5473 | "please contact your Intel or hardware " |
| 5474 | "representative who provided you with this " |
| 5475 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 5476 | break; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5477 | default: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5478 | e_dev_err("Hardware Error: %d\n", err); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5479 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5480 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5481 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
Alexander Duyck | 0f079d2 | 2015-10-22 16:26:36 -0700 | [diff] [blame] | 5482 | |
| 5483 | /* flush entries out of MAC table */ |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 5484 | ixgbe_flush_sw_mac_table(adapter); |
Alexander Duyck | 0f079d2 | 2015-10-22 16:26:36 -0700 | [diff] [blame] | 5485 | __dev_uc_unsync(netdev, NULL); |
| 5486 | |
| 5487 | /* do not flush user set addresses */ |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 5488 | ixgbe_mac_set_default_filter(adapter); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 5489 | |
| 5490 | /* update SAN MAC vmdq pool selection */ |
| 5491 | if (hw->mac.san_mac_rar_index) |
| 5492 | hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0)); |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 5493 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 5494 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 5495 | ixgbe_ptp_reset(adapter); |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 5496 | |
| 5497 | if (hw->phy.ops.set_phy_power) { |
| 5498 | if (!netif_running(adapter->netdev) && !adapter->wol) |
| 5499 | hw->phy.ops.set_phy_power(hw, false); |
| 5500 | else |
| 5501 | hw->phy.ops.set_phy_power(hw, true); |
| 5502 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5503 | } |
| 5504 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5505 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5506 | * ixgbe_clean_tx_ring - Free Tx Buffers |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5507 | * @tx_ring: ring to be cleaned |
| 5508 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5509 | static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5510 | { |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5511 | u16 i = tx_ring->next_to_clean; |
| 5512 | struct ixgbe_tx_buffer *tx_buffer = &tx_ring->tx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5513 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5514 | while (i != tx_ring->next_to_use) { |
| 5515 | union ixgbe_adv_tx_desc *eop_desc, *tx_desc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5516 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5517 | /* Free all the Tx ring sk_buffs */ |
| 5518 | dev_kfree_skb_any(tx_buffer->skb); |
| 5519 | |
| 5520 | /* unmap skb header data */ |
| 5521 | dma_unmap_single(tx_ring->dev, |
| 5522 | dma_unmap_addr(tx_buffer, dma), |
| 5523 | dma_unmap_len(tx_buffer, len), |
| 5524 | DMA_TO_DEVICE); |
| 5525 | |
| 5526 | /* check for eop_desc to determine the end of the packet */ |
| 5527 | eop_desc = tx_buffer->next_to_watch; |
| 5528 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
| 5529 | |
| 5530 | /* unmap remaining buffers */ |
| 5531 | while (tx_desc != eop_desc) { |
| 5532 | tx_buffer++; |
| 5533 | tx_desc++; |
| 5534 | i++; |
| 5535 | if (unlikely(i == tx_ring->count)) { |
| 5536 | i = 0; |
| 5537 | tx_buffer = tx_ring->tx_buffer_info; |
| 5538 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
| 5539 | } |
| 5540 | |
| 5541 | /* unmap any remaining paged data */ |
| 5542 | if (dma_unmap_len(tx_buffer, len)) |
| 5543 | dma_unmap_page(tx_ring->dev, |
| 5544 | dma_unmap_addr(tx_buffer, dma), |
| 5545 | dma_unmap_len(tx_buffer, len), |
| 5546 | DMA_TO_DEVICE); |
| 5547 | } |
| 5548 | |
| 5549 | /* move us one more past the eop_desc for start of next pkt */ |
| 5550 | tx_buffer++; |
| 5551 | i++; |
| 5552 | if (unlikely(i == tx_ring->count)) { |
| 5553 | i = 0; |
| 5554 | tx_buffer = tx_ring->tx_buffer_info; |
| 5555 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5556 | } |
| 5557 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5558 | /* reset BQL for queue */ |
John Fastabend | dad8a3b | 2012-04-23 12:22:39 +0000 | [diff] [blame] | 5559 | netdev_tx_reset_queue(txring_txq(tx_ring)); |
| 5560 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5561 | /* reset next_to_use and next_to_clean */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5562 | tx_ring->next_to_use = 0; |
| 5563 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5564 | } |
| 5565 | |
| 5566 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5567 | * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues |
| 5568 | * @adapter: board private structure |
| 5569 | **/ |
| 5570 | static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter) |
| 5571 | { |
| 5572 | int i; |
| 5573 | |
| 5574 | for (i = 0; i < adapter->num_rx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5575 | ixgbe_clean_rx_ring(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5576 | } |
| 5577 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5578 | /** |
| 5579 | * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues |
| 5580 | * @adapter: board private structure |
| 5581 | **/ |
| 5582 | static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter) |
| 5583 | { |
| 5584 | int i; |
| 5585 | |
| 5586 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5587 | ixgbe_clean_tx_ring(adapter->tx_ring[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5588 | } |
| 5589 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5590 | static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter) |
| 5591 | { |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 5592 | struct hlist_node *node2; |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5593 | struct ixgbe_fdir_filter *filter; |
| 5594 | |
| 5595 | spin_lock(&adapter->fdir_perfect_lock); |
| 5596 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 5597 | hlist_for_each_entry_safe(filter, node2, |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5598 | &adapter->fdir_filter_list, fdir_node) { |
| 5599 | hlist_del(&filter->fdir_node); |
| 5600 | kfree(filter); |
| 5601 | } |
| 5602 | adapter->fdir_filter_count = 0; |
| 5603 | |
| 5604 | spin_unlock(&adapter->fdir_perfect_lock); |
| 5605 | } |
| 5606 | |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 5607 | static int ixgbe_disable_macvlan(struct net_device *upper, void *data) |
| 5608 | { |
| 5609 | if (netif_is_macvlan(upper)) { |
| 5610 | struct macvlan_dev *vlan = netdev_priv(upper); |
| 5611 | |
| 5612 | if (vlan->fwd_priv) { |
| 5613 | netif_tx_stop_all_queues(upper); |
| 5614 | netif_carrier_off(upper); |
| 5615 | netif_tx_disable(upper); |
| 5616 | } |
| 5617 | } |
| 5618 | |
| 5619 | return 0; |
| 5620 | } |
| 5621 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5622 | void ixgbe_down(struct ixgbe_adapter *adapter) |
| 5623 | { |
| 5624 | struct net_device *netdev = adapter->netdev; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5625 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 5626 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5627 | |
| 5628 | /* signal that we are down to the interrupt handler */ |
Mark Rustad | c3049c8 | 2014-01-14 18:53:12 -0800 | [diff] [blame] | 5629 | if (test_and_set_bit(__IXGBE_DOWN, &adapter->state)) |
| 5630 | return; /* do nothing if already down */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5631 | |
| 5632 | /* disable receives */ |
Don Skidmore | 1f9ac57 | 2015-03-13 13:54:30 -0700 | [diff] [blame] | 5633 | hw->mac.ops.disable_rx(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5634 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 5635 | /* disable all enabled rx queues */ |
| 5636 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 5637 | /* this call also flushes the previous write */ |
| 5638 | ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]); |
| 5639 | |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 5640 | usleep_range(10000, 20000); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5641 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5642 | netif_tx_stop_all_queues(netdev); |
| 5643 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5644 | /* call carrier off first to avoid false dev_watchdog timeouts */ |
John Fastabend | c0dfb90 | 2010-04-27 02:13:39 +0000 | [diff] [blame] | 5645 | netif_carrier_off(netdev); |
| 5646 | netif_tx_disable(netdev); |
| 5647 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5648 | /* disable any upper devices */ |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 5649 | netdev_walk_all_upper_dev_rcu(adapter->netdev, |
| 5650 | ixgbe_disable_macvlan, NULL); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5651 | |
John Fastabend | c0dfb90 | 2010-04-27 02:13:39 +0000 | [diff] [blame] | 5652 | ixgbe_irq_disable(adapter); |
| 5653 | |
| 5654 | ixgbe_napi_disable_all(adapter); |
| 5655 | |
Emil Tantilov | 57ca2a4 | 2016-07-29 14:46:31 -0700 | [diff] [blame] | 5656 | clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state); |
| 5657 | adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5658 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 5659 | |
| 5660 | del_timer_sync(&adapter->service_timer); |
| 5661 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 5662 | if (adapter->num_vfs) { |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 5663 | /* Clear EITR Select mapping */ |
| 5664 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0); |
| 5665 | |
| 5666 | /* Mark all the VFs as inactive */ |
| 5667 | for (i = 0 ; i < adapter->num_vfs; i++) |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 5668 | adapter->vfinfo[i].clear_to_send = false; |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 5669 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 5670 | /* ping all the active vfs to let them know we are going down */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5671 | ixgbe_ping_all_vfs(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5672 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5673 | /* Disable all VFTE/VFRE TX/RX */ |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 5674 | ixgbe_disable_tx_rx(adapter); |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 5675 | } |
| 5676 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5677 | /* disable transmits in the hardware now that interrupts are off */ |
| 5678 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 5679 | u8 reg_idx = adapter->tx_ring[i]->reg_idx; |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 5680 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5681 | } |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 5682 | |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5683 | /* Disable the Tx DMA engine on 82599 and later MAC */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5684 | switch (hw->mac.type) { |
| 5685 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5686 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5687 | case ixgbe_mac_X550: |
| 5688 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 5689 | case ixgbe_mac_x550em_a: |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 5690 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 5691 | (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) & |
| 5692 | ~IXGBE_DMATXCTL_TE)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5693 | break; |
| 5694 | default: |
| 5695 | break; |
| 5696 | } |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5697 | |
Paul Larson | 6f4a0e4 | 2008-06-24 17:00:56 -0700 | [diff] [blame] | 5698 | if (!pci_channel_offline(adapter->pdev)) |
| 5699 | ixgbe_reset(adapter); |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 5700 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 5701 | /* power down the optics for 82599 SFP+ fiber */ |
| 5702 | if (hw->mac.ops.disable_tx_laser) |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 5703 | hw->mac.ops.disable_tx_laser(hw); |
| 5704 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5705 | ixgbe_clean_all_tx_rings(adapter); |
| 5706 | ixgbe_clean_all_rx_rings(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5707 | } |
| 5708 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5709 | /** |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 5710 | * ixgbe_eee_capable - helper function to determine EEE support on X550 |
| 5711 | * @adapter: board private structure |
| 5712 | */ |
| 5713 | static void ixgbe_set_eee_capable(struct ixgbe_adapter *adapter) |
| 5714 | { |
| 5715 | struct ixgbe_hw *hw = &adapter->hw; |
| 5716 | |
| 5717 | switch (hw->device_id) { |
| 5718 | case IXGBE_DEV_ID_X550EM_A_1G_T: |
| 5719 | case IXGBE_DEV_ID_X550EM_A_1G_T_L: |
| 5720 | if (!hw->phy.eee_speeds_supported) |
| 5721 | break; |
| 5722 | adapter->flags2 |= IXGBE_FLAG2_EEE_CAPABLE; |
| 5723 | if (!hw->phy.eee_speeds_advertised) |
| 5724 | break; |
| 5725 | adapter->flags2 |= IXGBE_FLAG2_EEE_ENABLED; |
| 5726 | break; |
| 5727 | default: |
| 5728 | adapter->flags2 &= ~IXGBE_FLAG2_EEE_CAPABLE; |
| 5729 | adapter->flags2 &= ~IXGBE_FLAG2_EEE_ENABLED; |
| 5730 | break; |
| 5731 | } |
| 5732 | } |
| 5733 | |
| 5734 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5735 | * ixgbe_tx_timeout - Respond to a Tx Hang |
| 5736 | * @netdev: network interface device structure |
| 5737 | **/ |
| 5738 | static void ixgbe_tx_timeout(struct net_device *netdev) |
| 5739 | { |
| 5740 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5741 | |
| 5742 | /* Do the reset outside of interrupt context */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 5743 | ixgbe_tx_timeout_reset(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5744 | } |
| 5745 | |
Usha Ketineni | 8829009 | 2016-04-26 05:00:26 -0700 | [diff] [blame] | 5746 | #ifdef CONFIG_IXGBE_DCB |
| 5747 | static void ixgbe_init_dcb(struct ixgbe_adapter *adapter) |
| 5748 | { |
| 5749 | struct ixgbe_hw *hw = &adapter->hw; |
| 5750 | struct tc_configuration *tc; |
| 5751 | int j; |
| 5752 | |
| 5753 | switch (hw->mac.type) { |
| 5754 | case ixgbe_mac_82598EB: |
| 5755 | case ixgbe_mac_82599EB: |
| 5756 | adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS; |
| 5757 | adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS; |
| 5758 | break; |
| 5759 | case ixgbe_mac_X540: |
| 5760 | case ixgbe_mac_X550: |
| 5761 | adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS; |
| 5762 | adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS; |
| 5763 | break; |
| 5764 | case ixgbe_mac_X550EM_x: |
| 5765 | case ixgbe_mac_x550em_a: |
| 5766 | default: |
| 5767 | adapter->dcb_cfg.num_tcs.pg_tcs = DEF_TRAFFIC_CLASS; |
| 5768 | adapter->dcb_cfg.num_tcs.pfc_tcs = DEF_TRAFFIC_CLASS; |
| 5769 | break; |
| 5770 | } |
| 5771 | |
| 5772 | /* Configure DCB traffic classes */ |
| 5773 | for (j = 0; j < MAX_TRAFFIC_CLASS; j++) { |
| 5774 | tc = &adapter->dcb_cfg.tc_config[j]; |
| 5775 | tc->path[DCB_TX_CONFIG].bwg_id = 0; |
| 5776 | tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1); |
| 5777 | tc->path[DCB_RX_CONFIG].bwg_id = 0; |
| 5778 | tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1); |
| 5779 | tc->dcb_pfc = pfc_disabled; |
| 5780 | } |
| 5781 | |
| 5782 | /* Initialize default user to priority mapping, UPx->TC0 */ |
| 5783 | tc = &adapter->dcb_cfg.tc_config[0]; |
| 5784 | tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF; |
| 5785 | tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF; |
| 5786 | |
| 5787 | adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100; |
| 5788 | adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100; |
| 5789 | adapter->dcb_cfg.pfc_mode_enable = false; |
| 5790 | adapter->dcb_set_bitmap = 0x00; |
| 5791 | if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE) |
| 5792 | adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE; |
| 5793 | memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg, |
| 5794 | sizeof(adapter->temp_dcb_cfg)); |
| 5795 | } |
| 5796 | #endif |
| 5797 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 5798 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5799 | * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter) |
| 5800 | * @adapter: board private structure to initialize |
| 5801 | * |
| 5802 | * ixgbe_sw_init initializes the Adapter private data structure. |
| 5803 | * Fields are initialized based on PCI device information and |
| 5804 | * OS network device settings (MTU size). |
| 5805 | **/ |
Emil Tantilov | 55570b6 | 2016-10-12 12:34:25 -0700 | [diff] [blame] | 5806 | static int ixgbe_sw_init(struct ixgbe_adapter *adapter, |
| 5807 | const struct ixgbe_info *ii) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5808 | { |
| 5809 | struct ixgbe_hw *hw = &adapter->hw; |
| 5810 | struct pci_dev *pdev = adapter->pdev; |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 5811 | unsigned int rss, fdir; |
Jacob Keller | cb6d0f5 | 2012-12-04 06:03:14 +0000 | [diff] [blame] | 5812 | u32 fwsm; |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 5813 | int i; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5814 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5815 | /* PCI config space info */ |
| 5816 | |
| 5817 | hw->vendor_id = pdev->vendor; |
| 5818 | hw->device_id = pdev->device; |
| 5819 | hw->revision_id = pdev->revision; |
| 5820 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 5821 | hw->subsystem_device_id = pdev->subsystem_device; |
| 5822 | |
Emil Tantilov | 55570b6 | 2016-10-12 12:34:25 -0700 | [diff] [blame] | 5823 | /* get_invariants needs the device IDs */ |
| 5824 | ii->get_invariants(hw); |
| 5825 | |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5826 | /* Set common capability flags and settings */ |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 5827 | rss = min_t(int, ixgbe_max_rss_indices(adapter), num_online_cpus()); |
Alexander Duyck | c087663 | 2012-05-10 00:01:46 +0000 | [diff] [blame] | 5828 | adapter->ring_feature[RING_F_RSS].limit = rss; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5829 | adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5830 | adapter->max_q_vectors = MAX_Q_VECTORS_82599; |
| 5831 | adapter->atr_sample_rate = 20; |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 5832 | fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus()); |
| 5833 | adapter->ring_feature[RING_F_FDIR].limit = fdir; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5834 | adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K; |
| 5835 | #ifdef CONFIG_IXGBE_DCA |
| 5836 | adapter->flags |= IXGBE_FLAG_DCA_CAPABLE; |
| 5837 | #endif |
Usha Ketineni | 8829009 | 2016-04-26 05:00:26 -0700 | [diff] [blame] | 5838 | #ifdef CONFIG_IXGBE_DCB |
| 5839 | adapter->flags |= IXGBE_FLAG_DCB_CAPABLE; |
| 5840 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
| 5841 | #endif |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5842 | #ifdef IXGBE_FCOE |
| 5843 | adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE; |
| 5844 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 5845 | #ifdef CONFIG_IXGBE_DCB |
| 5846 | /* Default traffic class to use for FCoE */ |
| 5847 | adapter->fcoe.up = IXGBE_FCOE_DEFTC; |
| 5848 | #endif /* CONFIG_IXGBE_DCB */ |
| 5849 | #endif /* IXGBE_FCOE */ |
| 5850 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 5851 | /* initialize static ixgbe jump table entries */ |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 5852 | adapter->jump_tables[0] = kzalloc(sizeof(*adapter->jump_tables[0]), |
| 5853 | GFP_KERNEL); |
| 5854 | if (!adapter->jump_tables[0]) |
| 5855 | return -ENOMEM; |
| 5856 | adapter->jump_tables[0]->mat = ixgbe_ipv4_fields; |
| 5857 | |
| 5858 | for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) |
| 5859 | adapter->jump_tables[i] = NULL; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 5860 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 5861 | adapter->mac_table = kzalloc(sizeof(struct ixgbe_mac_addr) * |
| 5862 | hw->mac.num_rar_entries, |
| 5863 | GFP_ATOMIC); |
Alexander Duyck | 530fd82 | 2015-11-02 17:09:29 -0800 | [diff] [blame] | 5864 | if (!adapter->mac_table) |
| 5865 | return -ENOMEM; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 5866 | |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5867 | /* Set MAC specific capability flags and exceptions */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5868 | switch (hw->mac.type) { |
| 5869 | case ixgbe_mac_82598EB: |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5870 | adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5871 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5872 | if (hw->device_id == IXGBE_DEV_ID_82598AT) |
| 5873 | adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5874 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 5875 | adapter->max_q_vectors = MAX_Q_VECTORS_82598; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5876 | adapter->ring_feature[RING_F_FDIR].limit = 0; |
| 5877 | adapter->atr_sample_rate = 0; |
| 5878 | adapter->fdir_pballoc = 0; |
| 5879 | #ifdef IXGBE_FCOE |
| 5880 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
| 5881 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 5882 | #ifdef CONFIG_IXGBE_DCB |
| 5883 | adapter->fcoe.up = 0; |
| 5884 | #endif /* IXGBE_DCB */ |
| 5885 | #endif /* IXGBE_FCOE */ |
| 5886 | break; |
| 5887 | case ixgbe_mac_82599EB: |
| 5888 | if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM) |
| 5889 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5890 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5891 | case ixgbe_mac_X540: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 5892 | fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw)); |
Jacob Keller | cb6d0f5 | 2012-12-04 06:03:14 +0000 | [diff] [blame] | 5893 | if (fwsm & IXGBE_FWSM_TS_ENABLED) |
| 5894 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5895 | break; |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 5896 | case ixgbe_mac_x550em_a: |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 5897 | adapter->flags |= IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE; |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 5898 | switch (hw->device_id) { |
| 5899 | case IXGBE_DEV_ID_X550EM_A_1G_T: |
| 5900 | case IXGBE_DEV_ID_X550EM_A_1G_T_L: |
| 5901 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
| 5902 | break; |
| 5903 | default: |
| 5904 | break; |
| 5905 | } |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 5906 | /* fall through */ |
| 5907 | case ixgbe_mac_X550EM_x: |
Usha Ketineni | 8829009 | 2016-04-26 05:00:26 -0700 | [diff] [blame] | 5908 | #ifdef CONFIG_IXGBE_DCB |
| 5909 | adapter->flags &= ~IXGBE_FLAG_DCB_CAPABLE; |
| 5910 | #endif |
| 5911 | #ifdef IXGBE_FCOE |
| 5912 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
| 5913 | #ifdef CONFIG_IXGBE_DCB |
| 5914 | adapter->fcoe.up = 0; |
| 5915 | #endif /* IXGBE_DCB */ |
| 5916 | #endif /* IXGBE_FCOE */ |
| 5917 | /* Fall Through */ |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5918 | case ixgbe_mac_X550: |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 5919 | if (hw->mac.type == ixgbe_mac_X550) |
| 5920 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5921 | #ifdef CONFIG_IXGBE_DCA |
| 5922 | adapter->flags &= ~IXGBE_FLAG_DCA_CAPABLE; |
| 5923 | #endif |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 5924 | adapter->flags |= IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE; |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5925 | break; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5926 | default: |
| 5927 | break; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5928 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5929 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 5930 | #ifdef IXGBE_FCOE |
| 5931 | /* FCoE support exists, always init the FCoE lock */ |
| 5932 | spin_lock_init(&adapter->fcoe.lock); |
| 5933 | |
| 5934 | #endif |
Alexander Duyck | 1fc5f03 | 2011-06-02 04:28:39 +0000 | [diff] [blame] | 5935 | /* n-tuple support exists, always init our spinlock */ |
| 5936 | spin_lock_init(&adapter->fdir_perfect_lock); |
| 5937 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5938 | #ifdef CONFIG_IXGBE_DCB |
Usha Ketineni | 8829009 | 2016-04-26 05:00:26 -0700 | [diff] [blame] | 5939 | ixgbe_init_dcb(adapter); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5940 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5941 | |
| 5942 | /* default flow control settings */ |
Don Skidmore | cd7664f | 2009-03-31 21:33:44 +0000 | [diff] [blame] | 5943 | hw->fc.requested_mode = ixgbe_fc_full; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 5944 | hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */ |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5945 | ixgbe_pbthresh_setup(adapter); |
Jesse Brandeburg | 2b9ade9 | 2008-08-26 04:27:10 -0700 | [diff] [blame] | 5946 | hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE; |
| 5947 | hw->fc.send_xon = true; |
Don Skidmore | 73d80953d | 2013-07-31 02:19:24 +0000 | [diff] [blame] | 5948 | hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5949 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 5950 | #ifdef CONFIG_PCI_IOV |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 5951 | if (max_vfs > 0) |
| 5952 | e_dev_warn("Enabling SR-IOV VFs using the max_vfs module parameter is deprecated - please use the pci sysfs interface instead.\n"); |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 5953 | |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 5954 | /* assign number of SR-IOV VFs */ |
| 5955 | if (hw->mac.type != ixgbe_mac_82598EB) { |
ethan.zhao | dcc23e3 | 2014-01-16 19:41:04 -0800 | [diff] [blame] | 5956 | if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) { |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 5957 | adapter->num_vfs = 0; |
| 5958 | e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n"); |
| 5959 | } else { |
| 5960 | adapter->num_vfs = max_vfs; |
| 5961 | } |
| 5962 | } |
| 5963 | #endif /* CONFIG_PCI_IOV */ |
| 5964 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5965 | /* enable itr by default in dynamic mode */ |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 5966 | adapter->rx_itr_setting = 1; |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 5967 | adapter->tx_itr_setting = 1; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5968 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5969 | /* set default ring sizes */ |
| 5970 | adapter->tx_ring_count = IXGBE_DEFAULT_TXD; |
| 5971 | adapter->rx_ring_count = IXGBE_DEFAULT_RXD; |
| 5972 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 5973 | /* set default work limits */ |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 5974 | adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 5975 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5976 | /* initialize eeprom parameters */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5977 | if (ixgbe_init_eeprom_params_generic(hw)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5978 | e_dev_err("EEPROM initialization failed\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5979 | return -EIO; |
| 5980 | } |
| 5981 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5982 | /* PF holds first pool slot */ |
| 5983 | set_bit(0, &adapter->fwd_bitmask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5984 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 5985 | |
| 5986 | return 0; |
| 5987 | } |
| 5988 | |
| 5989 | /** |
| 5990 | * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5991 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5992 | * |
| 5993 | * Return 0 on success, negative on failure |
| 5994 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5995 | int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5996 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5997 | struct device *dev = tx_ring->dev; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5998 | int orig_node = dev_to_node(dev); |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5999 | int ring_node = -1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6000 | int size; |
| 6001 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 6002 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 6003 | |
| 6004 | if (tx_ring->q_vector) |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 6005 | ring_node = tx_ring->q_vector->numa_node; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 6006 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 6007 | tx_ring->tx_buffer_info = vmalloc_node(size, ring_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 6008 | if (!tx_ring->tx_buffer_info) |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 6009 | tx_ring->tx_buffer_info = vmalloc(size); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 6010 | if (!tx_ring->tx_buffer_info) |
| 6011 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6012 | |
John Stultz | 827da44 | 2013-10-07 15:51:58 -0700 | [diff] [blame] | 6013 | u64_stats_init(&tx_ring->syncp); |
| 6014 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6015 | /* round up to nearest 4K */ |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 6016 | tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 6017 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6018 | |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 6019 | set_dev_node(dev, ring_node); |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 6020 | tx_ring->desc = dma_alloc_coherent(dev, |
| 6021 | tx_ring->size, |
| 6022 | &tx_ring->dma, |
| 6023 | GFP_KERNEL); |
| 6024 | set_dev_node(dev, orig_node); |
| 6025 | if (!tx_ring->desc) |
| 6026 | tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size, |
| 6027 | &tx_ring->dma, GFP_KERNEL); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 6028 | if (!tx_ring->desc) |
| 6029 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6030 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 6031 | tx_ring->next_to_use = 0; |
| 6032 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6033 | return 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 6034 | |
| 6035 | err: |
| 6036 | vfree(tx_ring->tx_buffer_info); |
| 6037 | tx_ring->tx_buffer_info = NULL; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6038 | dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n"); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 6039 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6040 | } |
| 6041 | |
| 6042 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6043 | * ixgbe_setup_all_tx_resources - allocate all queues Tx resources |
| 6044 | * @adapter: board private structure |
| 6045 | * |
| 6046 | * If this function returns with an error, then it's possible one or |
| 6047 | * more of the rings is populated (while the rest are not). It is the |
| 6048 | * callers duty to clean those orphaned rings. |
| 6049 | * |
| 6050 | * Return 0 on success, negative on failure |
| 6051 | **/ |
| 6052 | static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) |
| 6053 | { |
| 6054 | int i, err = 0; |
| 6055 | |
| 6056 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6057 | err = ixgbe_setup_tx_resources(adapter->tx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6058 | if (!err) |
| 6059 | continue; |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6060 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 6061 | e_err(probe, "Allocation for Tx Queue %u failed\n", i); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6062 | goto err_setup_tx; |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6063 | } |
| 6064 | |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6065 | return 0; |
| 6066 | err_setup_tx: |
| 6067 | /* rewind the index freeing the rings as we go */ |
| 6068 | while (i--) |
| 6069 | ixgbe_free_tx_resources(adapter->tx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6070 | return err; |
| 6071 | } |
| 6072 | |
| 6073 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6074 | * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 6075 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6076 | * |
| 6077 | * Returns 0 on success, negative on failure |
| 6078 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6079 | int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6080 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6081 | struct device *dev = rx_ring->dev; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 6082 | int orig_node = dev_to_node(dev); |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 6083 | int ring_node = -1; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6084 | int size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6085 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 6086 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 6087 | |
| 6088 | if (rx_ring->q_vector) |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 6089 | ring_node = rx_ring->q_vector->numa_node; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 6090 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 6091 | rx_ring->rx_buffer_info = vmalloc_node(size, ring_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 6092 | if (!rx_ring->rx_buffer_info) |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 6093 | rx_ring->rx_buffer_info = vmalloc(size); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6094 | if (!rx_ring->rx_buffer_info) |
| 6095 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6096 | |
John Stultz | 827da44 | 2013-10-07 15:51:58 -0700 | [diff] [blame] | 6097 | u64_stats_init(&rx_ring->syncp); |
| 6098 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6099 | /* Round up to nearest 4K */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 6100 | rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); |
| 6101 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6102 | |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 6103 | set_dev_node(dev, ring_node); |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 6104 | rx_ring->desc = dma_alloc_coherent(dev, |
| 6105 | rx_ring->size, |
| 6106 | &rx_ring->dma, |
| 6107 | GFP_KERNEL); |
| 6108 | set_dev_node(dev, orig_node); |
| 6109 | if (!rx_ring->desc) |
| 6110 | rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size, |
| 6111 | &rx_ring->dma, GFP_KERNEL); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6112 | if (!rx_ring->desc) |
| 6113 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6114 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 6115 | rx_ring->next_to_clean = 0; |
| 6116 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6117 | |
| 6118 | return 0; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6119 | err: |
| 6120 | vfree(rx_ring->rx_buffer_info); |
| 6121 | rx_ring->rx_buffer_info = NULL; |
| 6122 | dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n"); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 6123 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6124 | } |
| 6125 | |
| 6126 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6127 | * ixgbe_setup_all_rx_resources - allocate all queues Rx resources |
| 6128 | * @adapter: board private structure |
| 6129 | * |
| 6130 | * If this function returns with an error, then it's possible one or |
| 6131 | * more of the rings is populated (while the rest are not). It is the |
| 6132 | * callers duty to clean those orphaned rings. |
| 6133 | * |
| 6134 | * Return 0 on success, negative on failure |
| 6135 | **/ |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6136 | static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) |
| 6137 | { |
| 6138 | int i, err = 0; |
| 6139 | |
| 6140 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6141 | err = ixgbe_setup_rx_resources(adapter->rx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6142 | if (!err) |
| 6143 | continue; |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6144 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 6145 | e_err(probe, "Allocation for Rx Queue %u failed\n", i); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6146 | goto err_setup_rx; |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6147 | } |
| 6148 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 6149 | #ifdef IXGBE_FCOE |
| 6150 | err = ixgbe_setup_fcoe_ddp_resources(adapter); |
| 6151 | if (!err) |
| 6152 | #endif |
| 6153 | return 0; |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6154 | err_setup_rx: |
| 6155 | /* rewind the index freeing the rings as we go */ |
| 6156 | while (i--) |
| 6157 | ixgbe_free_rx_resources(adapter->rx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6158 | return err; |
| 6159 | } |
| 6160 | |
| 6161 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6162 | * ixgbe_free_tx_resources - Free Tx Resources per Queue |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6163 | * @tx_ring: Tx descriptor ring for a specific queue |
| 6164 | * |
| 6165 | * Free all transmit software resources |
| 6166 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6167 | void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6168 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6169 | ixgbe_clean_tx_ring(tx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6170 | |
| 6171 | vfree(tx_ring->tx_buffer_info); |
| 6172 | tx_ring->tx_buffer_info = NULL; |
| 6173 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6174 | /* if not set, then don't free */ |
| 6175 | if (!tx_ring->desc) |
| 6176 | return; |
| 6177 | |
| 6178 | dma_free_coherent(tx_ring->dev, tx_ring->size, |
| 6179 | tx_ring->desc, tx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6180 | |
| 6181 | tx_ring->desc = NULL; |
| 6182 | } |
| 6183 | |
| 6184 | /** |
| 6185 | * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues |
| 6186 | * @adapter: board private structure |
| 6187 | * |
| 6188 | * Free all transmit software resources |
| 6189 | **/ |
| 6190 | static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter) |
| 6191 | { |
| 6192 | int i; |
| 6193 | |
| 6194 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 6195 | if (adapter->tx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6196 | ixgbe_free_tx_resources(adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6197 | } |
| 6198 | |
| 6199 | /** |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6200 | * ixgbe_free_rx_resources - Free Rx Resources |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6201 | * @rx_ring: ring to clean the resources from |
| 6202 | * |
| 6203 | * Free all receive software resources |
| 6204 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6205 | void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6206 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6207 | ixgbe_clean_rx_ring(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6208 | |
| 6209 | vfree(rx_ring->rx_buffer_info); |
| 6210 | rx_ring->rx_buffer_info = NULL; |
| 6211 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6212 | /* if not set, then don't free */ |
| 6213 | if (!rx_ring->desc) |
| 6214 | return; |
| 6215 | |
| 6216 | dma_free_coherent(rx_ring->dev, rx_ring->size, |
| 6217 | rx_ring->desc, rx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6218 | |
| 6219 | rx_ring->desc = NULL; |
| 6220 | } |
| 6221 | |
| 6222 | /** |
| 6223 | * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues |
| 6224 | * @adapter: board private structure |
| 6225 | * |
| 6226 | * Free all receive software resources |
| 6227 | **/ |
| 6228 | static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter) |
| 6229 | { |
| 6230 | int i; |
| 6231 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 6232 | #ifdef IXGBE_FCOE |
| 6233 | ixgbe_free_fcoe_ddp_resources(adapter); |
| 6234 | |
| 6235 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6236 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 6237 | if (adapter->rx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6238 | ixgbe_free_rx_resources(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6239 | } |
| 6240 | |
| 6241 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6242 | * ixgbe_change_mtu - Change the Maximum Transfer Unit |
| 6243 | * @netdev: network interface device structure |
| 6244 | * @new_mtu: new value for maximum frame size |
| 6245 | * |
| 6246 | * Returns 0 on success, negative on failure |
| 6247 | **/ |
| 6248 | static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu) |
| 6249 | { |
| 6250 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 655309e | 2012-02-08 07:50:35 +0000 | [diff] [blame] | 6251 | |
| 6252 | /* |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 6253 | * For 82599EB we cannot allow legacy VFs to enable their receive |
| 6254 | * paths when MTU greater than 1500 is configured. So display a |
| 6255 | * warning that legacy VFs will be disabled. |
Alexander Duyck | 655309e | 2012-02-08 07:50:35 +0000 | [diff] [blame] | 6256 | */ |
| 6257 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && |
| 6258 | (adapter->hw.mac.type == ixgbe_mac_82599EB) && |
Jarod Wilson | 91c527a | 2016-10-17 15:54:05 -0400 | [diff] [blame] | 6259 | (new_mtu > ETH_DATA_LEN)) |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 6260 | e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6261 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 6262 | e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu); |
Alexander Duyck | 655309e | 2012-02-08 07:50:35 +0000 | [diff] [blame] | 6263 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6264 | /* must set new MTU before calling down or up */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6265 | netdev->mtu = new_mtu; |
| 6266 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 6267 | if (netif_running(netdev)) |
| 6268 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6269 | |
| 6270 | return 0; |
| 6271 | } |
| 6272 | |
| 6273 | /** |
| 6274 | * ixgbe_open - Called when a network interface is made active |
| 6275 | * @netdev: network interface device structure |
| 6276 | * |
| 6277 | * Returns 0 on success, negative value on failure |
| 6278 | * |
| 6279 | * The open entry point is called when a network interface is made |
| 6280 | * active by the system (IFF_UP). At this point all resources needed |
| 6281 | * for transmit and receive operations are allocated, the interrupt |
| 6282 | * handler is registered with the OS, the watchdog timer is started, |
| 6283 | * and the stack is notified that the interface is ready. |
| 6284 | **/ |
Stefan Assmann | 6c211fe1 | 2016-02-03 09:20:48 +0100 | [diff] [blame] | 6285 | int ixgbe_open(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6286 | { |
| 6287 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 6288 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 6289 | int err, queues; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6290 | |
Auke Kok | 4bebfaa | 2008-02-11 09:26:01 -0800 | [diff] [blame] | 6291 | /* disallow open during test */ |
| 6292 | if (test_bit(__IXGBE_TESTING, &adapter->state)) |
| 6293 | return -EBUSY; |
| 6294 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 6295 | netif_carrier_off(netdev); |
| 6296 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6297 | /* allocate transmit descriptors */ |
| 6298 | err = ixgbe_setup_all_tx_resources(adapter); |
| 6299 | if (err) |
| 6300 | goto err_setup_tx; |
| 6301 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6302 | /* allocate receive descriptors */ |
| 6303 | err = ixgbe_setup_all_rx_resources(adapter); |
| 6304 | if (err) |
| 6305 | goto err_setup_rx; |
| 6306 | |
| 6307 | ixgbe_configure(adapter); |
| 6308 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6309 | err = ixgbe_request_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6310 | if (err) |
| 6311 | goto err_req_irq; |
| 6312 | |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6313 | /* Notify the stack of the actual queue counts. */ |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 6314 | if (adapter->num_rx_pools > 1) |
| 6315 | queues = adapter->num_rx_queues_per_pool; |
| 6316 | else |
| 6317 | queues = adapter->num_tx_queues; |
| 6318 | |
| 6319 | err = netif_set_real_num_tx_queues(netdev, queues); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6320 | if (err) |
| 6321 | goto err_set_queues; |
| 6322 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 6323 | if (adapter->num_rx_pools > 1 && |
| 6324 | adapter->num_rx_queues > IXGBE_MAX_L2A_QUEUES) |
| 6325 | queues = IXGBE_MAX_L2A_QUEUES; |
| 6326 | else |
| 6327 | queues = adapter->num_rx_queues; |
| 6328 | err = netif_set_real_num_rx_queues(netdev, queues); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6329 | if (err) |
| 6330 | goto err_set_queues; |
| 6331 | |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6332 | ixgbe_ptp_init(adapter); |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6333 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 6334 | ixgbe_up_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6335 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 6336 | ixgbe_clear_udp_tunnel_port(adapter, IXGBE_VXLANCTRL_ALL_UDPPORT_MASK); |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 6337 | udp_tunnel_get_rx_info(netdev); |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 6338 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6339 | return 0; |
| 6340 | |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6341 | err_set_queues: |
| 6342 | ixgbe_free_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6343 | err_req_irq: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 6344 | ixgbe_free_all_rx_resources(adapter); |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 6345 | if (hw->phy.ops.set_phy_power && !adapter->wol) |
| 6346 | hw->phy.ops.set_phy_power(&adapter->hw, false); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6347 | err_setup_rx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 6348 | ixgbe_free_all_tx_resources(adapter); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6349 | err_setup_tx: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6350 | ixgbe_reset(adapter); |
| 6351 | |
| 6352 | return err; |
| 6353 | } |
| 6354 | |
Jacob Keller | a0cccce | 2014-05-16 05:12:29 +0000 | [diff] [blame] | 6355 | static void ixgbe_close_suspend(struct ixgbe_adapter *adapter) |
| 6356 | { |
| 6357 | ixgbe_ptp_suspend(adapter); |
| 6358 | |
Don Skidmore | 6ac7439 | 2015-06-17 17:34:31 -0400 | [diff] [blame] | 6359 | if (adapter->hw.phy.ops.enter_lplu) { |
| 6360 | adapter->hw.phy.reset_disable = true; |
| 6361 | ixgbe_down(adapter); |
| 6362 | adapter->hw.phy.ops.enter_lplu(&adapter->hw); |
| 6363 | adapter->hw.phy.reset_disable = false; |
| 6364 | } else { |
| 6365 | ixgbe_down(adapter); |
| 6366 | } |
| 6367 | |
Jacob Keller | a0cccce | 2014-05-16 05:12:29 +0000 | [diff] [blame] | 6368 | ixgbe_free_irq(adapter); |
| 6369 | |
| 6370 | ixgbe_free_all_tx_resources(adapter); |
| 6371 | ixgbe_free_all_rx_resources(adapter); |
| 6372 | } |
| 6373 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6374 | /** |
| 6375 | * ixgbe_close - Disables a network interface |
| 6376 | * @netdev: network interface device structure |
| 6377 | * |
| 6378 | * Returns 0, this is not allowed to fail |
| 6379 | * |
| 6380 | * The close entry point is called when an interface is de-activated |
| 6381 | * by the OS. The hardware is still under the drivers control, but |
| 6382 | * needs to be disabled. A global MAC reset is issued to stop the |
| 6383 | * hardware, and all transmit and receive resources are freed. |
| 6384 | **/ |
Stefan Assmann | 6c211fe1 | 2016-02-03 09:20:48 +0100 | [diff] [blame] | 6385 | int ixgbe_close(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6386 | { |
| 6387 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6388 | |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6389 | ixgbe_ptp_stop(adapter); |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6390 | |
Emil Tantilov | f7f37e7 | 2016-11-11 10:07:47 -0800 | [diff] [blame] | 6391 | if (netif_device_present(netdev)) |
| 6392 | ixgbe_close_suspend(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6393 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 6394 | ixgbe_fdir_filter_exit(adapter); |
| 6395 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 6396 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6397 | |
| 6398 | return 0; |
| 6399 | } |
| 6400 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6401 | #ifdef CONFIG_PM |
| 6402 | static int ixgbe_resume(struct pci_dev *pdev) |
| 6403 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 6404 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 6405 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6406 | u32 err; |
| 6407 | |
Mark Rustad | 0391bbe | 2014-02-28 15:48:55 -0800 | [diff] [blame] | 6408 | adapter->hw.hw_addr = adapter->io_addr; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6409 | pci_set_power_state(pdev, PCI_D0); |
| 6410 | pci_restore_state(pdev); |
Don Skidmore | 656ab81 | 2009-12-23 21:19:19 -0800 | [diff] [blame] | 6411 | /* |
| 6412 | * pci_restore_state clears dev->state_saved so call |
| 6413 | * pci_save_state to restore it. |
| 6414 | */ |
| 6415 | pci_save_state(pdev); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 6416 | |
| 6417 | err = pci_enable_device_mem(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6418 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 6419 | e_dev_err("Cannot enable PCI device from suspend\n"); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6420 | return err; |
| 6421 | } |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 6422 | smp_mb__before_atomic(); |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 6423 | clear_bit(__IXGBE_DISABLED, &adapter->state); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6424 | pci_set_master(pdev); |
| 6425 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 6426 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6427 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6428 | ixgbe_reset(adapter); |
| 6429 | |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 6430 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
| 6431 | |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6432 | rtnl_lock(); |
| 6433 | err = ixgbe_init_interrupt_scheme(adapter); |
| 6434 | if (!err && netif_running(netdev)) |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 6435 | err = ixgbe_open(netdev); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6436 | |
Emil Tantilov | f7f37e7 | 2016-11-11 10:07:47 -0800 | [diff] [blame] | 6437 | |
| 6438 | if (!err) |
| 6439 | netif_device_attach(netdev); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6440 | rtnl_unlock(); |
| 6441 | |
Emil Tantilov | f7f37e7 | 2016-11-11 10:07:47 -0800 | [diff] [blame] | 6442 | return err; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6443 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6444 | #endif /* CONFIG_PM */ |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6445 | |
| 6446 | static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6447 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 6448 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 6449 | struct net_device *netdev = adapter->netdev; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6450 | struct ixgbe_hw *hw = &adapter->hw; |
| 6451 | u32 ctrl, fctrl; |
| 6452 | u32 wufc = adapter->wol; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6453 | #ifdef CONFIG_PM |
| 6454 | int retval = 0; |
| 6455 | #endif |
| 6456 | |
Emil Tantilov | f7f37e7 | 2016-11-11 10:07:47 -0800 | [diff] [blame] | 6457 | rtnl_lock(); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6458 | netif_device_detach(netdev); |
| 6459 | |
Jacob Keller | a0cccce | 2014-05-16 05:12:29 +0000 | [diff] [blame] | 6460 | if (netif_running(netdev)) |
| 6461 | ixgbe_close_suspend(adapter); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6462 | |
Alexander Duyck | 5f5ae6f | 2010-11-16 19:26:52 -0800 | [diff] [blame] | 6463 | ixgbe_clear_interrupt_scheme(adapter); |
Emil Tantilov | f7f37e7 | 2016-11-11 10:07:47 -0800 | [diff] [blame] | 6464 | rtnl_unlock(); |
Alexander Duyck | 5f5ae6f | 2010-11-16 19:26:52 -0800 | [diff] [blame] | 6465 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6466 | #ifdef CONFIG_PM |
| 6467 | retval = pci_save_state(pdev); |
| 6468 | if (retval) |
| 6469 | return retval; |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 6470 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6471 | #endif |
Jacob Keller | f4f1040 | 2013-06-25 07:59:23 +0000 | [diff] [blame] | 6472 | if (hw->mac.ops.stop_link_on_d3) |
| 6473 | hw->mac.ops.stop_link_on_d3(hw); |
| 6474 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6475 | if (wufc) { |
| 6476 | ixgbe_set_rx_mode(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6477 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 6478 | /* enable the optics for 82599 SFP+ fiber as we can WoL */ |
| 6479 | if (hw->mac.ops.enable_tx_laser) |
Don Skidmore | c509e75 | 2012-04-05 08:12:05 +0000 | [diff] [blame] | 6480 | hw->mac.ops.enable_tx_laser(hw); |
| 6481 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6482 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 6483 | if (wufc & IXGBE_WUFC_MC) { |
| 6484 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 6485 | fctrl |= IXGBE_FCTRL_MPE; |
| 6486 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
| 6487 | } |
| 6488 | |
| 6489 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 6490 | ctrl |= IXGBE_CTRL_GIO_DIS; |
| 6491 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); |
| 6492 | |
| 6493 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc); |
| 6494 | } else { |
| 6495 | IXGBE_WRITE_REG(hw, IXGBE_WUC, 0); |
| 6496 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0); |
| 6497 | } |
| 6498 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6499 | switch (hw->mac.type) { |
| 6500 | case ixgbe_mac_82598EB: |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 6501 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6502 | break; |
| 6503 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 6504 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6505 | case ixgbe_mac_X550: |
| 6506 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 6507 | case ixgbe_mac_x550em_a: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6508 | pci_wake_from_d3(pdev, !!wufc); |
| 6509 | break; |
| 6510 | default: |
| 6511 | break; |
| 6512 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6513 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6514 | *enable_wake = !!wufc; |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 6515 | if (hw->phy.ops.set_phy_power && !*enable_wake) |
| 6516 | hw->phy.ops.set_phy_power(hw, false); |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6517 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6518 | ixgbe_release_hw_control(adapter); |
| 6519 | |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 6520 | if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state)) |
| 6521 | pci_disable_device(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6522 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6523 | return 0; |
| 6524 | } |
| 6525 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6526 | #ifdef CONFIG_PM |
| 6527 | static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state) |
| 6528 | { |
| 6529 | int retval; |
| 6530 | bool wake; |
| 6531 | |
| 6532 | retval = __ixgbe_shutdown(pdev, &wake); |
| 6533 | if (retval) |
| 6534 | return retval; |
| 6535 | |
| 6536 | if (wake) { |
| 6537 | pci_prepare_to_sleep(pdev); |
| 6538 | } else { |
| 6539 | pci_wake_from_d3(pdev, false); |
| 6540 | pci_set_power_state(pdev, PCI_D3hot); |
| 6541 | } |
| 6542 | |
| 6543 | return 0; |
| 6544 | } |
| 6545 | #endif /* CONFIG_PM */ |
| 6546 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6547 | static void ixgbe_shutdown(struct pci_dev *pdev) |
| 6548 | { |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6549 | bool wake; |
| 6550 | |
| 6551 | __ixgbe_shutdown(pdev, &wake); |
| 6552 | |
| 6553 | if (system_state == SYSTEM_POWER_OFF) { |
| 6554 | pci_wake_from_d3(pdev, wake); |
| 6555 | pci_set_power_state(pdev, PCI_D3hot); |
| 6556 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6557 | } |
| 6558 | |
| 6559 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6560 | * ixgbe_update_stats - Update the board statistics counters. |
| 6561 | * @adapter: board private structure |
| 6562 | **/ |
| 6563 | void ixgbe_update_stats(struct ixgbe_adapter *adapter) |
| 6564 | { |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 6565 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6566 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6567 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6568 | u64 total_mpc = 0; |
| 6569 | u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6570 | u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0; |
| 6571 | u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 6572 | u64 bytes = 0, packets = 0, hw_csum_rx_error = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6573 | |
Don Skidmore | d08935c | 2010-06-11 13:20:29 +0000 | [diff] [blame] | 6574 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 6575 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 6576 | return; |
| 6577 | |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 6578 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 6579 | u64 rsc_count = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 6580 | u64 rsc_flush = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 6581 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6582 | rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count; |
| 6583 | rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 6584 | } |
| 6585 | adapter->rsc_total_count = rsc_count; |
| 6586 | adapter->rsc_total_flush = rsc_flush; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 6587 | } |
| 6588 | |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6589 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 6590 | struct ixgbe_ring *rx_ring = adapter->rx_ring[i]; |
| 6591 | non_eop_descs += rx_ring->rx_stats.non_eop_descs; |
| 6592 | alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed; |
| 6593 | alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 6594 | hw_csum_rx_error += rx_ring->rx_stats.csum_err; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6595 | bytes += rx_ring->stats.bytes; |
| 6596 | packets += rx_ring->stats.packets; |
| 6597 | } |
Mallikarjuna R Chilakala | eb985f0 | 2009-12-15 11:56:59 +0000 | [diff] [blame] | 6598 | adapter->non_eop_descs = non_eop_descs; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6599 | adapter->alloc_rx_page_failed = alloc_rx_page_failed; |
| 6600 | adapter->alloc_rx_buff_failed = alloc_rx_buff_failed; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 6601 | adapter->hw_csum_rx_error = hw_csum_rx_error; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6602 | netdev->stats.rx_bytes = bytes; |
| 6603 | netdev->stats.rx_packets = packets; |
| 6604 | |
| 6605 | bytes = 0; |
| 6606 | packets = 0; |
| 6607 | /* gather some stats to the adapter struct that are per queue */ |
| 6608 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 6609 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 6610 | restart_queue += tx_ring->tx_stats.restart_queue; |
| 6611 | tx_busy += tx_ring->tx_stats.tx_busy; |
| 6612 | bytes += tx_ring->stats.bytes; |
| 6613 | packets += tx_ring->stats.packets; |
| 6614 | } |
| 6615 | adapter->restart_queue = restart_queue; |
| 6616 | adapter->tx_busy = tx_busy; |
| 6617 | netdev->stats.tx_bytes = bytes; |
| 6618 | netdev->stats.tx_packets = packets; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 6619 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6620 | hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS); |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6621 | |
| 6622 | /* 8 register reads */ |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6623 | for (i = 0; i < 8; i++) { |
| 6624 | /* for packet buffers not used, the register should read 0 */ |
| 6625 | mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i)); |
| 6626 | missed_rx += mpc; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6627 | hwstats->mpc[i] += mpc; |
| 6628 | total_mpc += hwstats->mpc[i]; |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6629 | hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i)); |
| 6630 | hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6631 | switch (hw->mac.type) { |
| 6632 | case ixgbe_mac_82598EB: |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6633 | hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i)); |
| 6634 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i)); |
| 6635 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i)); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6636 | hwstats->pxonrxc[i] += |
| 6637 | IXGBE_READ_REG(hw, IXGBE_PXONRXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6638 | break; |
| 6639 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 6640 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6641 | case ixgbe_mac_X550: |
| 6642 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 6643 | case ixgbe_mac_x550em_a: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6644 | hwstats->pxonrxc[i] += |
| 6645 | IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6646 | break; |
| 6647 | default: |
| 6648 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6649 | } |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6650 | } |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6651 | |
| 6652 | /*16 register reads */ |
| 6653 | for (i = 0; i < 16; i++) { |
| 6654 | hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i)); |
| 6655 | hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i)); |
| 6656 | if ((hw->mac.type == ixgbe_mac_82599EB) || |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6657 | (hw->mac.type == ixgbe_mac_X540) || |
| 6658 | (hw->mac.type == ixgbe_mac_X550) || |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 6659 | (hw->mac.type == ixgbe_mac_X550EM_x) || |
| 6660 | (hw->mac.type == ixgbe_mac_x550em_a)) { |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6661 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i)); |
| 6662 | IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */ |
| 6663 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i)); |
| 6664 | IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */ |
| 6665 | } |
| 6666 | } |
| 6667 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6668 | hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6669 | /* work around hardware counting issue */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6670 | hwstats->gprc -= missed_rx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6671 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 6672 | ixgbe_update_xoff_received(adapter); |
| 6673 | |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6674 | /* 82598 hardware only has a 32 bit counter in the high register */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6675 | switch (hw->mac.type) { |
| 6676 | case ixgbe_mac_82598EB: |
| 6677 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6678 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH); |
| 6679 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH); |
| 6680 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH); |
| 6681 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 6682 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6683 | case ixgbe_mac_X550: |
| 6684 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 6685 | case ixgbe_mac_x550em_a: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6686 | /* OS2BMC stats are X540 and later */ |
Emil Tantilov | 58f6bcf | 2011-04-21 08:43:43 +0000 | [diff] [blame] | 6687 | hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC); |
| 6688 | hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC); |
| 6689 | hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC); |
| 6690 | hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC); |
| 6691 | case ixgbe_mac_82599EB: |
Alexander Duyck | a4d4f62 | 2012-03-28 08:03:32 +0000 | [diff] [blame] | 6692 | for (i = 0; i < 16; i++) |
| 6693 | adapter->hw_rx_no_dma_resources += |
| 6694 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6695 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6696 | IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6697 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6698 | IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6699 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6700 | IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6701 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6702 | hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH); |
| 6703 | hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS); |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 6704 | #ifdef IXGBE_FCOE |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6705 | hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC); |
| 6706 | hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC); |
| 6707 | hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC); |
| 6708 | hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC); |
| 6709 | hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC); |
| 6710 | hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC); |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 6711 | /* Add up per cpu counters for total ddp aloc fail */ |
Alexander Duyck | 5a1ee27 | 2012-05-05 17:14:28 +0000 | [diff] [blame] | 6712 | if (adapter->fcoe.ddp_pool) { |
| 6713 | struct ixgbe_fcoe *fcoe = &adapter->fcoe; |
| 6714 | struct ixgbe_fcoe_ddp_pool *ddp_pool; |
| 6715 | unsigned int cpu; |
| 6716 | u64 noddp = 0, noddp_ext_buff = 0; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 6717 | for_each_possible_cpu(cpu) { |
Alexander Duyck | 5a1ee27 | 2012-05-05 17:14:28 +0000 | [diff] [blame] | 6718 | ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu); |
| 6719 | noddp += ddp_pool->noddp; |
| 6720 | noddp_ext_buff += ddp_pool->noddp_ext_buff; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 6721 | } |
Alexander Duyck | 5a1ee27 | 2012-05-05 17:14:28 +0000 | [diff] [blame] | 6722 | hwstats->fcoe_noddp = noddp; |
| 6723 | hwstats->fcoe_noddp_ext_buff = noddp_ext_buff; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 6724 | } |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 6725 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6726 | break; |
| 6727 | default: |
| 6728 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6729 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6730 | bprc = IXGBE_READ_REG(hw, IXGBE_BPRC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6731 | hwstats->bprc += bprc; |
| 6732 | hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6733 | if (hw->mac.type == ixgbe_mac_82598EB) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6734 | hwstats->mprc -= bprc; |
| 6735 | hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC); |
| 6736 | hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64); |
| 6737 | hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127); |
| 6738 | hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255); |
| 6739 | hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511); |
| 6740 | hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023); |
| 6741 | hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522); |
| 6742 | hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6743 | lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6744 | hwstats->lxontxc += lxon; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6745 | lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6746 | hwstats->lxofftxc += lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6747 | hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC); |
| 6748 | hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6749 | /* |
| 6750 | * 82598 errata - tx of flow control packets is included in tx counters |
| 6751 | */ |
| 6752 | xon_off_tot = lxon + lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6753 | hwstats->gptc -= xon_off_tot; |
| 6754 | hwstats->mptc -= xon_off_tot; |
| 6755 | hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN)); |
| 6756 | hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 6757 | hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC); |
| 6758 | hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC); |
| 6759 | hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR); |
| 6760 | hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64); |
| 6761 | hwstats->ptc64 -= xon_off_tot; |
| 6762 | hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127); |
| 6763 | hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255); |
| 6764 | hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511); |
| 6765 | hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023); |
| 6766 | hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522); |
| 6767 | hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6768 | |
| 6769 | /* Fill out the OS statistics structure */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6770 | netdev->stats.multicast = hwstats->mprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6771 | |
| 6772 | /* Rx Errors */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6773 | netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 6774 | netdev->stats.rx_dropped = 0; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6775 | netdev->stats.rx_length_errors = hwstats->rlec; |
| 6776 | netdev->stats.rx_crc_errors = hwstats->crcerrs; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 6777 | netdev->stats.rx_missed_errors = total_mpc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6778 | } |
| 6779 | |
| 6780 | /** |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6781 | * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6782 | * @adapter: pointer to the device adapter structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6783 | **/ |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6784 | static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6785 | { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6786 | struct ixgbe_hw *hw = &adapter->hw; |
| 6787 | int i; |
| 6788 | |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6789 | if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 6790 | return; |
| 6791 | |
| 6792 | adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 6793 | |
| 6794 | /* if interface is down do nothing */ |
| 6795 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 6796 | return; |
| 6797 | |
| 6798 | /* do nothing if we are not using signature filters */ |
| 6799 | if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) |
| 6800 | return; |
| 6801 | |
| 6802 | adapter->fdir_overflow++; |
| 6803 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6804 | if (ixgbe_reinit_fdir_tables_82599(hw) == 0) { |
| 6805 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 6806 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 6807 | &(adapter->tx_ring[i]->state)); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6808 | /* re-enable flow director interrupts */ |
| 6809 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6810 | } else { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 6811 | e_err(probe, "failed to finish FDIR re-initialization, " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 6812 | "ignored adding FDIR ATR filters\n"); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6813 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6814 | } |
| 6815 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6816 | /** |
| 6817 | * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6818 | * @adapter: pointer to the device adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6819 | * |
| 6820 | * This function serves two purposes. First it strobes the interrupt lines |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 6821 | * in order to make certain interrupts are occurring. Secondly it sets the |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6822 | * bits needed to check for TX hangs. As a result we should immediately |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 6823 | * determine if a hang has occurred. |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6824 | */ |
| 6825 | static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter) |
| 6826 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6827 | struct ixgbe_hw *hw = &adapter->hw; |
| 6828 | u64 eics = 0; |
| 6829 | int i; |
| 6830 | |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 6831 | /* If we're down, removing or resetting, just bail */ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6832 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 6833 | test_bit(__IXGBE_REMOVING, &adapter->state) || |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6834 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 6835 | return; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6836 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6837 | /* Force detection of hung controller */ |
| 6838 | if (netif_carrier_ok(adapter->netdev)) { |
| 6839 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 6840 | set_check_for_tx_hang(adapter->tx_ring[i]); |
| 6841 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6842 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 6843 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6844 | /* |
| 6845 | * for legacy and MSI interrupts don't set any bits |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 6846 | * that are enabled for EIAM, because this operation |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6847 | * would set *both* EIMS and EICS for any bit in EIAM |
| 6848 | */ |
| 6849 | IXGBE_WRITE_REG(hw, IXGBE_EICS, |
| 6850 | (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER)); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6851 | } else { |
| 6852 | /* get one bit for every active tx/rx interrupt vector */ |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 6853 | for (i = 0; i < adapter->num_q_vectors; i++) { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6854 | struct ixgbe_q_vector *qv = adapter->q_vector[i]; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 6855 | if (qv->rx.ring || qv->tx.ring) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 6856 | eics |= BIT_ULL(i); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6857 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6858 | } |
| 6859 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6860 | /* Cause software interrupt to ensure rings are cleaned */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6861 | ixgbe_irq_rearm_queues(adapter, eics); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6862 | } |
| 6863 | |
| 6864 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6865 | * ixgbe_watchdog_update_link - update the link status |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6866 | * @adapter: pointer to the device adapter structure |
| 6867 | * @link_speed: pointer to a u32 to store the link_speed |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6868 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6869 | static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter) |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6870 | { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6871 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6872 | u32 link_speed = adapter->link_speed; |
| 6873 | bool link_up = adapter->link_up; |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 6874 | bool pfc_en = adapter->dcb_cfg.pfc_mode_enable; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6875 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6876 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) |
| 6877 | return; |
| 6878 | |
| 6879 | if (hw->mac.ops.check_link) { |
| 6880 | hw->mac.ops.check_link(hw, &link_speed, &link_up, false); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6881 | } else { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6882 | /* always assume link is up, if no check link function */ |
| 6883 | link_speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 6884 | link_up = true; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6885 | } |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 6886 | |
| 6887 | if (adapter->ixgbe_ieee_pfc) |
| 6888 | pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en); |
| 6889 | |
Alexander Duyck | 3ebe8fd | 2012-04-25 04:36:38 +0000 | [diff] [blame] | 6890 | if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) { |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 6891 | hw->mac.ops.fc_enable(hw); |
Alexander Duyck | 3ebe8fd | 2012-04-25 04:36:38 +0000 | [diff] [blame] | 6892 | ixgbe_set_rx_drop_en(adapter); |
| 6893 | } |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6894 | |
| 6895 | if (link_up || |
| 6896 | time_after(jiffies, (adapter->link_check_timeout + |
| 6897 | IXGBE_TRY_LINK_TIMEOUT))) { |
| 6898 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 6899 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC); |
| 6900 | IXGBE_WRITE_FLUSH(hw); |
| 6901 | } |
| 6902 | |
| 6903 | adapter->link_up = link_up; |
| 6904 | adapter->link_speed = link_speed; |
| 6905 | } |
| 6906 | |
Alexander Duyck | 107d301 | 2012-10-02 00:17:03 +0000 | [diff] [blame] | 6907 | static void ixgbe_update_default_up(struct ixgbe_adapter *adapter) |
| 6908 | { |
| 6909 | #ifdef CONFIG_IXGBE_DCB |
| 6910 | struct net_device *netdev = adapter->netdev; |
| 6911 | struct dcb_app app = { |
| 6912 | .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE, |
| 6913 | .protocol = 0, |
| 6914 | }; |
| 6915 | u8 up = 0; |
| 6916 | |
| 6917 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE) |
| 6918 | up = dcb_ieee_getapp_mask(netdev, &app); |
| 6919 | |
| 6920 | adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0; |
| 6921 | #endif |
| 6922 | } |
| 6923 | |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 6924 | static int ixgbe_enable_macvlan(struct net_device *upper, void *data) |
| 6925 | { |
| 6926 | if (netif_is_macvlan(upper)) { |
| 6927 | struct macvlan_dev *vlan = netdev_priv(upper); |
| 6928 | |
| 6929 | if (vlan->fwd_priv) |
| 6930 | netif_tx_wake_all_queues(upper); |
| 6931 | } |
| 6932 | |
| 6933 | return 0; |
| 6934 | } |
| 6935 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6936 | /** |
| 6937 | * ixgbe_watchdog_link_is_up - update netif_carrier status and |
| 6938 | * print link up message |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6939 | * @adapter: pointer to the device adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6940 | **/ |
| 6941 | static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter) |
| 6942 | { |
| 6943 | struct net_device *netdev = adapter->netdev; |
| 6944 | struct ixgbe_hw *hw = &adapter->hw; |
| 6945 | u32 link_speed = adapter->link_speed; |
Mark Rustad | 454adb0 | 2015-07-10 14:19:22 -0700 | [diff] [blame] | 6946 | const char *speed_str; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6947 | bool flow_rx, flow_tx; |
| 6948 | |
| 6949 | /* only continue if link was previously down */ |
| 6950 | if (netif_carrier_ok(netdev)) |
| 6951 | return; |
| 6952 | |
| 6953 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 6954 | |
| 6955 | switch (hw->mac.type) { |
| 6956 | case ixgbe_mac_82598EB: { |
| 6957 | u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 6958 | u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS); |
| 6959 | flow_rx = !!(frctl & IXGBE_FCTRL_RFCE); |
| 6960 | flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X); |
| 6961 | } |
| 6962 | break; |
| 6963 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6964 | case ixgbe_mac_X550: |
| 6965 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 6966 | case ixgbe_mac_x550em_a: |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6967 | case ixgbe_mac_82599EB: { |
| 6968 | u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN); |
| 6969 | u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG); |
| 6970 | flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE); |
| 6971 | flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X); |
| 6972 | } |
| 6973 | break; |
| 6974 | default: |
| 6975 | flow_tx = false; |
| 6976 | flow_rx = false; |
| 6977 | break; |
| 6978 | } |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 6979 | |
Jacob Keller | 6cb562d | 2012-12-05 07:24:41 +0000 | [diff] [blame] | 6980 | adapter->last_rx_ptp_check = jiffies; |
| 6981 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 6982 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6983 | ixgbe_ptp_start_cyclecounter(adapter); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 6984 | |
Mark Rustad | 454adb0 | 2015-07-10 14:19:22 -0700 | [diff] [blame] | 6985 | switch (link_speed) { |
| 6986 | case IXGBE_LINK_SPEED_10GB_FULL: |
| 6987 | speed_str = "10 Gbps"; |
| 6988 | break; |
| 6989 | case IXGBE_LINK_SPEED_2_5GB_FULL: |
| 6990 | speed_str = "2.5 Gbps"; |
| 6991 | break; |
| 6992 | case IXGBE_LINK_SPEED_1GB_FULL: |
| 6993 | speed_str = "1 Gbps"; |
| 6994 | break; |
| 6995 | case IXGBE_LINK_SPEED_100_FULL: |
| 6996 | speed_str = "100 Mbps"; |
| 6997 | break; |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 6998 | case IXGBE_LINK_SPEED_10_FULL: |
| 6999 | speed_str = "10 Mbps"; |
| 7000 | break; |
Mark Rustad | 454adb0 | 2015-07-10 14:19:22 -0700 | [diff] [blame] | 7001 | default: |
| 7002 | speed_str = "unknown speed"; |
| 7003 | break; |
| 7004 | } |
| 7005 | e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", speed_str, |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7006 | ((flow_rx && flow_tx) ? "RX/TX" : |
| 7007 | (flow_rx ? "RX" : |
| 7008 | (flow_tx ? "TX" : "None")))); |
| 7009 | |
| 7010 | netif_carrier_on(netdev); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7011 | ixgbe_check_vf_rate_limit(adapter); |
Alexander Duyck | befa2af | 2012-05-05 05:30:38 +0000 | [diff] [blame] | 7012 | |
Emil Tantilov | cdc04dc | 2014-03-20 03:47:53 +0000 | [diff] [blame] | 7013 | /* enable transmits */ |
| 7014 | netif_tx_wake_all_queues(adapter->netdev); |
| 7015 | |
| 7016 | /* enable any upper devices */ |
| 7017 | rtnl_lock(); |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 7018 | netdev_walk_all_upper_dev_rcu(adapter->netdev, |
| 7019 | ixgbe_enable_macvlan, NULL); |
Emil Tantilov | cdc04dc | 2014-03-20 03:47:53 +0000 | [diff] [blame] | 7020 | rtnl_unlock(); |
| 7021 | |
Alexander Duyck | 107d301 | 2012-10-02 00:17:03 +0000 | [diff] [blame] | 7022 | /* update the default user priority for VFs */ |
| 7023 | ixgbe_update_default_up(adapter); |
| 7024 | |
Alexander Duyck | befa2af | 2012-05-05 05:30:38 +0000 | [diff] [blame] | 7025 | /* ping all the active vfs to let them know link has changed */ |
| 7026 | ixgbe_ping_all_vfs(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7027 | } |
| 7028 | |
| 7029 | /** |
| 7030 | * ixgbe_watchdog_link_is_down - update netif_carrier status and |
| 7031 | * print link down message |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7032 | * @adapter: pointer to the adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7033 | **/ |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 7034 | static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7035 | { |
| 7036 | struct net_device *netdev = adapter->netdev; |
| 7037 | struct ixgbe_hw *hw = &adapter->hw; |
| 7038 | |
| 7039 | adapter->link_up = false; |
| 7040 | adapter->link_speed = 0; |
| 7041 | |
| 7042 | /* only continue if link was up previously */ |
| 7043 | if (!netif_carrier_ok(netdev)) |
| 7044 | return; |
| 7045 | |
| 7046 | /* poll for SFP+ cable when link is down */ |
| 7047 | if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB) |
| 7048 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 7049 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 7050 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 7051 | ixgbe_ptp_start_cyclecounter(adapter); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7052 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7053 | e_info(drv, "NIC Link is Down\n"); |
| 7054 | netif_carrier_off(netdev); |
Alexander Duyck | befa2af | 2012-05-05 05:30:38 +0000 | [diff] [blame] | 7055 | |
| 7056 | /* ping all the active vfs to let them know link has changed */ |
| 7057 | ixgbe_ping_all_vfs(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7058 | } |
| 7059 | |
Emil Tantilov | 07923c1 | 2014-08-12 07:12:08 +0000 | [diff] [blame] | 7060 | static bool ixgbe_ring_tx_pending(struct ixgbe_adapter *adapter) |
| 7061 | { |
| 7062 | int i; |
| 7063 | |
| 7064 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 7065 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 7066 | |
| 7067 | if (tx_ring->next_to_use != tx_ring->next_to_clean) |
| 7068 | return true; |
| 7069 | } |
| 7070 | |
| 7071 | return false; |
| 7072 | } |
| 7073 | |
| 7074 | static bool ixgbe_vf_tx_pending(struct ixgbe_adapter *adapter) |
| 7075 | { |
| 7076 | struct ixgbe_hw *hw = &adapter->hw; |
| 7077 | struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ]; |
| 7078 | u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask); |
| 7079 | |
| 7080 | int i, j; |
| 7081 | |
| 7082 | if (!adapter->num_vfs) |
| 7083 | return false; |
| 7084 | |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 7085 | /* resetting the PF is only needed for MAC before X550 */ |
| 7086 | if (hw->mac.type >= ixgbe_mac_X550) |
| 7087 | return false; |
| 7088 | |
Emil Tantilov | 07923c1 | 2014-08-12 07:12:08 +0000 | [diff] [blame] | 7089 | for (i = 0; i < adapter->num_vfs; i++) { |
| 7090 | for (j = 0; j < q_per_pool; j++) { |
| 7091 | u32 h, t; |
| 7092 | |
| 7093 | h = IXGBE_READ_REG(hw, IXGBE_PVFTDHN(q_per_pool, i, j)); |
| 7094 | t = IXGBE_READ_REG(hw, IXGBE_PVFTDTN(q_per_pool, i, j)); |
| 7095 | |
| 7096 | if (h != t) |
| 7097 | return true; |
| 7098 | } |
| 7099 | } |
| 7100 | |
| 7101 | return false; |
| 7102 | } |
| 7103 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7104 | /** |
| 7105 | * ixgbe_watchdog_flush_tx - flush queues on link down |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7106 | * @adapter: pointer to the device adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7107 | **/ |
| 7108 | static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter) |
| 7109 | { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7110 | if (!netif_carrier_ok(adapter->netdev)) { |
Emil Tantilov | 07923c1 | 2014-08-12 07:12:08 +0000 | [diff] [blame] | 7111 | if (ixgbe_ring_tx_pending(adapter) || |
| 7112 | ixgbe_vf_tx_pending(adapter)) { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7113 | /* We've lost link, so the controller stops DMA, |
| 7114 | * but we've got queued Tx work that's never going |
| 7115 | * to get done, so reset controller to flush Tx. |
| 7116 | * (Do the reset outside of interrupt context). |
| 7117 | */ |
Jacob Keller | 12ff3f3 | 2012-12-01 07:57:17 +0000 | [diff] [blame] | 7118 | e_warn(drv, "initiating reset to clear Tx work after link loss\n"); |
Emil Tantilov | 57ca2a4 | 2016-07-29 14:46:31 -0700 | [diff] [blame] | 7119 | set_bit(__IXGBE_RESET_REQUESTED, &adapter->state); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7120 | } |
| 7121 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7122 | } |
| 7123 | |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7124 | #ifdef CONFIG_PCI_IOV |
| 7125 | static inline void ixgbe_issue_vf_flr(struct ixgbe_adapter *adapter, |
| 7126 | struct pci_dev *vfdev) |
| 7127 | { |
| 7128 | if (!pci_wait_for_pending_transaction(vfdev)) |
| 7129 | e_dev_warn("Issuing VFLR with pending transactions\n"); |
| 7130 | |
| 7131 | e_dev_err("Issuing VFLR for VF %s\n", pci_name(vfdev)); |
| 7132 | pcie_capability_set_word(vfdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_BCR_FLR); |
| 7133 | |
| 7134 | msleep(100); |
| 7135 | } |
| 7136 | |
| 7137 | static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter) |
| 7138 | { |
| 7139 | struct ixgbe_hw *hw = &adapter->hw; |
| 7140 | struct pci_dev *pdev = adapter->pdev; |
Mark Rustad | 988d130 | 2015-10-30 15:29:34 -0700 | [diff] [blame] | 7141 | unsigned int vf; |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7142 | u32 gpc; |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7143 | |
| 7144 | if (!(netif_carrier_ok(adapter->netdev))) |
| 7145 | return; |
| 7146 | |
| 7147 | gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC); |
| 7148 | if (gpc) /* If incrementing then no need for the check below */ |
| 7149 | return; |
| 7150 | /* Check to see if a bad DMA write target from an errant or |
| 7151 | * malicious VF has caused a PCIe error. If so then we can |
| 7152 | * issue a VFLR to the offending VF(s) and then resume without |
| 7153 | * requesting a full slot reset. |
| 7154 | */ |
| 7155 | |
| 7156 | if (!pdev) |
| 7157 | return; |
| 7158 | |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7159 | /* check status reg for all VFs owned by this PF */ |
Mark Rustad | 988d130 | 2015-10-30 15:29:34 -0700 | [diff] [blame] | 7160 | for (vf = 0; vf < adapter->num_vfs; ++vf) { |
| 7161 | struct pci_dev *vfdev = adapter->vfinfo[vf].vfdev; |
| 7162 | u16 status_reg; |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7163 | |
Mark Rustad | 988d130 | 2015-10-30 15:29:34 -0700 | [diff] [blame] | 7164 | if (!vfdev) |
| 7165 | continue; |
| 7166 | pci_read_config_word(vfdev, PCI_STATUS, &status_reg); |
| 7167 | if (status_reg != IXGBE_FAILED_READ_CFG_WORD && |
| 7168 | status_reg & PCI_STATUS_REC_MASTER_ABORT) |
| 7169 | ixgbe_issue_vf_flr(adapter, vfdev); |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7170 | } |
| 7171 | } |
| 7172 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 7173 | static void ixgbe_spoof_check(struct ixgbe_adapter *adapter) |
| 7174 | { |
| 7175 | u32 ssvpc; |
| 7176 | |
Greg Rose | 0584d99 | 2012-08-08 00:00:58 +0000 | [diff] [blame] | 7177 | /* Do not perform spoof check for 82598 or if not in IOV mode */ |
| 7178 | if (adapter->hw.mac.type == ixgbe_mac_82598EB || |
| 7179 | adapter->num_vfs == 0) |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 7180 | return; |
| 7181 | |
| 7182 | ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC); |
| 7183 | |
| 7184 | /* |
| 7185 | * ssvpc register is cleared on read, if zero then no |
| 7186 | * spoofed packets in the last interval. |
| 7187 | */ |
| 7188 | if (!ssvpc) |
| 7189 | return; |
| 7190 | |
Emil Tantilov | d6ea075 | 2012-08-08 06:28:37 +0000 | [diff] [blame] | 7191 | e_warn(drv, "%u Spoofed packets detected\n", ssvpc); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 7192 | } |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7193 | #else |
| 7194 | static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused *adapter) |
| 7195 | { |
| 7196 | } |
| 7197 | |
| 7198 | static void |
| 7199 | ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused *adapter) |
| 7200 | { |
| 7201 | } |
| 7202 | #endif /* CONFIG_PCI_IOV */ |
| 7203 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 7204 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7205 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7206 | * ixgbe_watchdog_subtask - check and bring link up |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7207 | * @adapter: pointer to the device adapter structure |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 7208 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7209 | static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 7210 | { |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 7211 | /* if interface is down, removing or resetting, do nothing */ |
Emil Tantilov | 7edebf9 | 2011-08-27 07:18:37 +0000 | [diff] [blame] | 7212 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 7213 | test_bit(__IXGBE_REMOVING, &adapter->state) || |
Emil Tantilov | 7edebf9 | 2011-08-27 07:18:37 +0000 | [diff] [blame] | 7214 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7215 | return; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 7216 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7217 | ixgbe_watchdog_update_link(adapter); |
John Fastabend | 10eec95 | 2010-02-03 14:23:32 +0000 | [diff] [blame] | 7218 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7219 | if (adapter->link_up) |
| 7220 | ixgbe_watchdog_link_is_up(adapter); |
| 7221 | else |
| 7222 | ixgbe_watchdog_link_is_down(adapter); |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 7223 | |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7224 | ixgbe_check_for_bad_vf(adapter); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 7225 | ixgbe_spoof_check(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7226 | ixgbe_update_stats(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7227 | |
| 7228 | ixgbe_watchdog_flush_tx(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7229 | } |
| 7230 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7231 | /** |
| 7232 | * ixgbe_sfp_detection_subtask - poll for SFP+ cable |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7233 | * @adapter: the ixgbe adapter structure |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7234 | **/ |
| 7235 | static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter) |
| 7236 | { |
| 7237 | struct ixgbe_hw *hw = &adapter->hw; |
| 7238 | s32 err; |
| 7239 | |
| 7240 | /* not searching for SFP so there is nothing to do here */ |
| 7241 | if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) && |
| 7242 | !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 7243 | return; |
| 7244 | |
Mark Rustad | 58e7cd2 | 2015-08-08 16:18:48 -0700 | [diff] [blame] | 7245 | if (adapter->sfp_poll_time && |
| 7246 | time_after(adapter->sfp_poll_time, jiffies)) |
| 7247 | return; /* If not yet time to poll for SFP */ |
| 7248 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7249 | /* someone else is in init, wait until next service event */ |
| 7250 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 7251 | return; |
| 7252 | |
Mark Rustad | 58e7cd2 | 2015-08-08 16:18:48 -0700 | [diff] [blame] | 7253 | adapter->sfp_poll_time = jiffies + IXGBE_SFP_POLL_JIFFIES - 1; |
| 7254 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7255 | err = hw->phy.ops.identify_sfp(hw); |
| 7256 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 7257 | goto sfp_out; |
| 7258 | |
| 7259 | if (err == IXGBE_ERR_SFP_NOT_PRESENT) { |
| 7260 | /* If no cable is present, then we need to reset |
| 7261 | * the next time we find a good cable. */ |
| 7262 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 7263 | } |
| 7264 | |
| 7265 | /* exit on error */ |
| 7266 | if (err) |
| 7267 | goto sfp_out; |
| 7268 | |
| 7269 | /* exit if reset not needed */ |
| 7270 | if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 7271 | goto sfp_out; |
| 7272 | |
| 7273 | adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 7274 | |
| 7275 | /* |
| 7276 | * A module may be identified correctly, but the EEPROM may not have |
| 7277 | * support for that module. setup_sfp() will fail in that case, so |
| 7278 | * we should not allow that module to load. |
| 7279 | */ |
| 7280 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 7281 | err = hw->phy.ops.reset(hw); |
| 7282 | else |
| 7283 | err = hw->mac.ops.setup_sfp(hw); |
| 7284 | |
| 7285 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 7286 | goto sfp_out; |
| 7287 | |
| 7288 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 7289 | e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type); |
| 7290 | |
| 7291 | sfp_out: |
| 7292 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 7293 | |
| 7294 | if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) && |
| 7295 | (adapter->netdev->reg_state == NETREG_REGISTERED)) { |
| 7296 | e_dev_err("failed to initialize because an unsupported " |
| 7297 | "SFP+ module type was detected.\n"); |
| 7298 | e_dev_err("Reload the driver after installing a " |
| 7299 | "supported module.\n"); |
| 7300 | unregister_netdev(adapter->netdev); |
| 7301 | } |
| 7302 | } |
| 7303 | |
| 7304 | /** |
| 7305 | * ixgbe_sfp_link_config_subtask - set up link SFP after module install |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7306 | * @adapter: the ixgbe adapter structure |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7307 | **/ |
| 7308 | static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter) |
| 7309 | { |
| 7310 | struct ixgbe_hw *hw = &adapter->hw; |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 7311 | u32 speed; |
| 7312 | bool autoneg = false; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7313 | |
| 7314 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG)) |
| 7315 | return; |
| 7316 | |
| 7317 | /* someone else is in init, wait until next service event */ |
| 7318 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 7319 | return; |
| 7320 | |
| 7321 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 7322 | |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 7323 | speed = hw->phy.autoneg_advertised; |
Emil Tantilov | ed33ff6 | 2013-08-30 07:55:24 +0000 | [diff] [blame] | 7324 | if ((!speed) && (hw->mac.ops.get_link_capabilities)) { |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 7325 | hw->mac.ops.get_link_capabilities(hw, &speed, &autoneg); |
Emil Tantilov | ed33ff6 | 2013-08-30 07:55:24 +0000 | [diff] [blame] | 7326 | |
| 7327 | /* setup the highest link when no autoneg */ |
| 7328 | if (!autoneg) { |
| 7329 | if (speed & IXGBE_LINK_SPEED_10GB_FULL) |
| 7330 | speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 7331 | } |
| 7332 | } |
| 7333 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7334 | if (hw->mac.ops.setup_link) |
Josh Hay | fd0326f | 2012-12-15 03:28:30 +0000 | [diff] [blame] | 7335 | hw->mac.ops.setup_link(hw, speed, true); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7336 | |
| 7337 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 7338 | adapter->link_check_timeout = jiffies; |
| 7339 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 7340 | } |
| 7341 | |
| 7342 | /** |
| 7343 | * ixgbe_service_timer - Timer Call-back |
| 7344 | * @data: pointer to adapter cast into an unsigned long |
| 7345 | **/ |
| 7346 | static void ixgbe_service_timer(unsigned long data) |
| 7347 | { |
| 7348 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
| 7349 | unsigned long next_event_offset; |
| 7350 | |
| 7351 | /* poll faster when waiting for link */ |
| 7352 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 7353 | next_event_offset = HZ / 10; |
| 7354 | else |
| 7355 | next_event_offset = HZ * 2; |
| 7356 | |
| 7357 | /* Reset the timer */ |
| 7358 | mod_timer(&adapter->service_timer, next_event_offset + jiffies); |
| 7359 | |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7360 | ixgbe_service_event_schedule(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7361 | } |
| 7362 | |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 7363 | static void ixgbe_phy_interrupt_subtask(struct ixgbe_adapter *adapter) |
| 7364 | { |
| 7365 | struct ixgbe_hw *hw = &adapter->hw; |
| 7366 | u32 status; |
| 7367 | |
| 7368 | if (!(adapter->flags2 & IXGBE_FLAG2_PHY_INTERRUPT)) |
| 7369 | return; |
| 7370 | |
| 7371 | adapter->flags2 &= ~IXGBE_FLAG2_PHY_INTERRUPT; |
| 7372 | |
| 7373 | if (!hw->phy.ops.handle_lasi) |
| 7374 | return; |
| 7375 | |
| 7376 | status = hw->phy.ops.handle_lasi(&adapter->hw); |
| 7377 | if (status != IXGBE_ERR_OVERTEMP) |
| 7378 | return; |
| 7379 | |
| 7380 | e_crit(drv, "%s\n", ixgbe_overheat_msg); |
| 7381 | } |
| 7382 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7383 | static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter) |
| 7384 | { |
Emil Tantilov | 57ca2a4 | 2016-07-29 14:46:31 -0700 | [diff] [blame] | 7385 | if (!test_and_clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state)) |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7386 | return; |
| 7387 | |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 7388 | /* If we're already down, removing or resetting, just bail */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7389 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 7390 | test_bit(__IXGBE_REMOVING, &adapter->state) || |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7391 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 7392 | return; |
| 7393 | |
| 7394 | ixgbe_dump(adapter); |
| 7395 | netdev_err(adapter->netdev, "Reset adapter\n"); |
| 7396 | adapter->tx_timeout_count++; |
| 7397 | |
John Fastabend | 8f4c5c9 | 2014-01-16 02:30:05 -0800 | [diff] [blame] | 7398 | rtnl_lock(); |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7399 | ixgbe_reinit_locked(adapter); |
John Fastabend | 8f4c5c9 | 2014-01-16 02:30:05 -0800 | [diff] [blame] | 7400 | rtnl_unlock(); |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7401 | } |
| 7402 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7403 | /** |
| 7404 | * ixgbe_service_task - manages and runs subtasks |
| 7405 | * @work: pointer to work_struct containing our data |
| 7406 | **/ |
| 7407 | static void ixgbe_service_task(struct work_struct *work) |
| 7408 | { |
| 7409 | struct ixgbe_adapter *adapter = container_of(work, |
| 7410 | struct ixgbe_adapter, |
| 7411 | service_task); |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 7412 | if (ixgbe_removed(adapter->hw.hw_addr)) { |
| 7413 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 7414 | rtnl_lock(); |
| 7415 | ixgbe_down(adapter); |
| 7416 | rtnl_unlock(); |
| 7417 | } |
| 7418 | ixgbe_service_event_complete(adapter); |
| 7419 | return; |
| 7420 | } |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 7421 | if (adapter->flags2 & IXGBE_FLAG2_UDP_TUN_REREG_NEEDED) { |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 7422 | rtnl_lock(); |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 7423 | adapter->flags2 &= ~IXGBE_FLAG2_UDP_TUN_REREG_NEEDED; |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 7424 | udp_tunnel_get_rx_info(adapter->netdev); |
| 7425 | rtnl_unlock(); |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7426 | } |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7427 | ixgbe_reset_subtask(adapter); |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 7428 | ixgbe_phy_interrupt_subtask(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7429 | ixgbe_sfp_detection_subtask(adapter); |
| 7430 | ixgbe_sfp_link_config_subtask(adapter); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 7431 | ixgbe_check_overtemp_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7432 | ixgbe_watchdog_subtask(adapter); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 7433 | ixgbe_fdir_reinit_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7434 | ixgbe_check_hang_subtask(adapter); |
Jacob Keller | 891dc08 | 2012-12-05 07:24:46 +0000 | [diff] [blame] | 7435 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 7436 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) { |
Jacob Keller | 891dc08 | 2012-12-05 07:24:46 +0000 | [diff] [blame] | 7437 | ixgbe_ptp_overflow_check(adapter); |
| 7438 | ixgbe_ptp_rx_hang(adapter); |
| 7439 | } |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7440 | |
| 7441 | ixgbe_service_event_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7442 | } |
| 7443 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7444 | static int ixgbe_tso(struct ixgbe_ring *tx_ring, |
| 7445 | struct ixgbe_tx_buffer *first, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7446 | u8 *hdr_len) |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7447 | { |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7448 | u32 vlan_macip_lens, type_tucmd, mss_l4len_idx; |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7449 | struct sk_buff *skb = first->skb; |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7450 | union { |
| 7451 | struct iphdr *v4; |
| 7452 | struct ipv6hdr *v6; |
| 7453 | unsigned char *hdr; |
| 7454 | } ip; |
| 7455 | union { |
| 7456 | struct tcphdr *tcp; |
| 7457 | unsigned char *hdr; |
| 7458 | } l4; |
| 7459 | u32 paylen, l4_offset; |
Francois Romieu | 2049e1f | 2014-03-30 03:14:27 +0000 | [diff] [blame] | 7460 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7461 | |
Alexander Duyck | 8f4fbb9 | 2012-10-30 06:01:40 +0000 | [diff] [blame] | 7462 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 7463 | return 0; |
| 7464 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7465 | if (!skb_is_gso(skb)) |
| 7466 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7467 | |
Francois Romieu | 2049e1f | 2014-03-30 03:14:27 +0000 | [diff] [blame] | 7468 | err = skb_cow_head(skb, 0); |
| 7469 | if (err < 0) |
| 7470 | return err; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 7471 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7472 | ip.hdr = skb_network_header(skb); |
| 7473 | l4.hdr = skb_checksum_start(skb); |
| 7474 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7475 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
| 7476 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 7477 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7478 | /* initialize outer IP header fields */ |
| 7479 | if (ip.v4->version == 4) { |
Alexander Duyck | c54cdc3 | 2016-11-28 10:42:29 -0500 | [diff] [blame] | 7480 | unsigned char *csum_start = skb_checksum_start(skb); |
| 7481 | unsigned char *trans_start = ip.hdr + (ip.v4->ihl * 4); |
| 7482 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7483 | /* IP header will have to cancel out any data that |
| 7484 | * is not a part of the outer IP header |
| 7485 | */ |
Alexander Duyck | c54cdc3 | 2016-11-28 10:42:29 -0500 | [diff] [blame] | 7486 | ip.v4->check = csum_fold(csum_partial(trans_start, |
| 7487 | csum_start - trans_start, |
| 7488 | 0)); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7489 | type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7490 | |
| 7491 | ip.v4->tot_len = 0; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7492 | first->tx_flags |= IXGBE_TX_FLAGS_TSO | |
| 7493 | IXGBE_TX_FLAGS_CSUM | |
| 7494 | IXGBE_TX_FLAGS_IPV4; |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7495 | } else { |
| 7496 | ip.v6->payload_len = 0; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7497 | first->tx_flags |= IXGBE_TX_FLAGS_TSO | |
| 7498 | IXGBE_TX_FLAGS_CSUM; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7499 | } |
| 7500 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7501 | /* determine offset of inner transport header */ |
| 7502 | l4_offset = l4.hdr - skb->data; |
| 7503 | |
| 7504 | /* compute length of segmentation header */ |
| 7505 | *hdr_len = (l4.tcp->doff * 4) + l4_offset; |
| 7506 | |
| 7507 | /* remove payload length from inner checksum */ |
| 7508 | paylen = skb->len - l4_offset; |
| 7509 | csum_replace_by_diff(&l4.tcp->check, htonl(paylen)); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7510 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 7511 | /* update gso size and bytecount with header size */ |
| 7512 | first->gso_segs = skb_shinfo(skb)->gso_segs; |
| 7513 | first->bytecount += (first->gso_segs - 1) * *hdr_len; |
| 7514 | |
Alexander Duyck | c44f5f5 | 2012-10-30 06:01:45 +0000 | [diff] [blame] | 7515 | /* mss_l4len_id: use 0 as index for TSO */ |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7516 | mss_l4len_idx = (*hdr_len - l4_offset) << IXGBE_ADVTXD_L4LEN_SHIFT; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7517 | mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7518 | |
| 7519 | /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */ |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7520 | vlan_macip_lens = l4.hdr - ip.hdr; |
| 7521 | vlan_macip_lens |= (ip.hdr - skb->data) << IXGBE_ADVTXD_MACLEN_SHIFT; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7522 | vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7523 | |
| 7524 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7525 | mss_l4len_idx); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7526 | |
| 7527 | return 1; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 7528 | } |
| 7529 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7530 | static inline bool ixgbe_ipv6_csum_is_sctp(struct sk_buff *skb) |
| 7531 | { |
| 7532 | unsigned int offset = 0; |
| 7533 | |
| 7534 | ipv6_find_hdr(skb, &offset, IPPROTO_SCTP, NULL, NULL); |
| 7535 | |
| 7536 | return offset == skb_checksum_start_offset(skb); |
| 7537 | } |
| 7538 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7539 | static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring, |
| 7540 | struct ixgbe_tx_buffer *first) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7541 | { |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7542 | struct sk_buff *skb = first->skb; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7543 | u32 vlan_macip_lens = 0; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7544 | u32 type_tucmd = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7545 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7546 | if (skb->ip_summed != CHECKSUM_PARTIAL) { |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7547 | csum_failed: |
| 7548 | if (!(first->tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | |
| 7549 | IXGBE_TX_FLAGS_CC))) |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7550 | return; |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7551 | goto no_csum; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7552 | } |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 7553 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7554 | switch (skb->csum_offset) { |
| 7555 | case offsetof(struct tcphdr, check): |
| 7556 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 7557 | /* fall through */ |
| 7558 | case offsetof(struct udphdr, check): |
| 7559 | break; |
| 7560 | case offsetof(struct sctphdr, checksum): |
| 7561 | /* validate that this is actually an SCTP request */ |
| 7562 | if (((first->protocol == htons(ETH_P_IP)) && |
| 7563 | (ip_hdr(skb)->protocol == IPPROTO_SCTP)) || |
| 7564 | ((first->protocol == htons(ETH_P_IPV6)) && |
| 7565 | ixgbe_ipv6_csum_is_sctp(skb))) { |
| 7566 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
| 7567 | break; |
| 7568 | } |
| 7569 | /* fall through */ |
| 7570 | default: |
| 7571 | skb_checksum_help(skb); |
| 7572 | goto csum_failed; |
| 7573 | } |
| 7574 | |
| 7575 | /* update TX checksum flag */ |
| 7576 | first->tx_flags |= IXGBE_TX_FLAGS_CSUM; |
| 7577 | vlan_macip_lens = skb_checksum_start_offset(skb) - |
| 7578 | skb_network_offset(skb); |
Mark Rustad | 36a92d7 | 2015-11-18 09:21:28 -0800 | [diff] [blame] | 7579 | no_csum: |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7580 | /* vlan_macip_lens: MACLEN, VLAN tag */ |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7581 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7582 | vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7583 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7584 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, 0); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7585 | } |
| 7586 | |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7587 | #define IXGBE_SET_FLAG(_input, _flag, _result) \ |
| 7588 | ((_flag <= _result) ? \ |
| 7589 | ((u32)(_input & _flag) * (_result / _flag)) : \ |
| 7590 | ((u32)(_input & _flag) / (_flag / _result))) |
| 7591 | |
| 7592 | static u32 ixgbe_tx_cmd_type(struct sk_buff *skb, u32 tx_flags) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7593 | { |
| 7594 | /* set type for advanced descriptor with frame checksum insertion */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7595 | u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA | |
| 7596 | IXGBE_ADVTXD_DCMD_DEXT | |
| 7597 | IXGBE_ADVTXD_DCMD_IFCS; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7598 | |
| 7599 | /* set HW vlan bit if vlan is present */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7600 | cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN, |
| 7601 | IXGBE_ADVTXD_DCMD_VLE); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7602 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7603 | /* set segmentation enable bits for TSO/FSO */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7604 | cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO, |
| 7605 | IXGBE_ADVTXD_DCMD_TSE); |
| 7606 | |
| 7607 | /* set timestamp bit if present */ |
| 7608 | cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP, |
| 7609 | IXGBE_ADVTXD_MAC_TSTAMP); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7610 | |
Alexander Duyck | 62748b7 | 2012-07-20 08:09:01 +0000 | [diff] [blame] | 7611 | /* insert frame checksum */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7612 | cmd_type ^= IXGBE_SET_FLAG(skb->no_fcs, 1, IXGBE_ADVTXD_DCMD_IFCS); |
Alexander Duyck | 62748b7 | 2012-07-20 08:09:01 +0000 | [diff] [blame] | 7613 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7614 | return cmd_type; |
| 7615 | } |
| 7616 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7617 | static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc, |
| 7618 | u32 tx_flags, unsigned int paylen) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7619 | { |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7620 | u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7621 | |
| 7622 | /* enable L4 checksum for TSO and TX checksum offload */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7623 | olinfo_status |= IXGBE_SET_FLAG(tx_flags, |
| 7624 | IXGBE_TX_FLAGS_CSUM, |
| 7625 | IXGBE_ADVTXD_POPTS_TXSM); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7626 | |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 7627 | /* enble IPv4 checksum for TSO */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7628 | olinfo_status |= IXGBE_SET_FLAG(tx_flags, |
| 7629 | IXGBE_TX_FLAGS_IPV4, |
| 7630 | IXGBE_ADVTXD_POPTS_IXSM); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7631 | |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 7632 | /* |
| 7633 | * Check Context must be set if Tx switch is enabled, which it |
| 7634 | * always is for case where virtual functions are running |
| 7635 | */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7636 | olinfo_status |= IXGBE_SET_FLAG(tx_flags, |
| 7637 | IXGBE_TX_FLAGS_CC, |
| 7638 | IXGBE_ADVTXD_CC); |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 7639 | |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7640 | tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7641 | } |
| 7642 | |
Daniel Borkmann | 2367a17 | 2014-08-26 19:34:18 +0200 | [diff] [blame] | 7643 | static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size) |
| 7644 | { |
| 7645 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 7646 | |
| 7647 | /* Herbert's original patch had: |
| 7648 | * smp_mb__after_netif_stop_queue(); |
| 7649 | * but since that doesn't exist yet, just open code it. |
| 7650 | */ |
| 7651 | smp_mb(); |
| 7652 | |
| 7653 | /* We need to check again in a case another CPU has just |
| 7654 | * made room available. |
| 7655 | */ |
| 7656 | if (likely(ixgbe_desc_unused(tx_ring) < size)) |
| 7657 | return -EBUSY; |
| 7658 | |
| 7659 | /* A reprieve! - use start_queue because it doesn't call schedule */ |
| 7660 | netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 7661 | ++tx_ring->tx_stats.restart_queue; |
| 7662 | return 0; |
| 7663 | } |
| 7664 | |
| 7665 | static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size) |
| 7666 | { |
| 7667 | if (likely(ixgbe_desc_unused(tx_ring) >= size)) |
| 7668 | return 0; |
| 7669 | |
| 7670 | return __ixgbe_maybe_stop_tx(tx_ring, size); |
| 7671 | } |
| 7672 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7673 | #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \ |
| 7674 | IXGBE_TXD_CMD_RS) |
| 7675 | |
| 7676 | static void ixgbe_tx_map(struct ixgbe_ring *tx_ring, |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7677 | struct ixgbe_tx_buffer *first, |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7678 | const u8 hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7679 | { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7680 | struct sk_buff *skb = first->skb; |
| 7681 | struct ixgbe_tx_buffer *tx_buffer; |
| 7682 | union ixgbe_adv_tx_desc *tx_desc; |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7683 | struct skb_frag_struct *frag; |
| 7684 | dma_addr_t dma; |
| 7685 | unsigned int data_len, size; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7686 | u32 tx_flags = first->tx_flags; |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7687 | u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7688 | u16 i = tx_ring->next_to_use; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7689 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7690 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
| 7691 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7692 | ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len); |
| 7693 | |
| 7694 | size = skb_headlen(skb); |
| 7695 | data_len = skb->data_len; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7696 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7697 | #ifdef IXGBE_FCOE |
| 7698 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7699 | if (data_len < sizeof(struct fcoe_crc_eof)) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7700 | size -= sizeof(struct fcoe_crc_eof) - data_len; |
| 7701 | data_len = 0; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7702 | } else { |
| 7703 | data_len -= sizeof(struct fcoe_crc_eof); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 7704 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7705 | } |
| 7706 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7707 | #endif |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7708 | dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7709 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7710 | tx_buffer = first; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7711 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7712 | for (frag = &skb_shinfo(skb)->frags[0];; frag++) { |
| 7713 | if (dma_mapping_error(tx_ring->dev, dma)) |
| 7714 | goto dma_error; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7715 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7716 | /* record length, and DMA address */ |
| 7717 | dma_unmap_len_set(tx_buffer, len, size); |
| 7718 | dma_unmap_addr_set(tx_buffer, dma, dma); |
| 7719 | |
| 7720 | tx_desc->read.buffer_addr = cpu_to_le64(dma); |
| 7721 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7722 | while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7723 | tx_desc->read.cmd_type_len = |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7724 | cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7725 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7726 | i++; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7727 | tx_desc++; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7728 | if (i == tx_ring->count) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 7729 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7730 | i = 0; |
| 7731 | } |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7732 | tx_desc->read.olinfo_status = 0; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7733 | |
| 7734 | dma += IXGBE_MAX_DATA_PER_TXD; |
| 7735 | size -= IXGBE_MAX_DATA_PER_TXD; |
| 7736 | |
| 7737 | tx_desc->read.buffer_addr = cpu_to_le64(dma); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7738 | } |
| 7739 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7740 | if (likely(!data_len)) |
| 7741 | break; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7742 | |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7743 | tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7744 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7745 | i++; |
| 7746 | tx_desc++; |
| 7747 | if (i == tx_ring->count) { |
| 7748 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
| 7749 | i = 0; |
| 7750 | } |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7751 | tx_desc->read.olinfo_status = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7752 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7753 | #ifdef IXGBE_FCOE |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 7754 | size = min_t(unsigned int, data_len, skb_frag_size(frag)); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7755 | #else |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 7756 | size = skb_frag_size(frag); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7757 | #endif |
| 7758 | data_len -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7759 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7760 | dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size, |
| 7761 | DMA_TO_DEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7762 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7763 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7764 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 7765 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7766 | /* write last descriptor with RS and EOP bits */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7767 | cmd_type |= size | IXGBE_TXD_CMD; |
| 7768 | tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7769 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 7770 | netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount); |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 7771 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7772 | /* set the timestamp */ |
| 7773 | first->time_stamp = jiffies; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7774 | |
| 7775 | /* |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7776 | * Force memory writes to complete before letting h/w know there |
| 7777 | * are new descriptors to fetch. (Only applicable for weak-ordered |
| 7778 | * memory model archs, such as IA-64). |
| 7779 | * |
| 7780 | * We also need this memory barrier to make certain all of the |
| 7781 | * status bits have been updated before next_to_watch is written. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7782 | */ |
| 7783 | wmb(); |
| 7784 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7785 | /* set next_to_watch value indicating a packet is present */ |
| 7786 | first->next_to_watch = tx_desc; |
| 7787 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7788 | i++; |
| 7789 | if (i == tx_ring->count) |
| 7790 | i = 0; |
| 7791 | |
| 7792 | tx_ring->next_to_use = i; |
| 7793 | |
Daniel Borkmann | 2367a17 | 2014-08-26 19:34:18 +0200 | [diff] [blame] | 7794 | ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED); |
| 7795 | |
| 7796 | if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) { |
Alexander Duyck | ad435ec | 2014-11-14 00:56:35 +0000 | [diff] [blame] | 7797 | writel(i, tx_ring->tail); |
| 7798 | |
| 7799 | /* we need this if more than one processor can write to our tail |
| 7800 | * at a time, it synchronizes IO on IA64/Altix systems |
| 7801 | */ |
| 7802 | mmiowb(); |
Daniel Borkmann | 9c938cd | 2014-08-24 15:42:16 +0200 | [diff] [blame] | 7803 | } |
Daniel Borkmann | 2367a17 | 2014-08-26 19:34:18 +0200 | [diff] [blame] | 7804 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7805 | return; |
| 7806 | dma_error: |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7807 | dev_err(tx_ring->dev, "TX DMA map failed\n"); |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 7808 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7809 | |
| 7810 | /* clear dma mappings for failed tx_buffer_info map */ |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 7811 | while (tx_buffer != first) { |
| 7812 | if (dma_unmap_len(tx_buffer, len)) |
| 7813 | dma_unmap_page(tx_ring->dev, |
| 7814 | dma_unmap_addr(tx_buffer, dma), |
| 7815 | dma_unmap_len(tx_buffer, len), |
| 7816 | DMA_TO_DEVICE); |
| 7817 | dma_unmap_len_set(tx_buffer, len, 0); |
| 7818 | |
| 7819 | if (i--) |
| 7820 | i += tx_ring->count; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7821 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7822 | } |
| 7823 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 7824 | if (dma_unmap_len(tx_buffer, len)) |
| 7825 | dma_unmap_single(tx_ring->dev, |
| 7826 | dma_unmap_addr(tx_buffer, dma), |
| 7827 | dma_unmap_len(tx_buffer, len), |
| 7828 | DMA_TO_DEVICE); |
| 7829 | dma_unmap_len_set(tx_buffer, len, 0); |
| 7830 | |
| 7831 | dev_kfree_skb_any(first->skb); |
| 7832 | first->skb = NULL; |
| 7833 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7834 | tx_ring->next_to_use = i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7835 | } |
| 7836 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7837 | static void ixgbe_atr(struct ixgbe_ring *ring, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7838 | struct ixgbe_tx_buffer *first) |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7839 | { |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7840 | struct ixgbe_q_vector *q_vector = ring->q_vector; |
| 7841 | union ixgbe_atr_hash_dword input = { .dword = 0 }; |
| 7842 | union ixgbe_atr_hash_dword common = { .dword = 0 }; |
| 7843 | union { |
| 7844 | unsigned char *network; |
| 7845 | struct iphdr *ipv4; |
| 7846 | struct ipv6hdr *ipv6; |
| 7847 | } hdr; |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 7848 | struct tcphdr *th; |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7849 | unsigned int hlen; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7850 | struct sk_buff *skb; |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 7851 | __be16 vlan_id; |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7852 | int l4_proto; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7853 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7854 | /* if ring doesn't have a interrupt vector, cannot perform ATR */ |
| 7855 | if (!q_vector) |
Guillaume Gaudonville | d3ead24 | 2010-06-29 18:29:00 +0000 | [diff] [blame] | 7856 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7857 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7858 | /* do nothing if sampling is disabled */ |
| 7859 | if (!ring->atr_sample_rate) |
| 7860 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7861 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7862 | ring->atr_count++; |
| 7863 | |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7864 | /* currently only IPv4/IPv6 with TCP is supported */ |
| 7865 | if ((first->protocol != htons(ETH_P_IP)) && |
| 7866 | (first->protocol != htons(ETH_P_IPV6))) |
| 7867 | return; |
| 7868 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7869 | /* snag network header to get L4 type and address */ |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7870 | skb = first->skb; |
| 7871 | hdr.network = skb_network_header(skb); |
Sowmini Varadhan | 9f3c750 | 2016-10-24 15:36:39 -0700 | [diff] [blame] | 7872 | if (unlikely(hdr.network <= skb->data)) |
| 7873 | return; |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 7874 | if (skb->encapsulation && |
| 7875 | first->protocol == htons(ETH_P_IP) && |
Sowmini Varadhan | 5202882 | 2016-10-24 15:36:38 -0700 | [diff] [blame] | 7876 | hdr.ipv4->protocol == IPPROTO_UDP) { |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7877 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7878 | |
Sowmini Varadhan | 9f3c750 | 2016-10-24 15:36:39 -0700 | [diff] [blame] | 7879 | if (unlikely(skb_tail_pointer(skb) < hdr.network + |
| 7880 | VXLAN_HEADROOM)) |
| 7881 | return; |
| 7882 | |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 7883 | /* verify the port is recognized as VXLAN */ |
| 7884 | if (adapter->vxlan_port && |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7885 | udp_hdr(skb)->dest == adapter->vxlan_port) |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 7886 | hdr.network = skb_inner_network_header(skb); |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 7887 | |
| 7888 | if (adapter->geneve_port && |
| 7889 | udp_hdr(skb)->dest == adapter->geneve_port) |
| 7890 | hdr.network = skb_inner_network_header(skb); |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7891 | } |
| 7892 | |
Sowmini Varadhan | 9f3c750 | 2016-10-24 15:36:39 -0700 | [diff] [blame] | 7893 | /* Make sure we have at least [minimum IPv4 header + TCP] |
| 7894 | * or [IPv6 header] bytes |
| 7895 | */ |
| 7896 | if (unlikely(skb_tail_pointer(skb) < hdr.network + 40)) |
| 7897 | return; |
| 7898 | |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7899 | /* Currently only IPv4/IPv6 with TCP is supported */ |
| 7900 | switch (hdr.ipv4->version) { |
| 7901 | case IPVERSION: |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7902 | /* access ihl as u8 to avoid unaligned access on ia64 */ |
| 7903 | hlen = (hdr.network[0] & 0x0F) << 2; |
| 7904 | l4_proto = hdr.ipv4->protocol; |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7905 | break; |
| 7906 | case 6: |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7907 | hlen = hdr.network - skb->data; |
| 7908 | l4_proto = ipv6_find_hdr(skb, &hlen, IPPROTO_TCP, NULL, NULL); |
| 7909 | hlen -= hdr.network - skb->data; |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7910 | break; |
| 7911 | default: |
| 7912 | return; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7913 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7914 | |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7915 | if (l4_proto != IPPROTO_TCP) |
| 7916 | return; |
| 7917 | |
Sowmini Varadhan | 9f3c750 | 2016-10-24 15:36:39 -0700 | [diff] [blame] | 7918 | if (unlikely(skb_tail_pointer(skb) < hdr.network + |
| 7919 | hlen + sizeof(struct tcphdr))) |
| 7920 | return; |
| 7921 | |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7922 | th = (struct tcphdr *)(hdr.network + hlen); |
| 7923 | |
| 7924 | /* skip this packet since the socket is closing */ |
| 7925 | if (th->fin) |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7926 | return; |
| 7927 | |
| 7928 | /* sample on all syn packets or once every atr sample count */ |
| 7929 | if (!th->syn && (ring->atr_count < ring->atr_sample_rate)) |
| 7930 | return; |
| 7931 | |
| 7932 | /* reset sample count */ |
| 7933 | ring->atr_count = 0; |
| 7934 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7935 | vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT); |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7936 | |
| 7937 | /* |
| 7938 | * src and dst are inverted, think how the receiver sees them |
| 7939 | * |
| 7940 | * The input is broken into two sections, a non-compressed section |
| 7941 | * containing vm_pool, vlan_id, and flow_type. The rest of the data |
| 7942 | * is XORed together and stored in the compressed dword. |
| 7943 | */ |
| 7944 | input.formatted.vlan_id = vlan_id; |
| 7945 | |
| 7946 | /* |
| 7947 | * since src port and flex bytes occupy the same word XOR them together |
| 7948 | * and write the value to source port portion of compressed dword |
| 7949 | */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7950 | if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN)) |
Joe Perches | a1108ff | 2014-03-13 05:19:25 +0000 | [diff] [blame] | 7951 | common.port.src ^= th->dest ^ htons(ETH_P_8021Q); |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7952 | else |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7953 | common.port.src ^= th->dest ^ first->protocol; |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7954 | common.port.dst ^= th->source; |
| 7955 | |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7956 | switch (hdr.ipv4->version) { |
| 7957 | case IPVERSION: |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7958 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4; |
| 7959 | common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr; |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7960 | break; |
| 7961 | case 6: |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7962 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6; |
| 7963 | common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^ |
| 7964 | hdr.ipv6->saddr.s6_addr32[1] ^ |
| 7965 | hdr.ipv6->saddr.s6_addr32[2] ^ |
| 7966 | hdr.ipv6->saddr.s6_addr32[3] ^ |
| 7967 | hdr.ipv6->daddr.s6_addr32[0] ^ |
| 7968 | hdr.ipv6->daddr.s6_addr32[1] ^ |
| 7969 | hdr.ipv6->daddr.s6_addr32[2] ^ |
| 7970 | hdr.ipv6->daddr.s6_addr32[3]; |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7971 | break; |
| 7972 | default: |
| 7973 | break; |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7974 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7975 | |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 7976 | if (hdr.network != skb_network_header(skb)) |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7977 | input.formatted.flow_type |= IXGBE_ATR_L4TYPE_TUNNEL_MASK; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7978 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7979 | /* This assumes the Rx queue and Tx queue are bound to the same CPU */ |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7980 | ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw, |
| 7981 | input, common, ring->queue_index); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7982 | } |
| 7983 | |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 7984 | static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb, |
Daniel Borkmann | 99932d4 | 2014-02-16 15:55:20 +0100 | [diff] [blame] | 7985 | void *accel_priv, select_queue_fallback_t fallback) |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 7986 | { |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 7987 | struct ixgbe_fwd_adapter *fwd_adapter = accel_priv; |
| 7988 | #ifdef IXGBE_FCOE |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 7989 | struct ixgbe_adapter *adapter; |
| 7990 | struct ixgbe_ring_feature *f; |
| 7991 | int txq; |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 7992 | #endif |
| 7993 | |
| 7994 | if (fwd_adapter) |
| 7995 | return skb->queue_mapping + fwd_adapter->tx_base_queue; |
| 7996 | |
| 7997 | #ifdef IXGBE_FCOE |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 7998 | |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 7999 | /* |
| 8000 | * only execute the code below if protocol is FCoE |
| 8001 | * or FIP and we have FCoE enabled on the adapter |
| 8002 | */ |
| 8003 | switch (vlan_get_protocol(skb)) { |
Joe Perches | a1108ff | 2014-03-13 05:19:25 +0000 | [diff] [blame] | 8004 | case htons(ETH_P_FCOE): |
| 8005 | case htons(ETH_P_FIP): |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 8006 | adapter = netdev_priv(dev); |
Alexander Duyck | c087663 | 2012-05-10 00:01:46 +0000 | [diff] [blame] | 8007 | |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 8008 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 8009 | break; |
| 8010 | default: |
Daniel Borkmann | 99932d4 | 2014-02-16 15:55:20 +0100 | [diff] [blame] | 8011 | return fallback(dev, skb); |
Krishna Kumar | fdd3d63 | 2010-02-03 13:13:10 +0000 | [diff] [blame] | 8012 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 8013 | |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 8014 | f = &adapter->ring_feature[RING_F_FCOE]; |
| 8015 | |
| 8016 | txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) : |
| 8017 | smp_processor_id(); |
| 8018 | |
| 8019 | while (txq >= f->indices) |
| 8020 | txq -= f->indices; |
| 8021 | |
| 8022 | return txq + f->offset; |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 8023 | #else |
Daniel Borkmann | 99932d4 | 2014-02-16 15:55:20 +0100 | [diff] [blame] | 8024 | return fallback(dev, skb); |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 8025 | #endif |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 8026 | } |
| 8027 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 8028 | netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb, |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 8029 | struct ixgbe_adapter *adapter, |
| 8030 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8031 | { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8032 | struct ixgbe_tx_buffer *first; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 8033 | int tso; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8034 | u32 tx_flags = 0; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 8035 | unsigned short f; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 8036 | u16 count = TXD_USE_COUNT(skb_headlen(skb)); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8037 | __be16 protocol = skb->protocol; |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 8038 | u8 hdr_len = 0; |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 8039 | |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 8040 | /* |
| 8041 | * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD, |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 8042 | * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD, |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 8043 | * + 2 desc gap to keep tail from touching head, |
| 8044 | * + 1 desc for context descriptor, |
| 8045 | * otherwise try next time |
| 8046 | */ |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 8047 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) |
| 8048 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size); |
Alexander Duyck | 7f66162 | 2013-02-09 01:19:55 +0000 | [diff] [blame] | 8049 | |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 8050 | if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) { |
| 8051 | tx_ring->tx_stats.tx_busy++; |
| 8052 | return NETDEV_TX_BUSY; |
| 8053 | } |
| 8054 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 8055 | /* record the location of the first descriptor for this packet */ |
| 8056 | first = &tx_ring->tx_buffer_info[tx_ring->next_to_use]; |
| 8057 | first->skb = skb; |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 8058 | first->bytecount = skb->len; |
| 8059 | first->gso_segs = 1; |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 8060 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8061 | /* if we have a HW VLAN tag being added default to the HW one */ |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 8062 | if (skb_vlan_tag_present(skb)) { |
| 8063 | tx_flags |= skb_vlan_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8064 | tx_flags |= IXGBE_TX_FLAGS_HW_VLAN; |
| 8065 | /* else if it is a SW VLAN check the next protocol and store the tag */ |
Joe Perches | a1108ff | 2014-03-13 05:19:25 +0000 | [diff] [blame] | 8066 | } else if (protocol == htons(ETH_P_8021Q)) { |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8067 | struct vlan_hdr *vhdr, _vhdr; |
| 8068 | vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr); |
| 8069 | if (!vhdr) |
| 8070 | goto out_drop; |
| 8071 | |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 8072 | tx_flags |= ntohs(vhdr->h_vlan_TCI) << |
| 8073 | IXGBE_TX_FLAGS_VLAN_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8074 | tx_flags |= IXGBE_TX_FLAGS_SW_VLAN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8075 | } |
Toshiaki Makita | 0213668 | 2015-01-29 20:37:09 +0900 | [diff] [blame] | 8076 | protocol = vlan_get_protocol(skb); |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 8077 | |
Mark Rustad | d523493 | 2014-08-09 07:02:09 +0000 | [diff] [blame] | 8078 | if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && |
| 8079 | adapter->ptp_clock && |
| 8080 | !test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS, |
| 8081 | &adapter->state)) { |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 8082 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; |
| 8083 | tx_flags |= IXGBE_TX_FLAGS_TSTAMP; |
Jacob Keller | 891dc08 | 2012-12-05 07:24:46 +0000 | [diff] [blame] | 8084 | |
| 8085 | /* schedule check for Tx timestamp */ |
| 8086 | adapter->ptp_tx_skb = skb_get(skb); |
| 8087 | adapter->ptp_tx_start = jiffies; |
| 8088 | schedule_work(&adapter->ptp_tx_work); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 8089 | } |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 8090 | |
Jakub Kicinski | ff29a86 | 2014-03-15 14:55:16 +0000 | [diff] [blame] | 8091 | skb_tx_timestamp(skb); |
| 8092 | |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 8093 | #ifdef CONFIG_PCI_IOV |
| 8094 | /* |
| 8095 | * Use the l2switch_enable flag - would be false if the DMA |
| 8096 | * Tx switch had been disabled. |
| 8097 | */ |
| 8098 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 8099 | tx_flags |= IXGBE_TX_FLAGS_CC; |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 8100 | |
| 8101 | #endif |
John Fastabend | 32701dc | 2011-09-27 03:51:56 +0000 | [diff] [blame] | 8102 | /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */ |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8103 | if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && |
Alexander Duyck | 09dca47 | 2011-07-20 00:09:10 +0000 | [diff] [blame] | 8104 | ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) || |
| 8105 | (skb->priority != TC_PRIO_CONTROL))) { |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8106 | tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK; |
John Fastabend | 32701dc | 2011-09-27 03:51:56 +0000 | [diff] [blame] | 8107 | tx_flags |= (skb->priority & 0x7) << |
| 8108 | IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8109 | if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) { |
| 8110 | struct vlan_ethhdr *vhdr; |
Francois Romieu | 2049e1f | 2014-03-30 03:14:27 +0000 | [diff] [blame] | 8111 | |
| 8112 | if (skb_cow_head(skb, 0)) |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8113 | goto out_drop; |
| 8114 | vhdr = (struct vlan_ethhdr *)skb->data; |
| 8115 | vhdr->h_vlan_TCI = htons(tx_flags >> |
| 8116 | IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 8117 | } else { |
| 8118 | tx_flags |= IXGBE_TX_FLAGS_HW_VLAN; |
| 8119 | } |
| 8120 | } |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 8121 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 8122 | /* record initial flags and protocol */ |
| 8123 | first->tx_flags = tx_flags; |
| 8124 | first->protocol = protocol; |
| 8125 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 8126 | #ifdef IXGBE_FCOE |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8127 | /* setup tx offload for FCoE */ |
Joe Perches | a1108ff | 2014-03-13 05:19:25 +0000 | [diff] [blame] | 8128 | if ((protocol == htons(ETH_P_FCOE)) && |
Alexander Duyck | a58915c | 2012-05-25 06:38:18 +0000 | [diff] [blame] | 8129 | (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) { |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 8130 | tso = ixgbe_fso(tx_ring, first, &hdr_len); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 8131 | if (tso < 0) |
| 8132 | goto out_drop; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8133 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8134 | goto xmit_fcoe; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 8135 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8136 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8137 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 8138 | tso = ixgbe_tso(tx_ring, first, &hdr_len); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8139 | if (tso < 0) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8140 | goto out_drop; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 8141 | else if (!tso) |
| 8142 | ixgbe_tx_csum(tx_ring, first); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8143 | |
| 8144 | /* add the ATR filter if ATR is on */ |
| 8145 | if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state)) |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 8146 | ixgbe_atr(tx_ring, first); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8147 | |
| 8148 | #ifdef IXGBE_FCOE |
| 8149 | xmit_fcoe: |
| 8150 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 8151 | ixgbe_tx_map(tx_ring, first, hdr_len); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8152 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8153 | return NETDEV_TX_OK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 8154 | |
| 8155 | out_drop: |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 8156 | dev_kfree_skb_any(first->skb); |
| 8157 | first->skb = NULL; |
| 8158 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 8159 | return NETDEV_TX_OK; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8160 | } |
| 8161 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8162 | static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb, |
| 8163 | struct net_device *netdev, |
| 8164 | struct ixgbe_ring *ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8165 | { |
| 8166 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 8167 | struct ixgbe_ring *tx_ring; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8168 | |
Alexander Duyck | a50c29d | 2012-02-08 07:50:40 +0000 | [diff] [blame] | 8169 | /* |
| 8170 | * The minimum packet size for olinfo paylen is 17 so pad the skb |
| 8171 | * in order to meet this minimum size requirement. |
| 8172 | */ |
Alexander Duyck | a94d9e2 | 2014-12-03 08:17:39 -0800 | [diff] [blame] | 8173 | if (skb_put_padto(skb, 17)) |
| 8174 | return NETDEV_TX_OK; |
Alexander Duyck | a50c29d | 2012-02-08 07:50:40 +0000 | [diff] [blame] | 8175 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8176 | tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping]; |
| 8177 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8178 | return ixgbe_xmit_frame_ring(skb, adapter, tx_ring); |
| 8179 | } |
| 8180 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8181 | static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, |
| 8182 | struct net_device *netdev) |
| 8183 | { |
| 8184 | return __ixgbe_xmit_frame(skb, netdev, NULL); |
| 8185 | } |
| 8186 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8187 | /** |
| 8188 | * ixgbe_set_mac - Change the Ethernet Address of the NIC |
| 8189 | * @netdev: network interface device structure |
| 8190 | * @p: pointer to an address structure |
| 8191 | * |
| 8192 | * Returns 0 on success, negative on failure |
| 8193 | **/ |
| 8194 | static int ixgbe_set_mac(struct net_device *netdev, void *p) |
| 8195 | { |
| 8196 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8197 | struct ixgbe_hw *hw = &adapter->hw; |
| 8198 | struct sockaddr *addr = p; |
| 8199 | |
| 8200 | if (!is_valid_ether_addr(addr->sa_data)) |
| 8201 | return -EADDRNOTAVAIL; |
| 8202 | |
| 8203 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 8204 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8205 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 8206 | ixgbe_mac_set_default_filter(adapter); |
| 8207 | |
| 8208 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8209 | } |
| 8210 | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 8211 | static int |
| 8212 | ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr) |
| 8213 | { |
| 8214 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8215 | struct ixgbe_hw *hw = &adapter->hw; |
| 8216 | u16 value; |
| 8217 | int rc; |
| 8218 | |
| 8219 | if (prtad != hw->phy.mdio.prtad) |
| 8220 | return -EINVAL; |
| 8221 | rc = hw->phy.ops.read_reg(hw, addr, devad, &value); |
| 8222 | if (!rc) |
| 8223 | rc = value; |
| 8224 | return rc; |
| 8225 | } |
| 8226 | |
| 8227 | static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad, |
| 8228 | u16 addr, u16 value) |
| 8229 | { |
| 8230 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8231 | struct ixgbe_hw *hw = &adapter->hw; |
| 8232 | |
| 8233 | if (prtad != hw->phy.mdio.prtad) |
| 8234 | return -EINVAL; |
| 8235 | return hw->phy.ops.write_reg(hw, addr, devad, value); |
| 8236 | } |
| 8237 | |
| 8238 | static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd) |
| 8239 | { |
| 8240 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8241 | |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 8242 | switch (cmd) { |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 8243 | case SIOCSHWTSTAMP: |
Jacob Keller | 93501d4 | 2014-02-28 15:48:58 -0800 | [diff] [blame] | 8244 | return ixgbe_ptp_set_ts_config(adapter, req); |
| 8245 | case SIOCGHWTSTAMP: |
| 8246 | return ixgbe_ptp_get_ts_config(adapter, req); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 8247 | default: |
| 8248 | return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd); |
| 8249 | } |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 8250 | } |
| 8251 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8252 | /** |
| 8253 | * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 8254 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8255 | * @netdev: network interface device structure |
| 8256 | * |
| 8257 | * Returns non-zero on failure |
| 8258 | **/ |
| 8259 | static int ixgbe_add_sanmac_netdev(struct net_device *dev) |
| 8260 | { |
| 8261 | int err = 0; |
| 8262 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 8263 | struct ixgbe_hw *hw = &adapter->hw; |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8264 | |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 8265 | if (is_valid_ether_addr(hw->mac.san_addr)) { |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8266 | rtnl_lock(); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 8267 | err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN); |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8268 | rtnl_unlock(); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 8269 | |
| 8270 | /* update SAN MAC vmdq pool selection */ |
| 8271 | hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0)); |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8272 | } |
| 8273 | return err; |
| 8274 | } |
| 8275 | |
| 8276 | /** |
| 8277 | * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 8278 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8279 | * @netdev: network interface device structure |
| 8280 | * |
| 8281 | * Returns non-zero on failure |
| 8282 | **/ |
| 8283 | static int ixgbe_del_sanmac_netdev(struct net_device *dev) |
| 8284 | { |
| 8285 | int err = 0; |
| 8286 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 8287 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 8288 | |
| 8289 | if (is_valid_ether_addr(mac->san_addr)) { |
| 8290 | rtnl_lock(); |
| 8291 | err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 8292 | rtnl_unlock(); |
| 8293 | } |
| 8294 | return err; |
| 8295 | } |
| 8296 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8297 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 8298 | /* |
| 8299 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 8300 | * without having to re-enable interrupts. It's not called while |
| 8301 | * the interrupt routine is executing. |
| 8302 | */ |
| 8303 | static void ixgbe_netpoll(struct net_device *netdev) |
| 8304 | { |
| 8305 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 8306 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8307 | |
Alexander Duyck | 1a647bd | 2010-01-13 01:49:13 +0000 | [diff] [blame] | 8308 | /* if interface is down do nothing */ |
| 8309 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 8310 | return; |
| 8311 | |
Alexander Duyck | 856f606 | 2015-02-25 17:45:54 +0000 | [diff] [blame] | 8312 | /* loop through and schedule all active queues */ |
| 8313 | for (i = 0; i < adapter->num_q_vectors; i++) |
| 8314 | ixgbe_msix_clean_rings(0, adapter->q_vector[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8315 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8316 | |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 8317 | #endif |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 8318 | |
| 8319 | static void ixgbe_get_stats64(struct net_device *netdev, |
| 8320 | struct rtnl_link_stats64 *stats) |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8321 | { |
| 8322 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8323 | int i; |
| 8324 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8325 | rcu_read_lock(); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8326 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8327 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8328 | u64 bytes, packets; |
| 8329 | unsigned int start; |
| 8330 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8331 | if (ring) { |
| 8332 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 8333 | start = u64_stats_fetch_begin_irq(&ring->syncp); |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8334 | packets = ring->stats.packets; |
| 8335 | bytes = ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 8336 | } while (u64_stats_fetch_retry_irq(&ring->syncp, start)); |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8337 | stats->rx_packets += packets; |
| 8338 | stats->rx_bytes += bytes; |
| 8339 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8340 | } |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 8341 | |
| 8342 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 8343 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]); |
| 8344 | u64 bytes, packets; |
| 8345 | unsigned int start; |
| 8346 | |
| 8347 | if (ring) { |
| 8348 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 8349 | start = u64_stats_fetch_begin_irq(&ring->syncp); |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 8350 | packets = ring->stats.packets; |
| 8351 | bytes = ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 8352 | } while (u64_stats_fetch_retry_irq(&ring->syncp, start)); |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 8353 | stats->tx_packets += packets; |
| 8354 | stats->tx_bytes += bytes; |
| 8355 | } |
| 8356 | } |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8357 | rcu_read_unlock(); |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 8358 | |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8359 | /* following stats updated by ixgbe_watchdog_task() */ |
| 8360 | stats->multicast = netdev->stats.multicast; |
| 8361 | stats->rx_errors = netdev->stats.rx_errors; |
| 8362 | stats->rx_length_errors = netdev->stats.rx_length_errors; |
| 8363 | stats->rx_crc_errors = netdev->stats.rx_crc_errors; |
| 8364 | stats->rx_missed_errors = netdev->stats.rx_missed_errors; |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8365 | } |
| 8366 | |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 8367 | #ifdef CONFIG_IXGBE_DCB |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 8368 | /** |
| 8369 | * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid. |
| 8370 | * @adapter: pointer to ixgbe_adapter |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8371 | * @tc: number of traffic classes currently enabled |
| 8372 | * |
| 8373 | * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm |
| 8374 | * 802.1Q priority maps to a packet buffer that exists. |
| 8375 | */ |
| 8376 | static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc) |
| 8377 | { |
| 8378 | struct ixgbe_hw *hw = &adapter->hw; |
| 8379 | u32 reg, rsave; |
| 8380 | int i; |
| 8381 | |
| 8382 | /* 82598 have a static priority to TC mapping that can not |
| 8383 | * be changed so no validation is needed. |
| 8384 | */ |
| 8385 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 8386 | return; |
| 8387 | |
| 8388 | reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC); |
| 8389 | rsave = reg; |
| 8390 | |
| 8391 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 8392 | u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT); |
| 8393 | |
| 8394 | /* If up2tc is out of bounds default to zero */ |
| 8395 | if (up2tc > tc) |
| 8396 | reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT); |
| 8397 | } |
| 8398 | |
| 8399 | if (reg != rsave) |
| 8400 | IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg); |
| 8401 | |
| 8402 | return; |
| 8403 | } |
| 8404 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 8405 | /** |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 8406 | * ixgbe_set_prio_tc_map - Configure netdev prio tc map |
| 8407 | * @adapter: Pointer to adapter struct |
| 8408 | * |
| 8409 | * Populate the netdev user priority to tc map |
| 8410 | */ |
| 8411 | static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter) |
| 8412 | { |
| 8413 | struct net_device *dev = adapter->netdev; |
| 8414 | struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg; |
| 8415 | struct ieee_ets *ets = adapter->ixgbe_ieee_ets; |
| 8416 | u8 prio; |
| 8417 | |
| 8418 | for (prio = 0; prio < MAX_USER_PRIORITY; prio++) { |
| 8419 | u8 tc = 0; |
| 8420 | |
| 8421 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) |
| 8422 | tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio); |
| 8423 | else if (ets) |
| 8424 | tc = ets->prio_tc[prio]; |
| 8425 | |
| 8426 | netdev_set_prio_tc_map(dev, prio, tc); |
| 8427 | } |
| 8428 | } |
| 8429 | |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 8430 | #endif /* CONFIG_IXGBE_DCB */ |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 8431 | /** |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 8432 | * ixgbe_setup_tc - configure net_device for multiple traffic classes |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8433 | * |
| 8434 | * @netdev: net device to configure |
| 8435 | * @tc: number of traffic classes to enable |
| 8436 | */ |
| 8437 | int ixgbe_setup_tc(struct net_device *dev, u8 tc) |
| 8438 | { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8439 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 8440 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8441 | bool pools; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8442 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8443 | /* Hardware supports up to 8 traffic classes */ |
Emil Tantilov | 7e3f5c8 | 2015-07-09 12:28:59 -0700 | [diff] [blame] | 8444 | if (tc > adapter->dcb_cfg.num_tcs.pg_tcs) |
| 8445 | return -EINVAL; |
| 8446 | |
| 8447 | if (hw->mac.type == ixgbe_mac_82598EB && tc && tc < MAX_TRAFFIC_CLASS) |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8448 | return -EINVAL; |
| 8449 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8450 | pools = (find_first_zero_bit(&adapter->fwd_bitmask, 32) > 1); |
| 8451 | if (tc && pools && adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS) |
| 8452 | return -EBUSY; |
| 8453 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8454 | /* Hardware has to reinitialize queues and interrupts to |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 8455 | * match packet buffer alignment. Unfortunately, the |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8456 | * hardware is not flexible enough to do this dynamically. |
| 8457 | */ |
| 8458 | if (netif_running(dev)) |
| 8459 | ixgbe_close(dev); |
Alexander Duyck | bf4d67d | 2015-10-20 13:28:17 -0700 | [diff] [blame] | 8460 | else |
| 8461 | ixgbe_reset(adapter); |
| 8462 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8463 | ixgbe_clear_interrupt_scheme(adapter); |
| 8464 | |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 8465 | #ifdef CONFIG_IXGBE_DCB |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8466 | if (tc) { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8467 | netdev_set_num_tc(dev, tc); |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 8468 | ixgbe_set_prio_tc_map(adapter); |
| 8469 | |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8470 | adapter->flags |= IXGBE_FLAG_DCB_ENABLED; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8471 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 8472 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 8473 | adapter->last_lfc_mode = adapter->hw.fc.requested_mode; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8474 | adapter->hw.fc.requested_mode = ixgbe_fc_none; |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 8475 | } |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8476 | } else { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8477 | netdev_reset_tc(dev); |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 8478 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 8479 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 8480 | adapter->hw.fc.requested_mode = adapter->last_lfc_mode; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8481 | |
| 8482 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8483 | |
| 8484 | adapter->temp_dcb_cfg.pfc_mode_enable = false; |
| 8485 | adapter->dcb_cfg.pfc_mode_enable = false; |
| 8486 | } |
| 8487 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8488 | ixgbe_validate_rtr(adapter, tc); |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 8489 | |
| 8490 | #endif /* CONFIG_IXGBE_DCB */ |
| 8491 | ixgbe_init_interrupt_scheme(adapter); |
| 8492 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8493 | if (netif_running(dev)) |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 8494 | return ixgbe_open(dev); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8495 | |
| 8496 | return 0; |
| 8497 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8498 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8499 | static int ixgbe_delete_clsu32(struct ixgbe_adapter *adapter, |
| 8500 | struct tc_cls_u32_offload *cls) |
| 8501 | { |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8502 | u32 hdl = cls->knode.handle; |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8503 | u32 uhtid = TC_U32_USERHTID(cls->knode.handle); |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8504 | u32 loc = cls->knode.handle & 0xfffff; |
| 8505 | int err = 0, i, j; |
| 8506 | struct ixgbe_jump_table *jump = NULL; |
| 8507 | |
| 8508 | if (loc > IXGBE_MAX_HW_ENTRIES) |
| 8509 | return -EINVAL; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8510 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8511 | if ((uhtid != 0x800) && (uhtid >= IXGBE_MAX_LINK_HANDLE)) |
| 8512 | return -EINVAL; |
| 8513 | |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8514 | /* Clear this filter in the link data it is associated with */ |
| 8515 | if (uhtid != 0x800) { |
| 8516 | jump = adapter->jump_tables[uhtid]; |
Amritha Nambiar | 12746fd | 2016-05-16 18:33:20 -0700 | [diff] [blame] | 8517 | if (!jump) |
| 8518 | return -EINVAL; |
| 8519 | if (!test_bit(loc - 1, jump->child_loc_map)) |
| 8520 | return -EINVAL; |
| 8521 | clear_bit(loc - 1, jump->child_loc_map); |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8522 | } |
| 8523 | |
| 8524 | /* Check if the filter being deleted is a link */ |
| 8525 | for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) { |
| 8526 | jump = adapter->jump_tables[i]; |
| 8527 | if (jump && jump->link_hdl == hdl) { |
| 8528 | /* Delete filters in the hardware in the child hash |
| 8529 | * table associated with this link |
| 8530 | */ |
| 8531 | for (j = 0; j < IXGBE_MAX_HW_ENTRIES; j++) { |
| 8532 | if (!test_bit(j, jump->child_loc_map)) |
| 8533 | continue; |
| 8534 | spin_lock(&adapter->fdir_perfect_lock); |
| 8535 | err = ixgbe_update_ethtool_fdir_entry(adapter, |
| 8536 | NULL, |
| 8537 | j + 1); |
| 8538 | spin_unlock(&adapter->fdir_perfect_lock); |
| 8539 | clear_bit(j, jump->child_loc_map); |
| 8540 | } |
| 8541 | /* Remove resources for this link */ |
| 8542 | kfree(jump->input); |
| 8543 | kfree(jump->mask); |
| 8544 | kfree(jump); |
| 8545 | adapter->jump_tables[i] = NULL; |
| 8546 | return err; |
| 8547 | } |
| 8548 | } |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8549 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8550 | spin_lock(&adapter->fdir_perfect_lock); |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8551 | err = ixgbe_update_ethtool_fdir_entry(adapter, NULL, loc); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8552 | spin_unlock(&adapter->fdir_perfect_lock); |
| 8553 | return err; |
| 8554 | } |
| 8555 | |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8556 | static int ixgbe_configure_clsu32_add_hnode(struct ixgbe_adapter *adapter, |
| 8557 | __be16 protocol, |
| 8558 | struct tc_cls_u32_offload *cls) |
| 8559 | { |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8560 | u32 uhtid = TC_U32_USERHTID(cls->hnode.handle); |
| 8561 | |
| 8562 | if (uhtid >= IXGBE_MAX_LINK_HANDLE) |
| 8563 | return -EINVAL; |
| 8564 | |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8565 | /* This ixgbe devices do not support hash tables at the moment |
| 8566 | * so abort when given hash tables. |
| 8567 | */ |
| 8568 | if (cls->hnode.divisor > 0) |
| 8569 | return -EINVAL; |
| 8570 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8571 | set_bit(uhtid - 1, &adapter->tables); |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8572 | return 0; |
| 8573 | } |
| 8574 | |
| 8575 | static int ixgbe_configure_clsu32_del_hnode(struct ixgbe_adapter *adapter, |
| 8576 | struct tc_cls_u32_offload *cls) |
| 8577 | { |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8578 | u32 uhtid = TC_U32_USERHTID(cls->hnode.handle); |
| 8579 | |
| 8580 | if (uhtid >= IXGBE_MAX_LINK_HANDLE) |
| 8581 | return -EINVAL; |
| 8582 | |
| 8583 | clear_bit(uhtid - 1, &adapter->tables); |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8584 | return 0; |
| 8585 | } |
| 8586 | |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8587 | #ifdef CONFIG_NET_CLS_ACT |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 8588 | struct upper_walk_data { |
| 8589 | struct ixgbe_adapter *adapter; |
| 8590 | u64 action; |
| 8591 | int ifindex; |
| 8592 | u8 queue; |
| 8593 | }; |
| 8594 | |
| 8595 | static int get_macvlan_queue(struct net_device *upper, void *_data) |
| 8596 | { |
| 8597 | if (netif_is_macvlan(upper)) { |
| 8598 | struct macvlan_dev *dfwd = netdev_priv(upper); |
| 8599 | struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv; |
| 8600 | struct upper_walk_data *data = _data; |
| 8601 | struct ixgbe_adapter *adapter = data->adapter; |
| 8602 | int ifindex = data->ifindex; |
| 8603 | |
| 8604 | if (vadapter && vadapter->netdev->ifindex == ifindex) { |
| 8605 | data->queue = adapter->rx_ring[vadapter->rx_base_queue]->reg_idx; |
| 8606 | data->action = data->queue; |
| 8607 | return 1; |
| 8608 | } |
| 8609 | } |
| 8610 | |
| 8611 | return 0; |
| 8612 | } |
| 8613 | |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8614 | static int handle_redirect_action(struct ixgbe_adapter *adapter, int ifindex, |
| 8615 | u8 *queue, u64 *action) |
| 8616 | { |
| 8617 | unsigned int num_vfs = adapter->num_vfs, vf; |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 8618 | struct upper_walk_data data; |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8619 | struct net_device *upper; |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8620 | |
| 8621 | /* redirect to a SRIOV VF */ |
| 8622 | for (vf = 0; vf < num_vfs; ++vf) { |
| 8623 | upper = pci_get_drvdata(adapter->vfinfo[vf].vfdev); |
| 8624 | if (upper->ifindex == ifindex) { |
| 8625 | if (adapter->num_rx_pools > 1) |
| 8626 | *queue = vf * 2; |
| 8627 | else |
| 8628 | *queue = vf * adapter->num_rx_queues_per_pool; |
| 8629 | |
| 8630 | *action = vf + 1; |
| 8631 | *action <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF; |
| 8632 | return 0; |
| 8633 | } |
| 8634 | } |
| 8635 | |
| 8636 | /* redirect to a offloaded macvlan netdev */ |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 8637 | data.adapter = adapter; |
| 8638 | data.ifindex = ifindex; |
| 8639 | data.action = 0; |
| 8640 | data.queue = 0; |
| 8641 | if (netdev_walk_all_upper_dev_rcu(adapter->netdev, |
| 8642 | get_macvlan_queue, &data)) { |
| 8643 | *action = data.action; |
| 8644 | *queue = data.queue; |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8645 | |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 8646 | return 0; |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8647 | } |
| 8648 | |
| 8649 | return -EINVAL; |
| 8650 | } |
| 8651 | |
| 8652 | static int parse_tc_actions(struct ixgbe_adapter *adapter, |
| 8653 | struct tcf_exts *exts, u64 *action, u8 *queue) |
| 8654 | { |
| 8655 | const struct tc_action *a; |
WANG Cong | 22dc13c | 2016-08-13 22:35:00 -0700 | [diff] [blame] | 8656 | LIST_HEAD(actions); |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8657 | int err; |
| 8658 | |
| 8659 | if (tc_no_actions(exts)) |
| 8660 | return -EINVAL; |
| 8661 | |
WANG Cong | 22dc13c | 2016-08-13 22:35:00 -0700 | [diff] [blame] | 8662 | tcf_exts_to_list(exts, &actions); |
| 8663 | list_for_each_entry(a, &actions, list) { |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8664 | |
| 8665 | /* Drop action */ |
| 8666 | if (is_tcf_gact_shot(a)) { |
| 8667 | *action = IXGBE_FDIR_DROP_QUEUE; |
| 8668 | *queue = IXGBE_FDIR_DROP_QUEUE; |
| 8669 | return 0; |
| 8670 | } |
| 8671 | |
| 8672 | /* Redirect to a VF or a offloaded macvlan */ |
Shmulik Ladkani | 5724b8b | 2016-10-13 09:06:43 +0300 | [diff] [blame] | 8673 | if (is_tcf_mirred_egress_redirect(a)) { |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8674 | int ifindex = tcf_mirred_ifindex(a); |
| 8675 | |
| 8676 | err = handle_redirect_action(adapter, ifindex, queue, |
| 8677 | action); |
| 8678 | if (err == 0) |
| 8679 | return err; |
| 8680 | } |
| 8681 | } |
| 8682 | |
| 8683 | return -EINVAL; |
| 8684 | } |
| 8685 | #else |
| 8686 | static int parse_tc_actions(struct ixgbe_adapter *adapter, |
| 8687 | struct tcf_exts *exts, u64 *action, u8 *queue) |
| 8688 | { |
| 8689 | return -EINVAL; |
| 8690 | } |
| 8691 | #endif /* CONFIG_NET_CLS_ACT */ |
| 8692 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8693 | static int ixgbe_clsu32_build_input(struct ixgbe_fdir_filter *input, |
| 8694 | union ixgbe_atr_input *mask, |
| 8695 | struct tc_cls_u32_offload *cls, |
| 8696 | struct ixgbe_mat_field *field_ptr, |
| 8697 | struct ixgbe_nexthdr *nexthdr) |
| 8698 | { |
| 8699 | int i, j, off; |
| 8700 | __be32 val, m; |
| 8701 | bool found_entry = false, found_jump_field = false; |
| 8702 | |
| 8703 | for (i = 0; i < cls->knode.sel->nkeys; i++) { |
| 8704 | off = cls->knode.sel->keys[i].off; |
| 8705 | val = cls->knode.sel->keys[i].val; |
| 8706 | m = cls->knode.sel->keys[i].mask; |
| 8707 | |
| 8708 | for (j = 0; field_ptr[j].val; j++) { |
| 8709 | if (field_ptr[j].off == off) { |
| 8710 | field_ptr[j].val(input, mask, val, m); |
| 8711 | input->filter.formatted.flow_type |= |
| 8712 | field_ptr[j].type; |
| 8713 | found_entry = true; |
| 8714 | break; |
| 8715 | } |
| 8716 | } |
| 8717 | if (nexthdr) { |
| 8718 | if (nexthdr->off == cls->knode.sel->keys[i].off && |
| 8719 | nexthdr->val == cls->knode.sel->keys[i].val && |
| 8720 | nexthdr->mask == cls->knode.sel->keys[i].mask) |
| 8721 | found_jump_field = true; |
| 8722 | else |
| 8723 | continue; |
| 8724 | } |
| 8725 | } |
| 8726 | |
| 8727 | if (nexthdr && !found_jump_field) |
| 8728 | return -EINVAL; |
| 8729 | |
| 8730 | if (!found_entry) |
| 8731 | return 0; |
| 8732 | |
| 8733 | mask->formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK | |
| 8734 | IXGBE_ATR_L4TYPE_MASK; |
| 8735 | |
| 8736 | if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4) |
| 8737 | mask->formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK; |
| 8738 | |
| 8739 | return 0; |
| 8740 | } |
| 8741 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8742 | static int ixgbe_configure_clsu32(struct ixgbe_adapter *adapter, |
| 8743 | __be16 protocol, |
| 8744 | struct tc_cls_u32_offload *cls) |
| 8745 | { |
| 8746 | u32 loc = cls->knode.handle & 0xfffff; |
| 8747 | struct ixgbe_hw *hw = &adapter->hw; |
| 8748 | struct ixgbe_mat_field *field_ptr; |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8749 | struct ixgbe_fdir_filter *input = NULL; |
| 8750 | union ixgbe_atr_input *mask = NULL; |
| 8751 | struct ixgbe_jump_table *jump = NULL; |
| 8752 | int i, err = -EINVAL; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8753 | u8 queue; |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8754 | u32 uhtid, link_uhtid; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8755 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8756 | uhtid = TC_U32_USERHTID(cls->knode.handle); |
| 8757 | link_uhtid = TC_U32_USERHTID(cls->knode.link_handle); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8758 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8759 | /* At the moment cls_u32 jumps to network layer and skips past |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8760 | * L2 headers. The canonical method to match L2 frames is to use |
| 8761 | * negative values. However this is error prone at best but really |
| 8762 | * just broken because there is no way to "know" what sort of hdr |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8763 | * is in front of the network layer. Fix cls_u32 to support L2 |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8764 | * headers when needed. |
| 8765 | */ |
| 8766 | if (protocol != htons(ETH_P_IP)) |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8767 | return err; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8768 | |
| 8769 | if (loc >= ((1024 << adapter->fdir_pballoc) - 2)) { |
| 8770 | e_err(drv, "Location out of range\n"); |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8771 | return err; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8772 | } |
| 8773 | |
| 8774 | /* cls u32 is a graph starting at root node 0x800. The driver tracks |
| 8775 | * links and also the fields used to advance the parser across each |
| 8776 | * link (e.g. nexthdr/eat parameters from 'tc'). This way we can map |
| 8777 | * the u32 graph onto the hardware parse graph denoted in ixgbe_model.h |
| 8778 | * To add support for new nodes update ixgbe_model.h parse structures |
| 8779 | * this function _should_ be generic try not to hardcode values here. |
| 8780 | */ |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8781 | if (uhtid == 0x800) { |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8782 | field_ptr = (adapter->jump_tables[0])->mat; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8783 | } else { |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8784 | if (uhtid >= IXGBE_MAX_LINK_HANDLE) |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8785 | return err; |
| 8786 | if (!adapter->jump_tables[uhtid]) |
| 8787 | return err; |
| 8788 | field_ptr = (adapter->jump_tables[uhtid])->mat; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8789 | } |
| 8790 | |
| 8791 | if (!field_ptr) |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8792 | return err; |
| 8793 | |
| 8794 | /* At this point we know the field_ptr is valid and need to either |
| 8795 | * build cls_u32 link or attach filter. Because adding a link to |
| 8796 | * a handle that does not exist is invalid and the same for adding |
| 8797 | * rules to handles that don't exist. |
| 8798 | */ |
| 8799 | |
| 8800 | if (link_uhtid) { |
| 8801 | struct ixgbe_nexthdr *nexthdr = ixgbe_ipv4_jumps; |
| 8802 | |
| 8803 | if (link_uhtid >= IXGBE_MAX_LINK_HANDLE) |
| 8804 | return err; |
| 8805 | |
| 8806 | if (!test_bit(link_uhtid - 1, &adapter->tables)) |
| 8807 | return err; |
| 8808 | |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8809 | /* Multiple filters as links to the same hash table are not |
| 8810 | * supported. To add a new filter with the same next header |
| 8811 | * but different match/jump conditions, create a new hash table |
| 8812 | * and link to it. |
| 8813 | */ |
| 8814 | if (adapter->jump_tables[link_uhtid] && |
| 8815 | (adapter->jump_tables[link_uhtid])->link_hdl) { |
| 8816 | e_err(drv, "Link filter exists for link: %x\n", |
| 8817 | link_uhtid); |
| 8818 | return err; |
| 8819 | } |
| 8820 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8821 | for (i = 0; nexthdr[i].jump; i++) { |
| 8822 | if (nexthdr[i].o != cls->knode.sel->offoff || |
| 8823 | nexthdr[i].s != cls->knode.sel->offshift || |
| 8824 | nexthdr[i].m != cls->knode.sel->offmask) |
| 8825 | return err; |
| 8826 | |
| 8827 | jump = kzalloc(sizeof(*jump), GFP_KERNEL); |
| 8828 | if (!jump) |
| 8829 | return -ENOMEM; |
| 8830 | input = kzalloc(sizeof(*input), GFP_KERNEL); |
| 8831 | if (!input) { |
| 8832 | err = -ENOMEM; |
| 8833 | goto free_jump; |
| 8834 | } |
| 8835 | mask = kzalloc(sizeof(*mask), GFP_KERNEL); |
| 8836 | if (!mask) { |
| 8837 | err = -ENOMEM; |
Amritha Nambiar | 12746fd | 2016-05-16 18:33:20 -0700 | [diff] [blame] | 8838 | goto free_input; |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8839 | } |
| 8840 | jump->input = input; |
| 8841 | jump->mask = mask; |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8842 | jump->link_hdl = cls->knode.handle; |
| 8843 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8844 | err = ixgbe_clsu32_build_input(input, mask, cls, |
| 8845 | field_ptr, &nexthdr[i]); |
| 8846 | if (!err) { |
| 8847 | jump->mat = nexthdr[i].jump; |
| 8848 | adapter->jump_tables[link_uhtid] = jump; |
| 8849 | break; |
| 8850 | } |
| 8851 | } |
| 8852 | return 0; |
| 8853 | } |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8854 | |
| 8855 | input = kzalloc(sizeof(*input), GFP_KERNEL); |
| 8856 | if (!input) |
| 8857 | return -ENOMEM; |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8858 | mask = kzalloc(sizeof(*mask), GFP_KERNEL); |
| 8859 | if (!mask) { |
| 8860 | err = -ENOMEM; |
Amritha Nambiar | 12746fd | 2016-05-16 18:33:20 -0700 | [diff] [blame] | 8861 | goto free_input; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8862 | } |
| 8863 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8864 | if ((uhtid != 0x800) && (adapter->jump_tables[uhtid])) { |
| 8865 | if ((adapter->jump_tables[uhtid])->input) |
| 8866 | memcpy(input, (adapter->jump_tables[uhtid])->input, |
| 8867 | sizeof(*input)); |
| 8868 | if ((adapter->jump_tables[uhtid])->mask) |
| 8869 | memcpy(mask, (adapter->jump_tables[uhtid])->mask, |
| 8870 | sizeof(*mask)); |
Amritha Nambiar | 12746fd | 2016-05-16 18:33:20 -0700 | [diff] [blame] | 8871 | |
| 8872 | /* Lookup in all child hash tables if this location is already |
| 8873 | * filled with a filter |
| 8874 | */ |
| 8875 | for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) { |
| 8876 | struct ixgbe_jump_table *link = adapter->jump_tables[i]; |
| 8877 | |
| 8878 | if (link && (test_bit(loc - 1, link->child_loc_map))) { |
| 8879 | e_err(drv, "Filter exists in location: %x\n", |
| 8880 | loc); |
| 8881 | err = -EINVAL; |
| 8882 | goto err_out; |
| 8883 | } |
| 8884 | } |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8885 | } |
| 8886 | err = ixgbe_clsu32_build_input(input, mask, cls, field_ptr, NULL); |
| 8887 | if (err) |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8888 | goto err_out; |
| 8889 | |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8890 | err = parse_tc_actions(adapter, cls->knode.exts, &input->action, |
| 8891 | &queue); |
| 8892 | if (err < 0) |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8893 | goto err_out; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8894 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8895 | input->sw_idx = loc; |
| 8896 | |
| 8897 | spin_lock(&adapter->fdir_perfect_lock); |
| 8898 | |
| 8899 | if (hlist_empty(&adapter->fdir_filter_list)) { |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8900 | memcpy(&adapter->fdir_mask, mask, sizeof(*mask)); |
| 8901 | err = ixgbe_fdir_set_input_mask_82599(hw, mask); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8902 | if (err) |
| 8903 | goto err_out_w_lock; |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8904 | } else if (memcmp(&adapter->fdir_mask, mask, sizeof(*mask))) { |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8905 | err = -EINVAL; |
| 8906 | goto err_out_w_lock; |
| 8907 | } |
| 8908 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8909 | ixgbe_atr_compute_perfect_hash_82599(&input->filter, mask); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8910 | err = ixgbe_fdir_write_perfect_filter_82599(hw, &input->filter, |
| 8911 | input->sw_idx, queue); |
| 8912 | if (!err) |
| 8913 | ixgbe_update_ethtool_fdir_entry(adapter, input, input->sw_idx); |
| 8914 | spin_unlock(&adapter->fdir_perfect_lock); |
| 8915 | |
Amritha Nambiar | 12746fd | 2016-05-16 18:33:20 -0700 | [diff] [blame] | 8916 | if ((uhtid != 0x800) && (adapter->jump_tables[uhtid])) |
| 8917 | set_bit(loc - 1, (adapter->jump_tables[uhtid])->child_loc_map); |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8918 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8919 | kfree(mask); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8920 | return err; |
| 8921 | err_out_w_lock: |
| 8922 | spin_unlock(&adapter->fdir_perfect_lock); |
| 8923 | err_out: |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8924 | kfree(mask); |
Amritha Nambiar | 12746fd | 2016-05-16 18:33:20 -0700 | [diff] [blame] | 8925 | free_input: |
| 8926 | kfree(input); |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8927 | free_jump: |
| 8928 | kfree(jump); |
| 8929 | return err; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8930 | } |
| 8931 | |
Emil Tantilov | 6e2a60b | 2016-02-17 15:55:06 -0800 | [diff] [blame] | 8932 | static int __ixgbe_setup_tc(struct net_device *dev, u32 handle, __be16 proto, |
| 8933 | struct tc_to_netdev *tc) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 8934 | { |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8935 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 8936 | |
| 8937 | if (TC_H_MAJ(handle) == TC_H_MAJ(TC_H_INGRESS) && |
| 8938 | tc->type == TC_SETUP_CLSU32) { |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8939 | switch (tc->cls_u32->command) { |
| 8940 | case TC_CLSU32_NEW_KNODE: |
| 8941 | case TC_CLSU32_REPLACE_KNODE: |
| 8942 | return ixgbe_configure_clsu32(adapter, |
| 8943 | proto, tc->cls_u32); |
| 8944 | case TC_CLSU32_DELETE_KNODE: |
| 8945 | return ixgbe_delete_clsu32(adapter, tc->cls_u32); |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8946 | case TC_CLSU32_NEW_HNODE: |
| 8947 | case TC_CLSU32_REPLACE_HNODE: |
| 8948 | return ixgbe_configure_clsu32_add_hnode(adapter, proto, |
| 8949 | tc->cls_u32); |
| 8950 | case TC_CLSU32_DELETE_HNODE: |
| 8951 | return ixgbe_configure_clsu32_del_hnode(adapter, |
| 8952 | tc->cls_u32); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8953 | default: |
| 8954 | return -EINVAL; |
| 8955 | } |
| 8956 | } |
| 8957 | |
John Fastabend | 5eb4dce | 2016-02-29 11:26:13 -0800 | [diff] [blame] | 8958 | if (tc->type != TC_SETUP_MQPRIO) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 8959 | return -EINVAL; |
| 8960 | |
Amritha Nambiar | 56f36ac | 2017-03-15 10:39:25 -0700 | [diff] [blame] | 8961 | tc->mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS; |
| 8962 | |
| 8963 | return ixgbe_setup_tc(dev, tc->mqprio->num_tc); |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 8964 | } |
| 8965 | |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 8966 | #ifdef CONFIG_PCI_IOV |
| 8967 | void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter) |
| 8968 | { |
| 8969 | struct net_device *netdev = adapter->netdev; |
| 8970 | |
| 8971 | rtnl_lock(); |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 8972 | ixgbe_setup_tc(netdev, netdev_get_num_tc(netdev)); |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 8973 | rtnl_unlock(); |
| 8974 | } |
| 8975 | |
| 8976 | #endif |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8977 | void ixgbe_do_reset(struct net_device *netdev) |
| 8978 | { |
| 8979 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8980 | |
| 8981 | if (netif_running(netdev)) |
| 8982 | ixgbe_reinit_locked(adapter); |
| 8983 | else |
| 8984 | ixgbe_reset(adapter); |
| 8985 | } |
| 8986 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 8987 | static netdev_features_t ixgbe_fix_features(struct net_device *netdev, |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8988 | netdev_features_t features) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8989 | { |
| 8990 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8991 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8992 | /* If Rx checksum is disabled, then RSC/LRO should also be disabled */ |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8993 | if (!(features & NETIF_F_RXCSUM)) |
| 8994 | features &= ~NETIF_F_LRO; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8995 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8996 | /* Turn off LRO if not RSC capable */ |
| 8997 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) |
| 8998 | features &= ~NETIF_F_LRO; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 8999 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9000 | return features; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9001 | } |
| 9002 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 9003 | static int ixgbe_set_features(struct net_device *netdev, |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9004 | netdev_features_t features) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9005 | { |
| 9006 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9007 | netdev_features_t changed = netdev->features ^ features; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9008 | bool need_reset = false; |
| 9009 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9010 | /* Make sure RSC matches LRO, reset if change */ |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9011 | if (!(features & NETIF_F_LRO)) { |
| 9012 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9013 | need_reset = true; |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9014 | adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED; |
| 9015 | } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) && |
| 9016 | !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) { |
| 9017 | if (adapter->rx_itr_setting == 1 || |
| 9018 | adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) { |
| 9019 | adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED; |
| 9020 | need_reset = true; |
| 9021 | } else if ((changed ^ features) & NETIF_F_LRO) { |
| 9022 | e_info(probe, "rx-usecs set too low, " |
| 9023 | "disabling RSC\n"); |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9024 | } |
| 9025 | } |
| 9026 | |
| 9027 | /* |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9028 | * Check if Flow Director n-tuple support or hw_tc support was |
| 9029 | * enabled or disabled. If the state changed, we need to reset. |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9030 | */ |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9031 | if ((features & NETIF_F_NTUPLE) || (features & NETIF_F_HW_TC)) { |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9032 | /* turn off ATR, enable perfect filters and reset */ |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 9033 | if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) |
| 9034 | need_reset = true; |
| 9035 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9036 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 9037 | adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9038 | } else { |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 9039 | /* turn off perfect filters, enable ATR and reset */ |
| 9040 | if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 9041 | need_reset = true; |
| 9042 | |
| 9043 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 9044 | |
| 9045 | /* We cannot enable ATR if SR-IOV is enabled */ |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9046 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED || |
| 9047 | /* We cannot enable ATR if we have 2 or more tcs */ |
| 9048 | (netdev_get_num_tc(netdev) > 1) || |
| 9049 | /* We cannot enable ATR if RSS is disabled */ |
| 9050 | (adapter->ring_feature[RING_F_RSS].limit <= 1) || |
| 9051 | /* A sample rate of 0 indicates ATR disabled */ |
| 9052 | (!adapter->atr_sample_rate)) |
| 9053 | ; /* do nothing not supported */ |
| 9054 | else /* otherwise supported and set the flag */ |
| 9055 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9056 | } |
| 9057 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 9058 | if (changed & NETIF_F_RXALL) |
| 9059 | need_reset = true; |
| 9060 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9061 | netdev->features = features; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 9062 | |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 9063 | if ((adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) { |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9064 | if (features & NETIF_F_RXCSUM) { |
| 9065 | adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED; |
| 9066 | } else { |
| 9067 | u32 port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK; |
| 9068 | |
| 9069 | ixgbe_clear_udp_tunnel_port(adapter, port_mask); |
| 9070 | } |
| 9071 | } |
| 9072 | |
| 9073 | if ((adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)) { |
| 9074 | if (features & NETIF_F_RXCSUM) { |
| 9075 | adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED; |
| 9076 | } else { |
| 9077 | u32 port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK; |
| 9078 | |
| 9079 | ixgbe_clear_udp_tunnel_port(adapter, port_mask); |
| 9080 | } |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 9081 | } |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 9082 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9083 | if (need_reset) |
| 9084 | ixgbe_do_reset(netdev); |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 9085 | else if (changed & (NETIF_F_HW_VLAN_CTAG_RX | |
| 9086 | NETIF_F_HW_VLAN_CTAG_FILTER)) |
| 9087 | ixgbe_set_rx_mode(netdev); |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9088 | |
| 9089 | return 0; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9090 | } |
| 9091 | |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9092 | /** |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9093 | * ixgbe_add_udp_tunnel_port - Get notifications about adding UDP tunnel ports |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9094 | * @dev: The port's netdev |
Sabrina Dubroca | e5de25d | 2016-07-11 13:12:28 +0200 | [diff] [blame] | 9095 | * @ti: Tunnel endpoint information |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9096 | **/ |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9097 | static void ixgbe_add_udp_tunnel_port(struct net_device *dev, |
| 9098 | struct udp_tunnel_info *ti) |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9099 | { |
| 9100 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 9101 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 9102 | __be16 port = ti->port; |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9103 | u32 port_shift = 0; |
| 9104 | u32 reg; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 9105 | |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 9106 | if (ti->sa_family != AF_INET) |
| 9107 | return; |
| 9108 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9109 | switch (ti->type) { |
| 9110 | case UDP_TUNNEL_TYPE_VXLAN: |
| 9111 | if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) |
| 9112 | return; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9113 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9114 | if (adapter->vxlan_port == port) |
| 9115 | return; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9116 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9117 | if (adapter->vxlan_port) { |
| 9118 | netdev_info(dev, |
| 9119 | "VXLAN port %d set, not adding port %d\n", |
| 9120 | ntohs(adapter->vxlan_port), |
| 9121 | ntohs(port)); |
| 9122 | return; |
| 9123 | } |
| 9124 | |
| 9125 | adapter->vxlan_port = port; |
| 9126 | break; |
| 9127 | case UDP_TUNNEL_TYPE_GENEVE: |
| 9128 | if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)) |
| 9129 | return; |
| 9130 | |
| 9131 | if (adapter->geneve_port == port) |
| 9132 | return; |
| 9133 | |
| 9134 | if (adapter->geneve_port) { |
| 9135 | netdev_info(dev, |
| 9136 | "GENEVE port %d set, not adding port %d\n", |
| 9137 | ntohs(adapter->geneve_port), |
| 9138 | ntohs(port)); |
| 9139 | return; |
| 9140 | } |
| 9141 | |
| 9142 | port_shift = IXGBE_VXLANCTRL_GENEVE_UDPPORT_SHIFT; |
| 9143 | adapter->geneve_port = port; |
| 9144 | break; |
| 9145 | default: |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9146 | return; |
| 9147 | } |
| 9148 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9149 | reg = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) | ntohs(port) << port_shift; |
| 9150 | IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, reg); |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9151 | } |
| 9152 | |
| 9153 | /** |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9154 | * ixgbe_del_udp_tunnel_port - Get notifications about removing UDP tunnel ports |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9155 | * @dev: The port's netdev |
Sabrina Dubroca | e5de25d | 2016-07-11 13:12:28 +0200 | [diff] [blame] | 9156 | * @ti: Tunnel endpoint information |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9157 | **/ |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9158 | static void ixgbe_del_udp_tunnel_port(struct net_device *dev, |
| 9159 | struct udp_tunnel_info *ti) |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9160 | { |
| 9161 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9162 | u32 port_mask; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9163 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9164 | if (ti->type != UDP_TUNNEL_TYPE_VXLAN && |
| 9165 | ti->type != UDP_TUNNEL_TYPE_GENEVE) |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 9166 | return; |
| 9167 | |
| 9168 | if (ti->sa_family != AF_INET) |
| 9169 | return; |
| 9170 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9171 | switch (ti->type) { |
| 9172 | case UDP_TUNNEL_TYPE_VXLAN: |
| 9173 | if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) |
| 9174 | return; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 9175 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9176 | if (adapter->vxlan_port != ti->port) { |
| 9177 | netdev_info(dev, "VXLAN port %d not found\n", |
| 9178 | ntohs(ti->port)); |
| 9179 | return; |
| 9180 | } |
| 9181 | |
| 9182 | port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK; |
| 9183 | break; |
| 9184 | case UDP_TUNNEL_TYPE_GENEVE: |
| 9185 | if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)) |
| 9186 | return; |
| 9187 | |
| 9188 | if (adapter->geneve_port != ti->port) { |
| 9189 | netdev_info(dev, "GENEVE port %d not found\n", |
| 9190 | ntohs(ti->port)); |
| 9191 | return; |
| 9192 | } |
| 9193 | |
| 9194 | port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK; |
| 9195 | break; |
| 9196 | default: |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9197 | return; |
| 9198 | } |
| 9199 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9200 | ixgbe_clear_udp_tunnel_port(adapter, port_mask); |
| 9201 | adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9202 | } |
| 9203 | |
stephen hemminger | edc7d57 | 2012-10-01 12:32:33 +0000 | [diff] [blame] | 9204 | static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 9205 | struct net_device *dev, |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 9206 | const unsigned char *addr, u16 vid, |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 9207 | u16 flags) |
| 9208 | { |
Alexander Duyck | bcfd343 | 2014-07-17 02:11:22 +0000 | [diff] [blame] | 9209 | /* guarantee we can provide a unique filter for the unicast address */ |
Ben Hutchings | 46acc46 | 2012-11-01 09:11:11 +0000 | [diff] [blame] | 9210 | if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) { |
Alexander Duyck | 2f9be16 | 2015-10-22 16:26:42 -0700 | [diff] [blame] | 9211 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 9212 | u16 pool = VMDQ_P(0); |
| 9213 | |
| 9214 | if (netdev_uc_count(dev) >= ixgbe_available_rars(adapter, pool)) |
Alexander Duyck | bcfd343 | 2014-07-17 02:11:22 +0000 | [diff] [blame] | 9215 | return -ENOMEM; |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 9216 | } |
| 9217 | |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 9218 | return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags); |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 9219 | } |
| 9220 | |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9221 | /** |
| 9222 | * ixgbe_configure_bridge_mode - set various bridge modes |
| 9223 | * @adapter - the private structure |
| 9224 | * @mode - requested bridge mode |
| 9225 | * |
| 9226 | * Configure some settings require for various bridge modes. |
| 9227 | **/ |
| 9228 | static int ixgbe_configure_bridge_mode(struct ixgbe_adapter *adapter, |
| 9229 | __u16 mode) |
| 9230 | { |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 9231 | struct ixgbe_hw *hw = &adapter->hw; |
| 9232 | unsigned int p, num_pools; |
| 9233 | u32 vmdctl; |
| 9234 | |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9235 | switch (mode) { |
| 9236 | case BRIDGE_MODE_VEPA: |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 9237 | /* disable Tx loopback, rely on switch hairpin mode */ |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9238 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, 0); |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 9239 | |
| 9240 | /* must enable Rx switching replication to allow multicast |
| 9241 | * packet reception on all VFs, and to enable source address |
| 9242 | * pruning. |
| 9243 | */ |
| 9244 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL); |
| 9245 | vmdctl |= IXGBE_VT_CTL_REPLEN; |
| 9246 | IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl); |
| 9247 | |
| 9248 | /* enable Rx source address pruning. Note, this requires |
| 9249 | * replication to be enabled or else it does nothing. |
| 9250 | */ |
| 9251 | num_pools = adapter->num_vfs + adapter->num_rx_pools; |
| 9252 | for (p = 0; p < num_pools; p++) { |
| 9253 | if (hw->mac.ops.set_source_address_pruning) |
| 9254 | hw->mac.ops.set_source_address_pruning(hw, |
| 9255 | true, |
| 9256 | p); |
| 9257 | } |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9258 | break; |
| 9259 | case BRIDGE_MODE_VEB: |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 9260 | /* enable Tx loopback for internal VF/PF communication */ |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9261 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, |
| 9262 | IXGBE_PFDTXGSWC_VT_LBEN); |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 9263 | |
| 9264 | /* disable Rx switching replication unless we have SR-IOV |
| 9265 | * virtual functions |
| 9266 | */ |
| 9267 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL); |
| 9268 | if (!adapter->num_vfs) |
| 9269 | vmdctl &= ~IXGBE_VT_CTL_REPLEN; |
| 9270 | IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl); |
| 9271 | |
| 9272 | /* disable Rx source address pruning, since we don't expect to |
| 9273 | * be receiving external loopback of our transmitted frames. |
| 9274 | */ |
| 9275 | num_pools = adapter->num_vfs + adapter->num_rx_pools; |
| 9276 | for (p = 0; p < num_pools; p++) { |
| 9277 | if (hw->mac.ops.set_source_address_pruning) |
| 9278 | hw->mac.ops.set_source_address_pruning(hw, |
| 9279 | false, |
| 9280 | p); |
| 9281 | } |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9282 | break; |
| 9283 | default: |
| 9284 | return -EINVAL; |
| 9285 | } |
| 9286 | |
| 9287 | adapter->bridge_mode = mode; |
| 9288 | |
| 9289 | e_info(drv, "enabling bridge mode: %s\n", |
| 9290 | mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
| 9291 | |
| 9292 | return 0; |
| 9293 | } |
| 9294 | |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9295 | static int ixgbe_ndo_bridge_setlink(struct net_device *dev, |
Roopa Prabhu | add511b | 2015-01-29 22:40:12 -0800 | [diff] [blame] | 9296 | struct nlmsghdr *nlh, u16 flags) |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9297 | { |
| 9298 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 9299 | struct nlattr *attr, *br_spec; |
| 9300 | int rem; |
| 9301 | |
| 9302 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 9303 | return -EOPNOTSUPP; |
| 9304 | |
| 9305 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
Thomas Graf | 4ea85e8 | 2014-11-26 13:42:18 +0100 | [diff] [blame] | 9306 | if (!br_spec) |
| 9307 | return -EINVAL; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9308 | |
| 9309 | nla_for_each_nested(attr, br_spec, rem) { |
Mark Rustad | a1e869d | 2015-04-10 10:36:36 -0700 | [diff] [blame] | 9310 | int status; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9311 | __u16 mode; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9312 | |
| 9313 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 9314 | continue; |
| 9315 | |
Thomas Graf | b7c1a31 | 2014-11-26 13:42:17 +0100 | [diff] [blame] | 9316 | if (nla_len(attr) < sizeof(mode)) |
| 9317 | return -EINVAL; |
| 9318 | |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9319 | mode = nla_get_u16(attr); |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9320 | status = ixgbe_configure_bridge_mode(adapter, mode); |
| 9321 | if (status) |
| 9322 | return status; |
Don Skidmore | aa2bacb | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9323 | |
| 9324 | break; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9325 | } |
| 9326 | |
| 9327 | return 0; |
| 9328 | } |
| 9329 | |
| 9330 | static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, |
Vlad Yasevich | 6cbdcee | 2013-02-13 12:00:13 +0000 | [diff] [blame] | 9331 | struct net_device *dev, |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 9332 | u32 filter_mask, int nlflags) |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9333 | { |
| 9334 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9335 | |
| 9336 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 9337 | return 0; |
| 9338 | |
Don Skidmore | aa2bacb | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9339 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, |
Scott Feldman | 7d4f8d8 | 2015-06-22 00:27:17 -0700 | [diff] [blame] | 9340 | adapter->bridge_mode, 0, 0, nlflags, |
| 9341 | filter_mask, NULL); |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9342 | } |
| 9343 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9344 | static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev) |
| 9345 | { |
| 9346 | struct ixgbe_fwd_adapter *fwd_adapter = NULL; |
| 9347 | struct ixgbe_adapter *adapter = netdev_priv(pdev); |
Jacob Keller | aac2f1b | 2014-08-21 06:17:59 +0000 | [diff] [blame] | 9348 | int used_pools = adapter->num_vfs + adapter->num_rx_pools; |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 9349 | unsigned int limit; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9350 | int pool, err; |
| 9351 | |
Jacob Keller | aac2f1b | 2014-08-21 06:17:59 +0000 | [diff] [blame] | 9352 | /* Hardware has a limited number of available pools. Each VF, and the |
| 9353 | * PF require a pool. Check to ensure we don't attempt to use more |
| 9354 | * then the available number of pools. |
| 9355 | */ |
| 9356 | if (used_pools >= IXGBE_MAX_VF_FUNCTIONS) |
| 9357 | return ERR_PTR(-EINVAL); |
| 9358 | |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 9359 | #ifdef CONFIG_RPS |
| 9360 | if (vdev->num_rx_queues != vdev->num_tx_queues) { |
| 9361 | netdev_info(pdev, "%s: Only supports a single queue count for TX and RX\n", |
| 9362 | vdev->name); |
| 9363 | return ERR_PTR(-EINVAL); |
| 9364 | } |
| 9365 | #endif |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9366 | /* Check for hardware restriction on number of rx/tx queues */ |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 9367 | if (vdev->num_tx_queues > IXGBE_MAX_L2A_QUEUES || |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9368 | vdev->num_tx_queues == IXGBE_BAD_L2A_QUEUE) { |
| 9369 | netdev_info(pdev, |
| 9370 | "%s: Supports RX/TX Queue counts 1,2, and 4\n", |
| 9371 | pdev->name); |
| 9372 | return ERR_PTR(-EINVAL); |
| 9373 | } |
| 9374 | |
| 9375 | if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && |
| 9376 | adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS - 1) || |
| 9377 | (adapter->num_rx_pools > IXGBE_MAX_MACVLANS)) |
| 9378 | return ERR_PTR(-EBUSY); |
| 9379 | |
Maninder Singh | bc52f95 | 2015-06-19 09:37:55 +0530 | [diff] [blame] | 9380 | fwd_adapter = kzalloc(sizeof(*fwd_adapter), GFP_KERNEL); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9381 | if (!fwd_adapter) |
| 9382 | return ERR_PTR(-ENOMEM); |
| 9383 | |
| 9384 | pool = find_first_zero_bit(&adapter->fwd_bitmask, 32); |
| 9385 | adapter->num_rx_pools++; |
| 9386 | set_bit(pool, &adapter->fwd_bitmask); |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 9387 | limit = find_last_bit(&adapter->fwd_bitmask, 32); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9388 | |
| 9389 | /* Enable VMDq flag so device will be set in VM mode */ |
| 9390 | adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED | IXGBE_FLAG_SRIOV_ENABLED; |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 9391 | adapter->ring_feature[RING_F_VMDQ].limit = limit + 1; |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 9392 | adapter->ring_feature[RING_F_RSS].limit = vdev->num_tx_queues; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9393 | |
| 9394 | /* Force reinit of ring allocation with VMDQ enabled */ |
| 9395 | err = ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev)); |
| 9396 | if (err) |
| 9397 | goto fwd_add_err; |
| 9398 | fwd_adapter->pool = pool; |
| 9399 | fwd_adapter->real_adapter = adapter; |
Emil Tantilov | a3b8cb1 | 2016-09-22 15:06:52 -0700 | [diff] [blame] | 9400 | |
| 9401 | if (netif_running(pdev)) { |
| 9402 | err = ixgbe_fwd_ring_up(vdev, fwd_adapter); |
| 9403 | if (err) |
| 9404 | goto fwd_add_err; |
| 9405 | netif_tx_start_all_queues(vdev); |
| 9406 | } |
| 9407 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9408 | return fwd_adapter; |
| 9409 | fwd_add_err: |
| 9410 | /* unwind counter and free adapter struct */ |
| 9411 | netdev_info(pdev, |
| 9412 | "%s: dfwd hardware acceleration failed\n", vdev->name); |
| 9413 | clear_bit(pool, &adapter->fwd_bitmask); |
| 9414 | adapter->num_rx_pools--; |
| 9415 | kfree(fwd_adapter); |
| 9416 | return ERR_PTR(err); |
| 9417 | } |
| 9418 | |
| 9419 | static void ixgbe_fwd_del(struct net_device *pdev, void *priv) |
| 9420 | { |
| 9421 | struct ixgbe_fwd_adapter *fwd_adapter = priv; |
| 9422 | struct ixgbe_adapter *adapter = fwd_adapter->real_adapter; |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 9423 | unsigned int limit; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9424 | |
| 9425 | clear_bit(fwd_adapter->pool, &adapter->fwd_bitmask); |
| 9426 | adapter->num_rx_pools--; |
| 9427 | |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 9428 | limit = find_last_bit(&adapter->fwd_bitmask, 32); |
| 9429 | adapter->ring_feature[RING_F_VMDQ].limit = limit + 1; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9430 | ixgbe_fwd_ring_down(fwd_adapter->netdev, fwd_adapter); |
| 9431 | ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev)); |
| 9432 | netdev_dbg(pdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n", |
| 9433 | fwd_adapter->pool, adapter->num_rx_pools, |
| 9434 | fwd_adapter->rx_base_queue, |
| 9435 | fwd_adapter->rx_base_queue + adapter->num_rx_queues_per_pool, |
| 9436 | adapter->fwd_bitmask); |
| 9437 | kfree(fwd_adapter); |
| 9438 | } |
| 9439 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9440 | #define IXGBE_MAX_MAC_HDR_LEN 127 |
| 9441 | #define IXGBE_MAX_NETWORK_HDR_LEN 511 |
| 9442 | |
Mark Rustad | f467bc0 | 2015-06-15 11:33:20 -0700 | [diff] [blame] | 9443 | static netdev_features_t |
| 9444 | ixgbe_features_check(struct sk_buff *skb, struct net_device *dev, |
| 9445 | netdev_features_t features) |
| 9446 | { |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9447 | unsigned int network_hdr_len, mac_hdr_len; |
Mark Rustad | f467bc0 | 2015-06-15 11:33:20 -0700 | [diff] [blame] | 9448 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9449 | /* Make certain the headers can be described by a context descriptor */ |
| 9450 | mac_hdr_len = skb_network_header(skb) - skb->data; |
| 9451 | if (unlikely(mac_hdr_len > IXGBE_MAX_MAC_HDR_LEN)) |
| 9452 | return features & ~(NETIF_F_HW_CSUM | |
| 9453 | NETIF_F_SCTP_CRC | |
| 9454 | NETIF_F_HW_VLAN_CTAG_TX | |
| 9455 | NETIF_F_TSO | |
| 9456 | NETIF_F_TSO6); |
| 9457 | |
| 9458 | network_hdr_len = skb_checksum_start(skb) - skb_network_header(skb); |
| 9459 | if (unlikely(network_hdr_len > IXGBE_MAX_NETWORK_HDR_LEN)) |
| 9460 | return features & ~(NETIF_F_HW_CSUM | |
| 9461 | NETIF_F_SCTP_CRC | |
| 9462 | NETIF_F_TSO | |
| 9463 | NETIF_F_TSO6); |
| 9464 | |
| 9465 | /* We can only support IPV4 TSO in tunnels if we can mangle the |
| 9466 | * inner IP ID field, so strip TSO if MANGLEID is not supported. |
| 9467 | */ |
| 9468 | if (skb->encapsulation && !(features & NETIF_F_TSO_MANGLEID)) |
| 9469 | features &= ~NETIF_F_TSO; |
Mark Rustad | f467bc0 | 2015-06-15 11:33:20 -0700 | [diff] [blame] | 9470 | |
| 9471 | return features; |
| 9472 | } |
| 9473 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 9474 | static const struct net_device_ops ixgbe_netdev_ops = { |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 9475 | .ndo_open = ixgbe_open, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 9476 | .ndo_stop = ixgbe_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 9477 | .ndo_start_xmit = ixgbe_xmit_frame, |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 9478 | .ndo_select_queue = ixgbe_select_queue, |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 9479 | .ndo_set_rx_mode = ixgbe_set_rx_mode, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 9480 | .ndo_validate_addr = eth_validate_addr, |
| 9481 | .ndo_set_mac_address = ixgbe_set_mac, |
| 9482 | .ndo_change_mtu = ixgbe_change_mtu, |
| 9483 | .ndo_tx_timeout = ixgbe_tx_timeout, |
Rostislav Pehlivanov | c04f90e | 2016-01-27 18:33:30 +0000 | [diff] [blame] | 9484 | .ndo_set_tx_maxrate = ixgbe_tx_maxrate, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 9485 | .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid, |
| 9486 | .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid, |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 9487 | .ndo_do_ioctl = ixgbe_ioctl, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 9488 | .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac, |
| 9489 | .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan, |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 9490 | .ndo_set_vf_rate = ixgbe_ndo_set_vf_bw, |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 9491 | .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk, |
Vlad Zolotarov | e65ce0d | 2015-03-30 21:35:24 +0300 | [diff] [blame] | 9492 | .ndo_set_vf_rss_query_en = ixgbe_ndo_set_vf_rss_query_en, |
Hiroshi Shimamoto | 54011e4 | 2015-08-28 06:58:33 +0000 | [diff] [blame] | 9493 | .ndo_set_vf_trust = ixgbe_ndo_set_vf_trust, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 9494 | .ndo_get_vf_config = ixgbe_ndo_get_vf_config, |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 9495 | .ndo_get_stats64 = ixgbe_get_stats64, |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 9496 | .ndo_setup_tc = __ixgbe_setup_tc, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 9497 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 9498 | .ndo_poll_controller = ixgbe_netpoll, |
| 9499 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 9500 | #ifdef IXGBE_FCOE |
| 9501 | .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get, |
Yi Zou | 68a683c | 2011-02-01 07:22:16 +0000 | [diff] [blame] | 9502 | .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 9503 | .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put, |
Yi Zou | 8450ff8 | 2009-08-31 12:32:14 +0000 | [diff] [blame] | 9504 | .ndo_fcoe_enable = ixgbe_fcoe_enable, |
| 9505 | .ndo_fcoe_disable = ixgbe_fcoe_disable, |
Yi Zou | 61a1fa1 | 2009-10-28 18:24:56 +0000 | [diff] [blame] | 9506 | .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn, |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 9507 | .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 9508 | #endif /* IXGBE_FCOE */ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9509 | .ndo_set_features = ixgbe_set_features, |
| 9510 | .ndo_fix_features = ixgbe_fix_features, |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 9511 | .ndo_fdb_add = ixgbe_ndo_fdb_add, |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9512 | .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink, |
| 9513 | .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink, |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9514 | .ndo_dfwd_add_station = ixgbe_fwd_add, |
| 9515 | .ndo_dfwd_del_station = ixgbe_fwd_del, |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9516 | .ndo_udp_tunnel_add = ixgbe_add_udp_tunnel_port, |
| 9517 | .ndo_udp_tunnel_del = ixgbe_del_udp_tunnel_port, |
Mark Rustad | f467bc0 | 2015-06-15 11:33:20 -0700 | [diff] [blame] | 9518 | .ndo_features_check = ixgbe_features_check, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 9519 | }; |
| 9520 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9521 | /** |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 9522 | * ixgbe_enumerate_functions - Get the number of ports this device has |
| 9523 | * @adapter: adapter structure |
| 9524 | * |
| 9525 | * This function enumerates the phsyical functions co-located on a single slot, |
| 9526 | * in order to determine how many ports a device has. This is most useful in |
| 9527 | * determining the required GT/s of PCIe bandwidth necessary for optimal |
| 9528 | * performance. |
| 9529 | **/ |
| 9530 | static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter) |
| 9531 | { |
Jacob Keller | caafb95 | 2014-07-19 07:17:17 +0000 | [diff] [blame] | 9532 | struct pci_dev *entry, *pdev = adapter->pdev; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 9533 | int physfns = 0; |
| 9534 | |
Jacob Keller | f1f9657 | 2013-08-31 02:45:38 +0000 | [diff] [blame] | 9535 | /* Some cards can not use the generic count PCIe functions method, |
| 9536 | * because they are behind a parent switch, so we hardcode these with |
| 9537 | * the correct number of functions. |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 9538 | */ |
Jacob Keller | 8818970 | 2014-07-19 07:17:16 +0000 | [diff] [blame] | 9539 | if (ixgbe_pcie_from_parent(&adapter->hw)) |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 9540 | physfns = 4; |
Jacob Keller | 8818970 | 2014-07-19 07:17:16 +0000 | [diff] [blame] | 9541 | |
| 9542 | list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) { |
| 9543 | /* don't count virtual functions */ |
Jacob Keller | caafb95 | 2014-07-19 07:17:17 +0000 | [diff] [blame] | 9544 | if (entry->is_virtfn) |
| 9545 | continue; |
| 9546 | |
| 9547 | /* When the devices on the bus don't all match our device ID, |
| 9548 | * we can't reliably determine the correct number of |
| 9549 | * functions. This can occur if a function has been direct |
| 9550 | * attached to a virtual machine using VT-d, for example. In |
| 9551 | * this case, simply return -1 to indicate this. |
| 9552 | */ |
| 9553 | if ((entry->vendor != pdev->vendor) || |
| 9554 | (entry->device != pdev->device)) |
| 9555 | return -1; |
| 9556 | |
| 9557 | physfns++; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 9558 | } |
| 9559 | |
| 9560 | return physfns; |
| 9561 | } |
| 9562 | |
| 9563 | /** |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9564 | * ixgbe_wol_supported - Check whether device supports WoL |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 9565 | * @adapter: the adapter private structure |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9566 | * @device_id: the device ID |
| 9567 | * @subdev_id: the subsystem device ID |
| 9568 | * |
| 9569 | * This function is used by probe and ethtool to determine |
| 9570 | * which devices have WoL support |
| 9571 | * |
| 9572 | **/ |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 9573 | bool ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id, |
| 9574 | u16 subdevice_id) |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9575 | { |
| 9576 | struct ixgbe_hw *hw = &adapter->hw; |
| 9577 | u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9578 | |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 9579 | /* WOL not supported on 82598 */ |
| 9580 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 9581 | return false; |
| 9582 | |
| 9583 | /* check eeprom to see if WOL is enabled for X540 and newer */ |
| 9584 | if (hw->mac.type >= ixgbe_mac_X540) { |
| 9585 | if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) || |
| 9586 | ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) && |
| 9587 | (hw->bus.func == 0))) |
| 9588 | return true; |
| 9589 | } |
| 9590 | |
| 9591 | /* WOL is determined based on device IDs for 82599 MACs */ |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9592 | switch (device_id) { |
| 9593 | case IXGBE_DEV_ID_82599_SFP: |
| 9594 | /* Only these subdevices could supports WOL */ |
| 9595 | switch (subdevice_id) { |
| 9596 | case IXGBE_SUBDEV_ID_82599_560FLR: |
Emil Tantilov | 00103a6c | 2016-04-21 11:37:06 -0700 | [diff] [blame] | 9597 | case IXGBE_SUBDEV_ID_82599_LOM_SNAP6: |
| 9598 | case IXGBE_SUBDEV_ID_82599_SFP_WOL0: |
| 9599 | case IXGBE_SUBDEV_ID_82599_SFP_2OCP: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9600 | /* only support first port */ |
| 9601 | if (hw->bus.func != 0) |
| 9602 | break; |
Emil Tantilov | 5700ff2 | 2013-04-18 08:18:55 +0000 | [diff] [blame] | 9603 | case IXGBE_SUBDEV_ID_82599_SP_560FLR: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9604 | case IXGBE_SUBDEV_ID_82599_SFP: |
Don Skidmore | b6dfd93 | 2012-07-11 07:17:42 +0000 | [diff] [blame] | 9605 | case IXGBE_SUBDEV_ID_82599_RNDC: |
Emil Tantilov | f8a06c2 | 2012-08-16 08:13:07 +0000 | [diff] [blame] | 9606 | case IXGBE_SUBDEV_ID_82599_ECNA_DP: |
Emil Tantilov | 00103a6c | 2016-04-21 11:37:06 -0700 | [diff] [blame] | 9607 | case IXGBE_SUBDEV_ID_82599_SFP_1OCP: |
| 9608 | case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM1: |
| 9609 | case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM2: |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 9610 | return true; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9611 | } |
| 9612 | break; |
Don Skidmore | 5daebbb | 2013-04-05 05:49:34 +0000 | [diff] [blame] | 9613 | case IXGBE_DEV_ID_82599EN_SFP: |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 9614 | /* Only these subdevices support WOL */ |
Don Skidmore | 5daebbb | 2013-04-05 05:49:34 +0000 | [diff] [blame] | 9615 | switch (subdevice_id) { |
| 9616 | case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1: |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 9617 | return true; |
Don Skidmore | 5daebbb | 2013-04-05 05:49:34 +0000 | [diff] [blame] | 9618 | } |
| 9619 | break; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9620 | case IXGBE_DEV_ID_82599_COMBO_BACKPLANE: |
| 9621 | /* All except this subdevice support WOL */ |
| 9622 | if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ) |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 9623 | return true; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9624 | break; |
| 9625 | case IXGBE_DEV_ID_82599_KX4: |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 9626 | return true; |
| 9627 | default: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9628 | break; |
| 9629 | } |
| 9630 | |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 9631 | return false; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9632 | } |
| 9633 | |
| 9634 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9635 | * ixgbe_probe - Device Initialization Routine |
| 9636 | * @pdev: PCI device information struct |
| 9637 | * @ent: entry in ixgbe_pci_tbl |
| 9638 | * |
| 9639 | * Returns 0 on success, negative on failure |
| 9640 | * |
| 9641 | * ixgbe_probe initializes an adapter identified by a pci_dev structure. |
| 9642 | * The OS initialization, configuring of the adapter private structure, |
| 9643 | * and a hardware reset occur. |
| 9644 | **/ |
Greg Kroah-Hartman | 1dd06ae | 2012-12-06 14:30:56 +0000 | [diff] [blame] | 9645 | static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9646 | { |
| 9647 | struct net_device *netdev; |
| 9648 | struct ixgbe_adapter *adapter = NULL; |
| 9649 | struct ixgbe_hw *hw; |
| 9650 | const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data]; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 9651 | int i, err, pci_using_dac, expected_gts; |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 9652 | unsigned int indices = MAX_TX_QUEUES; |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 9653 | u8 part_str[IXGBE_PBANUM_LENGTH]; |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 9654 | bool disable_dev = false; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 9655 | #ifdef IXGBE_FCOE |
| 9656 | u16 device_caps; |
| 9657 | #endif |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 9658 | u32 eec; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9659 | |
Andy Gospodarek | bded64a | 2010-07-21 06:40:31 +0000 | [diff] [blame] | 9660 | /* Catch broken hardware that put the wrong VF device ID in |
| 9661 | * the PCIe SR-IOV capability. |
| 9662 | */ |
| 9663 | if (pdev->is_virtfn) { |
| 9664 | WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n", |
| 9665 | pci_name(pdev), pdev->vendor, pdev->device); |
| 9666 | return -EINVAL; |
| 9667 | } |
| 9668 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 9669 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9670 | if (err) |
| 9671 | return err; |
| 9672 | |
Russell King | f5f2eda | 2013-06-10 12:47:42 +0100 | [diff] [blame] | 9673 | if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9674 | pci_using_dac = 1; |
| 9675 | } else { |
Russell King | f5f2eda | 2013-06-10 12:47:42 +0100 | [diff] [blame] | 9676 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9677 | if (err) { |
Russell King | f5f2eda | 2013-06-10 12:47:42 +0100 | [diff] [blame] | 9678 | dev_err(&pdev->dev, |
| 9679 | "No usable DMA configuration, aborting\n"); |
| 9680 | goto err_dma; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9681 | } |
| 9682 | pci_using_dac = 0; |
| 9683 | } |
| 9684 | |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 9685 | err = pci_request_mem_regions(pdev, ixgbe_driver_name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9686 | if (err) { |
Dan Carpenter | b8bc042 | 2010-07-27 00:05:56 +0000 | [diff] [blame] | 9687 | dev_err(&pdev->dev, |
| 9688 | "pci_request_selected_regions failed 0x%x\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9689 | goto err_pci_reg; |
| 9690 | } |
| 9691 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 9692 | pci_enable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9693 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9694 | pci_set_master(pdev); |
Wendy Xiong | fb3b27b | 2008-04-23 11:09:24 -0700 | [diff] [blame] | 9695 | pci_save_state(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9696 | |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 9697 | if (ii->mac == ixgbe_mac_82598EB) { |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 9698 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 9699 | /* 8 TC w/ 4 queues per TC */ |
| 9700 | indices = 4 * MAX_TRAFFIC_CLASS; |
| 9701 | #else |
| 9702 | indices = IXGBE_MAX_RSS_INDICES; |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 9703 | #endif |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 9704 | } |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 9705 | |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 9706 | netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9707 | if (!netdev) { |
| 9708 | err = -ENOMEM; |
| 9709 | goto err_alloc_etherdev; |
| 9710 | } |
| 9711 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9712 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 9713 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9714 | adapter = netdev_priv(netdev); |
| 9715 | |
| 9716 | adapter->netdev = netdev; |
| 9717 | adapter->pdev = pdev; |
| 9718 | hw = &adapter->hw; |
| 9719 | hw->back = adapter; |
stephen hemminger | b3f4d59 | 2012-03-13 06:04:20 +0000 | [diff] [blame] | 9720 | adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9721 | |
Jeff Kirsher | 0585798 | 2008-09-11 19:57:00 -0700 | [diff] [blame] | 9722 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 9723 | pci_resource_len(pdev, 0)); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 9724 | adapter->io_addr = hw->hw_addr; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9725 | if (!hw->hw_addr) { |
| 9726 | err = -EIO; |
| 9727 | goto err_ioremap; |
| 9728 | } |
| 9729 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 9730 | netdev->netdev_ops = &ixgbe_netdev_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9731 | ixgbe_set_ethtool_ops(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9732 | netdev->watchdog_timeo = 5 * HZ; |
Mark Rustad | 339de30 | 2014-06-06 01:57:06 +0000 | [diff] [blame] | 9733 | strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9734 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9735 | /* Setup hw api */ |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 9736 | hw->mac.ops = *ii->mac_ops; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 9737 | hw->mac.type = ii->mac; |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 9738 | hw->mvals = ii->mvals; |
Emil Tantilov | b71f6c4 | 2016-10-10 14:54:03 -0700 | [diff] [blame] | 9739 | if (ii->link_ops) |
| 9740 | hw->link.ops = *ii->link_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9741 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9742 | /* EEPROM */ |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 9743 | hw->eeprom.ops = *ii->eeprom_ops; |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 9744 | eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw)); |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 9745 | if (ixgbe_removed(hw->hw_addr)) { |
| 9746 | err = -EIO; |
| 9747 | goto err_ioremap; |
| 9748 | } |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9749 | /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */ |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 9750 | if (!(eec & BIT(8))) |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9751 | hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic; |
| 9752 | |
| 9753 | /* PHY */ |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 9754 | hw->phy.ops = *ii->phy_ops; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 9755 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 9756 | /* ixgbe_identify_phy_generic will set prtad and mmds properly */ |
| 9757 | hw->phy.mdio.prtad = MDIO_PRTAD_NONE; |
| 9758 | hw->phy.mdio.mmds = 0; |
| 9759 | hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 9760 | hw->phy.mdio.dev = netdev; |
| 9761 | hw->phy.mdio.mdio_read = ixgbe_mdio_read; |
| 9762 | hw->phy.mdio.mdio_write = ixgbe_mdio_write; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 9763 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9764 | /* setup the private structure */ |
Emil Tantilov | 55570b6 | 2016-10-12 12:34:25 -0700 | [diff] [blame] | 9765 | err = ixgbe_sw_init(adapter, ii); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9766 | if (err) |
| 9767 | goto err_sw_init; |
| 9768 | |
Don Skidmore | dbd15b8 | 2016-03-09 16:45:00 -0500 | [diff] [blame] | 9769 | /* Make sure the SWFW semaphore is in a valid state */ |
| 9770 | if (hw->mac.ops.init_swfw_sync) |
| 9771 | hw->mac.ops.init_swfw_sync(hw); |
| 9772 | |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 9773 | /* Make it possible the adapter to be woken up via WOL */ |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 9774 | switch (adapter->hw.mac.type) { |
| 9775 | case ixgbe_mac_82599EB: |
| 9776 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 9777 | case ixgbe_mac_X550: |
| 9778 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 9779 | case ixgbe_mac_x550em_a: |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 9780 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 9781 | break; |
| 9782 | default: |
| 9783 | break; |
| 9784 | } |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 9785 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 9786 | /* |
| 9787 | * If there is a fan on this device and it has failed log the |
| 9788 | * failure. |
| 9789 | */ |
| 9790 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 9791 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 9792 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 9793 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 9794 | } |
| 9795 | |
Peter P Waskiewicz Jr | 8ef78ad | 2012-02-01 09:19:21 +0000 | [diff] [blame] | 9796 | if (allow_unsupported_sfp) |
| 9797 | hw->allow_unsupported_sfp = allow_unsupported_sfp; |
| 9798 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9799 | /* reset_hw fills in the perm_addr as well */ |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 9800 | hw->phy.reset_if_overtemp = true; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9801 | err = hw->mac.ops.reset_hw(hw); |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 9802 | hw->phy.reset_if_overtemp = false; |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 9803 | ixgbe_set_eee_capable(adapter); |
Mark Rustad | 29a8dca | 2015-08-08 16:17:46 -0700 | [diff] [blame] | 9804 | if (err == IXGBE_ERR_SFP_NOT_PRESENT) { |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 9805 | err = 0; |
| 9806 | } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 1b1bf31 | 2013-07-31 05:27:04 +0000 | [diff] [blame] | 9807 | e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n"); |
| 9808 | e_dev_err("Reload the driver after installing a supported module.\n"); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 9809 | goto err_sw_init; |
| 9810 | } else if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 9811 | e_dev_err("HW Init failed: %d\n", err); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9812 | goto err_sw_init; |
| 9813 | } |
| 9814 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 9815 | #ifdef CONFIG_PCI_IOV |
Greg Rose | 60a1a68 | 2012-12-11 08:26:33 +0000 | [diff] [blame] | 9816 | /* SR-IOV not supported on the 82598 */ |
| 9817 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 9818 | goto skip_sriov; |
| 9819 | /* Mailbox */ |
| 9820 | ixgbe_init_mbx_params_pf(hw); |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 9821 | hw->mbx.ops = ii->mbx_ops; |
ethan.zhao | dcc23e3 | 2014-01-16 19:41:04 -0800 | [diff] [blame] | 9822 | pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT); |
ethan.zhao | 31ac910 | 2014-01-16 19:41:05 -0800 | [diff] [blame] | 9823 | ixgbe_enable_sriov(adapter); |
Greg Rose | 60a1a68 | 2012-12-11 08:26:33 +0000 | [diff] [blame] | 9824 | skip_sriov: |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 9825 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 9826 | #endif |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 9827 | netdev->features = NETIF_F_SG | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9828 | NETIF_F_TSO | |
| 9829 | NETIF_F_TSO6 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9830 | NETIF_F_RXHASH | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 9831 | NETIF_F_RXCSUM | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9832 | NETIF_F_HW_CSUM; |
| 9833 | |
| 9834 | #define IXGBE_GSO_PARTIAL_FEATURES (NETIF_F_GSO_GRE | \ |
| 9835 | NETIF_F_GSO_GRE_CSUM | \ |
Tom Herbert | 7e13318 | 2016-05-18 09:06:10 -0700 | [diff] [blame] | 9836 | NETIF_F_GSO_IPXIP4 | \ |
Alexander Duyck | bf2d1df | 2016-05-18 10:44:53 -0700 | [diff] [blame] | 9837 | NETIF_F_GSO_IPXIP6 | \ |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9838 | NETIF_F_GSO_UDP_TUNNEL | \ |
| 9839 | NETIF_F_GSO_UDP_TUNNEL_CSUM) |
| 9840 | |
| 9841 | netdev->gso_partial_features = IXGBE_GSO_PARTIAL_FEATURES; |
| 9842 | netdev->features |= NETIF_F_GSO_PARTIAL | |
| 9843 | IXGBE_GSO_PARTIAL_FEATURES; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9844 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 9845 | if (hw->mac.type >= ixgbe_mac_82599EB) |
Tom Herbert | 53692b1 | 2015-12-14 11:19:41 -0800 | [diff] [blame] | 9846 | netdev->features |= NETIF_F_SCTP_CRC; |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 9847 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 9848 | /* copy netdev features into list of user selectable features */ |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9849 | netdev->hw_features |= netdev->features | |
Alexander Duyck | 3d95182 | 2016-08-12 09:53:39 -0700 | [diff] [blame] | 9850 | NETIF_F_HW_VLAN_CTAG_FILTER | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9851 | NETIF_F_HW_VLAN_CTAG_RX | |
| 9852 | NETIF_F_HW_VLAN_CTAG_TX | |
| 9853 | NETIF_F_RXALL | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 9854 | NETIF_F_HW_L2FW_DOFFLOAD; |
| 9855 | |
| 9856 | if (hw->mac.type >= ixgbe_mac_82599EB) |
| 9857 | netdev->hw_features |= NETIF_F_NTUPLE | |
| 9858 | NETIF_F_HW_TC; |
| 9859 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9860 | if (pci_using_dac) |
| 9861 | netdev->features |= NETIF_F_HIGHDMA; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 9862 | |
Alexander Duyck | 5eee87c | 2016-05-11 13:23:34 -0700 | [diff] [blame] | 9863 | netdev->vlan_features |= netdev->features | NETIF_F_TSO_MANGLEID; |
| 9864 | netdev->hw_enc_features |= netdev->vlan_features; |
| 9865 | netdev->mpls_features |= NETIF_F_HW_CSUM; |
| 9866 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9867 | /* set this bit last since it cannot be part of vlan_features */ |
| 9868 | netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER | |
| 9869 | NETIF_F_HW_VLAN_CTAG_RX | |
| 9870 | NETIF_F_HW_VLAN_CTAG_TX; |
| 9871 | |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 9872 | netdev->priv_flags |= IFF_UNICAST_FLT; |
Ben Greear | f43f313 | 2012-03-06 09:42:04 +0000 | [diff] [blame] | 9873 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 9874 | |
Jarod Wilson | 91c527a | 2016-10-17 15:54:05 -0400 | [diff] [blame] | 9875 | /* MTU range: 68 - 9710 */ |
| 9876 | netdev->min_mtu = ETH_MIN_MTU; |
| 9877 | netdev->max_mtu = IXGBE_MAX_JUMBO_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN); |
| 9878 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 9879 | #ifdef CONFIG_IXGBE_DCB |
Usha Ketineni | 8829009 | 2016-04-26 05:00:26 -0700 | [diff] [blame] | 9880 | if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE) |
Stephen Hemminger | 3f40c74 | 2016-11-21 09:52:40 -0800 | [diff] [blame] | 9881 | netdev->dcbnl_ops = &ixgbe_dcbnl_ops; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 9882 | #endif |
| 9883 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 9884 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 9885 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 9886 | unsigned int fcoe_l; |
| 9887 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 9888 | if (hw->mac.ops.get_device_caps) { |
| 9889 | hw->mac.ops.get_device_caps(hw, &device_caps); |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 9890 | if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS) |
| 9891 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 9892 | } |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 9893 | |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 9894 | |
| 9895 | fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus()); |
| 9896 | adapter->ring_feature[RING_F_FCOE].limit = fcoe_l; |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 9897 | |
Alexander Duyck | a58915c | 2012-05-25 06:38:18 +0000 | [diff] [blame] | 9898 | netdev->features |= NETIF_F_FSO | |
| 9899 | NETIF_F_FCOE_CRC; |
| 9900 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 9901 | netdev->vlan_features |= NETIF_F_FSO | |
| 9902 | NETIF_F_FCOE_CRC | |
| 9903 | NETIF_F_FCOE_MTU; |
Yi Zou | 5e09d7f | 2010-07-19 13:59:52 +0000 | [diff] [blame] | 9904 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 9905 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9906 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9907 | if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) |
| 9908 | netdev->hw_features |= NETIF_F_LRO; |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 9909 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 9910 | netdev->features |= NETIF_F_LRO; |
| 9911 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9912 | /* make sure the EEPROM is good */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9913 | if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 9914 | e_dev_err("The EEPROM Checksum Is Not Valid\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9915 | err = -EIO; |
Alexander Duyck | 35937c0 | 2012-02-08 07:51:37 +0000 | [diff] [blame] | 9916 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9917 | } |
| 9918 | |
Sowmini Varadhan | c7374b5 | 2016-01-12 19:32:30 -0800 | [diff] [blame] | 9919 | eth_platform_get_mac_address(&adapter->pdev->dev, |
| 9920 | adapter->hw.mac.perm_addr); |
Martin K Petersen | c762dff | 2014-11-15 14:24:51 +0000 | [diff] [blame] | 9921 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9922 | memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9923 | |
Jiri Pirko | aaeb6cd | 2013-01-08 01:38:26 +0000 | [diff] [blame] | 9924 | if (!is_valid_ether_addr(netdev->dev_addr)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 9925 | e_dev_err("invalid MAC address\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9926 | err = -EIO; |
Alexander Duyck | 35937c0 | 2012-02-08 07:51:37 +0000 | [diff] [blame] | 9927 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9928 | } |
| 9929 | |
Tushar Dave | 5676804 | 2016-01-07 14:17:03 -0800 | [diff] [blame] | 9930 | /* Set hw->mac.addr to permanent MAC address */ |
| 9931 | ether_addr_copy(hw->mac.addr, hw->mac.perm_addr); |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 9932 | ixgbe_mac_set_default_filter(adapter); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 9933 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 9934 | setup_timer(&adapter->service_timer, &ixgbe_service_timer, |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 9935 | (unsigned long) adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9936 | |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 9937 | if (ixgbe_removed(hw->hw_addr)) { |
| 9938 | err = -EIO; |
| 9939 | goto err_sw_init; |
| 9940 | } |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 9941 | INIT_WORK(&adapter->service_task, ixgbe_service_task); |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 9942 | set_bit(__IXGBE_SERVICE_INITED, &adapter->state); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 9943 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9944 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 9945 | err = ixgbe_init_interrupt_scheme(adapter); |
| 9946 | if (err) |
| 9947 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9948 | |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9949 | /* WOL not supported for all devices */ |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 9950 | adapter->wol = 0; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9951 | hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap); |
Jacob Keller | 6b92b0b | 2013-04-13 05:40:37 +0000 | [diff] [blame] | 9952 | hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device, |
Don Skidmore | b8f8363 | 2013-02-28 08:08:44 +0000 | [diff] [blame] | 9953 | pdev->subsystem_device); |
Jacob Keller | 6b92b0b | 2013-04-13 05:40:37 +0000 | [diff] [blame] | 9954 | if (hw->wol_enabled) |
Andy Gospodarek | 9417c46 | 2011-07-16 07:31:33 +0000 | [diff] [blame] | 9955 | adapter->wol = IXGBE_WUFC_MAG; |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 9956 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 9957 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 9958 | |
Emil Tantilov | 15e5209 | 2011-09-29 05:01:29 +0000 | [diff] [blame] | 9959 | /* save off EEPROM version number */ |
| 9960 | hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh); |
| 9961 | hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl); |
| 9962 | |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 9963 | /* pick up the PCI bus settings for reporting later */ |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 9964 | if (ixgbe_pcie_from_parent(hw)) |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 9965 | ixgbe_get_parent_bus_info(adapter); |
Don Skidmore | f9328bc | 2015-06-18 13:24:06 -0400 | [diff] [blame] | 9966 | else |
| 9967 | hw->mac.ops.get_bus_info(hw); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 9968 | |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 9969 | /* calculate the expected PCIe bandwidth required for optimal |
| 9970 | * performance. Note that some older parts will never have enough |
| 9971 | * bandwidth due to being older generation PCIe parts. We clamp these |
| 9972 | * parts to ensure no warning is displayed if it can't be fixed. |
| 9973 | */ |
| 9974 | switch (hw->mac.type) { |
| 9975 | case ixgbe_mac_82598EB: |
| 9976 | expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16); |
| 9977 | break; |
| 9978 | default: |
| 9979 | expected_gts = ixgbe_enumerate_functions(adapter) * 10; |
| 9980 | break; |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 9981 | } |
Jacob Keller | caafb95 | 2014-07-19 07:17:17 +0000 | [diff] [blame] | 9982 | |
| 9983 | /* don't check link if we failed to enumerate functions */ |
| 9984 | if (expected_gts > 0) |
| 9985 | ixgbe_check_minimum_link(adapter, expected_gts); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 9986 | |
Mark Rustad | 339de30 | 2014-06-06 01:57:06 +0000 | [diff] [blame] | 9987 | err = ixgbe_read_pba_string_generic(hw, part_str, sizeof(part_str)); |
Jacob Keller | 6a2aae5 | 2013-10-18 05:09:24 +0000 | [diff] [blame] | 9988 | if (err) |
Mark Rustad | 339de30 | 2014-06-06 01:57:06 +0000 | [diff] [blame] | 9989 | strlcpy(part_str, "Unknown", sizeof(part_str)); |
Jacob Keller | 6a2aae5 | 2013-10-18 05:09:24 +0000 | [diff] [blame] | 9990 | if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present) |
| 9991 | e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n", |
| 9992 | hw->mac.type, hw->phy.type, hw->phy.sfp_type, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 9993 | part_str); |
Jacob Keller | 6a2aae5 | 2013-10-18 05:09:24 +0000 | [diff] [blame] | 9994 | else |
| 9995 | e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n", |
| 9996 | hw->mac.type, hw->phy.type, part_str); |
| 9997 | |
| 9998 | e_dev_info("%pM\n", netdev->dev_addr); |
| 9999 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10000 | /* reset the hardware with the new settings */ |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 10001 | err = hw->mac.ops.start_hw(hw); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 10002 | if (err == IXGBE_ERR_EEPROM_VERSION) { |
| 10003 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 10004 | e_dev_warn("This device is a pre-production adapter/LOM. " |
| 10005 | "Please be aware there may be issues associated " |
| 10006 | "with your hardware. If you are experiencing " |
| 10007 | "problems please contact your Intel or hardware " |
| 10008 | "representative who provided you with this " |
| 10009 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 10010 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10011 | strcpy(netdev->name, "eth%d"); |
| 10012 | err = register_netdev(netdev); |
| 10013 | if (err) |
| 10014 | goto err_register; |
| 10015 | |
Emil Tantilov | 0fb6a55 | 2014-12-04 03:03:38 +0000 | [diff] [blame] | 10016 | pci_set_drvdata(pdev, adapter); |
| 10017 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 10018 | /* power down the optics for 82599 SFP+ fiber */ |
| 10019 | if (hw->mac.ops.disable_tx_laser) |
Emil Tantilov | 93d3ce8 | 2011-10-19 07:59:55 +0000 | [diff] [blame] | 10020 | hw->mac.ops.disable_tx_laser(hw); |
| 10021 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 10022 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 10023 | netif_carrier_off(netdev); |
| 10024 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 10025 | #ifdef CONFIG_IXGBE_DCA |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 10026 | if (dca_add_requester(&pdev->dev) == 0) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10027 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10028 | ixgbe_setup_dca(adapter); |
| 10029 | } |
| 10030 | #endif |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 10031 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 10032 | e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 10033 | for (i = 0; i < adapter->num_vfs; i++) |
| 10034 | ixgbe_vf_configuration(pdev, (i | 0x10000000)); |
| 10035 | } |
| 10036 | |
Jacob Keller | 2466dd9 | 2011-09-08 03:50:54 +0000 | [diff] [blame] | 10037 | /* firmware requires driver version to be 0xFFFFFFFF |
| 10038 | * since os does not support feature |
| 10039 | */ |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 10040 | if (hw->mac.ops.set_fw_drv_ver) |
Tony Nguyen | cb8e051 | 2016-10-26 16:25:18 -0700 | [diff] [blame] | 10041 | hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, 0xFF, |
| 10042 | sizeof(ixgbe_driver_version) - 1, |
| 10043 | ixgbe_driver_version); |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 10044 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 10045 | /* add san mac addr to netdev */ |
| 10046 | ixgbe_add_sanmac_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10047 | |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 10048 | e_dev_info("%s\n", ixgbe_default_device_descr); |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 10049 | |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 10050 | #ifdef CONFIG_IXGBE_HWMON |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 10051 | if (ixgbe_sysfs_init(adapter)) |
| 10052 | e_err(probe, "failed to allocate sysfs resources\n"); |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 10053 | #endif /* CONFIG_IXGBE_HWMON */ |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 10054 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 10055 | ixgbe_dbg_adapter_init(adapter); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 10056 | |
Emil Tantilov | d1a35ee | 2014-05-13 08:24:00 +0000 | [diff] [blame] | 10057 | /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */ |
| 10058 | if (ixgbe_mng_enabled(hw) && ixgbe_is_sfp(hw) && hw->mac.ops.setup_link) |
Don Skidmore | 0b2679d | 2013-02-21 03:00:04 +0000 | [diff] [blame] | 10059 | hw->mac.ops.setup_link(hw, |
| 10060 | IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL, |
| 10061 | true); |
| 10062 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10063 | return 0; |
| 10064 | |
| 10065 | err_register: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 10066 | ixgbe_release_hw_control(adapter); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 10067 | ixgbe_clear_interrupt_scheme(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10068 | err_sw_init: |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 10069 | ixgbe_disable_sriov(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 10070 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 10071 | iounmap(adapter->io_addr); |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 10072 | kfree(adapter->jump_tables[0]); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 10073 | kfree(adapter->mac_table); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10074 | err_ioremap: |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 10075 | disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10076 | free_netdev(netdev); |
| 10077 | err_alloc_etherdev: |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 10078 | pci_release_mem_regions(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10079 | err_pci_reg: |
| 10080 | err_dma: |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 10081 | if (!adapter || disable_dev) |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10082 | pci_disable_device(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10083 | return err; |
| 10084 | } |
| 10085 | |
| 10086 | /** |
| 10087 | * ixgbe_remove - Device Removal Routine |
| 10088 | * @pdev: PCI device information struct |
| 10089 | * |
| 10090 | * ixgbe_remove is called by the PCI subsystem to alert the driver |
| 10091 | * that it should release a PCI device. The could be caused by a |
| 10092 | * Hot-Plug event, or because the driver is going to be removed from |
| 10093 | * memory. |
| 10094 | **/ |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 10095 | static void ixgbe_remove(struct pci_dev *pdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10096 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 10097 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
Emil Tantilov | 0fb6a55 | 2014-12-04 03:03:38 +0000 | [diff] [blame] | 10098 | struct net_device *netdev; |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 10099 | bool disable_dev; |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 10100 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10101 | |
Emil Tantilov | 0fb6a55 | 2014-12-04 03:03:38 +0000 | [diff] [blame] | 10102 | /* if !adapter then we already cleaned up in probe */ |
| 10103 | if (!adapter) |
| 10104 | return; |
| 10105 | |
| 10106 | netdev = adapter->netdev; |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 10107 | ixgbe_dbg_adapter_exit(adapter); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 10108 | |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 10109 | set_bit(__IXGBE_REMOVING, &adapter->state); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 10110 | cancel_work_sync(&adapter->service_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10111 | |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 10112 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 10113 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10114 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 10115 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 10116 | dca_remove_requester(&pdev->dev); |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 10117 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 10118 | IXGBE_DCA_CTRL_DCA_DISABLE); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10119 | } |
| 10120 | |
| 10121 | #endif |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 10122 | #ifdef CONFIG_IXGBE_HWMON |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 10123 | ixgbe_sysfs_exit(adapter); |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 10124 | #endif /* CONFIG_IXGBE_HWMON */ |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 10125 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 10126 | /* remove the added san mac */ |
| 10127 | ixgbe_del_sanmac_netdev(netdev); |
| 10128 | |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 10129 | #ifdef CONFIG_PCI_IOV |
Alex Williamson | 7837e28 | 2015-07-10 15:31:34 -0600 | [diff] [blame] | 10130 | ixgbe_disable_sriov(adapter); |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 10131 | #endif |
Alex Williamson | 6b010e9 | 2015-07-29 14:38:21 -0600 | [diff] [blame] | 10132 | if (netdev->reg_state == NETREG_REGISTERED) |
| 10133 | unregister_netdev(netdev); |
| 10134 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 10135 | ixgbe_clear_interrupt_scheme(adapter); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 10136 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 10137 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10138 | |
Alexander Duyck | 2b1588c | 2012-03-17 02:39:16 +0000 | [diff] [blame] | 10139 | #ifdef CONFIG_DCB |
| 10140 | kfree(adapter->ixgbe_ieee_pfc); |
| 10141 | kfree(adapter->ixgbe_ieee_ets); |
| 10142 | |
| 10143 | #endif |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 10144 | iounmap(adapter->io_addr); |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 10145 | pci_release_mem_regions(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10146 | |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 10147 | e_dev_info("complete\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 10148 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 10149 | for (i = 0; i < IXGBE_MAX_LINK_HANDLE; i++) { |
| 10150 | if (adapter->jump_tables[i]) { |
| 10151 | kfree(adapter->jump_tables[i]->input); |
| 10152 | kfree(adapter->jump_tables[i]->mask); |
| 10153 | } |
| 10154 | kfree(adapter->jump_tables[i]); |
| 10155 | } |
| 10156 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 10157 | kfree(adapter->mac_table); |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 10158 | disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10159 | free_netdev(netdev); |
| 10160 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 10161 | pci_disable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10162 | |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 10163 | if (disable_dev) |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10164 | pci_disable_device(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10165 | } |
| 10166 | |
| 10167 | /** |
| 10168 | * ixgbe_io_error_detected - called when PCI error is detected |
| 10169 | * @pdev: Pointer to PCI device |
| 10170 | * @state: The current pci connection state |
| 10171 | * |
| 10172 | * This function is called after a PCI bus error affecting |
| 10173 | * this device has been detected. |
| 10174 | */ |
| 10175 | static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 10176 | pci_channel_state_t state) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10177 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 10178 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 10179 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10180 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10181 | #ifdef CONFIG_PCI_IOV |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 10182 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10183 | struct pci_dev *bdev, *vfdev; |
| 10184 | u32 dw0, dw1, dw2, dw3; |
| 10185 | int vf, pos; |
| 10186 | u16 req_id, pf_func; |
| 10187 | |
| 10188 | if (adapter->hw.mac.type == ixgbe_mac_82598EB || |
| 10189 | adapter->num_vfs == 0) |
| 10190 | goto skip_bad_vf_detection; |
| 10191 | |
| 10192 | bdev = pdev->bus->self; |
Yijing Wang | 62f87c0 | 2012-07-24 17:20:03 +0800 | [diff] [blame] | 10193 | while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT)) |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10194 | bdev = bdev->bus->self; |
| 10195 | |
| 10196 | if (!bdev) |
| 10197 | goto skip_bad_vf_detection; |
| 10198 | |
| 10199 | pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR); |
| 10200 | if (!pos) |
| 10201 | goto skip_bad_vf_detection; |
| 10202 | |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 10203 | dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG); |
| 10204 | dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4); |
| 10205 | dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8); |
| 10206 | dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12); |
| 10207 | if (ixgbe_removed(hw->hw_addr)) |
| 10208 | goto skip_bad_vf_detection; |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10209 | |
| 10210 | req_id = dw1 >> 16; |
| 10211 | /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */ |
| 10212 | if (!(req_id & 0x0080)) |
| 10213 | goto skip_bad_vf_detection; |
| 10214 | |
| 10215 | pf_func = req_id & 0x01; |
| 10216 | if ((pf_func & 1) == (pdev->devfn & 1)) { |
| 10217 | unsigned int device_id; |
| 10218 | |
| 10219 | vf = (req_id & 0x7F) >> 1; |
| 10220 | e_dev_err("VF %d has caused a PCIe error\n", vf); |
| 10221 | e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: " |
| 10222 | "%8.8x\tdw3: %8.8x\n", |
| 10223 | dw0, dw1, dw2, dw3); |
| 10224 | switch (adapter->hw.mac.type) { |
| 10225 | case ixgbe_mac_82599EB: |
| 10226 | device_id = IXGBE_82599_VF_DEVICE_ID; |
| 10227 | break; |
| 10228 | case ixgbe_mac_X540: |
| 10229 | device_id = IXGBE_X540_VF_DEVICE_ID; |
| 10230 | break; |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 10231 | case ixgbe_mac_X550: |
| 10232 | device_id = IXGBE_DEV_ID_X550_VF; |
| 10233 | break; |
| 10234 | case ixgbe_mac_X550EM_x: |
| 10235 | device_id = IXGBE_DEV_ID_X550EM_X_VF; |
| 10236 | break; |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 10237 | case ixgbe_mac_x550em_a: |
| 10238 | device_id = IXGBE_DEV_ID_X550EM_A_VF; |
| 10239 | break; |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10240 | default: |
| 10241 | device_id = 0; |
| 10242 | break; |
| 10243 | } |
| 10244 | |
| 10245 | /* Find the pci device of the offending VF */ |
Jon Mason | 36e9031 | 2012-07-19 21:02:09 +0000 | [diff] [blame] | 10246 | vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL); |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10247 | while (vfdev) { |
| 10248 | if (vfdev->devfn == (req_id & 0xFF)) |
| 10249 | break; |
Jon Mason | 36e9031 | 2012-07-19 21:02:09 +0000 | [diff] [blame] | 10250 | vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10251 | device_id, vfdev); |
| 10252 | } |
| 10253 | /* |
| 10254 | * There's a slim chance the VF could have been hot plugged, |
| 10255 | * so if it is no longer present we don't need to issue the |
| 10256 | * VFLR. Just clean up the AER in that case. |
| 10257 | */ |
| 10258 | if (vfdev) { |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 10259 | ixgbe_issue_vf_flr(adapter, vfdev); |
Greg Rose | b4fafbe | 2012-12-13 01:14:06 +0000 | [diff] [blame] | 10260 | /* Free device reference count */ |
| 10261 | pci_dev_put(vfdev); |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10262 | } |
| 10263 | |
| 10264 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 10265 | } |
| 10266 | |
| 10267 | /* |
| 10268 | * Even though the error may have occurred on the other port |
| 10269 | * we still need to increment the vf error reference count for |
| 10270 | * both ports because the I/O resume function will be called |
| 10271 | * for both of them. |
| 10272 | */ |
| 10273 | adapter->vferr_refcount++; |
| 10274 | |
| 10275 | return PCI_ERS_RESULT_RECOVERED; |
| 10276 | |
| 10277 | skip_bad_vf_detection: |
| 10278 | #endif /* CONFIG_PCI_IOV */ |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 10279 | if (!test_bit(__IXGBE_SERVICE_INITED, &adapter->state)) |
| 10280 | return PCI_ERS_RESULT_DISCONNECT; |
| 10281 | |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10282 | rtnl_lock(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10283 | netif_device_detach(netdev); |
| 10284 | |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10285 | if (state == pci_channel_io_perm_failure) { |
| 10286 | rtnl_unlock(); |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 10287 | return PCI_ERS_RESULT_DISCONNECT; |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10288 | } |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 10289 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10290 | if (netif_running(netdev)) |
Emil Tantilov | 126db13 | 2016-11-16 09:48:02 -0800 | [diff] [blame] | 10291 | ixgbe_close_suspend(adapter); |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10292 | |
| 10293 | if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state)) |
| 10294 | pci_disable_device(pdev); |
| 10295 | rtnl_unlock(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10296 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 10297 | /* Request a slot reset. */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10298 | return PCI_ERS_RESULT_NEED_RESET; |
| 10299 | } |
| 10300 | |
| 10301 | /** |
| 10302 | * ixgbe_io_slot_reset - called after the pci bus has been reset. |
| 10303 | * @pdev: Pointer to PCI device |
| 10304 | * |
| 10305 | * Restart the card from scratch, as if from a cold-boot. |
| 10306 | */ |
| 10307 | static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev) |
| 10308 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 10309 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10310 | pci_ers_result_t result; |
| 10311 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10312 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 10313 | if (pci_enable_device_mem(pdev)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 10314 | e_err(probe, "Cannot re-enable PCI device after reset.\n"); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10315 | result = PCI_ERS_RESULT_DISCONNECT; |
| 10316 | } else { |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 10317 | smp_mb__before_atomic(); |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10318 | clear_bit(__IXGBE_DISABLED, &adapter->state); |
Mark Rustad | 0391bbe | 2014-02-28 15:48:55 -0800 | [diff] [blame] | 10319 | adapter->hw.hw_addr = adapter->io_addr; |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10320 | pci_set_master(pdev); |
| 10321 | pci_restore_state(pdev); |
Breno Leitao | c0e1f68 | 2009-11-10 08:37:47 +0000 | [diff] [blame] | 10322 | pci_save_state(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10323 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 10324 | pci_wake_from_d3(pdev, false); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10325 | |
| 10326 | ixgbe_reset(adapter); |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 10327 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10328 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10329 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10330 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10331 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 10332 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 10333 | e_dev_err("pci_cleanup_aer_uncorrect_error_status " |
| 10334 | "failed 0x%0x\n", err); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10335 | /* non-fatal, continue */ |
| 10336 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10337 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10338 | return result; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10339 | } |
| 10340 | |
| 10341 | /** |
| 10342 | * ixgbe_io_resume - called when traffic can start flowing again. |
| 10343 | * @pdev: Pointer to PCI device |
| 10344 | * |
| 10345 | * This callback is called when the error recovery driver tells us that |
| 10346 | * its OK to resume normal operation. |
| 10347 | */ |
| 10348 | static void ixgbe_io_resume(struct pci_dev *pdev) |
| 10349 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 10350 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 10351 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10352 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10353 | #ifdef CONFIG_PCI_IOV |
| 10354 | if (adapter->vferr_refcount) { |
| 10355 | e_info(drv, "Resuming after VF err\n"); |
| 10356 | adapter->vferr_refcount--; |
| 10357 | return; |
| 10358 | } |
| 10359 | |
| 10360 | #endif |
Emil Tantilov | 126db13 | 2016-11-16 09:48:02 -0800 | [diff] [blame] | 10361 | rtnl_lock(); |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 10362 | if (netif_running(netdev)) |
Emil Tantilov | 126db13 | 2016-11-16 09:48:02 -0800 | [diff] [blame] | 10363 | ixgbe_open(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10364 | |
| 10365 | netif_device_attach(netdev); |
Emil Tantilov | 126db13 | 2016-11-16 09:48:02 -0800 | [diff] [blame] | 10366 | rtnl_unlock(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10367 | } |
| 10368 | |
Stephen Hemminger | 3646f0e | 2012-09-07 09:33:15 -0700 | [diff] [blame] | 10369 | static const struct pci_error_handlers ixgbe_err_handler = { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10370 | .error_detected = ixgbe_io_error_detected, |
| 10371 | .slot_reset = ixgbe_io_slot_reset, |
| 10372 | .resume = ixgbe_io_resume, |
| 10373 | }; |
| 10374 | |
| 10375 | static struct pci_driver ixgbe_driver = { |
| 10376 | .name = ixgbe_driver_name, |
| 10377 | .id_table = ixgbe_pci_tbl, |
| 10378 | .probe = ixgbe_probe, |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 10379 | .remove = ixgbe_remove, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10380 | #ifdef CONFIG_PM |
| 10381 | .suspend = ixgbe_suspend, |
| 10382 | .resume = ixgbe_resume, |
| 10383 | #endif |
| 10384 | .shutdown = ixgbe_shutdown, |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 10385 | .sriov_configure = ixgbe_pci_sriov_configure, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10386 | .err_handler = &ixgbe_err_handler |
| 10387 | }; |
| 10388 | |
| 10389 | /** |
| 10390 | * ixgbe_init_module - Driver Registration Routine |
| 10391 | * |
| 10392 | * ixgbe_init_module is the first routine called when the driver is |
| 10393 | * loaded. All it does is register with the PCI subsystem. |
| 10394 | **/ |
| 10395 | static int __init ixgbe_init_module(void) |
| 10396 | { |
| 10397 | int ret; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 10398 | pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version); |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 10399 | pr_info("%s\n", ixgbe_copyright); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10400 | |
Mark Rustad | 780484d | 2015-10-21 17:21:10 -0700 | [diff] [blame] | 10401 | ixgbe_wq = create_singlethread_workqueue(ixgbe_driver_name); |
| 10402 | if (!ixgbe_wq) { |
| 10403 | pr_err("%s: Failed to create workqueue\n", ixgbe_driver_name); |
| 10404 | return -ENOMEM; |
| 10405 | } |
| 10406 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 10407 | ixgbe_dbg_init(); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 10408 | |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 10409 | ret = pci_register_driver(&ixgbe_driver); |
| 10410 | if (ret) { |
Wei Yongjun | 6b83687 | 2016-07-12 15:17:02 +0000 | [diff] [blame] | 10411 | destroy_workqueue(ixgbe_wq); |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 10412 | ixgbe_dbg_exit(); |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 10413 | return ret; |
| 10414 | } |
| 10415 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 10416 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10417 | dca_register_notify(&dca_notifier); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10418 | #endif |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 10419 | |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 10420 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10421 | } |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 10422 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10423 | module_init(ixgbe_init_module); |
| 10424 | |
| 10425 | /** |
| 10426 | * ixgbe_exit_module - Driver Exit Cleanup Routine |
| 10427 | * |
| 10428 | * ixgbe_exit_module is called just before the driver is removed |
| 10429 | * from memory. |
| 10430 | **/ |
| 10431 | static void __exit ixgbe_exit_module(void) |
| 10432 | { |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 10433 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10434 | dca_unregister_notify(&dca_notifier); |
| 10435 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10436 | pci_unregister_driver(&ixgbe_driver); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 10437 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 10438 | ixgbe_dbg_exit(); |
Mark Rustad | 780484d | 2015-10-21 17:21:10 -0700 | [diff] [blame] | 10439 | if (ixgbe_wq) { |
| 10440 | destroy_workqueue(ixgbe_wq); |
| 10441 | ixgbe_wq = NULL; |
| 10442 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10443 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10444 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 10445 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10446 | static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 10447 | void *p) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10448 | { |
| 10449 | int ret_val; |
| 10450 | |
| 10451 | ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 10452 | __ixgbe_notify_dca); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10453 | |
| 10454 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; |
| 10455 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10456 | |
Alexander Duyck | b453368 | 2009-03-31 21:32:42 +0000 | [diff] [blame] | 10457 | #endif /* CONFIG_IXGBE_DCA */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 10458 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10459 | module_exit(ixgbe_exit_module); |
| 10460 | |
| 10461 | /* ixgbe_main.c */ |