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> |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 53 | #include <net/vxlan.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> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 56 | |
| 57 | #include "ixgbe.h" |
| 58 | #include "ixgbe_common.h" |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 59 | #include "ixgbe_dcb_82599.h" |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 60 | #include "ixgbe_sriov.h" |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 61 | #include "ixgbe_model.h" |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 62 | |
| 63 | char ixgbe_driver_name[] = "ixgbe"; |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 64 | static const char ixgbe_driver_string[] = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 65 | "Intel(R) 10 Gigabit PCI Express Network Driver"; |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 66 | #ifdef IXGBE_FCOE |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 67 | char ixgbe_default_device_descr[] = |
| 68 | "Intel(R) 10 Gigabit Network Connection"; |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 69 | #else |
| 70 | static char ixgbe_default_device_descr[] = |
| 71 | "Intel(R) 10 Gigabit Network Connection"; |
| 72 | #endif |
Mark Rustad | 21dd560 | 2015-08-11 13:11:58 -0700 | [diff] [blame] | 73 | #define DRV_VERSION "4.2.1-k" |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 74 | const char ixgbe_driver_version[] = DRV_VERSION; |
Don Skidmore | a52055e | 2011-02-23 09:58:39 +0000 | [diff] [blame] | 75 | static const char ixgbe_copyright[] = |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 76 | "Copyright (c) 1999-2015 Intel Corporation."; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 77 | |
Don Skidmore | f44e751 | 2015-06-09 16:36:23 -0700 | [diff] [blame] | 78 | 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"; |
| 79 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 80 | static const struct ixgbe_info *ixgbe_info_tbl[] = { |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 81 | [board_82598] = &ixgbe_82598_info, |
| 82 | [board_82599] = &ixgbe_82599_info, |
| 83 | [board_X540] = &ixgbe_X540_info, |
| 84 | [board_X550] = &ixgbe_X550_info, |
| 85 | [board_X550EM_x] = &ixgbe_X550EM_x_info, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | /* ixgbe_pci_tbl - PCI Device ID Table |
| 89 | * |
| 90 | * Wildcard entries (PCI_ANY_ID) should come last |
| 91 | * Last entry must be all 0s |
| 92 | * |
| 93 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 94 | * Class, Class Mask, private data (not used) } |
| 95 | */ |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 96 | static const struct pci_device_id ixgbe_pci_tbl[] = { |
Alexander Duyck | 54239c6 | 2011-07-15 03:06:06 +0000 | [diff] [blame] | 97 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 }, |
| 98 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 }, |
| 99 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 }, |
| 100 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 }, |
| 101 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 }, |
| 102 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 }, |
| 103 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 }, |
| 104 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 }, |
| 105 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 }, |
| 106 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 }, |
| 107 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 }, |
| 108 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 }, |
| 109 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 }, |
| 110 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 }, |
| 111 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 }, |
| 112 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 }, |
| 113 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 }, |
| 114 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 }, |
| 115 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 }, |
| 116 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 }, |
| 117 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 }, |
| 118 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 }, |
| 119 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 }, |
| 120 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 }, |
| 121 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 }, |
| 122 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 }, |
Don Skidmore | 8f58332 | 2013-07-27 06:25:38 +0000 | [diff] [blame] | 123 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_QSFP_SF_QP), board_82599 }, |
Emil Tantilov | 7d14528 | 2011-09-08 08:30:14 +0000 | [diff] [blame] | 124 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 }, |
Emil Tantilov | 9e791e4 | 2011-11-04 06:43:29 +0000 | [diff] [blame] | 125 | {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] | 126 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 }, |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 127 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T), board_X550}, |
| 128 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KX4), board_X550EM_x}, |
| 129 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KR), board_X550EM_x}, |
Don Skidmore | deda562 | 2015-06-09 17:39:46 -0700 | [diff] [blame] | 130 | {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] | 131 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_SFP), board_X550EM_x}, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 132 | /* required last entry */ |
| 133 | {0, } |
| 134 | }; |
| 135 | MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl); |
| 136 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 137 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 138 | static int ixgbe_notify_dca(struct notifier_block *, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 139 | void *p); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 140 | static struct notifier_block dca_notifier = { |
| 141 | .notifier_call = ixgbe_notify_dca, |
| 142 | .next = NULL, |
| 143 | .priority = 0 |
| 144 | }; |
| 145 | #endif |
| 146 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 147 | #ifdef CONFIG_PCI_IOV |
| 148 | static unsigned int max_vfs; |
| 149 | module_param(max_vfs, uint, 0); |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 150 | MODULE_PARM_DESC(max_vfs, |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 151 | "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] | 152 | #endif /* CONFIG_PCI_IOV */ |
| 153 | |
Peter P Waskiewicz Jr | 8ef78ad | 2012-02-01 09:19:21 +0000 | [diff] [blame] | 154 | static unsigned int allow_unsupported_sfp; |
| 155 | module_param(allow_unsupported_sfp, uint, 0); |
| 156 | MODULE_PARM_DESC(allow_unsupported_sfp, |
| 157 | "Allow unsupported and untested SFP+ modules on 82599-based adapters"); |
| 158 | |
stephen hemminger | b3f4d59 | 2012-03-13 06:04:20 +0000 | [diff] [blame] | 159 | #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK) |
| 160 | static int debug = -1; |
| 161 | module_param(debug, int, 0); |
| 162 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 163 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 164 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 165 | MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver"); |
| 166 | MODULE_LICENSE("GPL"); |
| 167 | MODULE_VERSION(DRV_VERSION); |
| 168 | |
Mark Rustad | 780484d | 2015-10-21 17:21:10 -0700 | [diff] [blame] | 169 | static struct workqueue_struct *ixgbe_wq; |
| 170 | |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 171 | static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev); |
| 172 | |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 173 | static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter *adapter, |
| 174 | u32 reg, u16 *value) |
| 175 | { |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 176 | struct pci_dev *parent_dev; |
| 177 | struct pci_bus *parent_bus; |
| 178 | |
| 179 | parent_bus = adapter->pdev->bus->parent; |
| 180 | if (!parent_bus) |
| 181 | return -1; |
| 182 | |
| 183 | parent_dev = parent_bus->self; |
| 184 | if (!parent_dev) |
| 185 | return -1; |
| 186 | |
Yijing Wang | c0798ed | 2013-09-04 17:30:08 +0000 | [diff] [blame] | 187 | if (!pci_is_pcie(parent_dev)) |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 188 | return -1; |
| 189 | |
Yijing Wang | c0798ed | 2013-09-04 17:30:08 +0000 | [diff] [blame] | 190 | pcie_capability_read_word(parent_dev, reg, value); |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 191 | if (*value == IXGBE_FAILED_READ_CFG_WORD && |
| 192 | ixgbe_check_cfg_remove(&adapter->hw, parent_dev)) |
| 193 | return -1; |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | static s32 ixgbe_get_parent_bus_info(struct ixgbe_adapter *adapter) |
| 198 | { |
| 199 | struct ixgbe_hw *hw = &adapter->hw; |
| 200 | u16 link_status = 0; |
| 201 | int err; |
| 202 | |
| 203 | hw->bus.type = ixgbe_bus_type_pci_express; |
| 204 | |
| 205 | /* Get the negotiated link width and speed from PCI config space of the |
| 206 | * parent, as this device is behind a switch |
| 207 | */ |
| 208 | err = ixgbe_read_pci_cfg_word_parent(adapter, 18, &link_status); |
| 209 | |
| 210 | /* assume caller will handle error case */ |
| 211 | if (err) |
| 212 | return err; |
| 213 | |
| 214 | hw->bus.width = ixgbe_convert_bus_width(link_status); |
| 215 | hw->bus.speed = ixgbe_convert_bus_speed(link_status); |
| 216 | |
| 217 | return 0; |
| 218 | } |
| 219 | |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 220 | /** |
| 221 | * ixgbe_check_from_parent - Determine whether PCIe info should come from parent |
| 222 | * @hw: hw specific details |
| 223 | * |
| 224 | * This function is used by probe to determine whether a device's PCI-Express |
| 225 | * bandwidth details should be gathered from the parent bus instead of from the |
| 226 | * device. Used to ensure that various locations all have the correct device ID |
| 227 | * checks. |
| 228 | */ |
| 229 | static inline bool ixgbe_pcie_from_parent(struct ixgbe_hw *hw) |
| 230 | { |
| 231 | switch (hw->device_id) { |
| 232 | case IXGBE_DEV_ID_82599_SFP_SF_QP: |
Don Skidmore | 8f58332 | 2013-07-27 06:25:38 +0000 | [diff] [blame] | 233 | case IXGBE_DEV_ID_82599_QSFP_SF_QP: |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 234 | return true; |
| 235 | default: |
| 236 | return false; |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | static void ixgbe_check_minimum_link(struct ixgbe_adapter *adapter, |
| 241 | int expected_gts) |
| 242 | { |
Don Skidmore | f9328bc | 2015-06-18 13:24:06 -0400 | [diff] [blame] | 243 | struct ixgbe_hw *hw = &adapter->hw; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 244 | int max_gts = 0; |
| 245 | enum pci_bus_speed speed = PCI_SPEED_UNKNOWN; |
| 246 | enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN; |
| 247 | struct pci_dev *pdev; |
| 248 | |
Don Skidmore | f9328bc | 2015-06-18 13:24:06 -0400 | [diff] [blame] | 249 | /* Some devices are not connected over PCIe and thus do not negotiate |
| 250 | * speed. These devices do not have valid bus info, and thus any report |
| 251 | * we generate may not be correct. |
| 252 | */ |
| 253 | if (hw->bus.type == ixgbe_bus_type_internal) |
| 254 | return; |
| 255 | |
Jacob Keller | 56d1392 | 2015-06-10 11:44:45 -0700 | [diff] [blame] | 256 | /* determine whether to use the parent device */ |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 257 | if (ixgbe_pcie_from_parent(&adapter->hw)) |
| 258 | pdev = adapter->pdev->bus->parent->self; |
| 259 | else |
| 260 | pdev = adapter->pdev; |
| 261 | |
| 262 | if (pcie_get_minimum_link(pdev, &speed, &width) || |
| 263 | speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) { |
| 264 | e_dev_warn("Unable to determine PCI Express bandwidth.\n"); |
| 265 | return; |
| 266 | } |
| 267 | |
| 268 | switch (speed) { |
| 269 | case PCIE_SPEED_2_5GT: |
| 270 | /* 8b/10b encoding reduces max throughput by 20% */ |
| 271 | max_gts = 2 * width; |
| 272 | break; |
| 273 | case PCIE_SPEED_5_0GT: |
| 274 | /* 8b/10b encoding reduces max throughput by 20% */ |
| 275 | max_gts = 4 * width; |
| 276 | break; |
| 277 | case PCIE_SPEED_8_0GT: |
Jacob Keller | 9f0a433 | 2013-10-18 05:09:19 +0000 | [diff] [blame] | 278 | /* 128b/130b encoding reduces throughput by less than 2% */ |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 279 | max_gts = 8 * width; |
| 280 | break; |
| 281 | default: |
| 282 | e_dev_warn("Unable to determine PCI Express bandwidth.\n"); |
| 283 | return; |
| 284 | } |
| 285 | |
| 286 | e_dev_info("PCI Express bandwidth of %dGT/s available\n", |
| 287 | max_gts); |
| 288 | e_dev_info("(Speed:%s, Width: x%d, Encoding Loss:%s)\n", |
| 289 | (speed == PCIE_SPEED_8_0GT ? "8.0GT/s" : |
| 290 | speed == PCIE_SPEED_5_0GT ? "5.0GT/s" : |
| 291 | speed == PCIE_SPEED_2_5GT ? "2.5GT/s" : |
| 292 | "Unknown"), |
| 293 | width, |
| 294 | (speed == PCIE_SPEED_2_5GT ? "20%" : |
| 295 | speed == PCIE_SPEED_5_0GT ? "20%" : |
Jacob Keller | 9f0a433 | 2013-10-18 05:09:19 +0000 | [diff] [blame] | 296 | speed == PCIE_SPEED_8_0GT ? "<2%" : |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 297 | "Unknown")); |
| 298 | |
| 299 | if (max_gts < expected_gts) { |
| 300 | e_dev_warn("This is not sufficient for optimal performance of this card.\n"); |
| 301 | e_dev_warn("For optimal performance, at least %dGT/s of bandwidth is required.\n", |
| 302 | expected_gts); |
| 303 | e_dev_warn("A slot with more lanes and/or higher speed is suggested.\n"); |
| 304 | } |
| 305 | } |
| 306 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 307 | static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter) |
| 308 | { |
| 309 | if (!test_bit(__IXGBE_DOWN, &adapter->state) && |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 310 | !test_bit(__IXGBE_REMOVING, &adapter->state) && |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 311 | !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state)) |
Mark Rustad | 780484d | 2015-10-21 17:21:10 -0700 | [diff] [blame] | 312 | queue_work(ixgbe_wq, &adapter->service_task); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 313 | } |
| 314 | |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 315 | static void ixgbe_remove_adapter(struct ixgbe_hw *hw) |
| 316 | { |
| 317 | struct ixgbe_adapter *adapter = hw->back; |
| 318 | |
| 319 | if (!hw->hw_addr) |
| 320 | return; |
| 321 | hw->hw_addr = NULL; |
| 322 | e_dev_err("Adapter removed\n"); |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 323 | if (test_bit(__IXGBE_SERVICE_INITED, &adapter->state)) |
| 324 | ixgbe_service_event_schedule(adapter); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 325 | } |
| 326 | |
Mark Rustad | f8e2472 | 2014-03-18 07:03:40 +0000 | [diff] [blame] | 327 | static void ixgbe_check_remove(struct ixgbe_hw *hw, u32 reg) |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 328 | { |
| 329 | u32 value; |
| 330 | |
| 331 | /* The following check not only optimizes a bit by not |
| 332 | * performing a read on the status register when the |
| 333 | * register just read was a status register read that |
| 334 | * returned IXGBE_FAILED_READ_REG. It also blocks any |
| 335 | * potential recursion. |
| 336 | */ |
| 337 | if (reg == IXGBE_STATUS) { |
| 338 | ixgbe_remove_adapter(hw); |
| 339 | return; |
| 340 | } |
| 341 | value = ixgbe_read_reg(hw, IXGBE_STATUS); |
| 342 | if (value == IXGBE_FAILED_READ_REG) |
| 343 | ixgbe_remove_adapter(hw); |
| 344 | } |
| 345 | |
Mark Rustad | f8e2472 | 2014-03-18 07:03:40 +0000 | [diff] [blame] | 346 | /** |
| 347 | * ixgbe_read_reg - Read from device register |
| 348 | * @hw: hw specific details |
| 349 | * @reg: offset of register to read |
| 350 | * |
| 351 | * Returns : value read or IXGBE_FAILED_READ_REG if removed |
| 352 | * |
| 353 | * This function is used to read device registers. It checks for device |
| 354 | * removal by confirming any read that returns all ones by checking the |
| 355 | * status register value for all ones. This function avoids reading from |
| 356 | * the hardware if a removal was previously detected in which case it |
| 357 | * returns IXGBE_FAILED_READ_REG (all ones). |
| 358 | */ |
| 359 | u32 ixgbe_read_reg(struct ixgbe_hw *hw, u32 reg) |
| 360 | { |
| 361 | u8 __iomem *reg_addr = ACCESS_ONCE(hw->hw_addr); |
| 362 | u32 value; |
| 363 | |
| 364 | if (ixgbe_removed(reg_addr)) |
| 365 | return IXGBE_FAILED_READ_REG; |
| 366 | value = readl(reg_addr + reg); |
| 367 | if (unlikely(value == IXGBE_FAILED_READ_REG)) |
| 368 | ixgbe_check_remove(hw, reg); |
| 369 | return value; |
| 370 | } |
| 371 | |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 372 | static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev) |
| 373 | { |
| 374 | u16 value; |
| 375 | |
| 376 | pci_read_config_word(pdev, PCI_VENDOR_ID, &value); |
| 377 | if (value == IXGBE_FAILED_READ_CFG_WORD) { |
| 378 | ixgbe_remove_adapter(hw); |
| 379 | return true; |
| 380 | } |
| 381 | return false; |
| 382 | } |
| 383 | |
| 384 | u16 ixgbe_read_pci_cfg_word(struct ixgbe_hw *hw, u32 reg) |
| 385 | { |
| 386 | struct ixgbe_adapter *adapter = hw->back; |
| 387 | u16 value; |
| 388 | |
| 389 | if (ixgbe_removed(hw->hw_addr)) |
| 390 | return IXGBE_FAILED_READ_CFG_WORD; |
| 391 | pci_read_config_word(adapter->pdev, reg, &value); |
| 392 | if (value == IXGBE_FAILED_READ_CFG_WORD && |
| 393 | ixgbe_check_cfg_remove(hw, adapter->pdev)) |
| 394 | return IXGBE_FAILED_READ_CFG_WORD; |
| 395 | return value; |
| 396 | } |
| 397 | |
| 398 | #ifdef CONFIG_PCI_IOV |
| 399 | static u32 ixgbe_read_pci_cfg_dword(struct ixgbe_hw *hw, u32 reg) |
| 400 | { |
| 401 | struct ixgbe_adapter *adapter = hw->back; |
| 402 | u32 value; |
| 403 | |
| 404 | if (ixgbe_removed(hw->hw_addr)) |
| 405 | return IXGBE_FAILED_READ_CFG_DWORD; |
| 406 | pci_read_config_dword(adapter->pdev, reg, &value); |
| 407 | if (value == IXGBE_FAILED_READ_CFG_DWORD && |
| 408 | ixgbe_check_cfg_remove(hw, adapter->pdev)) |
| 409 | return IXGBE_FAILED_READ_CFG_DWORD; |
| 410 | return value; |
| 411 | } |
| 412 | #endif /* CONFIG_PCI_IOV */ |
| 413 | |
Jacob Keller | ed19231 | 2014-02-22 01:23:53 +0000 | [diff] [blame] | 414 | void ixgbe_write_pci_cfg_word(struct ixgbe_hw *hw, u32 reg, u16 value) |
| 415 | { |
| 416 | struct ixgbe_adapter *adapter = hw->back; |
| 417 | |
| 418 | if (ixgbe_removed(hw->hw_addr)) |
| 419 | return; |
| 420 | pci_write_config_word(adapter->pdev, reg, value); |
| 421 | } |
| 422 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 423 | static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter) |
| 424 | { |
| 425 | BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state)); |
| 426 | |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 427 | /* flush memory to make sure state is correct before next watchdog */ |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 428 | smp_mb__before_atomic(); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 429 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
| 430 | } |
| 431 | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 432 | struct ixgbe_reg_info { |
| 433 | u32 ofs; |
| 434 | char *name; |
| 435 | }; |
| 436 | |
| 437 | static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = { |
| 438 | |
| 439 | /* General Registers */ |
| 440 | {IXGBE_CTRL, "CTRL"}, |
| 441 | {IXGBE_STATUS, "STATUS"}, |
| 442 | {IXGBE_CTRL_EXT, "CTRL_EXT"}, |
| 443 | |
| 444 | /* Interrupt Registers */ |
| 445 | {IXGBE_EICR, "EICR"}, |
| 446 | |
| 447 | /* RX Registers */ |
| 448 | {IXGBE_SRRCTL(0), "SRRCTL"}, |
| 449 | {IXGBE_DCA_RXCTRL(0), "DRXCTL"}, |
| 450 | {IXGBE_RDLEN(0), "RDLEN"}, |
| 451 | {IXGBE_RDH(0), "RDH"}, |
| 452 | {IXGBE_RDT(0), "RDT"}, |
| 453 | {IXGBE_RXDCTL(0), "RXDCTL"}, |
| 454 | {IXGBE_RDBAL(0), "RDBAL"}, |
| 455 | {IXGBE_RDBAH(0), "RDBAH"}, |
| 456 | |
| 457 | /* TX Registers */ |
| 458 | {IXGBE_TDBAL(0), "TDBAL"}, |
| 459 | {IXGBE_TDBAH(0), "TDBAH"}, |
| 460 | {IXGBE_TDLEN(0), "TDLEN"}, |
| 461 | {IXGBE_TDH(0), "TDH"}, |
| 462 | {IXGBE_TDT(0), "TDT"}, |
| 463 | {IXGBE_TXDCTL(0), "TXDCTL"}, |
| 464 | |
| 465 | /* List Terminator */ |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 466 | { .name = NULL } |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 467 | }; |
| 468 | |
| 469 | |
| 470 | /* |
| 471 | * ixgbe_regdump - register printout routine |
| 472 | */ |
| 473 | static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo) |
| 474 | { |
| 475 | int i = 0, j = 0; |
| 476 | char rname[16]; |
| 477 | u32 regs[64]; |
| 478 | |
| 479 | switch (reginfo->ofs) { |
| 480 | case IXGBE_SRRCTL(0): |
| 481 | for (i = 0; i < 64; i++) |
| 482 | regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i)); |
| 483 | break; |
| 484 | case IXGBE_DCA_RXCTRL(0): |
| 485 | for (i = 0; i < 64; i++) |
| 486 | regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i)); |
| 487 | break; |
| 488 | case IXGBE_RDLEN(0): |
| 489 | for (i = 0; i < 64; i++) |
| 490 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i)); |
| 491 | break; |
| 492 | case IXGBE_RDH(0): |
| 493 | for (i = 0; i < 64; i++) |
| 494 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i)); |
| 495 | break; |
| 496 | case IXGBE_RDT(0): |
| 497 | for (i = 0; i < 64; i++) |
| 498 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i)); |
| 499 | break; |
| 500 | case IXGBE_RXDCTL(0): |
| 501 | for (i = 0; i < 64; i++) |
| 502 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i)); |
| 503 | break; |
| 504 | case IXGBE_RDBAL(0): |
| 505 | for (i = 0; i < 64; i++) |
| 506 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i)); |
| 507 | break; |
| 508 | case IXGBE_RDBAH(0): |
| 509 | for (i = 0; i < 64; i++) |
| 510 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i)); |
| 511 | break; |
| 512 | case IXGBE_TDBAL(0): |
| 513 | for (i = 0; i < 64; i++) |
| 514 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i)); |
| 515 | break; |
| 516 | case IXGBE_TDBAH(0): |
| 517 | for (i = 0; i < 64; i++) |
| 518 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i)); |
| 519 | break; |
| 520 | case IXGBE_TDLEN(0): |
| 521 | for (i = 0; i < 64; i++) |
| 522 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i)); |
| 523 | break; |
| 524 | case IXGBE_TDH(0): |
| 525 | for (i = 0; i < 64; i++) |
| 526 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i)); |
| 527 | break; |
| 528 | case IXGBE_TDT(0): |
| 529 | for (i = 0; i < 64; i++) |
| 530 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i)); |
| 531 | break; |
| 532 | case IXGBE_TXDCTL(0): |
| 533 | for (i = 0; i < 64; i++) |
| 534 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i)); |
| 535 | break; |
| 536 | default: |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 537 | pr_info("%-15s %08x\n", reginfo->name, |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 538 | IXGBE_READ_REG(hw, reginfo->ofs)); |
| 539 | return; |
| 540 | } |
| 541 | |
| 542 | for (i = 0; i < 8; i++) { |
| 543 | snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 544 | pr_err("%-15s", rname); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 545 | for (j = 0; j < 8; j++) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 546 | pr_cont(" %08x", regs[i*8+j]); |
| 547 | pr_cont("\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | } |
| 551 | |
| 552 | /* |
| 553 | * ixgbe_dump - Print registers, tx-rings and rx-rings |
| 554 | */ |
| 555 | static void ixgbe_dump(struct ixgbe_adapter *adapter) |
| 556 | { |
| 557 | struct net_device *netdev = adapter->netdev; |
| 558 | struct ixgbe_hw *hw = &adapter->hw; |
| 559 | struct ixgbe_reg_info *reginfo; |
| 560 | int n = 0; |
| 561 | struct ixgbe_ring *tx_ring; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 562 | struct ixgbe_tx_buffer *tx_buffer; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 563 | union ixgbe_adv_tx_desc *tx_desc; |
| 564 | struct my_u0 { u64 a; u64 b; } *u0; |
| 565 | struct ixgbe_ring *rx_ring; |
| 566 | union ixgbe_adv_rx_desc *rx_desc; |
| 567 | struct ixgbe_rx_buffer *rx_buffer_info; |
| 568 | u32 staterr; |
| 569 | int i = 0; |
| 570 | |
| 571 | if (!netif_msg_hw(adapter)) |
| 572 | return; |
| 573 | |
| 574 | /* Print netdevice Info */ |
| 575 | if (netdev) { |
| 576 | dev_info(&adapter->pdev->dev, "Net device Info\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 577 | pr_info("Device Name state " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 578 | "trans_start last_rx\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 579 | pr_info("%-15s %016lX %016lX %016lX\n", |
| 580 | netdev->name, |
| 581 | netdev->state, |
| 582 | netdev->trans_start, |
| 583 | netdev->last_rx); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | /* Print Registers */ |
| 587 | dev_info(&adapter->pdev->dev, "Register Dump\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 588 | pr_info(" Register Name Value\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 589 | for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl; |
| 590 | reginfo->name; reginfo++) { |
| 591 | ixgbe_regdump(hw, reginfo); |
| 592 | } |
| 593 | |
| 594 | /* Print TX Ring Summary */ |
| 595 | if (!netdev || !netif_running(netdev)) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 596 | return; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 597 | |
| 598 | dev_info(&adapter->pdev->dev, "TX Rings Summary\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 599 | pr_info(" %s %s %s %s\n", |
| 600 | "Queue [NTU] [NTC] [bi(ntc)->dma ]", |
| 601 | "leng", "ntw", "timestamp"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 602 | for (n = 0; n < adapter->num_tx_queues; n++) { |
| 603 | tx_ring = adapter->tx_ring[n]; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 604 | tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean]; |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 605 | pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n", |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 606 | n, tx_ring->next_to_use, tx_ring->next_to_clean, |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 607 | (u64)dma_unmap_addr(tx_buffer, dma), |
| 608 | dma_unmap_len(tx_buffer, len), |
| 609 | tx_buffer->next_to_watch, |
| 610 | (u64)tx_buffer->time_stamp); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | /* Print TX Rings */ |
| 614 | if (!netif_msg_tx_done(adapter)) |
| 615 | goto rx_ring_summary; |
| 616 | |
| 617 | dev_info(&adapter->pdev->dev, "TX Rings Dump\n"); |
| 618 | |
| 619 | /* Transmit Descriptor Formats |
| 620 | * |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 621 | * 82598 Advanced Transmit Descriptor |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 622 | * +--------------------------------------------------------------+ |
| 623 | * 0 | Buffer Address [63:0] | |
| 624 | * +--------------------------------------------------------------+ |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 625 | * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 626 | * +--------------------------------------------------------------+ |
| 627 | * 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] | 628 | * |
| 629 | * 82598 Advanced Transmit Descriptor (Write-Back Format) |
| 630 | * +--------------------------------------------------------------+ |
| 631 | * 0 | RSV [63:0] | |
| 632 | * +--------------------------------------------------------------+ |
| 633 | * 8 | RSV | STA | NXTSEQ | |
| 634 | * +--------------------------------------------------------------+ |
| 635 | * 63 36 35 32 31 0 |
| 636 | * |
| 637 | * 82599+ Advanced Transmit Descriptor |
| 638 | * +--------------------------------------------------------------+ |
| 639 | * 0 | Buffer Address [63:0] | |
| 640 | * +--------------------------------------------------------------+ |
| 641 | * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN | |
| 642 | * +--------------------------------------------------------------+ |
| 643 | * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0 |
| 644 | * |
| 645 | * 82599+ Advanced Transmit Descriptor (Write-Back Format) |
| 646 | * +--------------------------------------------------------------+ |
| 647 | * 0 | RSV [63:0] | |
| 648 | * +--------------------------------------------------------------+ |
| 649 | * 8 | RSV | STA | RSV | |
| 650 | * +--------------------------------------------------------------+ |
| 651 | * 63 36 35 32 31 0 |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 652 | */ |
| 653 | |
| 654 | for (n = 0; n < adapter->num_tx_queues; n++) { |
| 655 | tx_ring = adapter->tx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 656 | pr_info("------------------------------------\n"); |
| 657 | pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index); |
| 658 | pr_info("------------------------------------\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 659 | pr_info("%s%s %s %s %s %s\n", |
| 660 | "T [desc] [address 63:0 ] ", |
| 661 | "[PlPOIdStDDt Ln] [bi->dma ] ", |
| 662 | "leng", "ntw", "timestamp", "bi->skb"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 663 | |
| 664 | for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 665 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 666 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 667 | u0 = (struct my_u0 *)tx_desc; |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 668 | if (dma_unmap_len(tx_buffer, len) > 0) { |
| 669 | pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p", |
| 670 | i, |
| 671 | le64_to_cpu(u0->a), |
| 672 | le64_to_cpu(u0->b), |
| 673 | (u64)dma_unmap_addr(tx_buffer, dma), |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 674 | dma_unmap_len(tx_buffer, len), |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 675 | tx_buffer->next_to_watch, |
| 676 | (u64)tx_buffer->time_stamp, |
| 677 | tx_buffer->skb); |
| 678 | if (i == tx_ring->next_to_use && |
| 679 | i == tx_ring->next_to_clean) |
| 680 | pr_cont(" NTC/U\n"); |
| 681 | else if (i == tx_ring->next_to_use) |
| 682 | pr_cont(" NTU\n"); |
| 683 | else if (i == tx_ring->next_to_clean) |
| 684 | pr_cont(" NTC\n"); |
| 685 | else |
| 686 | pr_cont("\n"); |
| 687 | |
| 688 | if (netif_msg_pktdata(adapter) && |
| 689 | tx_buffer->skb) |
| 690 | print_hex_dump(KERN_INFO, "", |
| 691 | DUMP_PREFIX_ADDRESS, 16, 1, |
| 692 | tx_buffer->skb->data, |
| 693 | dma_unmap_len(tx_buffer, len), |
| 694 | true); |
| 695 | } |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 696 | } |
| 697 | } |
| 698 | |
| 699 | /* Print RX Rings Summary */ |
| 700 | rx_ring_summary: |
| 701 | dev_info(&adapter->pdev->dev, "RX Rings Summary\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 702 | pr_info("Queue [NTU] [NTC]\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 703 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 704 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 705 | pr_info("%5d %5X %5X\n", |
| 706 | n, rx_ring->next_to_use, rx_ring->next_to_clean); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | /* Print RX Rings */ |
| 710 | if (!netif_msg_rx_status(adapter)) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 711 | return; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 712 | |
| 713 | dev_info(&adapter->pdev->dev, "RX Rings Dump\n"); |
| 714 | |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 715 | /* Receive Descriptor Formats |
| 716 | * |
| 717 | * 82598 Advanced Receive Descriptor (Read) Format |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 718 | * 63 1 0 |
| 719 | * +-----------------------------------------------------+ |
| 720 | * 0 | Packet Buffer Address [63:1] |A0/NSE| |
| 721 | * +----------------------------------------------+------+ |
| 722 | * 8 | Header Buffer Address [63:1] | DD | |
| 723 | * +-----------------------------------------------------+ |
| 724 | * |
| 725 | * |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 726 | * 82598 Advanced Receive Descriptor (Write-Back) Format |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 727 | * |
| 728 | * 63 48 47 32 31 30 21 20 16 15 4 3 0 |
| 729 | * +------------------------------------------------------+ |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 730 | * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS | |
| 731 | * | Packet | IP | | | | Type | Type | |
| 732 | * | Checksum | Ident | | | | | | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 733 | * +------------------------------------------------------+ |
| 734 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | |
| 735 | * +------------------------------------------------------+ |
| 736 | * 63 48 47 32 31 20 19 0 |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 737 | * |
| 738 | * 82599+ Advanced Receive Descriptor (Read) Format |
| 739 | * 63 1 0 |
| 740 | * +-----------------------------------------------------+ |
| 741 | * 0 | Packet Buffer Address [63:1] |A0/NSE| |
| 742 | * +----------------------------------------------+------+ |
| 743 | * 8 | Header Buffer Address [63:1] | DD | |
| 744 | * +-----------------------------------------------------+ |
| 745 | * |
| 746 | * |
| 747 | * 82599+ Advanced Receive Descriptor (Write-Back) Format |
| 748 | * |
| 749 | * 63 48 47 32 31 30 21 20 17 16 4 3 0 |
| 750 | * +------------------------------------------------------+ |
| 751 | * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS | |
| 752 | * |/ RTT / PCoE_PARAM | | | CNT | Type | Type | |
| 753 | * |/ Flow Dir Flt ID | | | | | | |
| 754 | * +------------------------------------------------------+ |
| 755 | * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP | |
| 756 | * +------------------------------------------------------+ |
| 757 | * 63 48 47 32 31 20 19 0 |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 758 | */ |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 759 | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 760 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 761 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 762 | pr_info("------------------------------------\n"); |
| 763 | pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index); |
| 764 | pr_info("------------------------------------\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 765 | pr_info("%s%s%s", |
| 766 | "R [desc] [ PktBuf A0] ", |
| 767 | "[ HeadBuf DD] [bi->dma ] [bi->skb ] ", |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 768 | "<-- Adv Rx Read format\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 769 | pr_info("%s%s%s", |
| 770 | "RWB[desc] [PcsmIpSHl PtRs] ", |
| 771 | "[vl er S cks ln] ---------------- [bi->skb ] ", |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 772 | "<-- Adv Rx Write-Back format\n"); |
| 773 | |
| 774 | for (i = 0; i < rx_ring->count; i++) { |
| 775 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 776 | rx_desc = IXGBE_RX_DESC(rx_ring, i); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 777 | u0 = (struct my_u0 *)rx_desc; |
| 778 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 779 | if (staterr & IXGBE_RXD_STAT_DD) { |
| 780 | /* Descriptor Done */ |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 781 | pr_info("RWB[0x%03X] %016llX " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 782 | "%016llX ---------------- %p", i, |
| 783 | le64_to_cpu(u0->a), |
| 784 | le64_to_cpu(u0->b), |
| 785 | rx_buffer_info->skb); |
| 786 | } else { |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 787 | pr_info("R [0x%03X] %016llX " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 788 | "%016llX %016llX %p", i, |
| 789 | le64_to_cpu(u0->a), |
| 790 | le64_to_cpu(u0->b), |
| 791 | (u64)rx_buffer_info->dma, |
| 792 | rx_buffer_info->skb); |
| 793 | |
Emil Tantilov | 9c50c03 | 2012-07-26 01:21:24 +0000 | [diff] [blame] | 794 | if (netif_msg_pktdata(adapter) && |
| 795 | rx_buffer_info->dma) { |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 796 | print_hex_dump(KERN_INFO, "", |
| 797 | DUMP_PREFIX_ADDRESS, 16, 1, |
Emil Tantilov | 9c50c03 | 2012-07-26 01:21:24 +0000 | [diff] [blame] | 798 | page_address(rx_buffer_info->page) + |
| 799 | rx_buffer_info->page_offset, |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 800 | ixgbe_rx_bufsz(rx_ring), true); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 801 | } |
| 802 | } |
| 803 | |
| 804 | if (i == rx_ring->next_to_use) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 805 | pr_cont(" NTU\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 806 | else if (i == rx_ring->next_to_clean) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 807 | pr_cont(" NTC\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 808 | else |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 809 | pr_cont("\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 810 | |
| 811 | } |
| 812 | } |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 813 | } |
| 814 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 815 | static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter) |
| 816 | { |
| 817 | u32 ctrl_ext; |
| 818 | |
| 819 | /* Let firmware take over control of h/w */ |
| 820 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 821 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 822 | ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter) |
| 826 | { |
| 827 | u32 ctrl_ext; |
| 828 | |
| 829 | /* Let firmware know the driver has taken over */ |
| 830 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 831 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 832 | ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 833 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 834 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 835 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 836 | * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors |
| 837 | * @adapter: pointer to adapter struct |
| 838 | * @direction: 0 for Rx, 1 for Tx, -1 for other causes |
| 839 | * @queue: queue to map the corresponding interrupt to |
| 840 | * @msix_vector: the vector to map to the corresponding queue |
| 841 | * |
| 842 | */ |
| 843 | static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 844 | u8 queue, u8 msix_vector) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 845 | { |
| 846 | u32 ivar, index; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 847 | struct ixgbe_hw *hw = &adapter->hw; |
| 848 | switch (hw->mac.type) { |
| 849 | case ixgbe_mac_82598EB: |
| 850 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 851 | if (direction == -1) |
| 852 | direction = 0; |
| 853 | index = (((direction * 64) + queue) >> 2) & 0x1F; |
| 854 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index)); |
| 855 | ivar &= ~(0xFF << (8 * (queue & 0x3))); |
| 856 | ivar |= (msix_vector << (8 * (queue & 0x3))); |
| 857 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar); |
| 858 | break; |
| 859 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 860 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 861 | case ixgbe_mac_X550: |
| 862 | case ixgbe_mac_X550EM_x: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 863 | if (direction == -1) { |
| 864 | /* other causes */ |
| 865 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 866 | index = ((queue & 1) * 8); |
| 867 | ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC); |
| 868 | ivar &= ~(0xFF << index); |
| 869 | ivar |= (msix_vector << index); |
| 870 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar); |
| 871 | break; |
| 872 | } else { |
| 873 | /* tx or rx causes */ |
| 874 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 875 | index = ((16 * (queue & 1)) + (8 * direction)); |
| 876 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1)); |
| 877 | ivar &= ~(0xFF << index); |
| 878 | ivar |= (msix_vector << index); |
| 879 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar); |
| 880 | break; |
| 881 | } |
| 882 | default: |
| 883 | break; |
| 884 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 885 | } |
| 886 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 887 | static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 888 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 889 | { |
| 890 | u32 mask; |
| 891 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 892 | switch (adapter->hw.mac.type) { |
| 893 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 894 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 895 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 896 | break; |
| 897 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 898 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 899 | case ixgbe_mac_X550: |
| 900 | case ixgbe_mac_X550EM_x: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 901 | mask = (qmask & 0xFFFFFFFF); |
| 902 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask); |
| 903 | mask = (qmask >> 32); |
| 904 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 905 | break; |
| 906 | default: |
| 907 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 908 | } |
| 909 | } |
| 910 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 911 | void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *ring, |
| 912 | struct ixgbe_tx_buffer *tx_buffer) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 913 | { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 914 | if (tx_buffer->skb) { |
| 915 | dev_kfree_skb_any(tx_buffer->skb); |
| 916 | if (dma_unmap_len(tx_buffer, len)) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 917 | dma_unmap_single(ring->dev, |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 918 | dma_unmap_addr(tx_buffer, dma), |
| 919 | dma_unmap_len(tx_buffer, len), |
| 920 | DMA_TO_DEVICE); |
| 921 | } else if (dma_unmap_len(tx_buffer, len)) { |
| 922 | dma_unmap_page(ring->dev, |
| 923 | dma_unmap_addr(tx_buffer, dma), |
| 924 | dma_unmap_len(tx_buffer, len), |
| 925 | DMA_TO_DEVICE); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 926 | } |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 927 | tx_buffer->next_to_watch = NULL; |
| 928 | tx_buffer->skb = NULL; |
| 929 | dma_unmap_len_set(tx_buffer, len, 0); |
| 930 | /* tx_buffer must be completely set up in the transmit path */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 931 | } |
| 932 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 933 | static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter) |
| 934 | { |
| 935 | struct ixgbe_hw *hw = &adapter->hw; |
| 936 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
| 937 | int i; |
| 938 | u32 data; |
| 939 | |
| 940 | if ((hw->fc.current_mode != ixgbe_fc_full) && |
| 941 | (hw->fc.current_mode != ixgbe_fc_rx_pause)) |
| 942 | return; |
| 943 | |
| 944 | switch (hw->mac.type) { |
| 945 | case ixgbe_mac_82598EB: |
| 946 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); |
| 947 | break; |
| 948 | default: |
| 949 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); |
| 950 | } |
| 951 | hwstats->lxoffrxc += data; |
| 952 | |
| 953 | /* refill credits (no tx hang) if we received xoff */ |
| 954 | if (!data) |
| 955 | return; |
| 956 | |
| 957 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 958 | clear_bit(__IXGBE_HANG_CHECK_ARMED, |
| 959 | &adapter->tx_ring[i]->state); |
| 960 | } |
| 961 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 962 | static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 963 | { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 964 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 965 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 966 | u32 xoff[8] = {0}; |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 967 | u8 tc; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 968 | int i; |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 969 | bool pfc_en = adapter->dcb_cfg.pfc_mode_enable; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 970 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 971 | if (adapter->ixgbe_ieee_pfc) |
| 972 | pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 973 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 974 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) { |
| 975 | ixgbe_update_xoff_rx_lfc(adapter); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 976 | return; |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 977 | } |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 978 | |
| 979 | /* update stats for each tc, only valid with PFC enabled */ |
| 980 | for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) { |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 981 | u32 pxoffrxc; |
| 982 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 983 | switch (hw->mac.type) { |
| 984 | case ixgbe_mac_82598EB: |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 985 | pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i)); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 986 | break; |
| 987 | default: |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 988 | pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i)); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 989 | } |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 990 | hwstats->pxoffrxc[i] += pxoffrxc; |
| 991 | /* Get the TC for given UP */ |
| 992 | tc = netdev_get_prio_tc_map(adapter->netdev, i); |
| 993 | xoff[tc] += pxoffrxc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 994 | } |
| 995 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 996 | /* disarm tx queues that have received xoff frames */ |
| 997 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 998 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 999 | |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 1000 | tc = tx_ring->dcb_tc; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1001 | if (xoff[tc]) |
| 1002 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
| 1003 | } |
| 1004 | } |
| 1005 | |
| 1006 | static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring) |
| 1007 | { |
Alexander Duyck | 7d7ce68 | 2012-02-08 07:50:51 +0000 | [diff] [blame] | 1008 | return ring->stats.packets; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring) |
| 1012 | { |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 1013 | struct ixgbe_adapter *adapter; |
| 1014 | struct ixgbe_hw *hw; |
| 1015 | u32 head, tail; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1016 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 1017 | if (ring->l2_accel_priv) |
| 1018 | adapter = ring->l2_accel_priv->real_adapter; |
| 1019 | else |
| 1020 | adapter = netdev_priv(ring->netdev); |
| 1021 | |
| 1022 | hw = &adapter->hw; |
| 1023 | head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx)); |
| 1024 | tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx)); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1025 | |
| 1026 | if (head != tail) |
| 1027 | return (head < tail) ? |
| 1028 | tail - head : (tail + ring->count - head); |
| 1029 | |
| 1030 | return 0; |
| 1031 | } |
| 1032 | |
| 1033 | static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring) |
| 1034 | { |
| 1035 | u32 tx_done = ixgbe_get_tx_completed(tx_ring); |
| 1036 | u32 tx_done_old = tx_ring->tx_stats.tx_done_old; |
| 1037 | u32 tx_pending = ixgbe_get_tx_pending(tx_ring); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1038 | |
| 1039 | clear_check_for_tx_hang(tx_ring); |
| 1040 | |
| 1041 | /* |
| 1042 | * Check for a hung queue, but be thorough. This verifies |
| 1043 | * that a transmit has been completed since the previous |
| 1044 | * check AND there is at least one packet pending. The |
| 1045 | * ARMED bit is set to indicate a potential hang. The |
| 1046 | * bit is cleared if a pause frame is received to remove |
| 1047 | * false hang detection due to PFC or 802.3x frames. By |
| 1048 | * requiring this to fail twice we avoid races with |
| 1049 | * pfc clearing the ARMED bit and conditions where we |
| 1050 | * run the check_tx_hang logic with a transmit completion |
| 1051 | * pending but without time to complete it yet. |
| 1052 | */ |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 1053 | if (tx_done_old == tx_done && tx_pending) |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1054 | /* make sure it is true for two checks in a row */ |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 1055 | return test_and_set_bit(__IXGBE_HANG_CHECK_ARMED, |
| 1056 | &tx_ring->state); |
| 1057 | /* update completed stats and continue */ |
| 1058 | tx_ring->tx_stats.tx_done_old = tx_done; |
| 1059 | /* reset the countdown */ |
| 1060 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1061 | |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 1062 | return false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1063 | } |
| 1064 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 1065 | /** |
| 1066 | * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout |
| 1067 | * @adapter: driver private struct |
| 1068 | **/ |
| 1069 | static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter) |
| 1070 | { |
| 1071 | |
| 1072 | /* Do the reset outside of interrupt context */ |
| 1073 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1074 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; |
Jacob Keller | 12ff3f3 | 2012-12-01 07:57:17 +0000 | [diff] [blame] | 1075 | e_warn(drv, "initiating reset due to tx timeout\n"); |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 1076 | ixgbe_service_event_schedule(adapter); |
| 1077 | } |
| 1078 | } |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1079 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1080 | /** |
Rostislav Pehlivanov | c04f90e | 2016-01-27 18:33:30 +0000 | [diff] [blame] | 1081 | * ixgbe_tx_maxrate - callback to set the maximum per-queue bitrate |
| 1082 | **/ |
| 1083 | static int ixgbe_tx_maxrate(struct net_device *netdev, |
| 1084 | int queue_index, u32 maxrate) |
| 1085 | { |
| 1086 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1087 | struct ixgbe_hw *hw = &adapter->hw; |
| 1088 | u32 bcnrc_val = ixgbe_link_mbps(adapter); |
| 1089 | |
| 1090 | if (!maxrate) |
| 1091 | return 0; |
| 1092 | |
| 1093 | /* Calculate the rate factor values to set */ |
| 1094 | bcnrc_val <<= IXGBE_RTTBCNRC_RF_INT_SHIFT; |
| 1095 | bcnrc_val /= maxrate; |
| 1096 | |
| 1097 | /* clear everything but the rate factor */ |
| 1098 | bcnrc_val &= IXGBE_RTTBCNRC_RF_INT_MASK | |
| 1099 | IXGBE_RTTBCNRC_RF_DEC_MASK; |
| 1100 | |
| 1101 | /* enable the rate scheduler */ |
| 1102 | bcnrc_val |= IXGBE_RTTBCNRC_RS_ENA; |
| 1103 | |
| 1104 | IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, queue_index); |
| 1105 | IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val); |
| 1106 | |
| 1107 | return 0; |
| 1108 | } |
| 1109 | |
| 1110 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1111 | * ixgbe_clean_tx_irq - Reclaim resources after transmit completes |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1112 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1113 | * @tx_ring: tx ring to clean |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1114 | **/ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1115 | 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] | 1116 | struct ixgbe_ring *tx_ring, int napi_budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1117 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1118 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1119 | struct ixgbe_tx_buffer *tx_buffer; |
| 1120 | union ixgbe_adv_tx_desc *tx_desc; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1121 | unsigned int total_bytes = 0, total_packets = 0; |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 1122 | unsigned int budget = q_vector->tx.work_limit; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1123 | unsigned int i = tx_ring->next_to_clean; |
| 1124 | |
| 1125 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1126 | return true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1127 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1128 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1129 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1130 | i -= tx_ring->count; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 1131 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1132 | do { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1133 | union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1134 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1135 | /* if next_to_watch is not set then there is no work pending */ |
| 1136 | if (!eop_desc) |
| 1137 | break; |
| 1138 | |
Alexander Duyck | 7f83a9e | 2012-02-08 07:49:23 +0000 | [diff] [blame] | 1139 | /* prevent any other reads prior to eop_desc */ |
Alexander Duyck | 7e63bf4 | 2013-01-08 07:00:58 +0000 | [diff] [blame] | 1140 | read_barrier_depends(); |
Alexander Duyck | 7f83a9e | 2012-02-08 07:49:23 +0000 | [diff] [blame] | 1141 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1142 | /* if DD is not set pending work has not been completed */ |
| 1143 | if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD))) |
| 1144 | break; |
| 1145 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1146 | /* clear next_to_watch to prevent false hangs */ |
| 1147 | tx_buffer->next_to_watch = NULL; |
| 1148 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 1149 | /* update the statistics for this packet */ |
| 1150 | total_bytes += tx_buffer->bytecount; |
| 1151 | total_packets += tx_buffer->gso_segs; |
| 1152 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1153 | /* free the skb */ |
Jesper Dangaard Brouer | a3a8749 | 2016-02-08 13:15:09 +0100 | [diff] [blame] | 1154 | napi_consume_skb(tx_buffer->skb, napi_budget); |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1155 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1156 | /* unmap skb header data */ |
| 1157 | dma_unmap_single(tx_ring->dev, |
| 1158 | dma_unmap_addr(tx_buffer, dma), |
| 1159 | dma_unmap_len(tx_buffer, len), |
| 1160 | DMA_TO_DEVICE); |
| 1161 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1162 | /* clear tx_buffer data */ |
| 1163 | tx_buffer->skb = NULL; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1164 | dma_unmap_len_set(tx_buffer, len, 0); |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1165 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1166 | /* unmap remaining buffers */ |
| 1167 | while (tx_desc != eop_desc) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1168 | tx_buffer++; |
| 1169 | tx_desc++; |
| 1170 | i++; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1171 | if (unlikely(!i)) { |
| 1172 | i -= tx_ring->count; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1173 | tx_buffer = tx_ring->tx_buffer_info; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1174 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1175 | } |
| 1176 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1177 | /* unmap any remaining paged data */ |
| 1178 | if (dma_unmap_len(tx_buffer, len)) { |
| 1179 | dma_unmap_page(tx_ring->dev, |
| 1180 | dma_unmap_addr(tx_buffer, dma), |
| 1181 | dma_unmap_len(tx_buffer, len), |
| 1182 | DMA_TO_DEVICE); |
| 1183 | dma_unmap_len_set(tx_buffer, len, 0); |
| 1184 | } |
| 1185 | } |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 1186 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1187 | /* move us one more past the eop_desc for start of next pkt */ |
| 1188 | tx_buffer++; |
| 1189 | tx_desc++; |
| 1190 | i++; |
| 1191 | if (unlikely(!i)) { |
| 1192 | i -= tx_ring->count; |
| 1193 | tx_buffer = tx_ring->tx_buffer_info; |
| 1194 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
| 1195 | } |
| 1196 | |
| 1197 | /* issue prefetch for next Tx descriptor */ |
| 1198 | prefetch(tx_desc); |
| 1199 | |
| 1200 | /* update budget accounting */ |
| 1201 | budget--; |
| 1202 | } while (likely(budget)); |
| 1203 | |
| 1204 | i += tx_ring->count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1205 | tx_ring->next_to_clean = i; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1206 | u64_stats_update_begin(&tx_ring->syncp); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1207 | tx_ring->stats.bytes += total_bytes; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1208 | tx_ring->stats.packets += total_packets; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1209 | u64_stats_update_end(&tx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1210 | q_vector->tx.total_bytes += total_bytes; |
| 1211 | q_vector->tx.total_packets += total_packets; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1212 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1213 | 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] | 1214 | /* schedule immediate reset if we believe we hung */ |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1215 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1216 | e_err(drv, "Detected Tx Unit Hang\n" |
| 1217 | " Tx Queue <%d>\n" |
| 1218 | " TDH, TDT <%x>, <%x>\n" |
| 1219 | " next_to_use <%x>\n" |
| 1220 | " next_to_clean <%x>\n" |
| 1221 | "tx_buffer_info[next_to_clean]\n" |
| 1222 | " time_stamp <%lx>\n" |
| 1223 | " jiffies <%lx>\n", |
| 1224 | tx_ring->queue_index, |
| 1225 | IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)), |
| 1226 | IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)), |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1227 | tx_ring->next_to_use, i, |
| 1228 | tx_ring->tx_buffer_info[i].time_stamp, jiffies); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1229 | |
| 1230 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 1231 | |
| 1232 | e_info(probe, |
| 1233 | "tx hang %d detected on queue %d, resetting adapter\n", |
| 1234 | adapter->tx_timeout_count + 1, tx_ring->queue_index); |
| 1235 | |
| 1236 | /* schedule immediate reset if we believe we hung */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 1237 | ixgbe_tx_timeout_reset(adapter); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1238 | |
| 1239 | /* the adapter is about to reset, no point in enabling stuff */ |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 1240 | return true; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1241 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1242 | |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 1243 | netdev_tx_completed_queue(txring_txq(tx_ring), |
| 1244 | total_packets, total_bytes); |
| 1245 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 1246 | #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) |
Alexander Duyck | 30065e6 | 2011-07-15 03:05:14 +0000 | [diff] [blame] | 1247 | if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) && |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 1248 | (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 1249 | /* Make sure that anybody stopping the queue after this |
| 1250 | * sees the new next_to_clean. |
| 1251 | */ |
| 1252 | smp_mb(); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1253 | if (__netif_subqueue_stopped(tx_ring->netdev, |
| 1254 | tx_ring->queue_index) |
| 1255 | && !test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1256 | netif_wake_subqueue(tx_ring->netdev, |
| 1257 | tx_ring->queue_index); |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 1258 | ++tx_ring->tx_stats.restart_queue; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 1259 | } |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 1260 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1261 | |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 1262 | return !!budget; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1263 | } |
| 1264 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1265 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1266 | static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter, |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1267 | struct ixgbe_ring *tx_ring, |
| 1268 | int cpu) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1269 | { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 1270 | struct ixgbe_hw *hw = &adapter->hw; |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1271 | u32 txctrl = 0; |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1272 | u16 reg_offset; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1273 | |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1274 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1275 | txctrl = dca3_get_tag(tx_ring->dev, cpu); |
| 1276 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1277 | switch (hw->mac.type) { |
| 1278 | case ixgbe_mac_82598EB: |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1279 | reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1280 | break; |
| 1281 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1282 | case ixgbe_mac_X540: |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1283 | reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx); |
| 1284 | txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599; |
| 1285 | break; |
| 1286 | default: |
| 1287 | /* for unknown hardware do not write register */ |
| 1288 | return; |
| 1289 | } |
| 1290 | |
| 1291 | /* |
| 1292 | * We can enable relaxed ordering for reads, but not writes when |
| 1293 | * DCA is enabled. This is due to a known issue in some chipsets |
| 1294 | * which will cause the DCA tag to be cleared. |
| 1295 | */ |
| 1296 | txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN | |
| 1297 | IXGBE_DCA_TXCTRL_DATA_RRO_EN | |
| 1298 | IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
| 1299 | |
| 1300 | IXGBE_WRITE_REG(hw, reg_offset, txctrl); |
| 1301 | } |
| 1302 | |
| 1303 | static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter, |
| 1304 | struct ixgbe_ring *rx_ring, |
| 1305 | int cpu) |
| 1306 | { |
| 1307 | struct ixgbe_hw *hw = &adapter->hw; |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1308 | u32 rxctrl = 0; |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1309 | u8 reg_idx = rx_ring->reg_idx; |
| 1310 | |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1311 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1312 | rxctrl = dca3_get_tag(rx_ring->dev, cpu); |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1313 | |
| 1314 | switch (hw->mac.type) { |
| 1315 | case ixgbe_mac_82599EB: |
| 1316 | case ixgbe_mac_X540: |
| 1317 | rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1318 | break; |
| 1319 | default: |
| 1320 | break; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1321 | } |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1322 | |
| 1323 | /* |
| 1324 | * We can enable relaxed ordering for reads, but not writes when |
| 1325 | * DCA is enabled. This is due to a known issue in some chipsets |
| 1326 | * which will cause the DCA tag to be cleared. |
| 1327 | */ |
| 1328 | rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN | |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1329 | IXGBE_DCA_RXCTRL_DATA_DCA_EN | |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1330 | IXGBE_DCA_RXCTRL_DESC_DCA_EN; |
| 1331 | |
| 1332 | IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1333 | } |
| 1334 | |
| 1335 | static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector) |
| 1336 | { |
| 1337 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1338 | struct ixgbe_ring *ring; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1339 | int cpu = get_cpu(); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1340 | |
| 1341 | if (q_vector->cpu == cpu) |
| 1342 | goto out_no_update; |
| 1343 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 1344 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1345 | ixgbe_update_tx_dca(adapter, ring, cpu); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1346 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 1347 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1348 | ixgbe_update_rx_dca(adapter, ring, cpu); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1349 | |
| 1350 | q_vector->cpu = cpu; |
| 1351 | out_no_update: |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1352 | put_cpu(); |
| 1353 | } |
| 1354 | |
| 1355 | static void ixgbe_setup_dca(struct ixgbe_adapter *adapter) |
| 1356 | { |
| 1357 | int i; |
| 1358 | |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 1359 | /* always use CB2 mode, difference is masked in the CB driver */ |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1360 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1361 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 1362 | IXGBE_DCA_CTRL_DCA_MODE_CB2); |
| 1363 | else |
| 1364 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 1365 | IXGBE_DCA_CTRL_DCA_DISABLE); |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 1366 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 1367 | for (i = 0; i < adapter->num_q_vectors; i++) { |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1368 | adapter->q_vector[i]->cpu = -1; |
| 1369 | ixgbe_update_dca(adapter->q_vector[i]); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1370 | } |
| 1371 | } |
| 1372 | |
| 1373 | static int __ixgbe_notify_dca(struct device *dev, void *data) |
| 1374 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 1375 | struct ixgbe_adapter *adapter = dev_get_drvdata(dev); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1376 | unsigned long event = *(unsigned long *)data; |
| 1377 | |
Don Skidmore | 2a72c31 | 2011-07-20 02:27:05 +0000 | [diff] [blame] | 1378 | if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE)) |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1379 | return 0; |
| 1380 | |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1381 | switch (event) { |
| 1382 | case DCA_PROVIDER_ADD: |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 1383 | /* if we're already enabled, don't do it again */ |
| 1384 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1385 | break; |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 1386 | if (dca_add_requester(dev) == 0) { |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 1387 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1388 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 1389 | IXGBE_DCA_CTRL_DCA_MODE_CB2); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1390 | break; |
| 1391 | } |
| 1392 | /* Fall Through since DCA is disabled. */ |
| 1393 | case DCA_PROVIDER_REMOVE: |
| 1394 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 1395 | dca_remove_requester(dev); |
| 1396 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1397 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 1398 | IXGBE_DCA_CTRL_DCA_DISABLE); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1399 | } |
| 1400 | break; |
| 1401 | } |
| 1402 | |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 1403 | return 0; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1404 | } |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1405 | |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1406 | #endif /* CONFIG_IXGBE_DCA */ |
Fan Du | 7edda4b8 | 2015-04-29 10:57:39 +0800 | [diff] [blame] | 1407 | |
| 1408 | #define IXGBE_RSS_L4_TYPES_MASK \ |
| 1409 | ((1ul << IXGBE_RXDADV_RSSTYPE_IPV4_TCP) | \ |
| 1410 | (1ul << IXGBE_RXDADV_RSSTYPE_IPV4_UDP) | \ |
| 1411 | (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_TCP) | \ |
| 1412 | (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_UDP)) |
| 1413 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1414 | static inline void ixgbe_rx_hash(struct ixgbe_ring *ring, |
| 1415 | union ixgbe_adv_rx_desc *rx_desc, |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1416 | struct sk_buff *skb) |
| 1417 | { |
Fan Du | 7edda4b8 | 2015-04-29 10:57:39 +0800 | [diff] [blame] | 1418 | u16 rss_type; |
| 1419 | |
| 1420 | if (!(ring->netdev->features & NETIF_F_RXHASH)) |
| 1421 | return; |
| 1422 | |
| 1423 | rss_type = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) & |
| 1424 | IXGBE_RXDADV_RSSTYPE_MASK; |
| 1425 | |
| 1426 | if (!rss_type) |
| 1427 | return; |
| 1428 | |
| 1429 | skb_set_hash(skb, le32_to_cpu(rx_desc->wb.lower.hi_dword.rss), |
| 1430 | (IXGBE_RSS_L4_TYPES_MASK & (1ul << rss_type)) ? |
| 1431 | PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3); |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1432 | } |
| 1433 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1434 | #ifdef IXGBE_FCOE |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1435 | /** |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1436 | * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1437 | * @ring: structure containing ring specific data |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1438 | * @rx_desc: advanced rx descriptor |
| 1439 | * |
| 1440 | * Returns : true if it is FCoE pkt |
| 1441 | */ |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1442 | static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring, |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1443 | union ixgbe_adv_rx_desc *rx_desc) |
| 1444 | { |
| 1445 | __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 1446 | |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1447 | return test_bit(__IXGBE_RX_FCOE, &ring->state) && |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1448 | ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) == |
| 1449 | (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE << |
| 1450 | IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT))); |
| 1451 | } |
| 1452 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1453 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1454 | /** |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1455 | * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1456 | * @ring: structure containing ring specific data |
| 1457 | * @rx_desc: current Rx descriptor being processed |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1458 | * @skb: skb currently being received and modified |
| 1459 | **/ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1460 | static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring, |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1461 | union ixgbe_adv_rx_desc *rx_desc, |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1462 | struct sk_buff *skb) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1463 | { |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1464 | __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 1465 | __le16 hdr_info = rx_desc->wb.lower.lo_dword.hs_rss.hdr_info; |
| 1466 | bool encap_pkt = false; |
| 1467 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1468 | skb_checksum_none_assert(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1469 | |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 1470 | /* Rx csum disabled */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1471 | if (!(ring->netdev->features & NETIF_F_RXCSUM)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1472 | return; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1473 | |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1474 | if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_VXLAN)) && |
| 1475 | (hdr_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_TUNNEL >> 16))) { |
| 1476 | encap_pkt = true; |
| 1477 | skb->encapsulation = 1; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1478 | } |
| 1479 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1480 | /* if IP and error */ |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1481 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) && |
| 1482 | ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1483 | ring->rx_stats.csum_err++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1484 | return; |
| 1485 | } |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1486 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1487 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS)) |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1488 | return; |
| 1489 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1490 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) { |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1491 | /* |
| 1492 | * 82599 errata, UDP frames with a 0 checksum can be marked as |
| 1493 | * checksum errors. |
| 1494 | */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1495 | if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) && |
| 1496 | test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state)) |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1497 | return; |
| 1498 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1499 | ring->rx_stats.csum_err++; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1500 | return; |
| 1501 | } |
| 1502 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1503 | /* It must be a TCP or UDP packet with a valid checksum */ |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1504 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1505 | if (encap_pkt) { |
| 1506 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_OUTERIPCS)) |
| 1507 | return; |
| 1508 | |
| 1509 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_OUTERIPER)) { |
Mark Rustad | d469251 | 2015-12-04 11:26:43 -0800 | [diff] [blame] | 1510 | skb->ip_summed = CHECKSUM_NONE; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1511 | return; |
| 1512 | } |
| 1513 | /* If we checked the outer header let the stack know */ |
| 1514 | skb->csum_level = 1; |
| 1515 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1516 | } |
| 1517 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1518 | static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring, |
| 1519 | struct ixgbe_rx_buffer *bi) |
| 1520 | { |
| 1521 | struct page *page = bi->page; |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1522 | dma_addr_t dma; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1523 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1524 | /* since we are recycling buffers we should seldom need to alloc */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1525 | if (likely(page)) |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1526 | return true; |
| 1527 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1528 | /* alloc new page for storage */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1529 | page = dev_alloc_pages(ixgbe_rx_pg_order(rx_ring)); |
| 1530 | if (unlikely(!page)) { |
| 1531 | rx_ring->rx_stats.alloc_rx_page_failed++; |
| 1532 | return false; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1533 | } |
| 1534 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1535 | /* map page for use */ |
| 1536 | dma = dma_map_page(rx_ring->dev, page, 0, |
| 1537 | ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1538 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1539 | /* |
| 1540 | * if mapping failed free memory back to system since |
| 1541 | * there isn't much point in holding memory we can't use |
| 1542 | */ |
| 1543 | if (dma_mapping_error(rx_ring->dev, dma)) { |
Alexander Duyck | dd411ec | 2012-04-06 04:24:50 +0000 | [diff] [blame] | 1544 | __free_pages(page, ixgbe_rx_pg_order(rx_ring)); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1545 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1546 | rx_ring->rx_stats.alloc_rx_page_failed++; |
| 1547 | return false; |
| 1548 | } |
| 1549 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1550 | bi->dma = dma; |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1551 | bi->page = page; |
Alexander Duyck | afaa945 | 2012-07-20 08:08:12 +0000 | [diff] [blame] | 1552 | bi->page_offset = 0; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1553 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1554 | return true; |
| 1555 | } |
| 1556 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1557 | /** |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1558 | * ixgbe_alloc_rx_buffers - Replace used receive buffers |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1559 | * @rx_ring: ring to place buffers on |
| 1560 | * @cleaned_count: number of buffers to replace |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1561 | **/ |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1562 | 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] | 1563 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1564 | union ixgbe_adv_rx_desc *rx_desc; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1565 | struct ixgbe_rx_buffer *bi; |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1566 | u16 i = rx_ring->next_to_use; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1567 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1568 | /* nothing to do */ |
| 1569 | if (!cleaned_count) |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1570 | return; |
| 1571 | |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1572 | rx_desc = IXGBE_RX_DESC(rx_ring, i); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1573 | bi = &rx_ring->rx_buffer_info[i]; |
| 1574 | i -= rx_ring->count; |
| 1575 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1576 | do { |
| 1577 | if (!ixgbe_alloc_mapped_page(rx_ring, bi)) |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1578 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1579 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1580 | /* |
| 1581 | * Refresh the desc even if buffer_addrs didn't change |
| 1582 | * because each write-back erases this info. |
| 1583 | */ |
| 1584 | 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] | 1585 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1586 | rx_desc++; |
| 1587 | bi++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1588 | i++; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1589 | if (unlikely(!i)) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1590 | rx_desc = IXGBE_RX_DESC(rx_ring, 0); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1591 | bi = rx_ring->rx_buffer_info; |
| 1592 | i -= rx_ring->count; |
| 1593 | } |
| 1594 | |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1595 | /* clear the status bits for the next_to_use descriptor */ |
| 1596 | rx_desc->wb.upper.status_error = 0; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1597 | |
| 1598 | cleaned_count--; |
| 1599 | } while (cleaned_count); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1600 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1601 | i += rx_ring->count; |
| 1602 | |
Alexander Duyck | ad435ec | 2014-11-14 00:56:35 +0000 | [diff] [blame] | 1603 | if (rx_ring->next_to_use != i) { |
| 1604 | rx_ring->next_to_use = i; |
| 1605 | |
| 1606 | /* update next to alloc since we have filled the ring */ |
| 1607 | rx_ring->next_to_alloc = i; |
| 1608 | |
| 1609 | /* Force memory writes to complete before letting h/w |
| 1610 | * know there are new descriptors to fetch. (Only |
| 1611 | * applicable for weak-ordered memory model archs, |
| 1612 | * such as IA-64). |
| 1613 | */ |
| 1614 | wmb(); |
| 1615 | writel(i, rx_ring->tail); |
| 1616 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1617 | } |
| 1618 | |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1619 | static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring, |
| 1620 | struct sk_buff *skb) |
| 1621 | { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1622 | u16 hdr_len = skb_headlen(skb); |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1623 | |
| 1624 | /* set gso_size to avoid messing up TCP MSS */ |
| 1625 | skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len), |
| 1626 | IXGBE_CB(skb)->append_cnt); |
Alexander Duyck | 96be80a | 2013-02-12 09:45:44 +0000 | [diff] [blame] | 1627 | skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4; |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1628 | } |
| 1629 | |
| 1630 | static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring, |
| 1631 | struct sk_buff *skb) |
| 1632 | { |
| 1633 | /* if append_cnt is 0 then frame is not RSC */ |
| 1634 | if (!IXGBE_CB(skb)->append_cnt) |
| 1635 | return; |
| 1636 | |
| 1637 | rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt; |
| 1638 | rx_ring->rx_stats.rsc_flush++; |
| 1639 | |
| 1640 | ixgbe_set_rsc_gso_size(rx_ring, skb); |
| 1641 | |
| 1642 | /* gso_size is computed using append_cnt so always clear it last */ |
| 1643 | IXGBE_CB(skb)->append_cnt = 0; |
| 1644 | } |
| 1645 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1646 | /** |
| 1647 | * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor |
| 1648 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1649 | * @rx_desc: pointer to the EOP Rx descriptor |
| 1650 | * @skb: pointer to current skb being populated |
| 1651 | * |
| 1652 | * This function checks the ring, descriptor, and packet information in |
| 1653 | * order to populate the hash, checksum, VLAN, timestamp, protocol, and |
| 1654 | * other fields within the skb. |
| 1655 | **/ |
| 1656 | static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring, |
| 1657 | union ixgbe_adv_rx_desc *rx_desc, |
| 1658 | struct sk_buff *skb) |
| 1659 | { |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1660 | struct net_device *dev = rx_ring->netdev; |
Mark Rustad | a9763f3 | 2015-10-27 09:58:07 -0700 | [diff] [blame] | 1661 | u32 flags = rx_ring->q_vector->adapter->flags; |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1662 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1663 | ixgbe_update_rsc_stats(rx_ring, skb); |
| 1664 | |
| 1665 | ixgbe_rx_hash(rx_ring, rx_desc, skb); |
| 1666 | |
| 1667 | ixgbe_rx_checksum(rx_ring, rx_desc, skb); |
| 1668 | |
Mark Rustad | a9763f3 | 2015-10-27 09:58:07 -0700 | [diff] [blame] | 1669 | if (unlikely(flags & IXGBE_FLAG_RX_HWTSTAMP_ENABLED)) |
| 1670 | ixgbe_ptp_rx_hwtstamp(rx_ring, rx_desc, skb); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 1671 | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 1672 | if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) && |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1673 | ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1674 | u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan); |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 1675 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid); |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1676 | } |
| 1677 | |
| 1678 | skb_record_rx_queue(skb, rx_ring->queue_index); |
| 1679 | |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1680 | skb->protocol = eth_type_trans(skb, dev); |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1681 | } |
| 1682 | |
| 1683 | static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector, |
| 1684 | struct sk_buff *skb) |
| 1685 | { |
Eric Dumazet | 93f93a4 | 2015-11-18 06:30:59 -0800 | [diff] [blame] | 1686 | skb_mark_napi_id(skb, &q_vector->napi); |
Jacob Keller | b464003 | 2013-10-01 04:33:54 -0700 | [diff] [blame] | 1687 | if (ixgbe_qv_busy_polling(q_vector)) |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 1688 | netif_receive_skb(skb); |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1689 | else |
Alexander Duyck | 856f606 | 2015-02-25 17:45:54 +0000 | [diff] [blame] | 1690 | napi_gro_receive(&q_vector->napi, skb); |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1691 | } |
Mallikarjuna R Chilakala | 43634e8 | 2010-02-25 23:14:37 +0000 | [diff] [blame] | 1692 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1693 | /** |
| 1694 | * ixgbe_is_non_eop - process handling of non-EOP buffers |
| 1695 | * @rx_ring: Rx ring being processed |
| 1696 | * @rx_desc: Rx descriptor for current buffer |
| 1697 | * @skb: Current socket buffer containing buffer in progress |
| 1698 | * |
| 1699 | * This function updates next to clean. If the buffer is an EOP buffer |
| 1700 | * this function exits returning false, otherwise it will place the |
| 1701 | * sk_buff in the next buffer to be chained and return true indicating |
| 1702 | * that this is in fact a non-EOP buffer. |
| 1703 | **/ |
| 1704 | static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring, |
| 1705 | union ixgbe_adv_rx_desc *rx_desc, |
| 1706 | struct sk_buff *skb) |
| 1707 | { |
| 1708 | u32 ntc = rx_ring->next_to_clean + 1; |
| 1709 | |
| 1710 | /* fetch, update, and store next to clean */ |
| 1711 | ntc = (ntc < rx_ring->count) ? ntc : 0; |
| 1712 | rx_ring->next_to_clean = ntc; |
| 1713 | |
| 1714 | prefetch(IXGBE_RX_DESC(rx_ring, ntc)); |
| 1715 | |
Alexander Duyck | 5a02cbd | 2012-07-20 08:08:51 +0000 | [diff] [blame] | 1716 | /* update RSC append count if present */ |
| 1717 | if (ring_is_rsc_enabled(rx_ring)) { |
| 1718 | __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data & |
| 1719 | cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK); |
| 1720 | |
| 1721 | if (unlikely(rsc_enabled)) { |
| 1722 | u32 rsc_cnt = le32_to_cpu(rsc_enabled); |
| 1723 | |
| 1724 | rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT; |
| 1725 | IXGBE_CB(skb)->append_cnt += rsc_cnt - 1; |
| 1726 | |
| 1727 | /* update ntc based on RSC value */ |
| 1728 | ntc = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 1729 | ntc &= IXGBE_RXDADV_NEXTP_MASK; |
| 1730 | ntc >>= IXGBE_RXDADV_NEXTP_SHIFT; |
| 1731 | } |
| 1732 | } |
| 1733 | |
| 1734 | /* 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] | 1735 | if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))) |
| 1736 | return false; |
| 1737 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1738 | /* place skb in next buffer to be received */ |
| 1739 | rx_ring->rx_buffer_info[ntc].skb = skb; |
| 1740 | rx_ring->rx_stats.non_eop_descs++; |
| 1741 | |
| 1742 | return true; |
| 1743 | } |
| 1744 | |
| 1745 | /** |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1746 | * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail |
| 1747 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1748 | * @skb: pointer to current skb being adjusted |
| 1749 | * |
| 1750 | * This function is an ixgbe specific version of __pskb_pull_tail. The |
| 1751 | * main difference between this version and the original function is that |
| 1752 | * this function can make several assumptions about the state of things |
| 1753 | * that allow for significant optimizations versus the standard function. |
| 1754 | * As a result we can do things like drop a frag and maintain an accurate |
| 1755 | * truesize for the skb. |
| 1756 | */ |
| 1757 | static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring, |
| 1758 | struct sk_buff *skb) |
| 1759 | { |
| 1760 | struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0]; |
| 1761 | unsigned char *va; |
| 1762 | unsigned int pull_len; |
| 1763 | |
| 1764 | /* |
| 1765 | * it is valid to use page_address instead of kmap since we are |
| 1766 | * working with pages allocated out of the lomem pool per |
| 1767 | * alloc_page(GFP_ATOMIC) |
| 1768 | */ |
| 1769 | va = skb_frag_address(frag); |
| 1770 | |
| 1771 | /* |
| 1772 | * we need the header to contain the greater of either ETH_HLEN or |
| 1773 | * 60 bytes if the skb->len is less than 60 for skb_pad. |
| 1774 | */ |
Alexander Duyck | 8496e338 | 2014-09-05 19:22:18 -0400 | [diff] [blame] | 1775 | pull_len = eth_get_headlen(va, IXGBE_RX_HDR_SIZE); |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1776 | |
| 1777 | /* align pull length to size of long to optimize memcpy performance */ |
| 1778 | skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long))); |
| 1779 | |
| 1780 | /* update all of the pointers */ |
| 1781 | skb_frag_size_sub(frag, pull_len); |
| 1782 | frag->page_offset += pull_len; |
| 1783 | skb->data_len -= pull_len; |
| 1784 | skb->tail += pull_len; |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1785 | } |
| 1786 | |
| 1787 | /** |
Alexander Duyck | 42073d9 | 2012-07-20 08:08:28 +0000 | [diff] [blame] | 1788 | * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB |
| 1789 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1790 | * @skb: pointer to current skb being updated |
| 1791 | * |
| 1792 | * This function provides a basic DMA sync up for the first fragment of an |
| 1793 | * skb. The reason for doing this is that the first fragment cannot be |
| 1794 | * unmapped until we have reached the end of packet descriptor for a buffer |
| 1795 | * chain. |
| 1796 | */ |
| 1797 | static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring, |
| 1798 | struct sk_buff *skb) |
| 1799 | { |
| 1800 | /* if the page was released unmap it, else just sync our portion */ |
| 1801 | if (unlikely(IXGBE_CB(skb)->page_released)) { |
| 1802 | dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma, |
| 1803 | ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE); |
| 1804 | IXGBE_CB(skb)->page_released = false; |
| 1805 | } else { |
| 1806 | struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0]; |
| 1807 | |
| 1808 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 1809 | IXGBE_CB(skb)->dma, |
| 1810 | frag->page_offset, |
| 1811 | ixgbe_rx_bufsz(rx_ring), |
| 1812 | DMA_FROM_DEVICE); |
| 1813 | } |
| 1814 | IXGBE_CB(skb)->dma = 0; |
| 1815 | } |
| 1816 | |
| 1817 | /** |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1818 | * ixgbe_cleanup_headers - Correct corrupted or empty headers |
| 1819 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1820 | * @rx_desc: pointer to the EOP Rx descriptor |
| 1821 | * @skb: pointer to current skb being fixed |
| 1822 | * |
| 1823 | * Check for corrupted packet headers caused by senders on the local L2 |
| 1824 | * embedded NIC switch not setting up their Tx Descriptors right. These |
| 1825 | * should be very rare. |
| 1826 | * |
| 1827 | * Also address the case where we are pulling data in on pages only |
| 1828 | * and as such no data is present in the skb header. |
| 1829 | * |
| 1830 | * In addition if skb is not at least 60 bytes we need to pad it so that |
| 1831 | * it is large enough to qualify as a valid Ethernet frame. |
| 1832 | * |
| 1833 | * Returns true if an error was encountered and skb was freed. |
| 1834 | **/ |
| 1835 | static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring, |
| 1836 | union ixgbe_adv_rx_desc *rx_desc, |
| 1837 | struct sk_buff *skb) |
| 1838 | { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1839 | struct net_device *netdev = rx_ring->netdev; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1840 | |
| 1841 | /* verify that the packet does not have any known errors */ |
| 1842 | if (unlikely(ixgbe_test_staterr(rx_desc, |
| 1843 | IXGBE_RXDADV_ERR_FRAME_ERR_MASK) && |
| 1844 | !(netdev->features & NETIF_F_RXALL))) { |
| 1845 | dev_kfree_skb_any(skb); |
| 1846 | return true; |
| 1847 | } |
| 1848 | |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1849 | /* place header in linear portion of buffer */ |
Alexander Duyck | cf3fe7a | 2012-07-20 08:08:39 +0000 | [diff] [blame] | 1850 | if (skb_is_nonlinear(skb)) |
| 1851 | ixgbe_pull_tail(rx_ring, skb); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1852 | |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1853 | #ifdef IXGBE_FCOE |
| 1854 | /* do not attempt to pad FCoE Frames as this will disrupt DDP */ |
| 1855 | if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) |
| 1856 | return false; |
| 1857 | |
| 1858 | #endif |
Alexander Duyck | a94d9e2 | 2014-12-03 08:17:39 -0800 | [diff] [blame] | 1859 | /* if eth_skb_pad returns an error the skb was freed */ |
| 1860 | if (eth_skb_pad(skb)) |
| 1861 | return true; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1862 | |
| 1863 | return false; |
| 1864 | } |
| 1865 | |
| 1866 | /** |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1867 | * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring |
| 1868 | * @rx_ring: rx descriptor ring to store buffers on |
| 1869 | * @old_buff: donor buffer to have page reused |
| 1870 | * |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1871 | * Synchronizes page for reuse by the adapter |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1872 | **/ |
| 1873 | static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring, |
| 1874 | struct ixgbe_rx_buffer *old_buff) |
| 1875 | { |
| 1876 | struct ixgbe_rx_buffer *new_buff; |
| 1877 | u16 nta = rx_ring->next_to_alloc; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1878 | |
| 1879 | new_buff = &rx_ring->rx_buffer_info[nta]; |
| 1880 | |
| 1881 | /* update, and store next to alloc */ |
| 1882 | nta++; |
| 1883 | rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0; |
| 1884 | |
| 1885 | /* transfer page from old buffer to new buffer */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1886 | *new_buff = *old_buff; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1887 | |
| 1888 | /* sync the buffer for use by the device */ |
| 1889 | dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma, |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1890 | new_buff->page_offset, |
| 1891 | ixgbe_rx_bufsz(rx_ring), |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1892 | DMA_FROM_DEVICE); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1893 | } |
| 1894 | |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1895 | static inline bool ixgbe_page_is_reserved(struct page *page) |
| 1896 | { |
Michal Hocko | 2f064f3 | 2015-08-21 14:11:51 -0700 | [diff] [blame] | 1897 | return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page); |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1898 | } |
| 1899 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1900 | /** |
| 1901 | * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff |
| 1902 | * @rx_ring: rx descriptor ring to transact packets on |
| 1903 | * @rx_buffer: buffer containing page to add |
| 1904 | * @rx_desc: descriptor containing length of buffer written by hardware |
| 1905 | * @skb: sk_buff to place the data into |
| 1906 | * |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1907 | * This function will add the data contained in rx_buffer->page to the skb. |
| 1908 | * This is done either through a direct copy if the data in the buffer is |
| 1909 | * less than the skb header size, otherwise it will just attach the page as |
| 1910 | * a frag to the skb. |
| 1911 | * |
| 1912 | * The function will then update the page offset if necessary and return |
| 1913 | * true if the buffer can be reused by the adapter. |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1914 | **/ |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1915 | static bool ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring, |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1916 | struct ixgbe_rx_buffer *rx_buffer, |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1917 | union ixgbe_adv_rx_desc *rx_desc, |
| 1918 | struct sk_buff *skb) |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1919 | { |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1920 | struct page *page = rx_buffer->page; |
| 1921 | unsigned int size = le16_to_cpu(rx_desc->wb.upper.length); |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1922 | #if (PAGE_SIZE < 8192) |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1923 | unsigned int truesize = ixgbe_rx_bufsz(rx_ring); |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1924 | #else |
| 1925 | unsigned int truesize = ALIGN(size, L1_CACHE_BYTES); |
| 1926 | unsigned int last_offset = ixgbe_rx_pg_size(rx_ring) - |
| 1927 | ixgbe_rx_bufsz(rx_ring); |
| 1928 | #endif |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1929 | |
Alexander Duyck | cf3fe7a | 2012-07-20 08:08:39 +0000 | [diff] [blame] | 1930 | if ((size <= IXGBE_RX_HDR_SIZE) && !skb_is_nonlinear(skb)) { |
| 1931 | unsigned char *va = page_address(page) + rx_buffer->page_offset; |
| 1932 | |
| 1933 | memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long))); |
| 1934 | |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1935 | /* page is not reserved, we can reuse buffer as-is */ |
| 1936 | if (likely(!ixgbe_page_is_reserved(page))) |
Alexander Duyck | cf3fe7a | 2012-07-20 08:08:39 +0000 | [diff] [blame] | 1937 | return true; |
| 1938 | |
| 1939 | /* this page cannot be reused so discard it */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1940 | __free_pages(page, ixgbe_rx_pg_order(rx_ring)); |
Alexander Duyck | cf3fe7a | 2012-07-20 08:08:39 +0000 | [diff] [blame] | 1941 | return false; |
| 1942 | } |
| 1943 | |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1944 | skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page, |
| 1945 | rx_buffer->page_offset, size, truesize); |
| 1946 | |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1947 | /* avoid re-using remote pages */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1948 | if (unlikely(ixgbe_page_is_reserved(page))) |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1949 | return false; |
| 1950 | |
| 1951 | #if (PAGE_SIZE < 8192) |
| 1952 | /* if we are only owner of page we can reuse it */ |
| 1953 | if (unlikely(page_count(page) != 1)) |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1954 | return false; |
| 1955 | |
| 1956 | /* flip page offset to other buffer */ |
| 1957 | rx_buffer->page_offset ^= truesize; |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1958 | #else |
| 1959 | /* move offset up to the next cache line */ |
| 1960 | rx_buffer->page_offset += truesize; |
| 1961 | |
| 1962 | if (rx_buffer->page_offset > last_offset) |
| 1963 | return false; |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1964 | #endif |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1965 | |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1966 | /* Even if we own the page, we are not allowed to use atomic_set() |
| 1967 | * This would break get_page_unless_zero() users. |
| 1968 | */ |
Joonsoo Kim | fe896d1 | 2016-03-17 14:19:26 -0700 | [diff] [blame] | 1969 | page_ref_inc(page); |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1970 | |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1971 | return true; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1972 | } |
| 1973 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 1974 | static struct sk_buff *ixgbe_fetch_rx_buffer(struct ixgbe_ring *rx_ring, |
| 1975 | union ixgbe_adv_rx_desc *rx_desc) |
| 1976 | { |
| 1977 | struct ixgbe_rx_buffer *rx_buffer; |
| 1978 | struct sk_buff *skb; |
| 1979 | struct page *page; |
| 1980 | |
| 1981 | rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean]; |
| 1982 | page = rx_buffer->page; |
| 1983 | prefetchw(page); |
| 1984 | |
| 1985 | skb = rx_buffer->skb; |
| 1986 | |
| 1987 | if (likely(!skb)) { |
| 1988 | void *page_addr = page_address(page) + |
| 1989 | rx_buffer->page_offset; |
| 1990 | |
| 1991 | /* prefetch first cache line of first page */ |
| 1992 | prefetch(page_addr); |
| 1993 | #if L1_CACHE_BYTES < 128 |
| 1994 | prefetch(page_addr + L1_CACHE_BYTES); |
| 1995 | #endif |
| 1996 | |
| 1997 | /* allocate a skb to store the frags */ |
Alexander Duyck | 67fd893 | 2014-12-09 19:40:56 -0800 | [diff] [blame] | 1998 | skb = napi_alloc_skb(&rx_ring->q_vector->napi, |
| 1999 | IXGBE_RX_HDR_SIZE); |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2000 | if (unlikely(!skb)) { |
| 2001 | rx_ring->rx_stats.alloc_rx_buff_failed++; |
| 2002 | return NULL; |
| 2003 | } |
| 2004 | |
| 2005 | /* |
| 2006 | * we will be copying header into skb->data in |
| 2007 | * pskb_may_pull so it is in our interest to prefetch |
| 2008 | * it now to avoid a possible cache miss |
| 2009 | */ |
| 2010 | prefetchw(skb->data); |
| 2011 | |
| 2012 | /* |
| 2013 | * Delay unmapping of the first packet. It carries the |
| 2014 | * header information, HW may still access the header |
| 2015 | * after the writeback. Only unmap it when EOP is |
| 2016 | * reached |
| 2017 | */ |
| 2018 | if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))) |
| 2019 | goto dma_sync; |
| 2020 | |
| 2021 | IXGBE_CB(skb)->dma = rx_buffer->dma; |
| 2022 | } else { |
| 2023 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)) |
| 2024 | ixgbe_dma_sync_frag(rx_ring, skb); |
| 2025 | |
| 2026 | dma_sync: |
| 2027 | /* we are reusing so sync this buffer for CPU use */ |
| 2028 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 2029 | rx_buffer->dma, |
| 2030 | rx_buffer->page_offset, |
| 2031 | ixgbe_rx_bufsz(rx_ring), |
| 2032 | DMA_FROM_DEVICE); |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 2033 | |
| 2034 | rx_buffer->skb = NULL; |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2035 | } |
| 2036 | |
| 2037 | /* pull page into skb */ |
| 2038 | if (ixgbe_add_rx_frag(rx_ring, rx_buffer, rx_desc, skb)) { |
| 2039 | /* hand second half of page back to the ring */ |
| 2040 | ixgbe_reuse_rx_page(rx_ring, rx_buffer); |
| 2041 | } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) { |
| 2042 | /* the page has been released from the ring */ |
| 2043 | IXGBE_CB(skb)->page_released = true; |
| 2044 | } else { |
| 2045 | /* we are not reusing the buffer so unmap it */ |
| 2046 | dma_unmap_page(rx_ring->dev, rx_buffer->dma, |
| 2047 | ixgbe_rx_pg_size(rx_ring), |
| 2048 | DMA_FROM_DEVICE); |
| 2049 | } |
| 2050 | |
| 2051 | /* clear contents of buffer_info */ |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2052 | rx_buffer->page = NULL; |
| 2053 | |
| 2054 | return skb; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2055 | } |
| 2056 | |
| 2057 | /** |
| 2058 | * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf |
| 2059 | * @q_vector: structure containing interrupt and ring information |
| 2060 | * @rx_ring: rx descriptor ring to transact packets on |
| 2061 | * @budget: Total limit on number of packets to process |
| 2062 | * |
| 2063 | * This function provides a "bounce buffer" approach to Rx interrupt |
| 2064 | * processing. The advantage to this is that on systems that have |
| 2065 | * expensive overhead for IOMMU access this provides a means of avoiding |
| 2066 | * it by maintaining the mapping of the page to the syste. |
| 2067 | * |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2068 | * Returns amount of work completed |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2069 | **/ |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2070 | static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2071 | struct ixgbe_ring *rx_ring, |
Alexander Duyck | f4de00e | 2012-09-25 00:29:37 +0000 | [diff] [blame] | 2072 | const int budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2073 | { |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 2074 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 2075 | #ifdef IXGBE_FCOE |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2076 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Mark Rustad | 4ffdf91 | 2012-07-18 06:05:50 +0000 | [diff] [blame] | 2077 | int ddp_bytes; |
| 2078 | unsigned int mss = 0; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 2079 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2080 | u16 cleaned_count = ixgbe_desc_unused(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2081 | |
Eric W. Biederman | fdabfc8a | 2014-03-14 18:00:41 -0700 | [diff] [blame] | 2082 | while (likely(total_rx_packets < budget)) { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2083 | union ixgbe_adv_rx_desc *rx_desc; |
| 2084 | struct sk_buff *skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2085 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2086 | /* return some buffers to hardware, one at a time is too slow */ |
| 2087 | if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) { |
| 2088 | ixgbe_alloc_rx_buffers(rx_ring, cleaned_count); |
| 2089 | cleaned_count = 0; |
| 2090 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2091 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2092 | rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2093 | |
Alexander Duyck | 124b74c | 2014-12-11 15:02:28 -0800 | [diff] [blame] | 2094 | if (!rx_desc->wb.upper.status_error) |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2095 | break; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 2096 | |
Alexander Duyck | 124b74c | 2014-12-11 15:02:28 -0800 | [diff] [blame] | 2097 | /* This memory barrier is needed to keep us from reading |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2098 | * any other fields out of the rx_desc until we know the |
Alexander Duyck | 124b74c | 2014-12-11 15:02:28 -0800 | [diff] [blame] | 2099 | * descriptor has been written back |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2100 | */ |
Alexander Duyck | 124b74c | 2014-12-11 15:02:28 -0800 | [diff] [blame] | 2101 | dma_rmb(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2102 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2103 | /* retrieve a buffer from the ring */ |
| 2104 | skb = ixgbe_fetch_rx_buffer(rx_ring, rx_desc); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2105 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2106 | /* exit if we failed to retrieve a buffer */ |
| 2107 | if (!skb) |
| 2108 | break; |
Alexander Duyck | 4c1975d | 2012-01-31 02:59:23 +0000 | [diff] [blame] | 2109 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2110 | cleaned_count++; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2111 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2112 | /* place incomplete frames back on ring for completion */ |
| 2113 | if (ixgbe_is_non_eop(rx_ring, rx_desc, skb)) |
| 2114 | continue; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2115 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2116 | /* verify the packet layout is correct */ |
| 2117 | if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb)) |
| 2118 | continue; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 2119 | |
| 2120 | /* probably a little skewed due to removing CRC */ |
| 2121 | total_rx_bytes += skb->len; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 2122 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 2123 | /* populate checksum, timestamp, VLAN, and protocol */ |
| 2124 | ixgbe_process_skb_fields(rx_ring, rx_desc, skb); |
| 2125 | |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 2126 | #ifdef IXGBE_FCOE |
| 2127 | /* if ddp, not passing to ULD unless for FCP_RSP or error */ |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 2128 | if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) { |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 2129 | ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb); |
Mark Rustad | 4ffdf91 | 2012-07-18 06:05:50 +0000 | [diff] [blame] | 2130 | /* include DDPed FCoE data */ |
| 2131 | if (ddp_bytes > 0) { |
| 2132 | if (!mss) { |
| 2133 | mss = rx_ring->netdev->mtu - |
| 2134 | sizeof(struct fcoe_hdr) - |
| 2135 | sizeof(struct fc_frame_header) - |
| 2136 | sizeof(struct fcoe_crc_eof); |
| 2137 | if (mss > 512) |
| 2138 | mss &= ~511; |
| 2139 | } |
| 2140 | total_rx_bytes += ddp_bytes; |
| 2141 | total_rx_packets += DIV_ROUND_UP(ddp_bytes, |
| 2142 | mss); |
| 2143 | } |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 2144 | if (!ddp_bytes) { |
| 2145 | dev_kfree_skb_any(skb); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2146 | continue; |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 2147 | } |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 2148 | } |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2149 | |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 2150 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 2151 | ixgbe_rx_skb(q_vector, skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2152 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2153 | /* update budget accounting */ |
Alexander Duyck | f4de00e | 2012-09-25 00:29:37 +0000 | [diff] [blame] | 2154 | total_rx_packets++; |
Eric W. Biederman | fdabfc8a | 2014-03-14 18:00:41 -0700 | [diff] [blame] | 2155 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2156 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 2157 | u64_stats_update_begin(&rx_ring->syncp); |
| 2158 | rx_ring->stats.packets += total_rx_packets; |
| 2159 | rx_ring->stats.bytes += total_rx_bytes; |
| 2160 | u64_stats_update_end(&rx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2161 | q_vector->rx.total_packets += total_rx_packets; |
| 2162 | q_vector->rx.total_bytes += total_rx_bytes; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2163 | |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2164 | return total_rx_packets; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2165 | } |
| 2166 | |
Cong Wang | e0d1095 | 2013-08-01 11:10:25 +0800 | [diff] [blame] | 2167 | #ifdef CONFIG_NET_RX_BUSY_POLL |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2168 | /* must be called with local_bh_disable()d */ |
| 2169 | static int ixgbe_low_latency_recv(struct napi_struct *napi) |
| 2170 | { |
| 2171 | struct ixgbe_q_vector *q_vector = |
| 2172 | container_of(napi, struct ixgbe_q_vector, napi); |
| 2173 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 2174 | struct ixgbe_ring *ring; |
| 2175 | int found = 0; |
| 2176 | |
| 2177 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2178 | return LL_FLUSH_FAILED; |
| 2179 | |
| 2180 | if (!ixgbe_qv_lock_poll(q_vector)) |
| 2181 | return LL_FLUSH_BUSY; |
| 2182 | |
| 2183 | ixgbe_for_each_ring(ring, q_vector->rx) { |
| 2184 | found = ixgbe_clean_rx_irq(q_vector, ring, 4); |
Jacob Keller | b464003 | 2013-10-01 04:33:54 -0700 | [diff] [blame] | 2185 | #ifdef BP_EXTENDED_STATS |
Eliezer Tamir | 7e15b90 | 2013-06-10 11:40:31 +0300 | [diff] [blame] | 2186 | if (found) |
| 2187 | ring->stats.cleaned += found; |
| 2188 | else |
| 2189 | ring->stats.misses++; |
| 2190 | #endif |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2191 | if (found) |
| 2192 | break; |
| 2193 | } |
| 2194 | |
| 2195 | ixgbe_qv_unlock_poll(q_vector); |
| 2196 | |
| 2197 | return found; |
| 2198 | } |
Cong Wang | e0d1095 | 2013-08-01 11:10:25 +0800 | [diff] [blame] | 2199 | #endif /* CONFIG_NET_RX_BUSY_POLL */ |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2200 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2201 | /** |
| 2202 | * ixgbe_configure_msix - Configure MSI-X hardware |
| 2203 | * @adapter: board private structure |
| 2204 | * |
| 2205 | * ixgbe_configure_msix sets up the hardware to properly generate MSI-X |
| 2206 | * interrupts. |
| 2207 | **/ |
| 2208 | static void ixgbe_configure_msix(struct ixgbe_adapter *adapter) |
| 2209 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2210 | struct ixgbe_q_vector *q_vector; |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2211 | int v_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2212 | u32 mask; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2213 | |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 2214 | /* Populate MSIX to EITR Select */ |
| 2215 | if (adapter->num_vfs > 32) { |
| 2216 | u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1; |
| 2217 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel); |
| 2218 | } |
| 2219 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 2220 | /* |
| 2221 | * Populate the IVAR table and set the ITR values to the |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2222 | * corresponding register. |
| 2223 | */ |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2224 | for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) { |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2225 | struct ixgbe_ring *ring; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2226 | q_vector = adapter->q_vector[v_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2227 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 2228 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2229 | ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2230 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 2231 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2232 | ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2233 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2234 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2235 | } |
| 2236 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2237 | switch (adapter->hw.mac.type) { |
| 2238 | case ixgbe_mac_82598EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2239 | ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2240 | v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2241 | break; |
| 2242 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2243 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2244 | case ixgbe_mac_X550: |
| 2245 | case ixgbe_mac_X550EM_x: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2246 | ixgbe_set_ivar(adapter, -1, 1, v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2247 | break; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2248 | default: |
| 2249 | break; |
| 2250 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2251 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2252 | |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 2253 | /* set up to autoclear timer, and the vectors */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2254 | mask = IXGBE_EIMS_ENABLE_MASK; |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2255 | mask &= ~(IXGBE_EIMS_OTHER | |
| 2256 | IXGBE_EIMS_MAILBOX | |
| 2257 | IXGBE_EIMS_LSC); |
| 2258 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2259 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2260 | } |
| 2261 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2262 | enum latency_range { |
| 2263 | lowest_latency = 0, |
| 2264 | low_latency = 1, |
| 2265 | bulk_latency = 2, |
| 2266 | latency_invalid = 255 |
| 2267 | }; |
| 2268 | |
| 2269 | /** |
| 2270 | * ixgbe_update_itr - update the dynamic ITR value based on statistics |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2271 | * @q_vector: structure containing interrupt and ring information |
| 2272 | * @ring_container: structure containing ring performance data |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2273 | * |
| 2274 | * Stores a new ITR value based on packets and byte |
| 2275 | * counts during the last interrupt. The advantage of per interrupt |
| 2276 | * computation is faster updates and more accurate ITR for the current |
| 2277 | * traffic pattern. Constants in this function were computed |
| 2278 | * based on theoretical maximum wire speed and thresholds were set based |
| 2279 | * on testing data as well as attempting to minimize response time |
| 2280 | * while increasing bulk throughput. |
| 2281 | * this functionality is controlled by the InterruptThrottleRate module |
| 2282 | * parameter (see ixgbe_param.c) |
| 2283 | **/ |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2284 | static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector, |
| 2285 | struct ixgbe_ring_container *ring_container) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2286 | { |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2287 | int bytes = ring_container->total_bytes; |
| 2288 | int packets = ring_container->total_packets; |
| 2289 | u32 timepassed_us; |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2290 | u64 bytes_perint; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2291 | u8 itr_setting = ring_container->itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2292 | |
| 2293 | if (packets == 0) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2294 | return; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2295 | |
| 2296 | /* simple throttlerate management |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2297 | * 0-10MB/s lowest (100000 ints/s) |
| 2298 | * 10-20MB/s low (20000 ints/s) |
Alexander Duyck | 8ac34f1 | 2015-07-30 15:19:28 -0700 | [diff] [blame] | 2299 | * 20-1249MB/s bulk (12000 ints/s) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2300 | */ |
| 2301 | /* what was last interrupt timeslice? */ |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2302 | timepassed_us = q_vector->itr >> 2; |
Don Skidmore | bdbeefe | 2013-03-02 07:17:37 +0000 | [diff] [blame] | 2303 | if (timepassed_us == 0) |
| 2304 | return; |
| 2305 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2306 | bytes_perint = bytes / timepassed_us; /* bytes/usec */ |
| 2307 | |
| 2308 | switch (itr_setting) { |
| 2309 | case lowest_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2310 | if (bytes_perint > 10) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2311 | itr_setting = low_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2312 | break; |
| 2313 | case low_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2314 | if (bytes_perint > 20) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2315 | itr_setting = bulk_latency; |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2316 | else if (bytes_perint <= 10) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2317 | itr_setting = lowest_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2318 | break; |
| 2319 | case bulk_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2320 | if (bytes_perint <= 20) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2321 | itr_setting = low_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2322 | break; |
| 2323 | } |
| 2324 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2325 | /* clear work counters since we have the values we need */ |
| 2326 | ring_container->total_bytes = 0; |
| 2327 | ring_container->total_packets = 0; |
| 2328 | |
| 2329 | /* write updated itr to ring container */ |
| 2330 | ring_container->itr = itr_setting; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2331 | } |
| 2332 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2333 | /** |
| 2334 | * ixgbe_write_eitr - write EITR register in hardware specific way |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2335 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2336 | * |
| 2337 | * This function is made to be called by ethtool and by the driver |
| 2338 | * when it needs to update EITR registers at runtime. Hardware |
| 2339 | * specific quirks/differences are taken care of here. |
| 2340 | */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2341 | void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector) |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2342 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2343 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2344 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2345 | int v_idx = q_vector->v_idx; |
Alexander Duyck | 5d967eb | 2012-02-08 07:49:43 +0000 | [diff] [blame] | 2346 | u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2347 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2348 | switch (adapter->hw.mac.type) { |
| 2349 | case ixgbe_mac_82598EB: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2350 | /* must write high and low 16 bits to reset counter */ |
| 2351 | itr_reg |= (itr_reg << 16); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2352 | break; |
| 2353 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2354 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2355 | case ixgbe_mac_X550: |
| 2356 | case ixgbe_mac_X550EM_x: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2357 | /* |
| 2358 | * set the WDIS bit to not clear the timer bits and cause an |
| 2359 | * immediate assertion of the interrupt |
| 2360 | */ |
| 2361 | itr_reg |= IXGBE_EITR_CNT_WDIS; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2362 | break; |
| 2363 | default: |
| 2364 | break; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2365 | } |
| 2366 | IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg); |
| 2367 | } |
| 2368 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2369 | static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2370 | { |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2371 | u32 new_itr = q_vector->itr; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2372 | u8 current_itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2373 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2374 | ixgbe_update_itr(q_vector, &q_vector->tx); |
| 2375 | ixgbe_update_itr(q_vector, &q_vector->rx); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2376 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2377 | current_itr = max(q_vector->rx.itr, q_vector->tx.itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2378 | |
| 2379 | switch (current_itr) { |
| 2380 | /* counts and packets in update_itr are dependent on these numbers */ |
| 2381 | case lowest_latency: |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2382 | new_itr = IXGBE_100K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2383 | break; |
| 2384 | case low_latency: |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2385 | new_itr = IXGBE_20K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2386 | break; |
| 2387 | case bulk_latency: |
Alexander Duyck | 8ac34f1 | 2015-07-30 15:19:28 -0700 | [diff] [blame] | 2388 | new_itr = IXGBE_12K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2389 | break; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2390 | default: |
| 2391 | break; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2392 | } |
| 2393 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2394 | if (new_itr != q_vector->itr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2395 | /* do an exponential smoothing */ |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2396 | new_itr = (10 * new_itr * q_vector->itr) / |
| 2397 | ((9 * new_itr) + q_vector->itr); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2398 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2399 | /* save the algorithm value here */ |
Alexander Duyck | 5d967eb | 2012-02-08 07:49:43 +0000 | [diff] [blame] | 2400 | q_vector->itr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2401 | |
| 2402 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2403 | } |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2404 | } |
| 2405 | |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2406 | /** |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2407 | * ixgbe_check_overtemp_subtask - check for over temperature |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2408 | * @adapter: pointer to adapter |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2409 | **/ |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2410 | static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter) |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2411 | { |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2412 | struct ixgbe_hw *hw = &adapter->hw; |
| 2413 | u32 eicr = adapter->interrupt_event; |
| 2414 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2415 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2416 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2417 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2418 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) && |
| 2419 | !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT)) |
| 2420 | return; |
| 2421 | |
| 2422 | adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2423 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2424 | switch (hw->device_id) { |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2425 | case IXGBE_DEV_ID_82599_T3_LOM: |
| 2426 | /* |
| 2427 | * Since the warning interrupt is for both ports |
| 2428 | * we don't have to check if: |
| 2429 | * - This interrupt wasn't for our port. |
| 2430 | * - We may have missed the interrupt so always have to |
| 2431 | * check if we got a LSC |
| 2432 | */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2433 | if (!(eicr & IXGBE_EICR_GPI_SDP0_8259X) && |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2434 | !(eicr & IXGBE_EICR_LSC)) |
| 2435 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2436 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2437 | if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) { |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 2438 | u32 speed; |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2439 | bool link_up = false; |
| 2440 | |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 2441 | hw->mac.ops.check_link(hw, &speed, &link_up, false); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2442 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2443 | if (link_up) |
| 2444 | return; |
| 2445 | } |
| 2446 | |
| 2447 | /* Check if this is not due to overtemp */ |
| 2448 | if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP) |
| 2449 | return; |
| 2450 | |
| 2451 | break; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2452 | default: |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 2453 | if (adapter->hw.mac.type >= ixgbe_mac_X540) |
| 2454 | return; |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2455 | if (!(eicr & IXGBE_EICR_GPI_SDP0(hw))) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2456 | return; |
| 2457 | break; |
| 2458 | } |
Don Skidmore | f44e751 | 2015-06-09 16:36:23 -0700 | [diff] [blame] | 2459 | e_crit(drv, "%s\n", ixgbe_overheat_msg); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2460 | |
| 2461 | adapter->interrupt_event = 0; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2462 | } |
| 2463 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2464 | static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr) |
| 2465 | { |
| 2466 | struct ixgbe_hw *hw = &adapter->hw; |
| 2467 | |
| 2468 | if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) && |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2469 | (eicr & IXGBE_EICR_GPI_SDP1(hw))) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2470 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2471 | /* write to clear the interrupt */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2472 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw)); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2473 | } |
| 2474 | } |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2475 | |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2476 | static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 2477 | { |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2478 | struct ixgbe_hw *hw = &adapter->hw; |
| 2479 | |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2480 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)) |
| 2481 | return; |
| 2482 | |
| 2483 | switch (adapter->hw.mac.type) { |
| 2484 | case ixgbe_mac_82599EB: |
| 2485 | /* |
| 2486 | * Need to check link state so complete overtemp check |
| 2487 | * on service task |
| 2488 | */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2489 | if (((eicr & IXGBE_EICR_GPI_SDP0(hw)) || |
| 2490 | (eicr & IXGBE_EICR_LSC)) && |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2491 | (!test_bit(__IXGBE_DOWN, &adapter->state))) { |
| 2492 | adapter->interrupt_event = eicr; |
| 2493 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2494 | ixgbe_service_event_schedule(adapter); |
| 2495 | return; |
| 2496 | } |
| 2497 | return; |
| 2498 | case ixgbe_mac_X540: |
| 2499 | if (!(eicr & IXGBE_EICR_TS)) |
| 2500 | return; |
| 2501 | break; |
| 2502 | default: |
| 2503 | return; |
| 2504 | } |
| 2505 | |
Don Skidmore | f44e751 | 2015-06-09 16:36:23 -0700 | [diff] [blame] | 2506 | e_crit(drv, "%s\n", ixgbe_overheat_msg); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2507 | } |
| 2508 | |
Don Skidmore | 45788d2 | 2015-06-09 16:59:04 -0700 | [diff] [blame] | 2509 | static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw) |
| 2510 | { |
| 2511 | switch (hw->mac.type) { |
| 2512 | case ixgbe_mac_82598EB: |
| 2513 | if (hw->phy.type == ixgbe_phy_nl) |
| 2514 | return true; |
| 2515 | return false; |
| 2516 | case ixgbe_mac_82599EB: |
| 2517 | case ixgbe_mac_X550EM_x: |
| 2518 | switch (hw->mac.ops.get_media_type(hw)) { |
| 2519 | case ixgbe_media_type_fiber: |
| 2520 | case ixgbe_media_type_fiber_qsfp: |
| 2521 | return true; |
| 2522 | default: |
| 2523 | return false; |
| 2524 | } |
| 2525 | default: |
| 2526 | return false; |
| 2527 | } |
| 2528 | } |
| 2529 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2530 | static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 2531 | { |
| 2532 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 4ccc650 | 2015-09-02 13:47:54 -0700 | [diff] [blame] | 2533 | u32 eicr_mask = IXGBE_EICR_GPI_SDP2(hw); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2534 | |
Don Skidmore | 4ccc650 | 2015-09-02 13:47:54 -0700 | [diff] [blame] | 2535 | if (!ixgbe_is_sfp(hw)) |
| 2536 | return; |
| 2537 | |
| 2538 | /* Later MAC's use different SDP */ |
| 2539 | if (hw->mac.type >= ixgbe_mac_X540) |
| 2540 | eicr_mask = IXGBE_EICR_GPI_SDP0_X540; |
| 2541 | |
| 2542 | if (eicr & eicr_mask) { |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2543 | /* Clear the interrupt */ |
Don Skidmore | 4ccc650 | 2015-09-02 13:47:54 -0700 | [diff] [blame] | 2544 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr_mask); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2545 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2546 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
Mark Rustad | 58e7cd2 | 2015-08-08 16:18:48 -0700 | [diff] [blame] | 2547 | adapter->sfp_poll_time = 0; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2548 | ixgbe_service_event_schedule(adapter); |
| 2549 | } |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2550 | } |
| 2551 | |
Don Skidmore | 4ccc650 | 2015-09-02 13:47:54 -0700 | [diff] [blame] | 2552 | if (adapter->hw.mac.type == ixgbe_mac_82599EB && |
| 2553 | (eicr & IXGBE_EICR_GPI_SDP1(hw))) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2554 | /* Clear the interrupt */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2555 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw)); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2556 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2557 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 2558 | ixgbe_service_event_schedule(adapter); |
| 2559 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2560 | } |
| 2561 | } |
| 2562 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2563 | static void ixgbe_check_lsc(struct ixgbe_adapter *adapter) |
| 2564 | { |
| 2565 | struct ixgbe_hw *hw = &adapter->hw; |
| 2566 | |
| 2567 | adapter->lsc_int++; |
| 2568 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 2569 | adapter->link_check_timeout = jiffies; |
| 2570 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2571 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC); |
Nelson, Shannon | 8a0717f | 2009-11-12 18:47:11 +0000 | [diff] [blame] | 2572 | IXGBE_WRITE_FLUSH(hw); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 2573 | ixgbe_service_event_schedule(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2574 | } |
| 2575 | } |
| 2576 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2577 | static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter, |
| 2578 | u64 qmask) |
| 2579 | { |
| 2580 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2581 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2582 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2583 | switch (hw->mac.type) { |
| 2584 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2585 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2586 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask); |
| 2587 | break; |
| 2588 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2589 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2590 | case ixgbe_mac_X550: |
| 2591 | case ixgbe_mac_X550EM_x: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2592 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2593 | if (mask) |
| 2594 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2595 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2596 | if (mask) |
| 2597 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask); |
| 2598 | break; |
| 2599 | default: |
| 2600 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2601 | } |
| 2602 | /* skip the flush */ |
| 2603 | } |
| 2604 | |
| 2605 | static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2606 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2607 | { |
| 2608 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2609 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2610 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2611 | switch (hw->mac.type) { |
| 2612 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2613 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2614 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask); |
| 2615 | break; |
| 2616 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2617 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2618 | case ixgbe_mac_X550: |
| 2619 | case ixgbe_mac_X550EM_x: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2620 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2621 | if (mask) |
| 2622 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2623 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2624 | if (mask) |
| 2625 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask); |
| 2626 | break; |
| 2627 | default: |
| 2628 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2629 | } |
| 2630 | /* skip the flush */ |
| 2631 | } |
| 2632 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2633 | /** |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2634 | * ixgbe_irq_enable - Enable default interrupt generation settings |
| 2635 | * @adapter: board private structure |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2636 | **/ |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2637 | static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues, |
| 2638 | bool flush) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2639 | { |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2640 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2641 | u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE); |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 2642 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2643 | /* don't reenable LSC while waiting for link */ |
| 2644 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 2645 | mask &= ~IXGBE_EIMS_LSC; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2646 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2647 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2648 | switch (adapter->hw.mac.type) { |
| 2649 | case ixgbe_mac_82599EB: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2650 | mask |= IXGBE_EIMS_GPI_SDP0(hw); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2651 | break; |
| 2652 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2653 | case ixgbe_mac_X550: |
| 2654 | case ixgbe_mac_X550EM_x: |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2655 | mask |= IXGBE_EIMS_TS; |
| 2656 | break; |
| 2657 | default: |
| 2658 | break; |
| 2659 | } |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2660 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2661 | mask |= IXGBE_EIMS_GPI_SDP1(hw); |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2662 | switch (adapter->hw.mac.type) { |
| 2663 | case ixgbe_mac_82599EB: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2664 | mask |= IXGBE_EIMS_GPI_SDP1(hw); |
| 2665 | mask |= IXGBE_EIMS_GPI_SDP2(hw); |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2666 | /* fall through */ |
Don Skidmore | 858bc08 | 2011-08-04 09:28:30 +0000 | [diff] [blame] | 2667 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2668 | case ixgbe_mac_X550: |
| 2669 | case ixgbe_mac_X550EM_x: |
Mark Rustad | cbd45ec | 2015-08-08 16:17:51 -0700 | [diff] [blame] | 2670 | if (adapter->hw.device_id == IXGBE_DEV_ID_X550EM_X_SFP) |
| 2671 | mask |= IXGBE_EIMS_GPI_SDP0(&adapter->hw); |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 2672 | if (adapter->hw.phy.type == ixgbe_phy_x550em_ext_t) |
| 2673 | mask |= IXGBE_EICR_GPI_SDP0_X540; |
Don Skidmore | 858bc08 | 2011-08-04 09:28:30 +0000 | [diff] [blame] | 2674 | mask |= IXGBE_EIMS_ECC; |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2675 | mask |= IXGBE_EIMS_MAILBOX; |
| 2676 | break; |
| 2677 | default: |
| 2678 | break; |
| 2679 | } |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2680 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2681 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) && |
| 2682 | !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 2683 | mask |= IXGBE_EIMS_FLOW_DIR; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2684 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2685 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
| 2686 | if (queues) |
| 2687 | ixgbe_irq_enable_queues(adapter, ~0); |
| 2688 | if (flush) |
| 2689 | IXGBE_WRITE_FLUSH(&adapter->hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2690 | } |
| 2691 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2692 | static irqreturn_t ixgbe_msix_other(int irq, void *data) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2693 | { |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2694 | struct ixgbe_adapter *adapter = data; |
| 2695 | struct ixgbe_hw *hw = &adapter->hw; |
| 2696 | u32 eicr; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2697 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2698 | /* |
| 2699 | * Workaround for Silicon errata. Use clear-by-write instead |
| 2700 | * of clear-by-read. Reading with EICS will return the |
| 2701 | * interrupt causes without clearing, which later be done |
| 2702 | * with the write to EICR. |
| 2703 | */ |
| 2704 | eicr = IXGBE_READ_REG(hw, IXGBE_EICS); |
Jacob Keller | d87d830 | 2013-03-02 07:51:42 +0000 | [diff] [blame] | 2705 | |
| 2706 | /* The lower 16bits of the EICR register are for the queue interrupts |
Joe Perches | dbedd44 | 2015-03-06 20:49:12 -0800 | [diff] [blame] | 2707 | * 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] | 2708 | * the bits are high when ixgbe_msix_other is called. There is a race |
| 2709 | * condition otherwise which results in possible performance loss |
| 2710 | * especially if the ixgbe_msix_other interrupt is triggering |
| 2711 | * consistently (as it would when PPS is turned on for the X540 device) |
| 2712 | */ |
| 2713 | eicr &= 0xFFFF0000; |
| 2714 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2715 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2716 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2717 | if (eicr & IXGBE_EICR_LSC) |
| 2718 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2719 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2720 | if (eicr & IXGBE_EICR_MAILBOX) |
| 2721 | ixgbe_msg_task(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2722 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2723 | switch (hw->mac.type) { |
| 2724 | case ixgbe_mac_82599EB: |
| 2725 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2726 | case ixgbe_mac_X550: |
| 2727 | case ixgbe_mac_X550EM_x: |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 2728 | if (hw->phy.type == ixgbe_phy_x550em_ext_t && |
| 2729 | (eicr & IXGBE_EICR_GPI_SDP0_X540)) { |
| 2730 | adapter->flags2 |= IXGBE_FLAG2_PHY_INTERRUPT; |
| 2731 | ixgbe_service_event_schedule(adapter); |
| 2732 | IXGBE_WRITE_REG(hw, IXGBE_EICR, |
| 2733 | IXGBE_EICR_GPI_SDP0_X540); |
| 2734 | } |
Don Skidmore | d773ce2 | 2014-02-25 17:58:53 -0800 | [diff] [blame] | 2735 | if (eicr & IXGBE_EICR_ECC) { |
| 2736 | e_info(link, "Received ECC Err, initiating reset\n"); |
| 2737 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; |
| 2738 | ixgbe_service_event_schedule(adapter); |
| 2739 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC); |
| 2740 | } |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2741 | /* Handle Flow Director Full threshold interrupt */ |
| 2742 | if (eicr & IXGBE_EICR_FLOW_DIR) { |
| 2743 | int reinit_count = 0; |
| 2744 | int i; |
| 2745 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2746 | struct ixgbe_ring *ring = adapter->tx_ring[i]; |
| 2747 | if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE, |
| 2748 | &ring->state)) |
| 2749 | reinit_count++; |
| 2750 | } |
| 2751 | if (reinit_count) { |
| 2752 | /* no more flow director interrupts until after init */ |
| 2753 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR); |
| 2754 | adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 2755 | ixgbe_service_event_schedule(adapter); |
| 2756 | } |
| 2757 | } |
| 2758 | ixgbe_check_sfp_event(adapter, eicr); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2759 | ixgbe_check_overtemp_event(adapter, eicr); |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2760 | break; |
| 2761 | default: |
| 2762 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2763 | } |
| 2764 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2765 | ixgbe_check_fan_failure(adapter, eicr); |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2766 | |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2767 | if (unlikely(eicr & IXGBE_EICR_TIMESYNC)) |
Mark Rustad | a9763f3 | 2015-10-27 09:58:07 -0700 | [diff] [blame] | 2768 | ixgbe_ptp_check_pps_event(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2769 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2770 | /* re-enable the original interrupt state, no lsc, no queues */ |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2771 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2772 | ixgbe_irq_enable(adapter, false, false); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2773 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2774 | return IRQ_HANDLED; |
| 2775 | } |
| 2776 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2777 | static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2778 | { |
| 2779 | struct ixgbe_q_vector *q_vector = data; |
| 2780 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2781 | /* EIAM disabled interrupts (on this vector) for us */ |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2782 | |
| 2783 | if (q_vector->rx.ring || q_vector->tx.ring) |
Alexander Duyck | ef2662b | 2015-09-29 15:19:43 -0700 | [diff] [blame] | 2784 | napi_schedule_irqoff(&q_vector->napi); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2785 | |
| 2786 | return IRQ_HANDLED; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2787 | } |
| 2788 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2789 | /** |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2790 | * ixgbe_poll - NAPI Rx polling callback |
| 2791 | * @napi: structure for representing this polling device |
| 2792 | * @budget: how many packets driver is allowed to clean |
| 2793 | * |
| 2794 | * This function is used for legacy and MSI, NAPI mode |
| 2795 | **/ |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 2796 | int ixgbe_poll(struct napi_struct *napi, int budget) |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2797 | { |
| 2798 | struct ixgbe_q_vector *q_vector = |
| 2799 | container_of(napi, struct ixgbe_q_vector, napi); |
| 2800 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 2801 | struct ixgbe_ring *ring; |
Jesse Brandeburg | 32b3e08 | 2015-09-24 16:35:47 -0700 | [diff] [blame] | 2802 | int per_ring_budget, work_done = 0; |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2803 | bool clean_complete = true; |
| 2804 | |
| 2805 | #ifdef CONFIG_IXGBE_DCA |
| 2806 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 2807 | ixgbe_update_dca(q_vector); |
| 2808 | #endif |
| 2809 | |
| 2810 | ixgbe_for_each_ring(ring, q_vector->tx) |
Jesper Dangaard Brouer | a3a8749 | 2016-02-08 13:15:09 +0100 | [diff] [blame] | 2811 | clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring, budget); |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2812 | |
Alexander Duyck | 5d6002b | 2015-09-22 14:35:41 -0700 | [diff] [blame] | 2813 | /* Exit if we are called by netpoll or busy polling is active */ |
| 2814 | if ((budget <= 0) || !ixgbe_qv_lock_napi(q_vector)) |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2815 | return budget; |
| 2816 | |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2817 | /* attempt to distribute budget to each queue fairly, but don't allow |
| 2818 | * the budget to go below 1 because we'll exit polling */ |
| 2819 | if (q_vector->rx.count > 1) |
| 2820 | per_ring_budget = max(budget/q_vector->rx.count, 1); |
| 2821 | else |
| 2822 | per_ring_budget = budget; |
| 2823 | |
Jesse Brandeburg | 32b3e08 | 2015-09-24 16:35:47 -0700 | [diff] [blame] | 2824 | ixgbe_for_each_ring(ring, q_vector->rx) { |
| 2825 | int cleaned = ixgbe_clean_rx_irq(q_vector, ring, |
| 2826 | per_ring_budget); |
| 2827 | |
| 2828 | work_done += cleaned; |
| 2829 | clean_complete &= (cleaned < per_ring_budget); |
| 2830 | } |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2831 | |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2832 | ixgbe_qv_unlock_napi(q_vector); |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2833 | /* If all work not completed, return budget and keep polling */ |
| 2834 | if (!clean_complete) |
| 2835 | return budget; |
| 2836 | |
| 2837 | /* all work done, exit the polling mode */ |
Jesse Brandeburg | 32b3e08 | 2015-09-24 16:35:47 -0700 | [diff] [blame] | 2838 | napi_complete_done(napi, work_done); |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2839 | if (adapter->rx_itr_setting & 1) |
| 2840 | ixgbe_set_itr(q_vector); |
| 2841 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2842 | ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx)); |
| 2843 | |
| 2844 | return 0; |
| 2845 | } |
| 2846 | |
| 2847 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2848 | * ixgbe_request_msix_irqs - Initialize MSI-X interrupts |
| 2849 | * @adapter: board private structure |
| 2850 | * |
| 2851 | * ixgbe_request_msix_irqs allocates MSI-X vectors and requests |
| 2852 | * interrupts from the kernel. |
| 2853 | **/ |
| 2854 | static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter) |
| 2855 | { |
| 2856 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2857 | int vector, err; |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2858 | int ri = 0, ti = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2859 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2860 | for (vector = 0; vector < adapter->num_q_vectors; vector++) { |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2861 | struct ixgbe_q_vector *q_vector = adapter->q_vector[vector]; |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2862 | struct msix_entry *entry = &adapter->msix_entries[vector]; |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 2863 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2864 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 2865 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2866 | "%s-%s-%d", netdev->name, "TxRx", ri++); |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2867 | ti++; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2868 | } else if (q_vector->rx.ring) { |
| 2869 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2870 | "%s-%s-%d", netdev->name, "rx", ri++); |
| 2871 | } else if (q_vector->tx.ring) { |
| 2872 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2873 | "%s-%s-%d", netdev->name, "tx", ti++); |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2874 | } else { |
| 2875 | /* skip this unused q_vector */ |
| 2876 | continue; |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2877 | } |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2878 | err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0, |
| 2879 | q_vector->name, q_vector); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2880 | if (err) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2881 | e_err(probe, "request_irq failed for MSIX interrupt " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 2882 | "Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2883 | goto free_queue_irqs; |
| 2884 | } |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2885 | /* If Flow Director is enabled, set interrupt affinity */ |
| 2886 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 2887 | /* assign the mask for this irq */ |
| 2888 | irq_set_affinity_hint(entry->vector, |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2889 | &q_vector->affinity_mask); |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2890 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2891 | } |
| 2892 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2893 | err = request_irq(adapter->msix_entries[vector].vector, |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2894 | ixgbe_msix_other, 0, netdev->name, adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2895 | if (err) { |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2896 | e_err(probe, "request_irq for msix_other failed: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2897 | goto free_queue_irqs; |
| 2898 | } |
| 2899 | |
| 2900 | return 0; |
| 2901 | |
| 2902 | free_queue_irqs: |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2903 | while (vector) { |
| 2904 | vector--; |
| 2905 | irq_set_affinity_hint(adapter->msix_entries[vector].vector, |
| 2906 | NULL); |
| 2907 | free_irq(adapter->msix_entries[vector].vector, |
| 2908 | adapter->q_vector[vector]); |
| 2909 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2910 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 2911 | pci_disable_msix(adapter->pdev); |
| 2912 | kfree(adapter->msix_entries); |
| 2913 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2914 | return err; |
| 2915 | } |
| 2916 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 2917 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2918 | * ixgbe_intr - legacy mode Interrupt Handler |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2919 | * @irq: interrupt number |
| 2920 | * @data: pointer to a network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2921 | **/ |
| 2922 | static irqreturn_t ixgbe_intr(int irq, void *data) |
| 2923 | { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2924 | struct ixgbe_adapter *adapter = data; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2925 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2926 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2927 | u32 eicr; |
| 2928 | |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 2929 | /* |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 2930 | * Workaround for silicon errata #26 on 82598. Mask the interrupt |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 2931 | * before the read of EICR. |
| 2932 | */ |
| 2933 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); |
| 2934 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2935 | /* 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] | 2936 | * therefore no explicit interrupt disable is necessary */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2937 | eicr = IXGBE_READ_REG(hw, IXGBE_EICR); |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2938 | if (!eicr) { |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2939 | /* |
| 2940 | * shared interrupt alert! |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2941 | * make sure interrupts are enabled because the read will |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2942 | * have disabled interrupts due to EIAM |
| 2943 | * finish the workaround of silicon errata on 82598. Unmask |
| 2944 | * the interrupt that we masked before the EICR read. |
| 2945 | */ |
| 2946 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2947 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2948 | return IRQ_NONE; /* Not our interrupt */ |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2949 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2950 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2951 | if (eicr & IXGBE_EICR_LSC) |
| 2952 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2953 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2954 | switch (hw->mac.type) { |
| 2955 | case ixgbe_mac_82599EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2956 | ixgbe_check_sfp_event(adapter, eicr); |
Don Skidmore | 0ccb974 | 2011-08-04 02:07:48 +0000 | [diff] [blame] | 2957 | /* Fall through */ |
| 2958 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2959 | case ixgbe_mac_X550: |
| 2960 | case ixgbe_mac_X550EM_x: |
Don Skidmore | d773ce2 | 2014-02-25 17:58:53 -0800 | [diff] [blame] | 2961 | if (eicr & IXGBE_EICR_ECC) { |
| 2962 | e_info(link, "Received ECC Err, initiating reset\n"); |
| 2963 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; |
| 2964 | ixgbe_service_event_schedule(adapter); |
| 2965 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC); |
| 2966 | } |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2967 | ixgbe_check_overtemp_event(adapter, eicr); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2968 | break; |
| 2969 | default: |
| 2970 | break; |
| 2971 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2972 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2973 | ixgbe_check_fan_failure(adapter, eicr); |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2974 | if (unlikely(eicr & IXGBE_EICR_TIMESYNC)) |
Mark Rustad | a9763f3 | 2015-10-27 09:58:07 -0700 | [diff] [blame] | 2975 | ixgbe_ptp_check_pps_event(adapter); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2976 | |
Alexander Duyck | b9f6ed2 | 2012-02-08 07:49:54 +0000 | [diff] [blame] | 2977 | /* would disable interrupts here but EIAM disabled it */ |
Alexander Duyck | ef2662b | 2015-09-29 15:19:43 -0700 | [diff] [blame] | 2978 | napi_schedule_irqoff(&q_vector->napi); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2979 | |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2980 | /* |
| 2981 | * re-enable link(maybe) and non-queue interrupts, no flush. |
| 2982 | * ixgbe_poll will re-enable the queue interrupts |
| 2983 | */ |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2984 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2985 | ixgbe_irq_enable(adapter, false, false); |
| 2986 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2987 | return IRQ_HANDLED; |
| 2988 | } |
| 2989 | |
| 2990 | /** |
| 2991 | * ixgbe_request_irq - initialize interrupts |
| 2992 | * @adapter: board private structure |
| 2993 | * |
| 2994 | * Attempts to configure interrupts using the best available |
| 2995 | * capabilities of the hardware and kernel. |
| 2996 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2997 | static int ixgbe_request_irq(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2998 | { |
| 2999 | struct net_device *netdev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3000 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3001 | |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 3002 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3003 | err = ixgbe_request_msix_irqs(adapter); |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 3004 | else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 3005 | err = request_irq(adapter->pdev->irq, ixgbe_intr, 0, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 3006 | netdev->name, adapter); |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 3007 | else |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 3008 | err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 3009 | netdev->name, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3010 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 3011 | if (err) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 3012 | e_err(probe, "request_irq failed, Error %d\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3013 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3014 | return err; |
| 3015 | } |
| 3016 | |
| 3017 | static void ixgbe_free_irq(struct ixgbe_adapter *adapter) |
| 3018 | { |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3019 | int vector; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3020 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3021 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 3022 | free_irq(adapter->pdev->irq, adapter); |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3023 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3024 | } |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3025 | |
| 3026 | for (vector = 0; vector < adapter->num_q_vectors; vector++) { |
| 3027 | struct ixgbe_q_vector *q_vector = adapter->q_vector[vector]; |
| 3028 | struct msix_entry *entry = &adapter->msix_entries[vector]; |
| 3029 | |
| 3030 | /* free only the irqs that were actually requested */ |
| 3031 | if (!q_vector->rx.ring && !q_vector->tx.ring) |
| 3032 | continue; |
| 3033 | |
| 3034 | /* clear the affinity_mask in the IRQ descriptor */ |
| 3035 | irq_set_affinity_hint(entry->vector, NULL); |
| 3036 | |
| 3037 | free_irq(entry->vector, q_vector); |
| 3038 | } |
| 3039 | |
| 3040 | free_irq(adapter->msix_entries[vector++].vector, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3041 | } |
| 3042 | |
| 3043 | /** |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3044 | * ixgbe_irq_disable - Mask off interrupt generation on the NIC |
| 3045 | * @adapter: board private structure |
| 3046 | **/ |
| 3047 | static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter) |
| 3048 | { |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3049 | switch (adapter->hw.mac.type) { |
| 3050 | case ixgbe_mac_82598EB: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 3051 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3052 | break; |
| 3053 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3054 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 3055 | case ixgbe_mac_X550: |
| 3056 | case ixgbe_mac_X550EM_x: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 3057 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000); |
| 3058 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3059 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3060 | break; |
| 3061 | default: |
| 3062 | break; |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3063 | } |
| 3064 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 3065 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3066 | int vector; |
| 3067 | |
| 3068 | for (vector = 0; vector < adapter->num_q_vectors; vector++) |
| 3069 | synchronize_irq(adapter->msix_entries[vector].vector); |
| 3070 | |
| 3071 | synchronize_irq(adapter->msix_entries[vector++].vector); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3072 | } else { |
| 3073 | synchronize_irq(adapter->pdev->irq); |
| 3074 | } |
| 3075 | } |
| 3076 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3077 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3078 | * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts |
| 3079 | * |
| 3080 | **/ |
| 3081 | static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter) |
| 3082 | { |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 3083 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3084 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 3085 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3086 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3087 | ixgbe_set_ivar(adapter, 0, 0, 0); |
| 3088 | ixgbe_set_ivar(adapter, 1, 0, 0); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3089 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 3090 | e_info(hw, "Legacy interrupt IVAR setup done\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3091 | } |
| 3092 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3093 | /** |
| 3094 | * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset |
| 3095 | * @adapter: board private structure |
| 3096 | * @ring: structure containing ring specific data |
| 3097 | * |
| 3098 | * Configure the Tx descriptor ring after a reset. |
| 3099 | **/ |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 3100 | void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter, |
| 3101 | struct ixgbe_ring *ring) |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3102 | { |
| 3103 | struct ixgbe_hw *hw = &adapter->hw; |
| 3104 | u64 tdba = ring->dma; |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3105 | int wait_loop = 10; |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3106 | u32 txdctl = IXGBE_TXDCTL_ENABLE; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3107 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3108 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3109 | /* disable queue to avoid issues while updating state */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3110 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3111 | IXGBE_WRITE_FLUSH(hw); |
| 3112 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3113 | IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3114 | (tdba & DMA_BIT_MASK(32))); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3115 | IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32)); |
| 3116 | IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx), |
| 3117 | ring->count * sizeof(union ixgbe_adv_tx_desc)); |
| 3118 | IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0); |
| 3119 | IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 3120 | ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3121 | |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3122 | /* |
| 3123 | * set WTHRESH to encourage burst writeback, it should not be set |
Emil Tantilov | 67da097 | 2013-01-25 06:19:20 +0000 | [diff] [blame] | 3124 | * higher than 1 when: |
| 3125 | * - ITR is 0 as it could cause false TX hangs |
| 3126 | * - ITR is set to > 100k int/sec and BQL is enabled |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3127 | * |
| 3128 | * In order to avoid issues WTHRESH + PTHRESH should always be equal |
| 3129 | * to or less than the number of on chip descriptors, which is |
| 3130 | * currently 40. |
| 3131 | */ |
Emil Tantilov | 67da097 | 2013-01-25 06:19:20 +0000 | [diff] [blame] | 3132 | if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR)) |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3133 | txdctl |= (1 << 16); /* WTHRESH = 1 */ |
| 3134 | else |
| 3135 | txdctl |= (8 << 16); /* WTHRESH = 8 */ |
| 3136 | |
Alexander Duyck | e954b37 | 2012-02-08 07:49:38 +0000 | [diff] [blame] | 3137 | /* |
| 3138 | * Setting PTHRESH to 32 both improves performance |
| 3139 | * and avoids a TX hang with DFP enabled |
| 3140 | */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3141 | txdctl |= (1 << 8) | /* HTHRESH = 1 */ |
| 3142 | 32; /* PTHRESH = 32 */ |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3143 | |
| 3144 | /* reinitialize flowdirector state */ |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 3145 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 3146 | ring->atr_sample_rate = adapter->atr_sample_rate; |
| 3147 | ring->atr_count = 0; |
| 3148 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state); |
| 3149 | } else { |
| 3150 | ring->atr_sample_rate = 0; |
| 3151 | } |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3152 | |
Alexander Duyck | fd786b7 | 2013-01-12 06:33:31 +0000 | [diff] [blame] | 3153 | /* initialize XPS */ |
| 3154 | if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) { |
| 3155 | struct ixgbe_q_vector *q_vector = ring->q_vector; |
| 3156 | |
| 3157 | if (q_vector) |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 3158 | netif_set_xps_queue(ring->netdev, |
Alexander Duyck | fd786b7 | 2013-01-12 06:33:31 +0000 | [diff] [blame] | 3159 | &q_vector->affinity_mask, |
| 3160 | ring->queue_index); |
| 3161 | } |
| 3162 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 3163 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state); |
| 3164 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3165 | /* enable queue */ |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3166 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl); |
| 3167 | |
| 3168 | /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 3169 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 3170 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 3171 | return; |
| 3172 | |
| 3173 | /* poll to verify queue is enabled */ |
| 3174 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 3175 | usleep_range(1000, 2000); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3176 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx)); |
| 3177 | } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE)); |
| 3178 | if (!wait_loop) |
| 3179 | e_err(drv, "Could not enable Tx Queue %d\n", reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3180 | } |
| 3181 | |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 3182 | static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter) |
| 3183 | { |
| 3184 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3185 | u32 rttdcs, mtqc; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3186 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 3187 | |
| 3188 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3189 | return; |
| 3190 | |
| 3191 | /* disable the arbiter while setting MTQC */ |
| 3192 | rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS); |
| 3193 | rttdcs |= IXGBE_RTTDCS_ARBDIS; |
| 3194 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 3195 | |
| 3196 | /* set transmit pool layout */ |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3197 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 3198 | mtqc = IXGBE_MTQC_VT_ENA; |
| 3199 | if (tcs > 4) |
| 3200 | mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ; |
| 3201 | else if (tcs > 1) |
| 3202 | mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ; |
| 3203 | else if (adapter->ring_feature[RING_F_RSS].indices == 4) |
| 3204 | mtqc |= IXGBE_MTQC_32VF; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3205 | else |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3206 | mtqc |= IXGBE_MTQC_64VF; |
| 3207 | } else { |
| 3208 | if (tcs > 4) |
| 3209 | mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ; |
| 3210 | else if (tcs > 1) |
| 3211 | mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ; |
| 3212 | else |
| 3213 | mtqc = IXGBE_MTQC_64Q_1PB; |
| 3214 | } |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3215 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3216 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3217 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3218 | /* Enable Security TX Buffer IFG for multiple pb */ |
| 3219 | if (tcs) { |
| 3220 | u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG); |
| 3221 | sectx |= IXGBE_SECTX_DCB; |
| 3222 | IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx); |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 3223 | } |
| 3224 | |
| 3225 | /* re-enable the arbiter */ |
| 3226 | rttdcs &= ~IXGBE_RTTDCS_ARBDIS; |
| 3227 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 3228 | } |
| 3229 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3230 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3231 | * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3232 | * @adapter: board private structure |
| 3233 | * |
| 3234 | * Configure the Tx unit of the MAC after a reset. |
| 3235 | **/ |
| 3236 | static void ixgbe_configure_tx(struct ixgbe_adapter *adapter) |
| 3237 | { |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3238 | struct ixgbe_hw *hw = &adapter->hw; |
| 3239 | u32 dmatxctl; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3240 | u32 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3241 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3242 | ixgbe_setup_mtqc(adapter); |
| 3243 | |
| 3244 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 3245 | /* DMATXCTL.EN must be before Tx queues are enabled */ |
| 3246 | dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); |
| 3247 | dmatxctl |= IXGBE_DMATXCTL_TE; |
| 3248 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl); |
| 3249 | } |
| 3250 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3251 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3252 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 3253 | ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3254 | } |
| 3255 | |
Alexander Duyck | 3ebe8fd | 2012-04-25 04:36:38 +0000 | [diff] [blame] | 3256 | static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter, |
| 3257 | struct ixgbe_ring *ring) |
| 3258 | { |
| 3259 | struct ixgbe_hw *hw = &adapter->hw; |
| 3260 | u8 reg_idx = ring->reg_idx; |
| 3261 | u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx)); |
| 3262 | |
| 3263 | srrctl |= IXGBE_SRRCTL_DROP_EN; |
| 3264 | |
| 3265 | IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl); |
| 3266 | } |
| 3267 | |
| 3268 | static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter, |
| 3269 | struct ixgbe_ring *ring) |
| 3270 | { |
| 3271 | struct ixgbe_hw *hw = &adapter->hw; |
| 3272 | u8 reg_idx = ring->reg_idx; |
| 3273 | u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx)); |
| 3274 | |
| 3275 | srrctl &= ~IXGBE_SRRCTL_DROP_EN; |
| 3276 | |
| 3277 | IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl); |
| 3278 | } |
| 3279 | |
| 3280 | #ifdef CONFIG_IXGBE_DCB |
| 3281 | void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter) |
| 3282 | #else |
| 3283 | static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter) |
| 3284 | #endif |
| 3285 | { |
| 3286 | int i; |
| 3287 | bool pfc_en = adapter->dcb_cfg.pfc_mode_enable; |
| 3288 | |
| 3289 | if (adapter->ixgbe_ieee_pfc) |
| 3290 | pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en); |
| 3291 | |
| 3292 | /* |
| 3293 | * We should set the drop enable bit if: |
| 3294 | * SR-IOV is enabled |
| 3295 | * or |
| 3296 | * Number of Rx queues > 1 and flow control is disabled |
| 3297 | * |
| 3298 | * This allows us to avoid head of line blocking for security |
| 3299 | * and performance reasons. |
| 3300 | */ |
| 3301 | if (adapter->num_vfs || (adapter->num_rx_queues > 1 && |
| 3302 | !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) { |
| 3303 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3304 | ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]); |
| 3305 | } else { |
| 3306 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3307 | ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]); |
| 3308 | } |
| 3309 | } |
| 3310 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3311 | #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3312 | |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 3313 | static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3314 | struct ixgbe_ring *rx_ring) |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3315 | { |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3316 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3317 | u32 srrctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3318 | u8 reg_idx = rx_ring->reg_idx; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3319 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3320 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 3321 | u16 mask = adapter->ring_feature[RING_F_RSS].mask; |
| 3322 | |
| 3323 | /* |
| 3324 | * if VMDq is not active we must program one srrctl register |
| 3325 | * per RSS queue since we have enabled RDRXCTL.MVMEN |
| 3326 | */ |
| 3327 | reg_idx &= mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3328 | } |
| 3329 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3330 | /* configure header buffer length, needed for RSC */ |
| 3331 | srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3332 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3333 | /* configure the packet buffer length */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 3334 | srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3335 | |
| 3336 | /* configure descriptor type */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 3337 | srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3338 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3339 | IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3340 | } |
| 3341 | |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3342 | /** |
Jean Sacren | a897a2a | 2015-09-19 05:08:44 -0600 | [diff] [blame] | 3343 | * ixgbe_rss_indir_tbl_entries - Return RSS indirection table entries |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3344 | * @adapter: device handle |
| 3345 | * |
| 3346 | * - 82598/82599/X540: 128 |
| 3347 | * - X550(non-SRIOV mode): 512 |
| 3348 | * - X550(SRIOV mode): 64 |
| 3349 | */ |
Vlad Zolotarov | 7f276ef | 2015-03-30 21:18:58 +0300 | [diff] [blame] | 3350 | u32 ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3351 | { |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3352 | if (adapter->hw.mac.type < ixgbe_mac_X550) |
| 3353 | return 128; |
| 3354 | else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 3355 | return 64; |
| 3356 | else |
| 3357 | return 512; |
| 3358 | } |
| 3359 | |
| 3360 | /** |
Jean Sacren | a897a2a | 2015-09-19 05:08:44 -0600 | [diff] [blame] | 3361 | * ixgbe_store_reta - Write the RETA table to HW |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3362 | * @adapter: device handle |
| 3363 | * |
| 3364 | * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW. |
| 3365 | */ |
Tom Barbette | 1c7cf07 | 2015-06-26 15:40:18 +0200 | [diff] [blame] | 3366 | void ixgbe_store_reta(struct ixgbe_adapter *adapter) |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3367 | { |
| 3368 | u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter); |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3369 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3370 | u32 reta = 0; |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3371 | u32 indices_multi; |
| 3372 | u8 *indir_tbl = adapter->rss_indir_tbl; |
John Fastabend | 86b4db3 | 2011-04-26 07:26:19 +0000 | [diff] [blame] | 3373 | |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3374 | /* Fill out the redirection table as follows: |
| 3375 | * - 82598: 8 bit wide entries containing pair of 4 bit RSS |
| 3376 | * indices. |
| 3377 | * - 82599/X540: 8 bit wide entries containing 4 bit RSS index |
| 3378 | * - X550: 8 bit wide entries containing 6 bit RSS index |
| 3379 | */ |
| 3380 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 3381 | indices_multi = 0x11; |
| 3382 | else |
| 3383 | indices_multi = 0x1; |
| 3384 | |
| 3385 | /* Write redirection table to HW */ |
| 3386 | for (i = 0; i < reta_entries; i++) { |
| 3387 | reta |= indices_multi * indir_tbl[i] << (i & 0x3) * 8; |
| 3388 | if ((i & 3) == 3) { |
| 3389 | if (i < 128) |
| 3390 | IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); |
| 3391 | else |
| 3392 | IXGBE_WRITE_REG(hw, IXGBE_ERETA((i >> 2) - 32), |
| 3393 | reta); |
| 3394 | reta = 0; |
| 3395 | } |
| 3396 | } |
| 3397 | } |
| 3398 | |
| 3399 | /** |
Jean Sacren | a897a2a | 2015-09-19 05:08:44 -0600 | [diff] [blame] | 3400 | * 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] | 3401 | * @adapter: device handle |
| 3402 | * |
| 3403 | * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW. |
| 3404 | */ |
| 3405 | static void ixgbe_store_vfreta(struct ixgbe_adapter *adapter) |
| 3406 | { |
| 3407 | u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter); |
| 3408 | struct ixgbe_hw *hw = &adapter->hw; |
| 3409 | u32 vfreta = 0; |
| 3410 | unsigned int pf_pool = adapter->num_vfs; |
| 3411 | |
| 3412 | /* Write redirection table to HW */ |
| 3413 | for (i = 0; i < reta_entries; i++) { |
| 3414 | vfreta |= (u32)adapter->rss_indir_tbl[i] << (i & 0x3) * 8; |
| 3415 | if ((i & 3) == 3) { |
| 3416 | IXGBE_WRITE_REG(hw, IXGBE_PFVFRETA(i >> 2, pf_pool), |
| 3417 | vfreta); |
| 3418 | vfreta = 0; |
| 3419 | } |
| 3420 | } |
| 3421 | } |
| 3422 | |
| 3423 | static void ixgbe_setup_reta(struct ixgbe_adapter *adapter) |
| 3424 | { |
| 3425 | struct ixgbe_hw *hw = &adapter->hw; |
| 3426 | u32 i, j; |
| 3427 | u32 reta_entries = ixgbe_rss_indir_tbl_entries(adapter); |
| 3428 | u16 rss_i = adapter->ring_feature[RING_F_RSS].indices; |
| 3429 | |
| 3430 | /* Program table for at least 2 queues w/ SR-IOV so that VFs can |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3431 | * make full use of any rings they may have. We will use the |
| 3432 | * PSRTYPE register to control how many rings we use within the PF. |
| 3433 | */ |
| 3434 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 2)) |
| 3435 | rss_i = 2; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3436 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3437 | /* Fill out hash function seeds */ |
| 3438 | for (i = 0; i < 10; i++) |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3439 | IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), adapter->rss_key[i]); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3440 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3441 | /* Fill out redirection table */ |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3442 | memset(adapter->rss_indir_tbl, 0, sizeof(adapter->rss_indir_tbl)); |
| 3443 | |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3444 | for (i = 0, j = 0; i < reta_entries; i++, j++) { |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3445 | if (j == rss_i) |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3446 | j = 0; |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3447 | |
| 3448 | adapter->rss_indir_tbl[i] = j; |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3449 | } |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3450 | |
| 3451 | ixgbe_store_reta(adapter); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3452 | } |
| 3453 | |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3454 | static void ixgbe_setup_vfreta(struct ixgbe_adapter *adapter) |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3455 | { |
| 3456 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3457 | u16 rss_i = adapter->ring_feature[RING_F_RSS].indices; |
| 3458 | unsigned int pf_pool = adapter->num_vfs; |
| 3459 | int i, j; |
| 3460 | |
| 3461 | /* Fill out hash function seeds */ |
| 3462 | for (i = 0; i < 10; i++) |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3463 | IXGBE_WRITE_REG(hw, IXGBE_PFVFRSSRK(i, pf_pool), |
| 3464 | adapter->rss_key[i]); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3465 | |
| 3466 | /* Fill out the redirection table */ |
| 3467 | for (i = 0, j = 0; i < 64; i++, j++) { |
| 3468 | if (j == rss_i) |
| 3469 | j = 0; |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3470 | |
| 3471 | adapter->rss_indir_tbl[i] = j; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3472 | } |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3473 | |
| 3474 | ixgbe_store_vfreta(adapter); |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3475 | } |
| 3476 | |
| 3477 | static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter) |
| 3478 | { |
| 3479 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3480 | u32 mrqc = 0, rss_field = 0, vfmrqc = 0; |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3481 | u32 rxcsum; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3482 | |
| 3483 | /* Disable indicating checksum in descriptor, enables RSS hash */ |
| 3484 | rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); |
| 3485 | rxcsum |= IXGBE_RXCSUM_PCSD; |
| 3486 | IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); |
| 3487 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3488 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 3489 | if (adapter->ring_feature[RING_F_RSS].mask) |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3490 | mrqc = IXGBE_MRQC_RSSEN; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3491 | } else { |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3492 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3493 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3494 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 3495 | if (tcs > 4) |
| 3496 | mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */ |
| 3497 | else if (tcs > 1) |
| 3498 | mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */ |
| 3499 | else if (adapter->ring_feature[RING_F_RSS].indices == 4) |
| 3500 | mrqc = IXGBE_MRQC_VMDQRSS32EN; |
| 3501 | else |
| 3502 | mrqc = IXGBE_MRQC_VMDQRSS64EN; |
| 3503 | } else { |
| 3504 | if (tcs > 4) |
| 3505 | mrqc = IXGBE_MRQC_RTRSS8TCEN; |
| 3506 | else if (tcs > 1) |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3507 | mrqc = IXGBE_MRQC_RTRSS4TCEN; |
| 3508 | else |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3509 | mrqc = IXGBE_MRQC_RSSEN; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3510 | } |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3511 | } |
| 3512 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3513 | /* Perform hash on these packet types */ |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3514 | rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4 | |
| 3515 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP | |
| 3516 | IXGBE_MRQC_RSS_FIELD_IPV6 | |
| 3517 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3518 | |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 3519 | if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP) |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3520 | rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP; |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 3521 | if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP) |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3522 | rss_field |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP; |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 3523 | |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3524 | netdev_rss_key_fill(adapter->rss_key, sizeof(adapter->rss_key)); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3525 | if ((hw->mac.type >= ixgbe_mac_X550) && |
| 3526 | (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) { |
| 3527 | unsigned int pf_pool = adapter->num_vfs; |
| 3528 | |
| 3529 | /* Enable VF RSS mode */ |
| 3530 | mrqc |= IXGBE_MRQC_MULTIPLE_RSS; |
| 3531 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
| 3532 | |
| 3533 | /* Setup RSS through the VF registers */ |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3534 | ixgbe_setup_vfreta(adapter); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3535 | vfmrqc = IXGBE_MRQC_RSSEN; |
| 3536 | vfmrqc |= rss_field; |
| 3537 | IXGBE_WRITE_REG(hw, IXGBE_PFVFMRQC(pf_pool), vfmrqc); |
| 3538 | } else { |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3539 | ixgbe_setup_reta(adapter); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3540 | mrqc |= rss_field; |
| 3541 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
| 3542 | } |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3543 | } |
| 3544 | |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3545 | /** |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3546 | * ixgbe_configure_rscctl - enable RSC for the indicated ring |
| 3547 | * @adapter: address of board private structure |
| 3548 | * @index: index of ring to set |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3549 | **/ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 3550 | static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3551 | struct ixgbe_ring *ring) |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3552 | { |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3553 | struct ixgbe_hw *hw = &adapter->hw; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3554 | u32 rscctrl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3555 | u8 reg_idx = ring->reg_idx; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3556 | |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3557 | if (!ring_is_rsc_enabled(ring)) |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3558 | return; |
| 3559 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3560 | rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx)); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3561 | rscctrl |= IXGBE_RSCCTL_RSCEN; |
| 3562 | /* |
| 3563 | * we must limit the number of descriptors so that the |
| 3564 | * total size of max desc * buf_len is not greater |
Alexander Duyck | 642c680 | 2011-11-10 09:09:17 +0000 | [diff] [blame] | 3565 | * than 65536 |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3566 | */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 3567 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3568 | IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3569 | } |
| 3570 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3571 | #define IXGBE_MAX_RX_DESC_POLL 10 |
| 3572 | static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter, |
| 3573 | struct ixgbe_ring *ring) |
| 3574 | { |
| 3575 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3576 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 3577 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3578 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3579 | |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 3580 | if (ixgbe_removed(hw->hw_addr)) |
| 3581 | return; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3582 | /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 3583 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 3584 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 3585 | return; |
| 3586 | |
| 3587 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 3588 | usleep_range(1000, 2000); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3589 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 3590 | } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 3591 | |
| 3592 | if (!wait_loop) { |
| 3593 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within " |
| 3594 | "the polling period\n", reg_idx); |
| 3595 | } |
| 3596 | } |
| 3597 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 3598 | void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter, |
| 3599 | struct ixgbe_ring *ring) |
| 3600 | { |
| 3601 | struct ixgbe_hw *hw = &adapter->hw; |
| 3602 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 3603 | u32 rxdctl; |
| 3604 | u8 reg_idx = ring->reg_idx; |
| 3605 | |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 3606 | if (ixgbe_removed(hw->hw_addr)) |
| 3607 | return; |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 3608 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 3609 | rxdctl &= ~IXGBE_RXDCTL_ENABLE; |
| 3610 | |
| 3611 | /* write value back with RXDCTL.ENABLE bit cleared */ |
| 3612 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 3613 | |
| 3614 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 3615 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 3616 | return; |
| 3617 | |
| 3618 | /* the hardware may take up to 100us to really disable the rx queue */ |
| 3619 | do { |
| 3620 | udelay(10); |
| 3621 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 3622 | } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 3623 | |
| 3624 | if (!wait_loop) { |
| 3625 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within " |
| 3626 | "the polling period\n", reg_idx); |
| 3627 | } |
| 3628 | } |
| 3629 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 3630 | void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter, |
| 3631 | struct ixgbe_ring *ring) |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3632 | { |
| 3633 | struct ixgbe_hw *hw = &adapter->hw; |
| 3634 | u64 rdba = ring->dma; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3635 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3636 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3637 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3638 | /* disable queue to avoid issues while updating state */ |
| 3639 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 3640 | ixgbe_disable_rx_queue(adapter, ring); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3641 | |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3642 | IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32))); |
| 3643 | IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32)); |
| 3644 | IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx), |
| 3645 | ring->count * sizeof(union ixgbe_adv_rx_desc)); |
Neerav Parikh | 8b75451 | 2015-12-08 22:13:58 -0800 | [diff] [blame] | 3646 | /* Force flushing of IXGBE_RDLEN to prevent MDD */ |
| 3647 | IXGBE_WRITE_FLUSH(hw); |
| 3648 | |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3649 | IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0); |
| 3650 | IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 3651 | ring->tail = adapter->io_addr + IXGBE_RDT(reg_idx); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3652 | |
| 3653 | ixgbe_configure_srrctl(adapter, ring); |
| 3654 | ixgbe_configure_rscctl(adapter, ring); |
| 3655 | |
| 3656 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 3657 | /* |
| 3658 | * enable cache line friendly hardware writes: |
| 3659 | * PTHRESH=32 descriptors (half the internal cache), |
| 3660 | * this also removes ugly rx_no_buffer_count increment |
| 3661 | * HTHRESH=4 descriptors (to minimize latency on fetch) |
| 3662 | * WTHRESH=8 burst writeback up to two cache lines |
| 3663 | */ |
| 3664 | rxdctl &= ~0x3FFFFF; |
| 3665 | rxdctl |= 0x080420; |
| 3666 | } |
| 3667 | |
| 3668 | /* enable receive descriptor ring */ |
| 3669 | rxdctl |= IXGBE_RXDCTL_ENABLE; |
| 3670 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 3671 | |
| 3672 | ixgbe_rx_desc_queue_enable(adapter, ring); |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 3673 | ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring)); |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3674 | } |
| 3675 | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3676 | static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter) |
| 3677 | { |
| 3678 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 3679 | int rss_i = adapter->ring_feature[RING_F_RSS].indices; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 3680 | u16 pool; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3681 | |
| 3682 | /* PSRTYPE must be initialized in non 82598 adapters */ |
| 3683 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3684 | IXGBE_PSRTYPE_UDPHDR | |
| 3685 | IXGBE_PSRTYPE_IPV4HDR | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3686 | IXGBE_PSRTYPE_L2HDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3687 | IXGBE_PSRTYPE_IPV6HDR; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3688 | |
| 3689 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3690 | return; |
| 3691 | |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 3692 | if (rss_i > 3) |
| 3693 | psrtype |= 2 << 29; |
| 3694 | else if (rss_i > 1) |
| 3695 | psrtype |= 1 << 29; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3696 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 3697 | for_each_set_bit(pool, &adapter->fwd_bitmask, 32) |
| 3698 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype); |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3699 | } |
| 3700 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3701 | static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter) |
| 3702 | { |
| 3703 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3704 | u32 reg_offset, vf_shift; |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3705 | u32 gcr_ext, vmdctl; |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 3706 | int i; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3707 | |
| 3708 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 3709 | return; |
| 3710 | |
| 3711 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL); |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3712 | vmdctl |= IXGBE_VMD_CTL_VMDQ_EN; |
| 3713 | vmdctl &= ~IXGBE_VT_CTL_POOL_MASK; |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3714 | vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT; |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3715 | vmdctl |= IXGBE_VT_CTL_REPLEN; |
| 3716 | IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3717 | |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3718 | vf_shift = VMDQ_P(0) % 32; |
| 3719 | reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3720 | |
| 3721 | /* Enable only the PF's pool for Tx/Rx */ |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3722 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (~0) << vf_shift); |
| 3723 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1); |
| 3724 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (~0) << vf_shift); |
| 3725 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1); |
Don Skidmore | aa2bacb | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 3726 | if (adapter->bridge_mode == BRIDGE_MODE_VEB) |
Greg Rose | 9b73598 | 2012-11-08 02:41:35 +0000 | [diff] [blame] | 3727 | IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3728 | |
| 3729 | /* 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] | 3730 | hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0)); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3731 | |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 3732 | /* clear VLAN promisc flag so VFTA will be updated if necessary */ |
| 3733 | adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC; |
| 3734 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3735 | /* |
| 3736 | * Set up VF register offsets for selected VT Mode, |
| 3737 | * i.e. 32 or 64 VFs for SR-IOV |
| 3738 | */ |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 3739 | switch (adapter->ring_feature[RING_F_VMDQ].mask) { |
| 3740 | case IXGBE_82599_VMDQ_8Q_MASK: |
| 3741 | gcr_ext = IXGBE_GCR_EXT_VT_MODE_16; |
| 3742 | break; |
| 3743 | case IXGBE_82599_VMDQ_4Q_MASK: |
| 3744 | gcr_ext = IXGBE_GCR_EXT_VT_MODE_32; |
| 3745 | break; |
| 3746 | default: |
| 3747 | gcr_ext = IXGBE_GCR_EXT_VT_MODE_64; |
| 3748 | break; |
| 3749 | } |
| 3750 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3751 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext); |
| 3752 | |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3753 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 3754 | /* Enable MAC Anti-Spoofing */ |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3755 | hw->mac.ops.set_mac_anti_spoofing(hw, (adapter->num_vfs != 0), |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 3756 | adapter->num_vfs); |
Don Skidmore | 5b7f000 | 2015-01-28 07:03:38 +0000 | [diff] [blame] | 3757 | |
Emil Tantilov | f079fa0 | 2015-08-20 15:31:20 -0700 | [diff] [blame] | 3758 | /* Ensure LLDP and FC is set for Ethertype Antispoofing if we will be |
Don Skidmore | 5b7f000 | 2015-01-28 07:03:38 +0000 | [diff] [blame] | 3759 | * calling set_ethertype_anti_spoofing for each VF in loop below |
| 3760 | */ |
Emil Tantilov | f079fa0 | 2015-08-20 15:31:20 -0700 | [diff] [blame] | 3761 | if (hw->mac.ops.set_ethertype_anti_spoofing) { |
Don Skidmore | 5b7f000 | 2015-01-28 07:03:38 +0000 | [diff] [blame] | 3762 | IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_LLDP), |
Emil Tantilov | f079fa0 | 2015-08-20 15:31:20 -0700 | [diff] [blame] | 3763 | (IXGBE_ETQF_FILTER_EN | |
| 3764 | IXGBE_ETQF_TX_ANTISPOOF | |
| 3765 | IXGBE_ETH_P_LLDP)); |
| 3766 | |
| 3767 | IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_FC), |
| 3768 | (IXGBE_ETQF_FILTER_EN | |
| 3769 | IXGBE_ETQF_TX_ANTISPOOF | |
| 3770 | ETH_P_PAUSE)); |
| 3771 | } |
Don Skidmore | 5b7f000 | 2015-01-28 07:03:38 +0000 | [diff] [blame] | 3772 | |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 3773 | /* For VFs that have spoof checking turned off */ |
| 3774 | for (i = 0; i < adapter->num_vfs; i++) { |
| 3775 | if (!adapter->vfinfo[i].spoofchk_enabled) |
| 3776 | ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false); |
Don Skidmore | 5b7f000 | 2015-01-28 07:03:38 +0000 | [diff] [blame] | 3777 | |
| 3778 | /* enable ethertype anti spoofing if hw supports it */ |
| 3779 | if (hw->mac.ops.set_ethertype_anti_spoofing) |
| 3780 | hw->mac.ops.set_ethertype_anti_spoofing(hw, true, i); |
Vlad Zolotarov | e65ce0d | 2015-03-30 21:35:24 +0300 | [diff] [blame] | 3781 | |
| 3782 | /* Enable/Disable RSS query feature */ |
| 3783 | ixgbe_ndo_set_vf_rss_query_en(adapter->netdev, i, |
| 3784 | adapter->vfinfo[i].rss_query_enabled); |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 3785 | } |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3786 | } |
| 3787 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3788 | static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3789 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3790 | struct ixgbe_hw *hw = &adapter->hw; |
| 3791 | struct net_device *netdev = adapter->netdev; |
| 3792 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3793 | struct ixgbe_ring *rx_ring; |
| 3794 | int i; |
| 3795 | u32 mhadd, hlreg0; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3796 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3797 | #ifdef IXGBE_FCOE |
| 3798 | /* adjust max frame to be able to do baby jumbo for FCoE */ |
| 3799 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 3800 | (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE)) |
| 3801 | max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 3802 | |
| 3803 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 3804 | |
| 3805 | /* adjust max frame to be at least the size of a standard frame */ |
| 3806 | if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN)) |
| 3807 | max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN); |
| 3808 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3809 | mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD); |
| 3810 | if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) { |
| 3811 | mhadd &= ~IXGBE_MHADD_MFS_MASK; |
| 3812 | mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT; |
| 3813 | |
| 3814 | IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3815 | } |
| 3816 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3817 | hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3818 | /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */ |
| 3819 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3820 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0); |
| 3821 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3822 | /* |
| 3823 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3824 | * the Base and Length of the Rx Descriptor Ring |
| 3825 | */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3826 | for (i = 0; i < adapter->num_rx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3827 | rx_ring = adapter->rx_ring[i]; |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3828 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
| 3829 | set_ring_rsc_enabled(rx_ring); |
| 3830 | else |
| 3831 | clear_ring_rsc_enabled(rx_ring); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3832 | } |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3833 | } |
| 3834 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3835 | static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter) |
| 3836 | { |
| 3837 | struct ixgbe_hw *hw = &adapter->hw; |
| 3838 | u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 3839 | |
| 3840 | switch (hw->mac.type) { |
| 3841 | case ixgbe_mac_82598EB: |
| 3842 | /* |
| 3843 | * For VMDq support of different descriptor types or |
| 3844 | * buffer sizes through the use of multiple SRRCTL |
| 3845 | * registers, RDRXCTL.MVMEN must be set to 1 |
| 3846 | * |
| 3847 | * also, the manual doesn't mention it clearly but DCA hints |
| 3848 | * will only use queue 0's tags unless this bit is set. Side |
| 3849 | * effects of setting this bit are only that SRRCTL must be |
| 3850 | * fully programmed [0..15] |
| 3851 | */ |
| 3852 | rdrxctl |= IXGBE_RDRXCTL_MVMEN; |
| 3853 | break; |
Mark Rustad | 052a1a7 | 2015-08-08 16:19:04 -0700 | [diff] [blame] | 3854 | case ixgbe_mac_X550: |
| 3855 | case ixgbe_mac_X550EM_x: |
Mark Rustad | f961dda | 2015-08-08 16:19:09 -0700 | [diff] [blame] | 3856 | if (adapter->num_vfs) |
| 3857 | rdrxctl |= IXGBE_RDRXCTL_PSP; |
| 3858 | /* fall through for older HW */ |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3859 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3860 | case ixgbe_mac_X540: |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3861 | /* Disable RSC for ACK packets */ |
| 3862 | IXGBE_WRITE_REG(hw, IXGBE_RSCDBU, |
| 3863 | (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU))); |
| 3864 | rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE; |
| 3865 | /* hardware requires some bits to be set by default */ |
| 3866 | rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX); |
| 3867 | rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP; |
| 3868 | break; |
| 3869 | default: |
| 3870 | /* We should do nothing since we don't know this hardware */ |
| 3871 | return; |
| 3872 | } |
| 3873 | |
| 3874 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
| 3875 | } |
| 3876 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3877 | /** |
| 3878 | * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset |
| 3879 | * @adapter: board private structure |
| 3880 | * |
| 3881 | * Configure the Rx unit of the MAC after a reset. |
| 3882 | **/ |
| 3883 | static void ixgbe_configure_rx(struct ixgbe_adapter *adapter) |
| 3884 | { |
| 3885 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3886 | int i; |
Jacob Keller | 6dcc28b | 2013-07-17 02:53:23 +0000 | [diff] [blame] | 3887 | u32 rxctrl, rfctl; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3888 | |
| 3889 | /* disable receives while setting up the descriptors */ |
Don Skidmore | 1f9ac57 | 2015-03-13 13:54:30 -0700 | [diff] [blame] | 3890 | hw->mac.ops.disable_rx(hw); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3891 | |
| 3892 | ixgbe_setup_psrtype(adapter); |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3893 | ixgbe_setup_rdrxctl(adapter); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3894 | |
Jacob Keller | 6dcc28b | 2013-07-17 02:53:23 +0000 | [diff] [blame] | 3895 | /* RSC Setup */ |
| 3896 | rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL); |
| 3897 | rfctl &= ~IXGBE_RFCTL_RSC_DIS; |
| 3898 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) |
| 3899 | rfctl |= IXGBE_RFCTL_RSC_DIS; |
| 3900 | IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl); |
| 3901 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3902 | /* Program registers for the distribution of queues */ |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3903 | ixgbe_setup_mrqc(adapter); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3904 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3905 | /* set_rx_buffer_len must be called before ring initialization */ |
| 3906 | ixgbe_set_rx_buffer_len(adapter); |
| 3907 | |
| 3908 | /* |
| 3909 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3910 | * the Base and Length of the Rx Descriptor Ring |
| 3911 | */ |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3912 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3913 | ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3914 | |
Don Skidmore | 1f9ac57 | 2015-03-13 13:54:30 -0700 | [diff] [blame] | 3915 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3916 | /* disable drop enable for 82598 parts */ |
| 3917 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3918 | rxctrl |= IXGBE_RXCTRL_DMBYPS; |
| 3919 | |
| 3920 | /* enable all receives */ |
| 3921 | rxctrl |= IXGBE_RXCTRL_RXEN; |
| 3922 | hw->mac.ops.enable_rx_dma(hw, rxctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3923 | } |
| 3924 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 3925 | static int ixgbe_vlan_rx_add_vid(struct net_device *netdev, |
| 3926 | __be16 proto, u16 vid) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3927 | { |
| 3928 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3929 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3930 | |
| 3931 | /* add VID to filter table */ |
Alexander Duyck | 18be4fc | 2016-01-06 22:48:44 -0800 | [diff] [blame] | 3932 | if (!vid || !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)) |
| 3933 | hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true, !!vid); |
| 3934 | |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3935 | set_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 3936 | |
| 3937 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3938 | } |
| 3939 | |
Alexander Duyck | e1d0a2a | 2015-11-02 17:10:19 -0800 | [diff] [blame] | 3940 | static int ixgbe_find_vlvf_entry(struct ixgbe_hw *hw, u32 vlan) |
| 3941 | { |
| 3942 | u32 vlvf; |
| 3943 | int idx; |
| 3944 | |
| 3945 | /* short cut the special case */ |
| 3946 | if (vlan == 0) |
| 3947 | return 0; |
| 3948 | |
| 3949 | /* Search for the vlan id in the VLVF entries */ |
| 3950 | for (idx = IXGBE_VLVF_ENTRIES; --idx;) { |
| 3951 | vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(idx)); |
| 3952 | if ((vlvf & VLAN_VID_MASK) == vlan) |
| 3953 | break; |
| 3954 | } |
| 3955 | |
| 3956 | return idx; |
| 3957 | } |
| 3958 | |
| 3959 | void ixgbe_update_pf_promisc_vlvf(struct ixgbe_adapter *adapter, u32 vid) |
| 3960 | { |
| 3961 | struct ixgbe_hw *hw = &adapter->hw; |
| 3962 | u32 bits, word; |
| 3963 | int idx; |
| 3964 | |
| 3965 | idx = ixgbe_find_vlvf_entry(hw, vid); |
| 3966 | if (!idx) |
| 3967 | return; |
| 3968 | |
| 3969 | /* See if any other pools are set for this VLAN filter |
| 3970 | * entry other than the PF. |
| 3971 | */ |
| 3972 | word = idx * 2 + (VMDQ_P(0) / 32); |
| 3973 | bits = ~(1 << (VMDQ_P(0)) % 32); |
| 3974 | bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word)); |
| 3975 | |
| 3976 | /* Disable the filter so this falls into the default pool. */ |
| 3977 | if (!bits && !IXGBE_READ_REG(hw, IXGBE_VLVFB(word ^ 1))) { |
| 3978 | if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)) |
| 3979 | IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), 0); |
| 3980 | IXGBE_WRITE_REG(hw, IXGBE_VLVF(idx), 0); |
| 3981 | } |
| 3982 | } |
| 3983 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 3984 | static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev, |
| 3985 | __be16 proto, u16 vid) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3986 | { |
| 3987 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3988 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3989 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3990 | /* remove VID from filter table */ |
Alexander Duyck | 18be4fc | 2016-01-06 22:48:44 -0800 | [diff] [blame] | 3991 | if (vid && !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)) |
Alexander Duyck | e1d0a2a | 2015-11-02 17:10:19 -0800 | [diff] [blame] | 3992 | hw->mac.ops.set_vfta(hw, vid, VMDQ_P(0), false, true); |
| 3993 | |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3994 | clear_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 3995 | |
| 3996 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3997 | } |
| 3998 | |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3999 | /** |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4000 | * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping |
| 4001 | * @adapter: driver data |
| 4002 | */ |
| 4003 | static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter) |
| 4004 | { |
| 4005 | struct ixgbe_hw *hw = &adapter->hw; |
| 4006 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4007 | int i, j; |
| 4008 | |
| 4009 | switch (hw->mac.type) { |
| 4010 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4011 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 4012 | vlnctrl &= ~IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4013 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4014 | break; |
| 4015 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4016 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 4017 | case ixgbe_mac_X550: |
| 4018 | case ixgbe_mac_X550EM_x: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4019 | for (i = 0; i < adapter->num_rx_queues; i++) { |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4020 | struct ixgbe_ring *ring = adapter->rx_ring[i]; |
| 4021 | |
| 4022 | if (ring->l2_accel_priv) |
| 4023 | continue; |
| 4024 | j = ring->reg_idx; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4025 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 4026 | vlnctrl &= ~IXGBE_RXDCTL_VME; |
| 4027 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 4028 | } |
| 4029 | break; |
| 4030 | default: |
| 4031 | break; |
| 4032 | } |
| 4033 | } |
| 4034 | |
| 4035 | /** |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4036 | * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4037 | * @adapter: driver data |
| 4038 | */ |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4039 | static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4040 | { |
| 4041 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4042 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4043 | int i, j; |
| 4044 | |
| 4045 | switch (hw->mac.type) { |
| 4046 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4047 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 4048 | vlnctrl |= IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4049 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4050 | break; |
| 4051 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4052 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 4053 | case ixgbe_mac_X550: |
| 4054 | case ixgbe_mac_X550EM_x: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4055 | for (i = 0; i < adapter->num_rx_queues; i++) { |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4056 | struct ixgbe_ring *ring = adapter->rx_ring[i]; |
| 4057 | |
| 4058 | if (ring->l2_accel_priv) |
| 4059 | continue; |
| 4060 | j = ring->reg_idx; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4061 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 4062 | vlnctrl |= IXGBE_RXDCTL_VME; |
| 4063 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 4064 | } |
| 4065 | break; |
| 4066 | default: |
| 4067 | break; |
| 4068 | } |
| 4069 | } |
| 4070 | |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4071 | static void ixgbe_vlan_promisc_enable(struct ixgbe_adapter *adapter) |
| 4072 | { |
| 4073 | struct ixgbe_hw *hw = &adapter->hw; |
| 4074 | u32 vlnctrl, i; |
| 4075 | |
| 4076 | switch (hw->mac.type) { |
| 4077 | case ixgbe_mac_82599EB: |
| 4078 | case ixgbe_mac_X540: |
| 4079 | case ixgbe_mac_X550: |
| 4080 | case ixgbe_mac_X550EM_x: |
| 4081 | default: |
| 4082 | if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) |
| 4083 | break; |
| 4084 | /* fall through */ |
| 4085 | case ixgbe_mac_82598EB: |
| 4086 | /* legacy case, we can just disable VLAN filtering */ |
| 4087 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 4088 | vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN); |
| 4089 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4090 | return; |
| 4091 | } |
| 4092 | |
| 4093 | /* We are already in VLAN promisc, nothing to do */ |
| 4094 | if (adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC) |
| 4095 | return; |
| 4096 | |
| 4097 | /* Set flag so we don't redo unnecessary work */ |
| 4098 | adapter->flags2 |= IXGBE_FLAG2_VLAN_PROMISC; |
| 4099 | |
| 4100 | /* Add PF to all active pools */ |
| 4101 | for (i = IXGBE_VLVF_ENTRIES; --i;) { |
| 4102 | u32 reg_offset = IXGBE_VLVFB(i * 2 + VMDQ_P(0) / 32); |
| 4103 | u32 vlvfb = IXGBE_READ_REG(hw, reg_offset); |
| 4104 | |
| 4105 | vlvfb |= 1 << (VMDQ_P(0) % 32); |
| 4106 | IXGBE_WRITE_REG(hw, reg_offset, vlvfb); |
| 4107 | } |
| 4108 | |
| 4109 | /* Set all bits in the VLAN filter table array */ |
| 4110 | for (i = hw->mac.vft_size; i--;) |
| 4111 | IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), ~0U); |
| 4112 | } |
| 4113 | |
| 4114 | #define VFTA_BLOCK_SIZE 8 |
| 4115 | static void ixgbe_scrub_vfta(struct ixgbe_adapter *adapter, u32 vfta_offset) |
| 4116 | { |
| 4117 | struct ixgbe_hw *hw = &adapter->hw; |
| 4118 | u32 vfta[VFTA_BLOCK_SIZE] = { 0 }; |
| 4119 | u32 vid_start = vfta_offset * 32; |
| 4120 | u32 vid_end = vid_start + (VFTA_BLOCK_SIZE * 32); |
| 4121 | u32 i, vid, word, bits; |
| 4122 | |
| 4123 | for (i = IXGBE_VLVF_ENTRIES; --i;) { |
| 4124 | u32 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(i)); |
| 4125 | |
| 4126 | /* pull VLAN ID from VLVF */ |
| 4127 | vid = vlvf & VLAN_VID_MASK; |
| 4128 | |
| 4129 | /* only concern outselves with a certain range */ |
| 4130 | if (vid < vid_start || vid >= vid_end) |
| 4131 | continue; |
| 4132 | |
| 4133 | if (vlvf) { |
| 4134 | /* record VLAN ID in VFTA */ |
| 4135 | vfta[(vid - vid_start) / 32] |= 1 << (vid % 32); |
| 4136 | |
| 4137 | /* if PF is part of this then continue */ |
| 4138 | if (test_bit(vid, adapter->active_vlans)) |
| 4139 | continue; |
| 4140 | } |
| 4141 | |
| 4142 | /* remove PF from the pool */ |
| 4143 | word = i * 2 + VMDQ_P(0) / 32; |
| 4144 | bits = ~(1 << (VMDQ_P(0) % 32)); |
| 4145 | bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word)); |
| 4146 | IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), bits); |
| 4147 | } |
| 4148 | |
| 4149 | /* extract values from active_vlans and write back to VFTA */ |
| 4150 | for (i = VFTA_BLOCK_SIZE; i--;) { |
| 4151 | vid = (vfta_offset + i) * 32; |
| 4152 | word = vid / BITS_PER_LONG; |
| 4153 | bits = vid % BITS_PER_LONG; |
| 4154 | |
| 4155 | vfta[i] |= adapter->active_vlans[word] >> bits; |
| 4156 | |
| 4157 | IXGBE_WRITE_REG(hw, IXGBE_VFTA(vfta_offset + i), vfta[i]); |
| 4158 | } |
| 4159 | } |
| 4160 | |
| 4161 | static void ixgbe_vlan_promisc_disable(struct ixgbe_adapter *adapter) |
| 4162 | { |
| 4163 | struct ixgbe_hw *hw = &adapter->hw; |
| 4164 | u32 vlnctrl, i; |
| 4165 | |
| 4166 | switch (hw->mac.type) { |
| 4167 | case ixgbe_mac_82599EB: |
| 4168 | case ixgbe_mac_X540: |
| 4169 | case ixgbe_mac_X550: |
| 4170 | case ixgbe_mac_X550EM_x: |
| 4171 | default: |
| 4172 | if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) |
| 4173 | break; |
| 4174 | /* fall through */ |
| 4175 | case ixgbe_mac_82598EB: |
| 4176 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 4177 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 4178 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
| 4179 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4180 | return; |
| 4181 | } |
| 4182 | |
| 4183 | /* We are not in VLAN promisc, nothing to do */ |
| 4184 | if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)) |
| 4185 | return; |
| 4186 | |
| 4187 | /* Set flag so we don't redo unnecessary work */ |
| 4188 | adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC; |
| 4189 | |
| 4190 | for (i = 0; i < hw->mac.vft_size; i += VFTA_BLOCK_SIZE) |
| 4191 | ixgbe_scrub_vfta(adapter, i); |
| 4192 | } |
| 4193 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4194 | static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter) |
| 4195 | { |
Alexander Duyck | 06bb1c3 | 2016-01-06 22:48:50 -0800 | [diff] [blame] | 4196 | u16 vid = 1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4197 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 4198 | ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4199 | |
Alexander Duyck | 06bb1c3 | 2016-01-06 22:48:50 -0800 | [diff] [blame] | 4200 | for_each_set_bit_from(vid, adapter->active_vlans, VLAN_N_VID) |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 4201 | ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4202 | } |
| 4203 | |
| 4204 | /** |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4205 | * ixgbe_write_mc_addr_list - write multicast addresses to MTA |
| 4206 | * @netdev: network interface device structure |
| 4207 | * |
| 4208 | * Writes multicast address list to the MTA hash table. |
| 4209 | * Returns: -ENOMEM on failure |
| 4210 | * 0 on no addresses written |
| 4211 | * X on writing X addresses to MTA |
| 4212 | **/ |
| 4213 | static int ixgbe_write_mc_addr_list(struct net_device *netdev) |
| 4214 | { |
| 4215 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4216 | struct ixgbe_hw *hw = &adapter->hw; |
| 4217 | |
| 4218 | if (!netif_running(netdev)) |
| 4219 | return 0; |
| 4220 | |
| 4221 | if (hw->mac.ops.update_mc_addr_list) |
| 4222 | hw->mac.ops.update_mc_addr_list(hw, netdev); |
| 4223 | else |
| 4224 | return -ENOMEM; |
| 4225 | |
| 4226 | #ifdef CONFIG_PCI_IOV |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4227 | ixgbe_restore_vf_multicasts(adapter); |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4228 | #endif |
| 4229 | |
| 4230 | return netdev_mc_count(netdev); |
| 4231 | } |
| 4232 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4233 | #ifdef CONFIG_PCI_IOV |
| 4234 | void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter) |
| 4235 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4236 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4237 | struct ixgbe_hw *hw = &adapter->hw; |
| 4238 | int i; |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4239 | |
| 4240 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4241 | mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED; |
| 4242 | |
| 4243 | if (mac_table->state & IXGBE_MAC_STATE_IN_USE) |
| 4244 | hw->mac.ops.set_rar(hw, i, |
| 4245 | mac_table->addr, |
| 4246 | mac_table->pool, |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4247 | IXGBE_RAH_AV); |
| 4248 | else |
| 4249 | hw->mac.ops.clear_rar(hw, i); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4250 | } |
| 4251 | } |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4252 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4253 | #endif |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4254 | static void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter) |
| 4255 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4256 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4257 | struct ixgbe_hw *hw = &adapter->hw; |
| 4258 | int i; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4259 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4260 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4261 | if (!(mac_table->state & IXGBE_MAC_STATE_MODIFIED)) |
| 4262 | continue; |
| 4263 | |
| 4264 | mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED; |
| 4265 | |
| 4266 | if (mac_table->state & IXGBE_MAC_STATE_IN_USE) |
| 4267 | hw->mac.ops.set_rar(hw, i, |
| 4268 | mac_table->addr, |
| 4269 | mac_table->pool, |
| 4270 | IXGBE_RAH_AV); |
| 4271 | else |
| 4272 | hw->mac.ops.clear_rar(hw, i); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4273 | } |
| 4274 | } |
| 4275 | |
| 4276 | static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter) |
| 4277 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4278 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4279 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4280 | int i; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4281 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4282 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4283 | mac_table->state |= IXGBE_MAC_STATE_MODIFIED; |
| 4284 | mac_table->state &= ~IXGBE_MAC_STATE_IN_USE; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4285 | } |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4286 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4287 | ixgbe_sync_mac_table(adapter); |
| 4288 | } |
| 4289 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4290 | static int ixgbe_available_rars(struct ixgbe_adapter *adapter, u16 pool) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4291 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4292 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4293 | struct ixgbe_hw *hw = &adapter->hw; |
| 4294 | int i, count = 0; |
| 4295 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4296 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4297 | /* do not count default RAR as available */ |
| 4298 | if (mac_table->state & IXGBE_MAC_STATE_DEFAULT) |
| 4299 | continue; |
| 4300 | |
| 4301 | /* only count unused and addresses that belong to us */ |
| 4302 | if (mac_table->state & IXGBE_MAC_STATE_IN_USE) { |
| 4303 | if (mac_table->pool != pool) |
| 4304 | continue; |
| 4305 | } |
| 4306 | |
| 4307 | count++; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4308 | } |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4309 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4310 | return count; |
| 4311 | } |
| 4312 | |
| 4313 | /* this function destroys the first RAR entry */ |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4314 | static void ixgbe_mac_set_default_filter(struct ixgbe_adapter *adapter) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4315 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4316 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4317 | struct ixgbe_hw *hw = &adapter->hw; |
| 4318 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4319 | memcpy(&mac_table->addr, hw->mac.addr, ETH_ALEN); |
| 4320 | mac_table->pool = VMDQ_P(0); |
| 4321 | |
| 4322 | mac_table->state = IXGBE_MAC_STATE_DEFAULT | IXGBE_MAC_STATE_IN_USE; |
| 4323 | |
| 4324 | 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] | 4325 | IXGBE_RAH_AV); |
| 4326 | } |
| 4327 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4328 | int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter, |
| 4329 | const u8 *addr, u16 pool) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4330 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4331 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4332 | struct ixgbe_hw *hw = &adapter->hw; |
| 4333 | int i; |
| 4334 | |
| 4335 | if (is_zero_ether_addr(addr)) |
| 4336 | return -EINVAL; |
| 4337 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4338 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4339 | if (mac_table->state & IXGBE_MAC_STATE_IN_USE) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4340 | continue; |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4341 | |
| 4342 | ether_addr_copy(mac_table->addr, addr); |
| 4343 | mac_table->pool = pool; |
| 4344 | |
| 4345 | mac_table->state |= IXGBE_MAC_STATE_MODIFIED | |
| 4346 | IXGBE_MAC_STATE_IN_USE; |
| 4347 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4348 | ixgbe_sync_mac_table(adapter); |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4349 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4350 | return i; |
| 4351 | } |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4352 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4353 | return -ENOMEM; |
| 4354 | } |
| 4355 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4356 | int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter, |
| 4357 | const u8 *addr, u16 pool) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4358 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4359 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4360 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4361 | int i; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4362 | |
| 4363 | if (is_zero_ether_addr(addr)) |
| 4364 | return -EINVAL; |
| 4365 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4366 | /* search table for addr, if found clear IN_USE flag and sync */ |
| 4367 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4368 | /* we can only delete an entry if it is in use */ |
| 4369 | if (!(mac_table->state & IXGBE_MAC_STATE_IN_USE)) |
| 4370 | continue; |
| 4371 | /* we only care about entries that belong to the given pool */ |
| 4372 | if (mac_table->pool != pool) |
| 4373 | continue; |
| 4374 | /* we only care about a specific MAC address */ |
| 4375 | if (!ether_addr_equal(addr, mac_table->addr)) |
| 4376 | continue; |
| 4377 | |
| 4378 | mac_table->state |= IXGBE_MAC_STATE_MODIFIED; |
| 4379 | mac_table->state &= ~IXGBE_MAC_STATE_IN_USE; |
| 4380 | |
| 4381 | ixgbe_sync_mac_table(adapter); |
| 4382 | |
| 4383 | return 0; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4384 | } |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4385 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4386 | return -ENOMEM; |
| 4387 | } |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4388 | /** |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4389 | * ixgbe_write_uc_addr_list - write unicast addresses to RAR table |
| 4390 | * @netdev: network interface device structure |
| 4391 | * |
| 4392 | * Writes unicast address list to the RAR table. |
| 4393 | * Returns: -ENOMEM on failure/insufficient address space |
| 4394 | * 0 on no addresses written |
| 4395 | * X on writing X addresses to the RAR table |
| 4396 | **/ |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4397 | 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] | 4398 | { |
| 4399 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4400 | int count = 0; |
| 4401 | |
| 4402 | /* return ENOMEM indicating insufficient memory for addresses */ |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4403 | if (netdev_uc_count(netdev) > ixgbe_available_rars(adapter, vfn)) |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4404 | return -ENOMEM; |
| 4405 | |
John Fastabend | 9544746 | 2012-05-31 12:42:26 +0000 | [diff] [blame] | 4406 | if (!netdev_uc_empty(netdev)) { |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4407 | struct netdev_hw_addr *ha; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4408 | netdev_for_each_uc_addr(ha, netdev) { |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4409 | ixgbe_del_mac_filter(adapter, ha->addr, vfn); |
| 4410 | ixgbe_add_mac_filter(adapter, ha->addr, vfn); |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4411 | count++; |
| 4412 | } |
| 4413 | } |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4414 | return count; |
| 4415 | } |
| 4416 | |
Alexander Duyck | 0f079d2 | 2015-10-22 16:26:36 -0700 | [diff] [blame] | 4417 | static int ixgbe_uc_sync(struct net_device *netdev, const unsigned char *addr) |
| 4418 | { |
| 4419 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4420 | int ret; |
| 4421 | |
| 4422 | ret = ixgbe_add_mac_filter(adapter, addr, VMDQ_P(0)); |
| 4423 | |
| 4424 | return min_t(int, ret, 0); |
| 4425 | } |
| 4426 | |
| 4427 | static int ixgbe_uc_unsync(struct net_device *netdev, const unsigned char *addr) |
| 4428 | { |
| 4429 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4430 | |
| 4431 | ixgbe_del_mac_filter(adapter, addr, VMDQ_P(0)); |
| 4432 | |
| 4433 | return 0; |
| 4434 | } |
| 4435 | |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4436 | /** |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 4437 | * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4438 | * @netdev: network interface device structure |
| 4439 | * |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 4440 | * The set_rx_method entry point is called whenever the unicast/multicast |
| 4441 | * address list or the network interface flags are updated. This routine is |
| 4442 | * responsible for configuring the hardware for proper unicast, multicast and |
| 4443 | * promiscuous mode. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4444 | **/ |
Greg Rose | 7f87047 | 2010-01-09 02:25:29 +0000 | [diff] [blame] | 4445 | void ixgbe_set_rx_mode(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4446 | { |
| 4447 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4448 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4449 | u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE; |
| 4450 | int count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4451 | |
| 4452 | /* Check for Promiscuous and All Multicast modes */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4453 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 4454 | |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 4455 | /* set all bits that we expect to always be set */ |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 4456 | fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */ |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 4457 | fctrl |= IXGBE_FCTRL_BAM; |
| 4458 | fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */ |
| 4459 | fctrl |= IXGBE_FCTRL_PMCF; |
| 4460 | |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4461 | /* clear the bits we are changing the status of */ |
| 4462 | fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4463 | if (netdev->flags & IFF_PROMISC) { |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 4464 | hw->addr_ctrl.user_set_promisc = true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4465 | fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4466 | vmolr |= IXGBE_VMOLR_MPE; |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4467 | ixgbe_vlan_promisc_enable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4468 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 4469 | if (netdev->flags & IFF_ALLMULTI) { |
| 4470 | fctrl |= IXGBE_FCTRL_MPE; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4471 | vmolr |= IXGBE_VMOLR_MPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 4472 | } |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 4473 | hw->addr_ctrl.user_set_promisc = false; |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4474 | ixgbe_vlan_promisc_disable(adapter); |
John Fastabend | 9dcb373 | 2012-04-15 06:44:25 +0000 | [diff] [blame] | 4475 | } |
| 4476 | |
| 4477 | /* |
| 4478 | * Write addresses to available RAR registers, if there is not |
| 4479 | * sufficient space to store all the addresses then enable |
| 4480 | * unicast promiscuous mode |
| 4481 | */ |
Alexander Duyck | 0f079d2 | 2015-10-22 16:26:36 -0700 | [diff] [blame] | 4482 | if (__dev_uc_sync(netdev, ixgbe_uc_sync, ixgbe_uc_unsync)) { |
John Fastabend | 9dcb373 | 2012-04-15 06:44:25 +0000 | [diff] [blame] | 4483 | fctrl |= IXGBE_FCTRL_UPE; |
| 4484 | vmolr |= IXGBE_VMOLR_ROPE; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4485 | } |
| 4486 | |
Emil Tantilov | cf78959 | 2013-10-26 08:13:20 +0000 | [diff] [blame] | 4487 | /* Write addresses to the MTA, if the attempt fails |
| 4488 | * then we should just turn on promiscuous mode so |
| 4489 | * that we can at least receive multicast traffic |
| 4490 | */ |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4491 | count = ixgbe_write_mc_addr_list(netdev); |
| 4492 | if (count < 0) { |
| 4493 | fctrl |= IXGBE_FCTRL_MPE; |
| 4494 | vmolr |= IXGBE_VMOLR_MPE; |
| 4495 | } else if (count) { |
| 4496 | vmolr |= IXGBE_VMOLR_ROMPE; |
| 4497 | } |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 4498 | |
| 4499 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 4500 | vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) & |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4501 | ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE | |
| 4502 | IXGBE_VMOLR_ROPE); |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 4503 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4504 | } |
| 4505 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 4506 | /* This is useful for sniffing bad packets. */ |
| 4507 | if (adapter->netdev->features & NETIF_F_RXALL) { |
| 4508 | /* UPE and MPE will be handled by normal PROMISC logic |
| 4509 | * in e1000e_set_rx_mode */ |
| 4510 | fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */ |
| 4511 | IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */ |
| 4512 | IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */ |
| 4513 | |
| 4514 | fctrl &= ~(IXGBE_FCTRL_DPF); |
| 4515 | /* NOTE: VLAN filtering is disabled by setting PROMISC */ |
| 4516 | } |
| 4517 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4518 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4519 | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 4520 | if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX) |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4521 | ixgbe_vlan_strip_enable(adapter); |
| 4522 | else |
| 4523 | ixgbe_vlan_strip_disable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4524 | } |
| 4525 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4526 | static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter) |
| 4527 | { |
| 4528 | int q_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4529 | |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 4530 | for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) { |
| 4531 | ixgbe_qv_init_lock(adapter->q_vector[q_idx]); |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 4532 | napi_enable(&adapter->q_vector[q_idx]->napi); |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 4533 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4534 | } |
| 4535 | |
| 4536 | static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter) |
| 4537 | { |
| 4538 | int q_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4539 | |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 4540 | for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) { |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 4541 | napi_disable(&adapter->q_vector[q_idx]->napi); |
Jacob Keller | 27d9ce4 | 2013-09-21 05:05:44 +0000 | [diff] [blame] | 4542 | while (!ixgbe_qv_disable(adapter->q_vector[q_idx])) { |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 4543 | pr_info("QV %d locked\n", q_idx); |
Jacob Keller | 27d9ce4 | 2013-09-21 05:05:44 +0000 | [diff] [blame] | 4544 | usleep_range(1000, 20000); |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 4545 | } |
| 4546 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4547 | } |
| 4548 | |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 4549 | static void ixgbe_clear_vxlan_port(struct ixgbe_adapter *adapter) |
| 4550 | { |
| 4551 | switch (adapter->hw.mac.type) { |
| 4552 | case ixgbe_mac_X550: |
| 4553 | case ixgbe_mac_X550EM_x: |
| 4554 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_VXLANCTRL, 0); |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 4555 | adapter->vxlan_port = 0; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 4556 | break; |
| 4557 | default: |
| 4558 | break; |
| 4559 | } |
| 4560 | } |
| 4561 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 4562 | #ifdef CONFIG_IXGBE_DCB |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4563 | /** |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4564 | * ixgbe_configure_dcb - Configure DCB hardware |
| 4565 | * @adapter: ixgbe adapter struct |
| 4566 | * |
| 4567 | * This is called by the driver on open to configure the DCB hardware. |
| 4568 | * This is also called by the gennetlink interface when reconfiguring |
| 4569 | * the DCB state. |
| 4570 | */ |
| 4571 | static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter) |
| 4572 | { |
| 4573 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 9806307a | 2010-10-28 00:59:57 +0000 | [diff] [blame] | 4574 | int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4575 | |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 4576 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) { |
| 4577 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4578 | netif_set_gso_max_size(adapter->netdev, 65536); |
| 4579 | return; |
| 4580 | } |
| 4581 | |
| 4582 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4583 | netif_set_gso_max_size(adapter->netdev, 32768); |
| 4584 | |
John Fastabend | b120818 | 2011-10-15 05:00:10 +0000 | [diff] [blame] | 4585 | #ifdef IXGBE_FCOE |
| 4586 | if (adapter->netdev->features & NETIF_F_FCOE_MTU) |
| 4587 | max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE); |
| 4588 | #endif |
| 4589 | |
Alexander Duyck | 01fa7d9 | 2010-11-16 19:26:53 -0800 | [diff] [blame] | 4590 | /* reconfigure the hardware */ |
John Fastabend | 6f70f6a | 2011-04-26 07:26:25 +0000 | [diff] [blame] | 4591 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) { |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 4592 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 4593 | DCB_TX_CONFIG); |
| 4594 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 4595 | DCB_RX_CONFIG); |
| 4596 | ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg); |
John Fastabend | b120818 | 2011-10-15 05:00:10 +0000 | [diff] [blame] | 4597 | } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) { |
| 4598 | ixgbe_dcb_hw_ets(&adapter->hw, |
| 4599 | adapter->ixgbe_ieee_ets, |
| 4600 | max_frame); |
| 4601 | ixgbe_dcb_hw_pfc_config(&adapter->hw, |
| 4602 | adapter->ixgbe_ieee_pfc->pfc_en, |
| 4603 | adapter->ixgbe_ieee_ets->prio_tc); |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 4604 | } |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 4605 | |
| 4606 | /* Enable RSS Hash per TC */ |
| 4607 | if (hw->mac.type != ixgbe_mac_82598EB) { |
Alexander Duyck | 4ae6373 | 2012-06-22 06:46:33 +0000 | [diff] [blame] | 4608 | u32 msb = 0; |
| 4609 | u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1; |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 4610 | |
Alexander Duyck | d411a93 | 2012-06-30 00:14:01 +0000 | [diff] [blame] | 4611 | while (rss_i) { |
| 4612 | msb++; |
| 4613 | rss_i >>= 1; |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 4614 | } |
Alexander Duyck | d411a93 | 2012-06-30 00:14:01 +0000 | [diff] [blame] | 4615 | |
Alexander Duyck | 4ae6373 | 2012-06-22 06:46:33 +0000 | [diff] [blame] | 4616 | /* write msb to all 8 TCs in one write */ |
| 4617 | IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111); |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 4618 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4619 | } |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4620 | #endif |
| 4621 | |
| 4622 | /* Additional bittime to account for IXGBE framing */ |
| 4623 | #define IXGBE_ETH_FRAMING 20 |
| 4624 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4625 | /** |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4626 | * ixgbe_hpbthresh - calculate high water mark for flow control |
| 4627 | * |
| 4628 | * @adapter: board private structure to calculate for |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4629 | * @pb: packet buffer to calculate |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4630 | */ |
| 4631 | static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb) |
| 4632 | { |
| 4633 | struct ixgbe_hw *hw = &adapter->hw; |
| 4634 | struct net_device *dev = adapter->netdev; |
| 4635 | int link, tc, kb, marker; |
| 4636 | u32 dv_id, rx_pba; |
| 4637 | |
| 4638 | /* Calculate max LAN frame size */ |
| 4639 | tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING; |
| 4640 | |
| 4641 | #ifdef IXGBE_FCOE |
| 4642 | /* FCoE traffic class uses FCOE jumbo frames */ |
Alexander Duyck | 800bd60 | 2012-06-02 00:11:02 +0000 | [diff] [blame] | 4643 | if ((dev->features & NETIF_F_FCOE_MTU) && |
| 4644 | (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) && |
| 4645 | (pb == ixgbe_fcoe_get_tc(adapter))) |
| 4646 | tc = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4647 | #endif |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4648 | |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4649 | /* Calculate delay value for device */ |
| 4650 | switch (hw->mac.type) { |
| 4651 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 4652 | case ixgbe_mac_X550: |
| 4653 | case ixgbe_mac_X550EM_x: |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4654 | dv_id = IXGBE_DV_X540(link, tc); |
| 4655 | break; |
| 4656 | default: |
| 4657 | dv_id = IXGBE_DV(link, tc); |
| 4658 | break; |
| 4659 | } |
| 4660 | |
| 4661 | /* Loopback switch introduces additional latency */ |
| 4662 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 4663 | dv_id += IXGBE_B2BT(tc); |
| 4664 | |
| 4665 | /* Delay value is calculated in bit times convert to KB */ |
| 4666 | kb = IXGBE_BT2KB(dv_id); |
| 4667 | rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10; |
| 4668 | |
| 4669 | marker = rx_pba - kb; |
| 4670 | |
| 4671 | /* It is possible that the packet buffer is not large enough |
| 4672 | * to provide required headroom. In this case throw an error |
| 4673 | * to user and a do the best we can. |
| 4674 | */ |
| 4675 | if (marker < 0) { |
| 4676 | e_warn(drv, "Packet Buffer(%i) can not provide enough" |
| 4677 | "headroom to support flow control." |
| 4678 | "Decrease MTU or number of traffic classes\n", pb); |
| 4679 | marker = tc + 1; |
| 4680 | } |
| 4681 | |
| 4682 | return marker; |
| 4683 | } |
| 4684 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4685 | /** |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4686 | * ixgbe_lpbthresh - calculate low water mark for for flow control |
| 4687 | * |
| 4688 | * @adapter: board private structure to calculate for |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4689 | * @pb: packet buffer to calculate |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4690 | */ |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4691 | static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb) |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4692 | { |
| 4693 | struct ixgbe_hw *hw = &adapter->hw; |
| 4694 | struct net_device *dev = adapter->netdev; |
| 4695 | int tc; |
| 4696 | u32 dv_id; |
| 4697 | |
| 4698 | /* Calculate max LAN frame size */ |
| 4699 | tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN; |
| 4700 | |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4701 | #ifdef IXGBE_FCOE |
| 4702 | /* FCoE traffic class uses FCOE jumbo frames */ |
| 4703 | if ((dev->features & NETIF_F_FCOE_MTU) && |
| 4704 | (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) && |
| 4705 | (pb == netdev_get_prio_tc_map(dev, adapter->fcoe.up))) |
| 4706 | tc = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 4707 | #endif |
| 4708 | |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4709 | /* Calculate delay value for device */ |
| 4710 | switch (hw->mac.type) { |
| 4711 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 4712 | case ixgbe_mac_X550: |
| 4713 | case ixgbe_mac_X550EM_x: |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4714 | dv_id = IXGBE_LOW_DV_X540(tc); |
| 4715 | break; |
| 4716 | default: |
| 4717 | dv_id = IXGBE_LOW_DV(tc); |
| 4718 | break; |
| 4719 | } |
| 4720 | |
| 4721 | /* Delay value is calculated in bit times convert to KB */ |
| 4722 | return IXGBE_BT2KB(dv_id); |
| 4723 | } |
| 4724 | |
| 4725 | /* |
| 4726 | * ixgbe_pbthresh_setup - calculate and setup high low water marks |
| 4727 | */ |
| 4728 | static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter) |
| 4729 | { |
| 4730 | struct ixgbe_hw *hw = &adapter->hw; |
| 4731 | int num_tc = netdev_get_num_tc(adapter->netdev); |
| 4732 | int i; |
| 4733 | |
| 4734 | if (!num_tc) |
| 4735 | num_tc = 1; |
| 4736 | |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4737 | for (i = 0; i < num_tc; i++) { |
| 4738 | hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i); |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4739 | hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i); |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4740 | |
| 4741 | /* Low water marks must not be larger than high water marks */ |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4742 | if (hw->fc.low_water[i] > hw->fc.high_water[i]) |
| 4743 | hw->fc.low_water[i] = 0; |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4744 | } |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4745 | |
| 4746 | for (; i < MAX_TRAFFIC_CLASS; i++) |
| 4747 | hw->fc.high_water[i] = 0; |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4748 | } |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4749 | |
| 4750 | static void ixgbe_configure_pb(struct ixgbe_adapter *adapter) |
| 4751 | { |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4752 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 4753 | int hdrm; |
| 4754 | u8 tc = netdev_get_num_tc(adapter->netdev); |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4755 | |
| 4756 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 4757 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 4758 | hdrm = 32 << adapter->fdir_pballoc; |
| 4759 | else |
| 4760 | hdrm = 0; |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4761 | |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 4762 | hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL); |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4763 | ixgbe_pbthresh_setup(adapter); |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4764 | } |
| 4765 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4766 | static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter) |
| 4767 | { |
| 4768 | struct ixgbe_hw *hw = &adapter->hw; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 4769 | struct hlist_node *node2; |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4770 | struct ixgbe_fdir_filter *filter; |
| 4771 | |
| 4772 | spin_lock(&adapter->fdir_perfect_lock); |
| 4773 | |
| 4774 | if (!hlist_empty(&adapter->fdir_filter_list)) |
| 4775 | ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask); |
| 4776 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 4777 | hlist_for_each_entry_safe(filter, node2, |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4778 | &adapter->fdir_filter_list, fdir_node) { |
| 4779 | ixgbe_fdir_write_perfect_filter_82599(hw, |
Alexander Duyck | 1f4d518 | 2011-05-14 01:16:02 +0000 | [diff] [blame] | 4780 | &filter->filter, |
| 4781 | filter->sw_idx, |
| 4782 | (filter->action == IXGBE_FDIR_DROP_QUEUE) ? |
| 4783 | IXGBE_FDIR_DROP_QUEUE : |
| 4784 | adapter->rx_ring[filter->action]->reg_idx); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4785 | } |
| 4786 | |
| 4787 | spin_unlock(&adapter->fdir_perfect_lock); |
| 4788 | } |
| 4789 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4790 | static void ixgbe_macvlan_set_rx_mode(struct net_device *dev, unsigned int pool, |
| 4791 | struct ixgbe_adapter *adapter) |
| 4792 | { |
| 4793 | struct ixgbe_hw *hw = &adapter->hw; |
| 4794 | u32 vmolr; |
| 4795 | |
| 4796 | /* No unicast promiscuous support for VMDQ devices. */ |
| 4797 | vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(pool)); |
| 4798 | vmolr |= (IXGBE_VMOLR_ROMPE | IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE); |
| 4799 | |
| 4800 | /* clear the affected bit */ |
| 4801 | vmolr &= ~IXGBE_VMOLR_MPE; |
| 4802 | |
| 4803 | if (dev->flags & IFF_ALLMULTI) { |
| 4804 | vmolr |= IXGBE_VMOLR_MPE; |
| 4805 | } else { |
| 4806 | vmolr |= IXGBE_VMOLR_ROMPE; |
| 4807 | hw->mac.ops.update_mc_addr_list(hw, dev); |
| 4808 | } |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4809 | ixgbe_write_uc_addr_list(adapter->netdev, pool); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4810 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(pool), vmolr); |
| 4811 | } |
| 4812 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4813 | static void ixgbe_fwd_psrtype(struct ixgbe_fwd_adapter *vadapter) |
| 4814 | { |
| 4815 | struct ixgbe_adapter *adapter = vadapter->real_adapter; |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 4816 | int rss_i = adapter->num_rx_queues_per_pool; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4817 | struct ixgbe_hw *hw = &adapter->hw; |
| 4818 | u16 pool = vadapter->pool; |
| 4819 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
| 4820 | IXGBE_PSRTYPE_UDPHDR | |
| 4821 | IXGBE_PSRTYPE_IPV4HDR | |
| 4822 | IXGBE_PSRTYPE_L2HDR | |
| 4823 | IXGBE_PSRTYPE_IPV6HDR; |
| 4824 | |
| 4825 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4826 | return; |
| 4827 | |
| 4828 | if (rss_i > 3) |
| 4829 | psrtype |= 2 << 29; |
| 4830 | else if (rss_i > 1) |
| 4831 | psrtype |= 1 << 29; |
| 4832 | |
| 4833 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype); |
| 4834 | } |
| 4835 | |
| 4836 | /** |
| 4837 | * ixgbe_clean_rx_ring - Free Rx Buffers per Queue |
| 4838 | * @rx_ring: ring to free buffers from |
| 4839 | **/ |
| 4840 | static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring) |
| 4841 | { |
| 4842 | struct device *dev = rx_ring->dev; |
| 4843 | unsigned long size; |
| 4844 | u16 i; |
| 4845 | |
| 4846 | /* ring already cleared, nothing to do */ |
| 4847 | if (!rx_ring->rx_buffer_info) |
| 4848 | return; |
| 4849 | |
| 4850 | /* Free all the Rx ring sk_buffs */ |
| 4851 | for (i = 0; i < rx_ring->count; i++) { |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 4852 | struct ixgbe_rx_buffer *rx_buffer = &rx_ring->rx_buffer_info[i]; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4853 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4854 | if (rx_buffer->skb) { |
| 4855 | struct sk_buff *skb = rx_buffer->skb; |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 4856 | if (IXGBE_CB(skb)->page_released) |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4857 | dma_unmap_page(dev, |
| 4858 | IXGBE_CB(skb)->dma, |
| 4859 | ixgbe_rx_bufsz(rx_ring), |
| 4860 | DMA_FROM_DEVICE); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4861 | dev_kfree_skb(skb); |
Junwei Zhang | 4d2fcfb | 2014-10-22 15:29:03 +0000 | [diff] [blame] | 4862 | rx_buffer->skb = NULL; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4863 | } |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 4864 | |
| 4865 | if (!rx_buffer->page) |
| 4866 | continue; |
| 4867 | |
| 4868 | dma_unmap_page(dev, rx_buffer->dma, |
| 4869 | ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE); |
| 4870 | __free_pages(rx_buffer->page, ixgbe_rx_pg_order(rx_ring)); |
| 4871 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4872 | rx_buffer->page = NULL; |
| 4873 | } |
| 4874 | |
| 4875 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 4876 | memset(rx_ring->rx_buffer_info, 0, size); |
| 4877 | |
| 4878 | /* Zero out the descriptor ring */ |
| 4879 | memset(rx_ring->desc, 0, rx_ring->size); |
| 4880 | |
| 4881 | rx_ring->next_to_alloc = 0; |
| 4882 | rx_ring->next_to_clean = 0; |
| 4883 | rx_ring->next_to_use = 0; |
| 4884 | } |
| 4885 | |
| 4886 | static void ixgbe_disable_fwd_ring(struct ixgbe_fwd_adapter *vadapter, |
| 4887 | struct ixgbe_ring *rx_ring) |
| 4888 | { |
| 4889 | struct ixgbe_adapter *adapter = vadapter->real_adapter; |
| 4890 | int index = rx_ring->queue_index + vadapter->rx_base_queue; |
| 4891 | |
| 4892 | /* shutdown specific queue receive and wait for dma to settle */ |
| 4893 | ixgbe_disable_rx_queue(adapter, rx_ring); |
| 4894 | usleep_range(10000, 20000); |
| 4895 | ixgbe_irq_disable_queues(adapter, ((u64)1 << index)); |
| 4896 | ixgbe_clean_rx_ring(rx_ring); |
| 4897 | rx_ring->l2_accel_priv = NULL; |
| 4898 | } |
| 4899 | |
John Fastabend | ae72c8d | 2013-11-09 07:11:26 +0000 | [diff] [blame] | 4900 | static int ixgbe_fwd_ring_down(struct net_device *vdev, |
| 4901 | struct ixgbe_fwd_adapter *accel) |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4902 | { |
| 4903 | struct ixgbe_adapter *adapter = accel->real_adapter; |
| 4904 | unsigned int rxbase = accel->rx_base_queue; |
| 4905 | unsigned int txbase = accel->tx_base_queue; |
| 4906 | int i; |
| 4907 | |
| 4908 | netif_tx_stop_all_queues(vdev); |
| 4909 | |
| 4910 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 4911 | ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]); |
| 4912 | adapter->rx_ring[rxbase + i]->netdev = adapter->netdev; |
| 4913 | } |
| 4914 | |
| 4915 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 4916 | adapter->tx_ring[txbase + i]->l2_accel_priv = NULL; |
| 4917 | adapter->tx_ring[txbase + i]->netdev = adapter->netdev; |
| 4918 | } |
| 4919 | |
| 4920 | |
| 4921 | return 0; |
| 4922 | } |
| 4923 | |
| 4924 | static int ixgbe_fwd_ring_up(struct net_device *vdev, |
| 4925 | struct ixgbe_fwd_adapter *accel) |
| 4926 | { |
| 4927 | struct ixgbe_adapter *adapter = accel->real_adapter; |
| 4928 | unsigned int rxbase, txbase, queues; |
| 4929 | int i, baseq, err = 0; |
| 4930 | |
| 4931 | if (!test_bit(accel->pool, &adapter->fwd_bitmask)) |
| 4932 | return 0; |
| 4933 | |
| 4934 | baseq = accel->pool * adapter->num_rx_queues_per_pool; |
| 4935 | netdev_dbg(vdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n", |
| 4936 | accel->pool, adapter->num_rx_pools, |
| 4937 | baseq, baseq + adapter->num_rx_queues_per_pool, |
| 4938 | adapter->fwd_bitmask); |
| 4939 | |
| 4940 | accel->netdev = vdev; |
| 4941 | accel->rx_base_queue = rxbase = baseq; |
| 4942 | accel->tx_base_queue = txbase = baseq; |
| 4943 | |
| 4944 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) |
| 4945 | ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]); |
| 4946 | |
| 4947 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 4948 | adapter->rx_ring[rxbase + i]->netdev = vdev; |
| 4949 | adapter->rx_ring[rxbase + i]->l2_accel_priv = accel; |
| 4950 | ixgbe_configure_rx_ring(adapter, adapter->rx_ring[rxbase + i]); |
| 4951 | } |
| 4952 | |
| 4953 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 4954 | adapter->tx_ring[txbase + i]->netdev = vdev; |
| 4955 | adapter->tx_ring[txbase + i]->l2_accel_priv = accel; |
| 4956 | } |
| 4957 | |
| 4958 | queues = min_t(unsigned int, |
| 4959 | adapter->num_rx_queues_per_pool, vdev->num_tx_queues); |
| 4960 | err = netif_set_real_num_tx_queues(vdev, queues); |
| 4961 | if (err) |
| 4962 | goto fwd_queue_err; |
| 4963 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4964 | err = netif_set_real_num_rx_queues(vdev, queues); |
| 4965 | if (err) |
| 4966 | goto fwd_queue_err; |
| 4967 | |
| 4968 | if (is_valid_ether_addr(vdev->dev_addr)) |
| 4969 | ixgbe_add_mac_filter(adapter, vdev->dev_addr, accel->pool); |
| 4970 | |
| 4971 | ixgbe_fwd_psrtype(accel); |
| 4972 | ixgbe_macvlan_set_rx_mode(vdev, accel->pool, adapter); |
| 4973 | return err; |
| 4974 | fwd_queue_err: |
| 4975 | ixgbe_fwd_ring_down(vdev, accel); |
| 4976 | return err; |
| 4977 | } |
| 4978 | |
| 4979 | static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter) |
| 4980 | { |
| 4981 | struct net_device *upper; |
| 4982 | struct list_head *iter; |
| 4983 | int err; |
| 4984 | |
| 4985 | netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) { |
| 4986 | if (netif_is_macvlan(upper)) { |
| 4987 | struct macvlan_dev *dfwd = netdev_priv(upper); |
| 4988 | struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv; |
| 4989 | |
| 4990 | if (dfwd->fwd_priv) { |
| 4991 | err = ixgbe_fwd_ring_up(upper, vadapter); |
| 4992 | if (err) |
| 4993 | continue; |
| 4994 | } |
| 4995 | } |
| 4996 | } |
| 4997 | } |
| 4998 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4999 | static void ixgbe_configure(struct ixgbe_adapter *adapter) |
| 5000 | { |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 5001 | struct ixgbe_hw *hw = &adapter->hw; |
| 5002 | |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 5003 | ixgbe_configure_pb(adapter); |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5004 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 5005 | ixgbe_configure_dcb(adapter); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5006 | #endif |
Alexander Duyck | b35d4d4 | 2012-05-23 05:39:25 +0000 | [diff] [blame] | 5007 | /* |
| 5008 | * We must restore virtualization before VLANs or else |
| 5009 | * the VLVF registers will not be populated |
| 5010 | */ |
| 5011 | ixgbe_configure_virtualization(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5012 | |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 5013 | ixgbe_set_rx_mode(adapter->netdev); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 5014 | ixgbe_restore_vlan(adapter); |
| 5015 | |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 5016 | switch (hw->mac.type) { |
| 5017 | case ixgbe_mac_82599EB: |
| 5018 | case ixgbe_mac_X540: |
| 5019 | hw->mac.ops.disable_rx_buff(hw); |
| 5020 | break; |
| 5021 | default: |
| 5022 | break; |
| 5023 | } |
| 5024 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5025 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 5026 | ixgbe_init_fdir_signature_82599(&adapter->hw, |
| 5027 | adapter->fdir_pballoc); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5028 | } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) { |
| 5029 | ixgbe_init_fdir_perfect_82599(&adapter->hw, |
| 5030 | adapter->fdir_pballoc); |
| 5031 | ixgbe_fdir_filter_restore(adapter); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5032 | } |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 5033 | |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 5034 | switch (hw->mac.type) { |
| 5035 | case ixgbe_mac_82599EB: |
| 5036 | case ixgbe_mac_X540: |
| 5037 | hw->mac.ops.enable_rx_buff(hw); |
| 5038 | break; |
| 5039 | default: |
| 5040 | break; |
| 5041 | } |
| 5042 | |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 5043 | #ifdef CONFIG_IXGBE_DCA |
| 5044 | /* configure DCA */ |
| 5045 | if (adapter->flags & IXGBE_FLAG_DCA_CAPABLE) |
| 5046 | ixgbe_setup_dca(adapter); |
| 5047 | #endif /* CONFIG_IXGBE_DCA */ |
| 5048 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 5049 | #ifdef IXGBE_FCOE |
| 5050 | /* configure FCoE L2 filters, redirection table, and Rx control */ |
| 5051 | ixgbe_configure_fcoe(adapter); |
| 5052 | |
| 5053 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5054 | ixgbe_configure_tx(adapter); |
| 5055 | ixgbe_configure_rx(adapter); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5056 | ixgbe_configure_dfwd(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5057 | } |
| 5058 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5059 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5060 | * ixgbe_sfp_link_config - set up SFP+ link |
| 5061 | * @adapter: pointer to private adapter struct |
| 5062 | **/ |
| 5063 | static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter) |
| 5064 | { |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5065 | /* |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 5066 | * We are assuming the worst case scenario here, and that |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5067 | * is that an SFP was inserted/removed after the reset |
| 5068 | * but before SFP detection was enabled. As such the best |
| 5069 | * solution is to just start searching as soon as we start |
| 5070 | */ |
| 5071 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 5072 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5073 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5074 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
Mark Rustad | 58e7cd2 | 2015-08-08 16:18:48 -0700 | [diff] [blame] | 5075 | adapter->sfp_poll_time = 0; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5076 | } |
| 5077 | |
| 5078 | /** |
| 5079 | * ixgbe_non_sfp_link_config - set up non-SFP+ link |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5080 | * @hw: pointer to private hardware struct |
| 5081 | * |
| 5082 | * Returns 0 on success, negative on failure |
| 5083 | **/ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5084 | 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] | 5085 | { |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 5086 | u32 speed; |
| 5087 | bool autoneg, link_up = false; |
Mark Rustad | a1e869d | 2015-04-10 10:36:36 -0700 | [diff] [blame] | 5088 | int ret = IXGBE_ERR_LINK_SETUP; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5089 | |
| 5090 | if (hw->mac.ops.check_link) |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 5091 | 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] | 5092 | |
| 5093 | if (ret) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 5094 | return ret; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5095 | |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 5096 | speed = hw->phy.autoneg_advertised; |
| 5097 | if ((!speed) && (hw->mac.ops.get_link_capabilities)) |
| 5098 | ret = hw->mac.ops.get_link_capabilities(hw, &speed, |
| 5099 | &autoneg); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5100 | if (ret) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 5101 | return ret; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5102 | |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 5103 | if (hw->mac.ops.setup_link) |
Josh Hay | fd0326f | 2012-12-15 03:28:30 +0000 | [diff] [blame] | 5104 | ret = hw->mac.ops.setup_link(hw, speed, link_up); |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 5105 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5106 | return ret; |
| 5107 | } |
| 5108 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5109 | static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5110 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5111 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5112 | u32 gpie = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5113 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 5114 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5115 | gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT | |
| 5116 | IXGBE_GPIE_OCD; |
| 5117 | gpie |= IXGBE_GPIE_EIAME; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 5118 | /* |
| 5119 | * use EIAM to auto-mask when MSI-X interrupt is asserted |
| 5120 | * this saves a register write for every interrupt |
| 5121 | */ |
| 5122 | switch (hw->mac.type) { |
| 5123 | case ixgbe_mac_82598EB: |
| 5124 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
| 5125 | break; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 5126 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5127 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5128 | case ixgbe_mac_X550: |
| 5129 | case ixgbe_mac_X550EM_x: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5130 | default: |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 5131 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF); |
| 5132 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF); |
| 5133 | break; |
| 5134 | } |
| 5135 | } else { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5136 | /* legacy interrupts, use EIAM to auto-mask when reading EICR, |
| 5137 | * specifically only auto mask tx and rx interrupts */ |
| 5138 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5139 | } |
| 5140 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5141 | /* XXX: to interrupt immediately for EICS writes, enable this */ |
| 5142 | /* gpie |= IXGBE_GPIE_EIMEN; */ |
| 5143 | |
| 5144 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 5145 | gpie &= ~IXGBE_GPIE_VTMODE_MASK; |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 5146 | |
| 5147 | switch (adapter->ring_feature[RING_F_VMDQ].mask) { |
| 5148 | case IXGBE_82599_VMDQ_8Q_MASK: |
| 5149 | gpie |= IXGBE_GPIE_VTMODE_16; |
| 5150 | break; |
| 5151 | case IXGBE_82599_VMDQ_4Q_MASK: |
| 5152 | gpie |= IXGBE_GPIE_VTMODE_32; |
| 5153 | break; |
| 5154 | default: |
| 5155 | gpie |= IXGBE_GPIE_VTMODE_64; |
| 5156 | break; |
| 5157 | } |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 5158 | } |
| 5159 | |
Alexander Duyck | 5fdd31f | 2011-07-21 00:40:45 +0000 | [diff] [blame] | 5160 | /* Enable Thermal over heat sensor interrupt */ |
Don Skidmore | f3df98e | 2011-08-17 10:15:21 +0000 | [diff] [blame] | 5161 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) { |
| 5162 | switch (adapter->hw.mac.type) { |
| 5163 | case ixgbe_mac_82599EB: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 5164 | gpie |= IXGBE_SDP0_GPIEN_8259X; |
Don Skidmore | f3df98e | 2011-08-17 10:15:21 +0000 | [diff] [blame] | 5165 | break; |
Don Skidmore | f3df98e | 2011-08-17 10:15:21 +0000 | [diff] [blame] | 5166 | default: |
| 5167 | break; |
| 5168 | } |
| 5169 | } |
Alexander Duyck | 5fdd31f | 2011-07-21 00:40:45 +0000 | [diff] [blame] | 5170 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5171 | /* Enable fan failure interrupt */ |
| 5172 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 5173 | gpie |= IXGBE_SDP1_GPIEN(hw); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 5174 | |
Don Skidmore | a023bbd | 2015-06-24 16:38:53 -0400 | [diff] [blame] | 5175 | switch (hw->mac.type) { |
| 5176 | case ixgbe_mac_82599EB: |
| 5177 | gpie |= IXGBE_SDP1_GPIEN_8259X | IXGBE_SDP2_GPIEN_8259X; |
| 5178 | break; |
| 5179 | case ixgbe_mac_X550EM_x: |
| 5180 | gpie |= IXGBE_SDP0_GPIEN_X540; |
| 5181 | break; |
| 5182 | default: |
| 5183 | break; |
Don Skidmore | 2698b20 | 2011-04-13 07:01:52 +0000 | [diff] [blame] | 5184 | } |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5185 | |
| 5186 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 5187 | } |
| 5188 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 5189 | static void ixgbe_up_complete(struct ixgbe_adapter *adapter) |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5190 | { |
| 5191 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5192 | int err; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5193 | u32 ctrl_ext; |
| 5194 | |
| 5195 | ixgbe_get_hw_control(adapter); |
| 5196 | ixgbe_setup_gpie(adapter); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5197 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5198 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 5199 | ixgbe_configure_msix(adapter); |
| 5200 | else |
| 5201 | ixgbe_configure_msi_and_legacy(adapter); |
| 5202 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 5203 | /* enable the optics for 82599 SFP+ fiber */ |
| 5204 | if (hw->mac.ops.enable_tx_laser) |
Peter Waskiewicz | 61fac74 | 2010-04-27 00:38:15 +0000 | [diff] [blame] | 5205 | hw->mac.ops.enable_tx_laser(hw); |
| 5206 | |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 5207 | if (hw->phy.ops.set_phy_power) |
| 5208 | hw->phy.ops.set_phy_power(hw, true); |
| 5209 | |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 5210 | smp_mb__before_atomic(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5211 | clear_bit(__IXGBE_DOWN, &adapter->state); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5212 | ixgbe_napi_enable_all(adapter); |
| 5213 | |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 5214 | if (ixgbe_is_sfp(hw)) { |
| 5215 | ixgbe_sfp_link_config(adapter); |
| 5216 | } else { |
| 5217 | err = ixgbe_non_sfp_link_config(hw); |
| 5218 | if (err) |
| 5219 | e_err(probe, "link_config FAILED %d\n", err); |
| 5220 | } |
| 5221 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5222 | /* clear any pending interrupts, may auto mask */ |
| 5223 | IXGBE_READ_REG(hw, IXGBE_EICR); |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 5224 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5225 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5226 | /* |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5227 | * If this adapter has a fan, check to see if we had a failure |
| 5228 | * before we enabled the interrupt. |
| 5229 | */ |
| 5230 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 5231 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 5232 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5233 | e_crit(drv, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5234 | } |
| 5235 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5236 | /* bring the link up in the watchdog, this could race with our first |
| 5237 | * link up interrupt but shouldn't be a problem */ |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5238 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 5239 | adapter->link_check_timeout = jiffies; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5240 | mod_timer(&adapter->service_timer, jiffies); |
Greg Rose | c920569 | 2010-01-22 22:46:22 +0000 | [diff] [blame] | 5241 | |
| 5242 | /* Set PF Reset Done bit so PF/VF Mail Ops can work */ |
| 5243 | ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); |
| 5244 | ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD; |
| 5245 | IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5246 | } |
| 5247 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5248 | void ixgbe_reinit_locked(struct ixgbe_adapter *adapter) |
| 5249 | { |
| 5250 | WARN_ON(in_interrupt()); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5251 | /* put off any impending NetWatchDogTimeout */ |
| 5252 | adapter->netdev->trans_start = jiffies; |
| 5253 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5254 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 5255 | usleep_range(1000, 2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5256 | ixgbe_down(adapter); |
Greg Rose | 5809a1a | 2010-03-24 09:36:08 +0000 | [diff] [blame] | 5257 | /* |
| 5258 | * If SR-IOV enabled then wait a bit before bringing the adapter |
| 5259 | * back up to give the VFs time to respond to the reset. The |
| 5260 | * two second wait is based upon the watchdog timer cycle in |
| 5261 | * the VF driver. |
| 5262 | */ |
| 5263 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 5264 | msleep(2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5265 | ixgbe_up(adapter); |
| 5266 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
| 5267 | } |
| 5268 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 5269 | void ixgbe_up(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5270 | { |
| 5271 | /* hardware has been reset, we need to reload some things */ |
| 5272 | ixgbe_configure(adapter); |
| 5273 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 5274 | ixgbe_up_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5275 | } |
| 5276 | |
| 5277 | void ixgbe_reset(struct ixgbe_adapter *adapter) |
| 5278 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5279 | struct ixgbe_hw *hw = &adapter->hw; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 5280 | struct net_device *netdev = adapter->netdev; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 5281 | int err; |
| 5282 | |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 5283 | if (ixgbe_removed(hw->hw_addr)) |
| 5284 | return; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5285 | /* lock SFP init bit to prevent race conditions with the watchdog */ |
| 5286 | while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 5287 | usleep_range(1000, 2000); |
| 5288 | |
| 5289 | /* clear all SFP and link config related flags while holding SFP_INIT */ |
| 5290 | adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP | |
| 5291 | IXGBE_FLAG2_SFP_NEEDS_RESET); |
| 5292 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 5293 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 5294 | err = hw->mac.ops.init_hw(hw); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5295 | switch (err) { |
| 5296 | case 0: |
| 5297 | case IXGBE_ERR_SFP_NOT_PRESENT: |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5298 | case IXGBE_ERR_SFP_NOT_SUPPORTED: |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5299 | break; |
| 5300 | case IXGBE_ERR_MASTER_REQUESTS_PENDING: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5301 | e_dev_err("master disable timed out\n"); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5302 | break; |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 5303 | case IXGBE_ERR_EEPROM_VERSION: |
| 5304 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5305 | e_dev_warn("This device is a pre-production adapter/LOM. " |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 5306 | "Please be aware there may be issues associated with " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5307 | "your hardware. If you are experiencing problems " |
| 5308 | "please contact your Intel or hardware " |
| 5309 | "representative who provided you with this " |
| 5310 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 5311 | break; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5312 | default: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5313 | e_dev_err("Hardware Error: %d\n", err); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5314 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5315 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5316 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
Alexander Duyck | 0f079d2 | 2015-10-22 16:26:36 -0700 | [diff] [blame] | 5317 | |
| 5318 | /* flush entries out of MAC table */ |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 5319 | ixgbe_flush_sw_mac_table(adapter); |
Alexander Duyck | 0f079d2 | 2015-10-22 16:26:36 -0700 | [diff] [blame] | 5320 | __dev_uc_unsync(netdev, NULL); |
| 5321 | |
| 5322 | /* do not flush user set addresses */ |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 5323 | ixgbe_mac_set_default_filter(adapter); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 5324 | |
| 5325 | /* update SAN MAC vmdq pool selection */ |
| 5326 | if (hw->mac.san_mac_rar_index) |
| 5327 | hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0)); |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 5328 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 5329 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 5330 | ixgbe_ptp_reset(adapter); |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 5331 | |
| 5332 | if (hw->phy.ops.set_phy_power) { |
| 5333 | if (!netif_running(adapter->netdev) && !adapter->wol) |
| 5334 | hw->phy.ops.set_phy_power(hw, false); |
| 5335 | else |
| 5336 | hw->phy.ops.set_phy_power(hw, true); |
| 5337 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5338 | } |
| 5339 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5340 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5341 | * ixgbe_clean_tx_ring - Free Tx Buffers |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5342 | * @tx_ring: ring to be cleaned |
| 5343 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5344 | static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5345 | { |
| 5346 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 5347 | unsigned long size; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5348 | u16 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5349 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 5350 | /* ring already cleared, nothing to do */ |
| 5351 | if (!tx_ring->tx_buffer_info) |
| 5352 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5353 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 5354 | /* Free all the Tx ring sk_buffs */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5355 | for (i = 0; i < tx_ring->count; i++) { |
| 5356 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5357 | ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5358 | } |
| 5359 | |
John Fastabend | dad8a3b | 2012-04-23 12:22:39 +0000 | [diff] [blame] | 5360 | netdev_tx_reset_queue(txring_txq(tx_ring)); |
| 5361 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5362 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 5363 | memset(tx_ring->tx_buffer_info, 0, size); |
| 5364 | |
| 5365 | /* Zero out the descriptor ring */ |
| 5366 | memset(tx_ring->desc, 0, tx_ring->size); |
| 5367 | |
| 5368 | tx_ring->next_to_use = 0; |
| 5369 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5370 | } |
| 5371 | |
| 5372 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5373 | * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues |
| 5374 | * @adapter: board private structure |
| 5375 | **/ |
| 5376 | static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter) |
| 5377 | { |
| 5378 | int i; |
| 5379 | |
| 5380 | for (i = 0; i < adapter->num_rx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5381 | ixgbe_clean_rx_ring(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5382 | } |
| 5383 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5384 | /** |
| 5385 | * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues |
| 5386 | * @adapter: board private structure |
| 5387 | **/ |
| 5388 | static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter) |
| 5389 | { |
| 5390 | int i; |
| 5391 | |
| 5392 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5393 | ixgbe_clean_tx_ring(adapter->tx_ring[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5394 | } |
| 5395 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5396 | static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter) |
| 5397 | { |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 5398 | struct hlist_node *node2; |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5399 | struct ixgbe_fdir_filter *filter; |
| 5400 | |
| 5401 | spin_lock(&adapter->fdir_perfect_lock); |
| 5402 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 5403 | hlist_for_each_entry_safe(filter, node2, |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5404 | &adapter->fdir_filter_list, fdir_node) { |
| 5405 | hlist_del(&filter->fdir_node); |
| 5406 | kfree(filter); |
| 5407 | } |
| 5408 | adapter->fdir_filter_count = 0; |
| 5409 | |
| 5410 | spin_unlock(&adapter->fdir_perfect_lock); |
| 5411 | } |
| 5412 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5413 | void ixgbe_down(struct ixgbe_adapter *adapter) |
| 5414 | { |
| 5415 | struct net_device *netdev = adapter->netdev; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5416 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5417 | struct net_device *upper; |
| 5418 | struct list_head *iter; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 5419 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5420 | |
| 5421 | /* signal that we are down to the interrupt handler */ |
Mark Rustad | c3049c8 | 2014-01-14 18:53:12 -0800 | [diff] [blame] | 5422 | if (test_and_set_bit(__IXGBE_DOWN, &adapter->state)) |
| 5423 | return; /* do nothing if already down */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5424 | |
| 5425 | /* disable receives */ |
Don Skidmore | 1f9ac57 | 2015-03-13 13:54:30 -0700 | [diff] [blame] | 5426 | hw->mac.ops.disable_rx(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5427 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 5428 | /* disable all enabled rx queues */ |
| 5429 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 5430 | /* this call also flushes the previous write */ |
| 5431 | ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]); |
| 5432 | |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 5433 | usleep_range(10000, 20000); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5434 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5435 | netif_tx_stop_all_queues(netdev); |
| 5436 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5437 | /* call carrier off first to avoid false dev_watchdog timeouts */ |
John Fastabend | c0dfb90 | 2010-04-27 02:13:39 +0000 | [diff] [blame] | 5438 | netif_carrier_off(netdev); |
| 5439 | netif_tx_disable(netdev); |
| 5440 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5441 | /* disable any upper devices */ |
| 5442 | netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) { |
| 5443 | if (netif_is_macvlan(upper)) { |
| 5444 | struct macvlan_dev *vlan = netdev_priv(upper); |
| 5445 | |
| 5446 | if (vlan->fwd_priv) { |
| 5447 | netif_tx_stop_all_queues(upper); |
| 5448 | netif_carrier_off(upper); |
| 5449 | netif_tx_disable(upper); |
| 5450 | } |
| 5451 | } |
| 5452 | } |
| 5453 | |
John Fastabend | c0dfb90 | 2010-04-27 02:13:39 +0000 | [diff] [blame] | 5454 | ixgbe_irq_disable(adapter); |
| 5455 | |
| 5456 | ixgbe_napi_disable_all(adapter); |
| 5457 | |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 5458 | adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT | |
| 5459 | IXGBE_FLAG2_RESET_REQUESTED); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5460 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 5461 | |
| 5462 | del_timer_sync(&adapter->service_timer); |
| 5463 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 5464 | if (adapter->num_vfs) { |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 5465 | /* Clear EITR Select mapping */ |
| 5466 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0); |
| 5467 | |
| 5468 | /* Mark all the VFs as inactive */ |
| 5469 | for (i = 0 ; i < adapter->num_vfs; i++) |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 5470 | adapter->vfinfo[i].clear_to_send = false; |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 5471 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 5472 | /* 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] | 5473 | ixgbe_ping_all_vfs(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5474 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5475 | /* Disable all VFTE/VFRE TX/RX */ |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 5476 | ixgbe_disable_tx_rx(adapter); |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 5477 | } |
| 5478 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5479 | /* disable transmits in the hardware now that interrupts are off */ |
| 5480 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 5481 | u8 reg_idx = adapter->tx_ring[i]->reg_idx; |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 5482 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5483 | } |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 5484 | |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5485 | /* Disable the Tx DMA engine on 82599 and later MAC */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5486 | switch (hw->mac.type) { |
| 5487 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5488 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5489 | case ixgbe_mac_X550: |
| 5490 | case ixgbe_mac_X550EM_x: |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 5491 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 5492 | (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) & |
| 5493 | ~IXGBE_DMATXCTL_TE)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5494 | break; |
| 5495 | default: |
| 5496 | break; |
| 5497 | } |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5498 | |
Paul Larson | 6f4a0e4 | 2008-06-24 17:00:56 -0700 | [diff] [blame] | 5499 | if (!pci_channel_offline(adapter->pdev)) |
| 5500 | ixgbe_reset(adapter); |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 5501 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 5502 | /* power down the optics for 82599 SFP+ fiber */ |
| 5503 | if (hw->mac.ops.disable_tx_laser) |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 5504 | hw->mac.ops.disable_tx_laser(hw); |
| 5505 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5506 | ixgbe_clean_all_tx_rings(adapter); |
| 5507 | ixgbe_clean_all_rx_rings(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5508 | } |
| 5509 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5510 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5511 | * ixgbe_tx_timeout - Respond to a Tx Hang |
| 5512 | * @netdev: network interface device structure |
| 5513 | **/ |
| 5514 | static void ixgbe_tx_timeout(struct net_device *netdev) |
| 5515 | { |
| 5516 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5517 | |
| 5518 | /* Do the reset outside of interrupt context */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 5519 | ixgbe_tx_timeout_reset(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5520 | } |
| 5521 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 5522 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5523 | * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter) |
| 5524 | * @adapter: board private structure to initialize |
| 5525 | * |
| 5526 | * ixgbe_sw_init initializes the Adapter private data structure. |
| 5527 | * Fields are initialized based on PCI device information and |
| 5528 | * OS network device settings (MTU size). |
| 5529 | **/ |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 5530 | static int ixgbe_sw_init(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5531 | { |
| 5532 | struct ixgbe_hw *hw = &adapter->hw; |
| 5533 | struct pci_dev *pdev = adapter->pdev; |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 5534 | unsigned int rss, fdir; |
Jacob Keller | cb6d0f5 | 2012-12-04 06:03:14 +0000 | [diff] [blame] | 5535 | u32 fwsm; |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5536 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5537 | int j; |
| 5538 | struct tc_configuration *tc; |
| 5539 | #endif |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5540 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5541 | /* PCI config space info */ |
| 5542 | |
| 5543 | hw->vendor_id = pdev->vendor; |
| 5544 | hw->device_id = pdev->device; |
| 5545 | hw->revision_id = pdev->revision; |
| 5546 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 5547 | hw->subsystem_device_id = pdev->subsystem_device; |
| 5548 | |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5549 | /* Set common capability flags and settings */ |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 5550 | rss = min_t(int, ixgbe_max_rss_indices(adapter), num_online_cpus()); |
Alexander Duyck | c087663 | 2012-05-10 00:01:46 +0000 | [diff] [blame] | 5551 | adapter->ring_feature[RING_F_RSS].limit = rss; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5552 | adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5553 | adapter->max_q_vectors = MAX_Q_VECTORS_82599; |
| 5554 | adapter->atr_sample_rate = 20; |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 5555 | fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus()); |
| 5556 | adapter->ring_feature[RING_F_FDIR].limit = fdir; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5557 | adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K; |
| 5558 | #ifdef CONFIG_IXGBE_DCA |
| 5559 | adapter->flags |= IXGBE_FLAG_DCA_CAPABLE; |
| 5560 | #endif |
| 5561 | #ifdef IXGBE_FCOE |
| 5562 | adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE; |
| 5563 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 5564 | #ifdef CONFIG_IXGBE_DCB |
| 5565 | /* Default traffic class to use for FCoE */ |
| 5566 | adapter->fcoe.up = IXGBE_FCOE_DEFTC; |
| 5567 | #endif /* CONFIG_IXGBE_DCB */ |
| 5568 | #endif /* IXGBE_FCOE */ |
| 5569 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 5570 | /* initialize static ixgbe jump table entries */ |
| 5571 | adapter->jump_tables[0] = ixgbe_ipv4_fields; |
| 5572 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 5573 | adapter->mac_table = kzalloc(sizeof(struct ixgbe_mac_addr) * |
| 5574 | hw->mac.num_rar_entries, |
| 5575 | GFP_ATOMIC); |
Alexander Duyck | 530fd82 | 2015-11-02 17:09:29 -0800 | [diff] [blame] | 5576 | if (!adapter->mac_table) |
| 5577 | return -ENOMEM; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 5578 | |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5579 | /* Set MAC specific capability flags and exceptions */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5580 | switch (hw->mac.type) { |
| 5581 | case ixgbe_mac_82598EB: |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5582 | adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5583 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5584 | if (hw->device_id == IXGBE_DEV_ID_82598AT) |
| 5585 | adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5586 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 5587 | adapter->max_q_vectors = MAX_Q_VECTORS_82598; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5588 | adapter->ring_feature[RING_F_FDIR].limit = 0; |
| 5589 | adapter->atr_sample_rate = 0; |
| 5590 | adapter->fdir_pballoc = 0; |
| 5591 | #ifdef IXGBE_FCOE |
| 5592 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
| 5593 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 5594 | #ifdef CONFIG_IXGBE_DCB |
| 5595 | adapter->fcoe.up = 0; |
| 5596 | #endif /* IXGBE_DCB */ |
| 5597 | #endif /* IXGBE_FCOE */ |
| 5598 | break; |
| 5599 | case ixgbe_mac_82599EB: |
| 5600 | if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM) |
| 5601 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5602 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5603 | case ixgbe_mac_X540: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 5604 | fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw)); |
Jacob Keller | cb6d0f5 | 2012-12-04 06:03:14 +0000 | [diff] [blame] | 5605 | if (fwsm & IXGBE_FWSM_TS_ENABLED) |
| 5606 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5607 | break; |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5608 | case ixgbe_mac_X550EM_x: |
| 5609 | case ixgbe_mac_X550: |
| 5610 | #ifdef CONFIG_IXGBE_DCA |
| 5611 | adapter->flags &= ~IXGBE_FLAG_DCA_CAPABLE; |
| 5612 | #endif |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 5613 | #ifdef CONFIG_IXGBE_VXLAN |
| 5614 | adapter->flags |= IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE; |
| 5615 | #endif |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5616 | break; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5617 | default: |
| 5618 | break; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5619 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5620 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 5621 | #ifdef IXGBE_FCOE |
| 5622 | /* FCoE support exists, always init the FCoE lock */ |
| 5623 | spin_lock_init(&adapter->fcoe.lock); |
| 5624 | |
| 5625 | #endif |
Alexander Duyck | 1fc5f03 | 2011-06-02 04:28:39 +0000 | [diff] [blame] | 5626 | /* n-tuple support exists, always init our spinlock */ |
| 5627 | spin_lock_init(&adapter->fdir_perfect_lock); |
| 5628 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5629 | #ifdef CONFIG_IXGBE_DCB |
John Fastabend | 4de2a02 | 2011-09-27 03:52:01 +0000 | [diff] [blame] | 5630 | switch (hw->mac.type) { |
| 5631 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5632 | case ixgbe_mac_X550: |
| 5633 | case ixgbe_mac_X550EM_x: |
John Fastabend | 4de2a02 | 2011-09-27 03:52:01 +0000 | [diff] [blame] | 5634 | adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS; |
| 5635 | adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS; |
| 5636 | break; |
| 5637 | default: |
| 5638 | adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS; |
| 5639 | adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS; |
| 5640 | break; |
| 5641 | } |
| 5642 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5643 | /* Configure DCB traffic classes */ |
| 5644 | for (j = 0; j < MAX_TRAFFIC_CLASS; j++) { |
| 5645 | tc = &adapter->dcb_cfg.tc_config[j]; |
| 5646 | tc->path[DCB_TX_CONFIG].bwg_id = 0; |
| 5647 | tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1); |
| 5648 | tc->path[DCB_RX_CONFIG].bwg_id = 0; |
| 5649 | tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1); |
| 5650 | tc->dcb_pfc = pfc_disabled; |
| 5651 | } |
John Fastabend | 4de2a02 | 2011-09-27 03:52:01 +0000 | [diff] [blame] | 5652 | |
| 5653 | /* Initialize default user to priority mapping, UPx->TC0 */ |
| 5654 | tc = &adapter->dcb_cfg.tc_config[0]; |
| 5655 | tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF; |
| 5656 | tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF; |
| 5657 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5658 | adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100; |
| 5659 | adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100; |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 5660 | adapter->dcb_cfg.pfc_mode_enable = false; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5661 | adapter->dcb_set_bitmap = 0x00; |
John Fastabend | 3032309 | 2011-03-01 05:25:35 +0000 | [diff] [blame] | 5662 | adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE; |
John Fastabend | f525c6d2 | 2012-04-18 22:42:27 +0000 | [diff] [blame] | 5663 | memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg, |
| 5664 | sizeof(adapter->temp_dcb_cfg)); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5665 | |
| 5666 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5667 | |
| 5668 | /* default flow control settings */ |
Don Skidmore | cd7664f | 2009-03-31 21:33:44 +0000 | [diff] [blame] | 5669 | hw->fc.requested_mode = ixgbe_fc_full; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 5670 | hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */ |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5671 | ixgbe_pbthresh_setup(adapter); |
Jesse Brandeburg | 2b9ade9 | 2008-08-26 04:27:10 -0700 | [diff] [blame] | 5672 | hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE; |
| 5673 | hw->fc.send_xon = true; |
Don Skidmore | 73d80953d | 2013-07-31 02:19:24 +0000 | [diff] [blame] | 5674 | hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5675 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 5676 | #ifdef CONFIG_PCI_IOV |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 5677 | if (max_vfs > 0) |
| 5678 | 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] | 5679 | |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 5680 | /* assign number of SR-IOV VFs */ |
| 5681 | if (hw->mac.type != ixgbe_mac_82598EB) { |
ethan.zhao | dcc23e3 | 2014-01-16 19:41:04 -0800 | [diff] [blame] | 5682 | if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) { |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 5683 | adapter->num_vfs = 0; |
| 5684 | e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n"); |
| 5685 | } else { |
| 5686 | adapter->num_vfs = max_vfs; |
| 5687 | } |
| 5688 | } |
| 5689 | #endif /* CONFIG_PCI_IOV */ |
| 5690 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5691 | /* enable itr by default in dynamic mode */ |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 5692 | adapter->rx_itr_setting = 1; |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 5693 | adapter->tx_itr_setting = 1; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5694 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5695 | /* set default ring sizes */ |
| 5696 | adapter->tx_ring_count = IXGBE_DEFAULT_TXD; |
| 5697 | adapter->rx_ring_count = IXGBE_DEFAULT_RXD; |
| 5698 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 5699 | /* set default work limits */ |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 5700 | adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 5701 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5702 | /* initialize eeprom parameters */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5703 | if (ixgbe_init_eeprom_params_generic(hw)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5704 | e_dev_err("EEPROM initialization failed\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5705 | return -EIO; |
| 5706 | } |
| 5707 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5708 | /* PF holds first pool slot */ |
| 5709 | set_bit(0, &adapter->fwd_bitmask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5710 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 5711 | |
| 5712 | return 0; |
| 5713 | } |
| 5714 | |
| 5715 | /** |
| 5716 | * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5717 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5718 | * |
| 5719 | * Return 0 on success, negative on failure |
| 5720 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5721 | int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5722 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5723 | struct device *dev = tx_ring->dev; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5724 | int orig_node = dev_to_node(dev); |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5725 | int ring_node = -1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5726 | int size; |
| 5727 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5728 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5729 | |
| 5730 | if (tx_ring->q_vector) |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5731 | ring_node = tx_ring->q_vector->numa_node; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5732 | |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5733 | tx_ring->tx_buffer_info = vzalloc_node(size, ring_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5734 | if (!tx_ring->tx_buffer_info) |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5735 | tx_ring->tx_buffer_info = vzalloc(size); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5736 | if (!tx_ring->tx_buffer_info) |
| 5737 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5738 | |
John Stultz | 827da44 | 2013-10-07 15:51:58 -0700 | [diff] [blame] | 5739 | u64_stats_init(&tx_ring->syncp); |
| 5740 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5741 | /* round up to nearest 4K */ |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 5742 | tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5743 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5744 | |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5745 | set_dev_node(dev, ring_node); |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5746 | tx_ring->desc = dma_alloc_coherent(dev, |
| 5747 | tx_ring->size, |
| 5748 | &tx_ring->dma, |
| 5749 | GFP_KERNEL); |
| 5750 | set_dev_node(dev, orig_node); |
| 5751 | if (!tx_ring->desc) |
| 5752 | tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size, |
| 5753 | &tx_ring->dma, GFP_KERNEL); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5754 | if (!tx_ring->desc) |
| 5755 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5756 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5757 | tx_ring->next_to_use = 0; |
| 5758 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5759 | return 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5760 | |
| 5761 | err: |
| 5762 | vfree(tx_ring->tx_buffer_info); |
| 5763 | tx_ring->tx_buffer_info = NULL; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5764 | 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] | 5765 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5766 | } |
| 5767 | |
| 5768 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5769 | * ixgbe_setup_all_tx_resources - allocate all queues Tx resources |
| 5770 | * @adapter: board private structure |
| 5771 | * |
| 5772 | * If this function returns with an error, then it's possible one or |
| 5773 | * more of the rings is populated (while the rest are not). It is the |
| 5774 | * callers duty to clean those orphaned rings. |
| 5775 | * |
| 5776 | * Return 0 on success, negative on failure |
| 5777 | **/ |
| 5778 | static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) |
| 5779 | { |
| 5780 | int i, err = 0; |
| 5781 | |
| 5782 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5783 | err = ixgbe_setup_tx_resources(adapter->tx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5784 | if (!err) |
| 5785 | continue; |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5786 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5787 | e_err(probe, "Allocation for Tx Queue %u failed\n", i); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5788 | goto err_setup_tx; |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5789 | } |
| 5790 | |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5791 | return 0; |
| 5792 | err_setup_tx: |
| 5793 | /* rewind the index freeing the rings as we go */ |
| 5794 | while (i--) |
| 5795 | ixgbe_free_tx_resources(adapter->tx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5796 | return err; |
| 5797 | } |
| 5798 | |
| 5799 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5800 | * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5801 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5802 | * |
| 5803 | * Returns 0 on success, negative on failure |
| 5804 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5805 | int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5806 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5807 | struct device *dev = rx_ring->dev; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5808 | int orig_node = dev_to_node(dev); |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5809 | int ring_node = -1; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5810 | int size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5811 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5812 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5813 | |
| 5814 | if (rx_ring->q_vector) |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5815 | ring_node = rx_ring->q_vector->numa_node; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5816 | |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5817 | rx_ring->rx_buffer_info = vzalloc_node(size, ring_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5818 | if (!rx_ring->rx_buffer_info) |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5819 | rx_ring->rx_buffer_info = vzalloc(size); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5820 | if (!rx_ring->rx_buffer_info) |
| 5821 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5822 | |
John Stultz | 827da44 | 2013-10-07 15:51:58 -0700 | [diff] [blame] | 5823 | u64_stats_init(&rx_ring->syncp); |
| 5824 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5825 | /* Round up to nearest 4K */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5826 | rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); |
| 5827 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5828 | |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5829 | set_dev_node(dev, ring_node); |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5830 | rx_ring->desc = dma_alloc_coherent(dev, |
| 5831 | rx_ring->size, |
| 5832 | &rx_ring->dma, |
| 5833 | GFP_KERNEL); |
| 5834 | set_dev_node(dev, orig_node); |
| 5835 | if (!rx_ring->desc) |
| 5836 | rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size, |
| 5837 | &rx_ring->dma, GFP_KERNEL); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5838 | if (!rx_ring->desc) |
| 5839 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5840 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5841 | rx_ring->next_to_clean = 0; |
| 5842 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5843 | |
| 5844 | return 0; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5845 | err: |
| 5846 | vfree(rx_ring->rx_buffer_info); |
| 5847 | rx_ring->rx_buffer_info = NULL; |
| 5848 | 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] | 5849 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5850 | } |
| 5851 | |
| 5852 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5853 | * ixgbe_setup_all_rx_resources - allocate all queues Rx resources |
| 5854 | * @adapter: board private structure |
| 5855 | * |
| 5856 | * If this function returns with an error, then it's possible one or |
| 5857 | * more of the rings is populated (while the rest are not). It is the |
| 5858 | * callers duty to clean those orphaned rings. |
| 5859 | * |
| 5860 | * Return 0 on success, negative on failure |
| 5861 | **/ |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5862 | static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) |
| 5863 | { |
| 5864 | int i, err = 0; |
| 5865 | |
| 5866 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5867 | err = ixgbe_setup_rx_resources(adapter->rx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5868 | if (!err) |
| 5869 | continue; |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5870 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5871 | e_err(probe, "Allocation for Rx Queue %u failed\n", i); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5872 | goto err_setup_rx; |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5873 | } |
| 5874 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 5875 | #ifdef IXGBE_FCOE |
| 5876 | err = ixgbe_setup_fcoe_ddp_resources(adapter); |
| 5877 | if (!err) |
| 5878 | #endif |
| 5879 | return 0; |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5880 | err_setup_rx: |
| 5881 | /* rewind the index freeing the rings as we go */ |
| 5882 | while (i--) |
| 5883 | ixgbe_free_rx_resources(adapter->rx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5884 | return err; |
| 5885 | } |
| 5886 | |
| 5887 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5888 | * ixgbe_free_tx_resources - Free Tx Resources per Queue |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5889 | * @tx_ring: Tx descriptor ring for a specific queue |
| 5890 | * |
| 5891 | * Free all transmit software resources |
| 5892 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5893 | void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5894 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5895 | ixgbe_clean_tx_ring(tx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5896 | |
| 5897 | vfree(tx_ring->tx_buffer_info); |
| 5898 | tx_ring->tx_buffer_info = NULL; |
| 5899 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5900 | /* if not set, then don't free */ |
| 5901 | if (!tx_ring->desc) |
| 5902 | return; |
| 5903 | |
| 5904 | dma_free_coherent(tx_ring->dev, tx_ring->size, |
| 5905 | tx_ring->desc, tx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5906 | |
| 5907 | tx_ring->desc = NULL; |
| 5908 | } |
| 5909 | |
| 5910 | /** |
| 5911 | * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues |
| 5912 | * @adapter: board private structure |
| 5913 | * |
| 5914 | * Free all transmit software resources |
| 5915 | **/ |
| 5916 | static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter) |
| 5917 | { |
| 5918 | int i; |
| 5919 | |
| 5920 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5921 | if (adapter->tx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5922 | ixgbe_free_tx_resources(adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5923 | } |
| 5924 | |
| 5925 | /** |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5926 | * ixgbe_free_rx_resources - Free Rx Resources |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5927 | * @rx_ring: ring to clean the resources from |
| 5928 | * |
| 5929 | * Free all receive software resources |
| 5930 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5931 | void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5932 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5933 | ixgbe_clean_rx_ring(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5934 | |
| 5935 | vfree(rx_ring->rx_buffer_info); |
| 5936 | rx_ring->rx_buffer_info = NULL; |
| 5937 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5938 | /* if not set, then don't free */ |
| 5939 | if (!rx_ring->desc) |
| 5940 | return; |
| 5941 | |
| 5942 | dma_free_coherent(rx_ring->dev, rx_ring->size, |
| 5943 | rx_ring->desc, rx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5944 | |
| 5945 | rx_ring->desc = NULL; |
| 5946 | } |
| 5947 | |
| 5948 | /** |
| 5949 | * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues |
| 5950 | * @adapter: board private structure |
| 5951 | * |
| 5952 | * Free all receive software resources |
| 5953 | **/ |
| 5954 | static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter) |
| 5955 | { |
| 5956 | int i; |
| 5957 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 5958 | #ifdef IXGBE_FCOE |
| 5959 | ixgbe_free_fcoe_ddp_resources(adapter); |
| 5960 | |
| 5961 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5962 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5963 | if (adapter->rx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5964 | ixgbe_free_rx_resources(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5965 | } |
| 5966 | |
| 5967 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5968 | * ixgbe_change_mtu - Change the Maximum Transfer Unit |
| 5969 | * @netdev: network interface device structure |
| 5970 | * @new_mtu: new value for maximum frame size |
| 5971 | * |
| 5972 | * Returns 0 on success, negative on failure |
| 5973 | **/ |
| 5974 | static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu) |
| 5975 | { |
| 5976 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5977 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 5978 | |
Jesse Brandeburg | 42c783c | 2008-09-11 19:56:28 -0700 | [diff] [blame] | 5979 | /* MTU < 68 is an error and causes problems on some kernels */ |
Alexander Duyck | 655309e | 2012-02-08 07:50:35 +0000 | [diff] [blame] | 5980 | if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) |
| 5981 | return -EINVAL; |
| 5982 | |
| 5983 | /* |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 5984 | * For 82599EB we cannot allow legacy VFs to enable their receive |
| 5985 | * paths when MTU greater than 1500 is configured. So display a |
| 5986 | * warning that legacy VFs will be disabled. |
Alexander Duyck | 655309e | 2012-02-08 07:50:35 +0000 | [diff] [blame] | 5987 | */ |
| 5988 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && |
| 5989 | (adapter->hw.mac.type == ixgbe_mac_82599EB) && |
Alexander Duyck | c560451 | 2013-01-09 08:50:42 +0000 | [diff] [blame] | 5990 | (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN))) |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 5991 | e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5992 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5993 | 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] | 5994 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5995 | /* must set new MTU before calling down or up */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5996 | netdev->mtu = new_mtu; |
| 5997 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5998 | if (netif_running(netdev)) |
| 5999 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6000 | |
| 6001 | return 0; |
| 6002 | } |
| 6003 | |
| 6004 | /** |
| 6005 | * ixgbe_open - Called when a network interface is made active |
| 6006 | * @netdev: network interface device structure |
| 6007 | * |
| 6008 | * Returns 0 on success, negative value on failure |
| 6009 | * |
| 6010 | * The open entry point is called when a network interface is made |
| 6011 | * active by the system (IFF_UP). At this point all resources needed |
| 6012 | * for transmit and receive operations are allocated, the interrupt |
| 6013 | * handler is registered with the OS, the watchdog timer is started, |
| 6014 | * and the stack is notified that the interface is ready. |
| 6015 | **/ |
Stefan Assmann | 6c211fe1 | 2016-02-03 09:20:48 +0100 | [diff] [blame] | 6016 | int ixgbe_open(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6017 | { |
| 6018 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 6019 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 6020 | int err, queues; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6021 | |
Auke Kok | 4bebfaa | 2008-02-11 09:26:01 -0800 | [diff] [blame] | 6022 | /* disallow open during test */ |
| 6023 | if (test_bit(__IXGBE_TESTING, &adapter->state)) |
| 6024 | return -EBUSY; |
| 6025 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 6026 | netif_carrier_off(netdev); |
| 6027 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6028 | /* allocate transmit descriptors */ |
| 6029 | err = ixgbe_setup_all_tx_resources(adapter); |
| 6030 | if (err) |
| 6031 | goto err_setup_tx; |
| 6032 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6033 | /* allocate receive descriptors */ |
| 6034 | err = ixgbe_setup_all_rx_resources(adapter); |
| 6035 | if (err) |
| 6036 | goto err_setup_rx; |
| 6037 | |
| 6038 | ixgbe_configure(adapter); |
| 6039 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6040 | err = ixgbe_request_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6041 | if (err) |
| 6042 | goto err_req_irq; |
| 6043 | |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6044 | /* Notify the stack of the actual queue counts. */ |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 6045 | if (adapter->num_rx_pools > 1) |
| 6046 | queues = adapter->num_rx_queues_per_pool; |
| 6047 | else |
| 6048 | queues = adapter->num_tx_queues; |
| 6049 | |
| 6050 | err = netif_set_real_num_tx_queues(netdev, queues); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6051 | if (err) |
| 6052 | goto err_set_queues; |
| 6053 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 6054 | if (adapter->num_rx_pools > 1 && |
| 6055 | adapter->num_rx_queues > IXGBE_MAX_L2A_QUEUES) |
| 6056 | queues = IXGBE_MAX_L2A_QUEUES; |
| 6057 | else |
| 6058 | queues = adapter->num_rx_queues; |
| 6059 | err = netif_set_real_num_rx_queues(netdev, queues); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6060 | if (err) |
| 6061 | goto err_set_queues; |
| 6062 | |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6063 | ixgbe_ptp_init(adapter); |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6064 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 6065 | ixgbe_up_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6066 | |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 6067 | ixgbe_clear_vxlan_port(adapter); |
| 6068 | #ifdef CONFIG_IXGBE_VXLAN |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 6069 | vxlan_get_rx_port(netdev); |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 6070 | #endif |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 6071 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6072 | return 0; |
| 6073 | |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6074 | err_set_queues: |
| 6075 | ixgbe_free_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6076 | err_req_irq: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 6077 | ixgbe_free_all_rx_resources(adapter); |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 6078 | if (hw->phy.ops.set_phy_power && !adapter->wol) |
| 6079 | hw->phy.ops.set_phy_power(&adapter->hw, false); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6080 | err_setup_rx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 6081 | ixgbe_free_all_tx_resources(adapter); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6082 | err_setup_tx: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6083 | ixgbe_reset(adapter); |
| 6084 | |
| 6085 | return err; |
| 6086 | } |
| 6087 | |
Jacob Keller | a0cccce | 2014-05-16 05:12:29 +0000 | [diff] [blame] | 6088 | static void ixgbe_close_suspend(struct ixgbe_adapter *adapter) |
| 6089 | { |
| 6090 | ixgbe_ptp_suspend(adapter); |
| 6091 | |
Don Skidmore | 6ac7439 | 2015-06-17 17:34:31 -0400 | [diff] [blame] | 6092 | if (adapter->hw.phy.ops.enter_lplu) { |
| 6093 | adapter->hw.phy.reset_disable = true; |
| 6094 | ixgbe_down(adapter); |
| 6095 | adapter->hw.phy.ops.enter_lplu(&adapter->hw); |
| 6096 | adapter->hw.phy.reset_disable = false; |
| 6097 | } else { |
| 6098 | ixgbe_down(adapter); |
| 6099 | } |
| 6100 | |
Jacob Keller | a0cccce | 2014-05-16 05:12:29 +0000 | [diff] [blame] | 6101 | ixgbe_free_irq(adapter); |
| 6102 | |
| 6103 | ixgbe_free_all_tx_resources(adapter); |
| 6104 | ixgbe_free_all_rx_resources(adapter); |
| 6105 | } |
| 6106 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6107 | /** |
| 6108 | * ixgbe_close - Disables a network interface |
| 6109 | * @netdev: network interface device structure |
| 6110 | * |
| 6111 | * Returns 0, this is not allowed to fail |
| 6112 | * |
| 6113 | * The close entry point is called when an interface is de-activated |
| 6114 | * by the OS. The hardware is still under the drivers control, but |
| 6115 | * needs to be disabled. A global MAC reset is issued to stop the |
| 6116 | * hardware, and all transmit and receive resources are freed. |
| 6117 | **/ |
Stefan Assmann | 6c211fe1 | 2016-02-03 09:20:48 +0100 | [diff] [blame] | 6118 | int ixgbe_close(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6119 | { |
| 6120 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6121 | |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6122 | ixgbe_ptp_stop(adapter); |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6123 | |
Jacob Keller | a0cccce | 2014-05-16 05:12:29 +0000 | [diff] [blame] | 6124 | ixgbe_close_suspend(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6125 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 6126 | ixgbe_fdir_filter_exit(adapter); |
| 6127 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 6128 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6129 | |
| 6130 | return 0; |
| 6131 | } |
| 6132 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6133 | #ifdef CONFIG_PM |
| 6134 | static int ixgbe_resume(struct pci_dev *pdev) |
| 6135 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 6136 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 6137 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6138 | u32 err; |
| 6139 | |
Mark Rustad | 0391bbe | 2014-02-28 15:48:55 -0800 | [diff] [blame] | 6140 | adapter->hw.hw_addr = adapter->io_addr; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6141 | pci_set_power_state(pdev, PCI_D0); |
| 6142 | pci_restore_state(pdev); |
Don Skidmore | 656ab81 | 2009-12-23 21:19:19 -0800 | [diff] [blame] | 6143 | /* |
| 6144 | * pci_restore_state clears dev->state_saved so call |
| 6145 | * pci_save_state to restore it. |
| 6146 | */ |
| 6147 | pci_save_state(pdev); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 6148 | |
| 6149 | err = pci_enable_device_mem(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6150 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 6151 | e_dev_err("Cannot enable PCI device from suspend\n"); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6152 | return err; |
| 6153 | } |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 6154 | smp_mb__before_atomic(); |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 6155 | clear_bit(__IXGBE_DISABLED, &adapter->state); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6156 | pci_set_master(pdev); |
| 6157 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 6158 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6159 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6160 | ixgbe_reset(adapter); |
| 6161 | |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 6162 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
| 6163 | |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6164 | rtnl_lock(); |
| 6165 | err = ixgbe_init_interrupt_scheme(adapter); |
| 6166 | if (!err && netif_running(netdev)) |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 6167 | err = ixgbe_open(netdev); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6168 | |
| 6169 | rtnl_unlock(); |
| 6170 | |
| 6171 | if (err) |
| 6172 | return err; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6173 | |
| 6174 | netif_device_attach(netdev); |
| 6175 | |
| 6176 | return 0; |
| 6177 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6178 | #endif /* CONFIG_PM */ |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6179 | |
| 6180 | static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6181 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 6182 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 6183 | struct net_device *netdev = adapter->netdev; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6184 | struct ixgbe_hw *hw = &adapter->hw; |
| 6185 | u32 ctrl, fctrl; |
| 6186 | u32 wufc = adapter->wol; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6187 | #ifdef CONFIG_PM |
| 6188 | int retval = 0; |
| 6189 | #endif |
| 6190 | |
| 6191 | netif_device_detach(netdev); |
| 6192 | |
akepner | 499ab5c | 2013-03-13 14:54:58 +0000 | [diff] [blame] | 6193 | rtnl_lock(); |
Jacob Keller | a0cccce | 2014-05-16 05:12:29 +0000 | [diff] [blame] | 6194 | if (netif_running(netdev)) |
| 6195 | ixgbe_close_suspend(adapter); |
akepner | 499ab5c | 2013-03-13 14:54:58 +0000 | [diff] [blame] | 6196 | rtnl_unlock(); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6197 | |
Alexander Duyck | 5f5ae6f | 2010-11-16 19:26:52 -0800 | [diff] [blame] | 6198 | ixgbe_clear_interrupt_scheme(adapter); |
| 6199 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6200 | #ifdef CONFIG_PM |
| 6201 | retval = pci_save_state(pdev); |
| 6202 | if (retval) |
| 6203 | return retval; |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 6204 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6205 | #endif |
Jacob Keller | f4f1040 | 2013-06-25 07:59:23 +0000 | [diff] [blame] | 6206 | if (hw->mac.ops.stop_link_on_d3) |
| 6207 | hw->mac.ops.stop_link_on_d3(hw); |
| 6208 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6209 | if (wufc) { |
| 6210 | ixgbe_set_rx_mode(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6211 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 6212 | /* enable the optics for 82599 SFP+ fiber as we can WoL */ |
| 6213 | if (hw->mac.ops.enable_tx_laser) |
Don Skidmore | c509e75 | 2012-04-05 08:12:05 +0000 | [diff] [blame] | 6214 | hw->mac.ops.enable_tx_laser(hw); |
| 6215 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6216 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 6217 | if (wufc & IXGBE_WUFC_MC) { |
| 6218 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 6219 | fctrl |= IXGBE_FCTRL_MPE; |
| 6220 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
| 6221 | } |
| 6222 | |
| 6223 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 6224 | ctrl |= IXGBE_CTRL_GIO_DIS; |
| 6225 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); |
| 6226 | |
| 6227 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc); |
| 6228 | } else { |
| 6229 | IXGBE_WRITE_REG(hw, IXGBE_WUC, 0); |
| 6230 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0); |
| 6231 | } |
| 6232 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6233 | switch (hw->mac.type) { |
| 6234 | case ixgbe_mac_82598EB: |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 6235 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6236 | break; |
| 6237 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 6238 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6239 | case ixgbe_mac_X550: |
| 6240 | case ixgbe_mac_X550EM_x: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6241 | pci_wake_from_d3(pdev, !!wufc); |
| 6242 | break; |
| 6243 | default: |
| 6244 | break; |
| 6245 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6246 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6247 | *enable_wake = !!wufc; |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 6248 | if (hw->phy.ops.set_phy_power && !*enable_wake) |
| 6249 | hw->phy.ops.set_phy_power(hw, false); |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6250 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6251 | ixgbe_release_hw_control(adapter); |
| 6252 | |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 6253 | if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state)) |
| 6254 | pci_disable_device(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6255 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6256 | return 0; |
| 6257 | } |
| 6258 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6259 | #ifdef CONFIG_PM |
| 6260 | static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state) |
| 6261 | { |
| 6262 | int retval; |
| 6263 | bool wake; |
| 6264 | |
| 6265 | retval = __ixgbe_shutdown(pdev, &wake); |
| 6266 | if (retval) |
| 6267 | return retval; |
| 6268 | |
| 6269 | if (wake) { |
| 6270 | pci_prepare_to_sleep(pdev); |
| 6271 | } else { |
| 6272 | pci_wake_from_d3(pdev, false); |
| 6273 | pci_set_power_state(pdev, PCI_D3hot); |
| 6274 | } |
| 6275 | |
| 6276 | return 0; |
| 6277 | } |
| 6278 | #endif /* CONFIG_PM */ |
| 6279 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6280 | static void ixgbe_shutdown(struct pci_dev *pdev) |
| 6281 | { |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6282 | bool wake; |
| 6283 | |
| 6284 | __ixgbe_shutdown(pdev, &wake); |
| 6285 | |
| 6286 | if (system_state == SYSTEM_POWER_OFF) { |
| 6287 | pci_wake_from_d3(pdev, wake); |
| 6288 | pci_set_power_state(pdev, PCI_D3hot); |
| 6289 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6290 | } |
| 6291 | |
| 6292 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6293 | * ixgbe_update_stats - Update the board statistics counters. |
| 6294 | * @adapter: board private structure |
| 6295 | **/ |
| 6296 | void ixgbe_update_stats(struct ixgbe_adapter *adapter) |
| 6297 | { |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 6298 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6299 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6300 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6301 | u64 total_mpc = 0; |
| 6302 | u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6303 | u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0; |
| 6304 | u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 6305 | u64 bytes = 0, packets = 0, hw_csum_rx_error = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6306 | |
Don Skidmore | d08935c | 2010-06-11 13:20:29 +0000 | [diff] [blame] | 6307 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 6308 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 6309 | return; |
| 6310 | |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 6311 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 6312 | u64 rsc_count = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 6313 | u64 rsc_flush = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 6314 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6315 | rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count; |
| 6316 | rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 6317 | } |
| 6318 | adapter->rsc_total_count = rsc_count; |
| 6319 | adapter->rsc_total_flush = rsc_flush; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 6320 | } |
| 6321 | |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6322 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 6323 | struct ixgbe_ring *rx_ring = adapter->rx_ring[i]; |
| 6324 | non_eop_descs += rx_ring->rx_stats.non_eop_descs; |
| 6325 | alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed; |
| 6326 | alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 6327 | hw_csum_rx_error += rx_ring->rx_stats.csum_err; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6328 | bytes += rx_ring->stats.bytes; |
| 6329 | packets += rx_ring->stats.packets; |
| 6330 | } |
Mallikarjuna R Chilakala | eb985f0 | 2009-12-15 11:56:59 +0000 | [diff] [blame] | 6331 | adapter->non_eop_descs = non_eop_descs; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6332 | adapter->alloc_rx_page_failed = alloc_rx_page_failed; |
| 6333 | adapter->alloc_rx_buff_failed = alloc_rx_buff_failed; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 6334 | adapter->hw_csum_rx_error = hw_csum_rx_error; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6335 | netdev->stats.rx_bytes = bytes; |
| 6336 | netdev->stats.rx_packets = packets; |
| 6337 | |
| 6338 | bytes = 0; |
| 6339 | packets = 0; |
| 6340 | /* gather some stats to the adapter struct that are per queue */ |
| 6341 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 6342 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 6343 | restart_queue += tx_ring->tx_stats.restart_queue; |
| 6344 | tx_busy += tx_ring->tx_stats.tx_busy; |
| 6345 | bytes += tx_ring->stats.bytes; |
| 6346 | packets += tx_ring->stats.packets; |
| 6347 | } |
| 6348 | adapter->restart_queue = restart_queue; |
| 6349 | adapter->tx_busy = tx_busy; |
| 6350 | netdev->stats.tx_bytes = bytes; |
| 6351 | netdev->stats.tx_packets = packets; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 6352 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6353 | hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS); |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6354 | |
| 6355 | /* 8 register reads */ |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6356 | for (i = 0; i < 8; i++) { |
| 6357 | /* for packet buffers not used, the register should read 0 */ |
| 6358 | mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i)); |
| 6359 | missed_rx += mpc; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6360 | hwstats->mpc[i] += mpc; |
| 6361 | total_mpc += hwstats->mpc[i]; |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6362 | hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i)); |
| 6363 | hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6364 | switch (hw->mac.type) { |
| 6365 | case ixgbe_mac_82598EB: |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6366 | hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i)); |
| 6367 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i)); |
| 6368 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i)); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6369 | hwstats->pxonrxc[i] += |
| 6370 | IXGBE_READ_REG(hw, IXGBE_PXONRXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6371 | break; |
| 6372 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 6373 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6374 | case ixgbe_mac_X550: |
| 6375 | case ixgbe_mac_X550EM_x: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6376 | hwstats->pxonrxc[i] += |
| 6377 | IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6378 | break; |
| 6379 | default: |
| 6380 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6381 | } |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6382 | } |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6383 | |
| 6384 | /*16 register reads */ |
| 6385 | for (i = 0; i < 16; i++) { |
| 6386 | hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i)); |
| 6387 | hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i)); |
| 6388 | if ((hw->mac.type == ixgbe_mac_82599EB) || |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6389 | (hw->mac.type == ixgbe_mac_X540) || |
| 6390 | (hw->mac.type == ixgbe_mac_X550) || |
| 6391 | (hw->mac.type == ixgbe_mac_X550EM_x)) { |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6392 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i)); |
| 6393 | IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */ |
| 6394 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i)); |
| 6395 | IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */ |
| 6396 | } |
| 6397 | } |
| 6398 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6399 | hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6400 | /* work around hardware counting issue */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6401 | hwstats->gprc -= missed_rx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6402 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 6403 | ixgbe_update_xoff_received(adapter); |
| 6404 | |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6405 | /* 82598 hardware only has a 32 bit counter in the high register */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6406 | switch (hw->mac.type) { |
| 6407 | case ixgbe_mac_82598EB: |
| 6408 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6409 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH); |
| 6410 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH); |
| 6411 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH); |
| 6412 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 6413 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6414 | case ixgbe_mac_X550: |
| 6415 | case ixgbe_mac_X550EM_x: |
| 6416 | /* OS2BMC stats are X540 and later */ |
Emil Tantilov | 58f6bcf | 2011-04-21 08:43:43 +0000 | [diff] [blame] | 6417 | hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC); |
| 6418 | hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC); |
| 6419 | hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC); |
| 6420 | hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC); |
| 6421 | case ixgbe_mac_82599EB: |
Alexander Duyck | a4d4f62 | 2012-03-28 08:03:32 +0000 | [diff] [blame] | 6422 | for (i = 0; i < 16; i++) |
| 6423 | adapter->hw_rx_no_dma_resources += |
| 6424 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6425 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6426 | IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6427 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6428 | IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6429 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6430 | IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6431 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6432 | hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH); |
| 6433 | hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS); |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 6434 | #ifdef IXGBE_FCOE |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6435 | hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC); |
| 6436 | hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC); |
| 6437 | hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC); |
| 6438 | hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC); |
| 6439 | hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC); |
| 6440 | hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC); |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 6441 | /* Add up per cpu counters for total ddp aloc fail */ |
Alexander Duyck | 5a1ee27 | 2012-05-05 17:14:28 +0000 | [diff] [blame] | 6442 | if (adapter->fcoe.ddp_pool) { |
| 6443 | struct ixgbe_fcoe *fcoe = &adapter->fcoe; |
| 6444 | struct ixgbe_fcoe_ddp_pool *ddp_pool; |
| 6445 | unsigned int cpu; |
| 6446 | u64 noddp = 0, noddp_ext_buff = 0; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 6447 | for_each_possible_cpu(cpu) { |
Alexander Duyck | 5a1ee27 | 2012-05-05 17:14:28 +0000 | [diff] [blame] | 6448 | ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu); |
| 6449 | noddp += ddp_pool->noddp; |
| 6450 | noddp_ext_buff += ddp_pool->noddp_ext_buff; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 6451 | } |
Alexander Duyck | 5a1ee27 | 2012-05-05 17:14:28 +0000 | [diff] [blame] | 6452 | hwstats->fcoe_noddp = noddp; |
| 6453 | hwstats->fcoe_noddp_ext_buff = noddp_ext_buff; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 6454 | } |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 6455 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6456 | break; |
| 6457 | default: |
| 6458 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6459 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6460 | bprc = IXGBE_READ_REG(hw, IXGBE_BPRC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6461 | hwstats->bprc += bprc; |
| 6462 | hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6463 | if (hw->mac.type == ixgbe_mac_82598EB) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6464 | hwstats->mprc -= bprc; |
| 6465 | hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC); |
| 6466 | hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64); |
| 6467 | hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127); |
| 6468 | hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255); |
| 6469 | hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511); |
| 6470 | hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023); |
| 6471 | hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522); |
| 6472 | hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6473 | lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6474 | hwstats->lxontxc += lxon; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6475 | lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6476 | hwstats->lxofftxc += lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6477 | hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC); |
| 6478 | hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6479 | /* |
| 6480 | * 82598 errata - tx of flow control packets is included in tx counters |
| 6481 | */ |
| 6482 | xon_off_tot = lxon + lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6483 | hwstats->gptc -= xon_off_tot; |
| 6484 | hwstats->mptc -= xon_off_tot; |
| 6485 | hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN)); |
| 6486 | hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 6487 | hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC); |
| 6488 | hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC); |
| 6489 | hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR); |
| 6490 | hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64); |
| 6491 | hwstats->ptc64 -= xon_off_tot; |
| 6492 | hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127); |
| 6493 | hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255); |
| 6494 | hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511); |
| 6495 | hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023); |
| 6496 | hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522); |
| 6497 | hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6498 | |
| 6499 | /* Fill out the OS statistics structure */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6500 | netdev->stats.multicast = hwstats->mprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6501 | |
| 6502 | /* Rx Errors */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6503 | netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 6504 | netdev->stats.rx_dropped = 0; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6505 | netdev->stats.rx_length_errors = hwstats->rlec; |
| 6506 | netdev->stats.rx_crc_errors = hwstats->crcerrs; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 6507 | netdev->stats.rx_missed_errors = total_mpc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6508 | } |
| 6509 | |
| 6510 | /** |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6511 | * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6512 | * @adapter: pointer to the device adapter structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6513 | **/ |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6514 | static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6515 | { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6516 | struct ixgbe_hw *hw = &adapter->hw; |
| 6517 | int i; |
| 6518 | |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6519 | if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 6520 | return; |
| 6521 | |
| 6522 | adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 6523 | |
| 6524 | /* if interface is down do nothing */ |
| 6525 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 6526 | return; |
| 6527 | |
| 6528 | /* do nothing if we are not using signature filters */ |
| 6529 | if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) |
| 6530 | return; |
| 6531 | |
| 6532 | adapter->fdir_overflow++; |
| 6533 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6534 | if (ixgbe_reinit_fdir_tables_82599(hw) == 0) { |
| 6535 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 6536 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 6537 | &(adapter->tx_ring[i]->state)); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6538 | /* re-enable flow director interrupts */ |
| 6539 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6540 | } else { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 6541 | e_err(probe, "failed to finish FDIR re-initialization, " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 6542 | "ignored adding FDIR ATR filters\n"); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6543 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6544 | } |
| 6545 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6546 | /** |
| 6547 | * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6548 | * @adapter: pointer to the device adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6549 | * |
| 6550 | * This function serves two purposes. First it strobes the interrupt lines |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 6551 | * in order to make certain interrupts are occurring. Secondly it sets the |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6552 | * 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] | 6553 | * determine if a hang has occurred. |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6554 | */ |
| 6555 | static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter) |
| 6556 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6557 | struct ixgbe_hw *hw = &adapter->hw; |
| 6558 | u64 eics = 0; |
| 6559 | int i; |
| 6560 | |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 6561 | /* If we're down, removing or resetting, just bail */ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6562 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 6563 | test_bit(__IXGBE_REMOVING, &adapter->state) || |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6564 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 6565 | return; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6566 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6567 | /* Force detection of hung controller */ |
| 6568 | if (netif_carrier_ok(adapter->netdev)) { |
| 6569 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 6570 | set_check_for_tx_hang(adapter->tx_ring[i]); |
| 6571 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6572 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 6573 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6574 | /* |
| 6575 | * for legacy and MSI interrupts don't set any bits |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 6576 | * that are enabled for EIAM, because this operation |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6577 | * would set *both* EIMS and EICS for any bit in EIAM |
| 6578 | */ |
| 6579 | IXGBE_WRITE_REG(hw, IXGBE_EICS, |
| 6580 | (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER)); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6581 | } else { |
| 6582 | /* get one bit for every active tx/rx interrupt vector */ |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 6583 | for (i = 0; i < adapter->num_q_vectors; i++) { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6584 | struct ixgbe_q_vector *qv = adapter->q_vector[i]; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 6585 | if (qv->rx.ring || qv->tx.ring) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6586 | eics |= ((u64)1 << i); |
| 6587 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6588 | } |
| 6589 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6590 | /* Cause software interrupt to ensure rings are cleaned */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6591 | ixgbe_irq_rearm_queues(adapter, eics); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6592 | } |
| 6593 | |
| 6594 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6595 | * ixgbe_watchdog_update_link - update the link status |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6596 | * @adapter: pointer to the device adapter structure |
| 6597 | * @link_speed: pointer to a u32 to store the link_speed |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6598 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6599 | static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter) |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6600 | { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6601 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6602 | u32 link_speed = adapter->link_speed; |
| 6603 | bool link_up = adapter->link_up; |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 6604 | bool pfc_en = adapter->dcb_cfg.pfc_mode_enable; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6605 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6606 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) |
| 6607 | return; |
| 6608 | |
| 6609 | if (hw->mac.ops.check_link) { |
| 6610 | 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] | 6611 | } else { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6612 | /* always assume link is up, if no check link function */ |
| 6613 | link_speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 6614 | link_up = true; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6615 | } |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 6616 | |
| 6617 | if (adapter->ixgbe_ieee_pfc) |
| 6618 | pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en); |
| 6619 | |
Alexander Duyck | 3ebe8fd | 2012-04-25 04:36:38 +0000 | [diff] [blame] | 6620 | if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) { |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 6621 | hw->mac.ops.fc_enable(hw); |
Alexander Duyck | 3ebe8fd | 2012-04-25 04:36:38 +0000 | [diff] [blame] | 6622 | ixgbe_set_rx_drop_en(adapter); |
| 6623 | } |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6624 | |
| 6625 | if (link_up || |
| 6626 | time_after(jiffies, (adapter->link_check_timeout + |
| 6627 | IXGBE_TRY_LINK_TIMEOUT))) { |
| 6628 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 6629 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC); |
| 6630 | IXGBE_WRITE_FLUSH(hw); |
| 6631 | } |
| 6632 | |
| 6633 | adapter->link_up = link_up; |
| 6634 | adapter->link_speed = link_speed; |
| 6635 | } |
| 6636 | |
Alexander Duyck | 107d301 | 2012-10-02 00:17:03 +0000 | [diff] [blame] | 6637 | static void ixgbe_update_default_up(struct ixgbe_adapter *adapter) |
| 6638 | { |
| 6639 | #ifdef CONFIG_IXGBE_DCB |
| 6640 | struct net_device *netdev = adapter->netdev; |
| 6641 | struct dcb_app app = { |
| 6642 | .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE, |
| 6643 | .protocol = 0, |
| 6644 | }; |
| 6645 | u8 up = 0; |
| 6646 | |
| 6647 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE) |
| 6648 | up = dcb_ieee_getapp_mask(netdev, &app); |
| 6649 | |
| 6650 | adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0; |
| 6651 | #endif |
| 6652 | } |
| 6653 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6654 | /** |
| 6655 | * ixgbe_watchdog_link_is_up - update netif_carrier status and |
| 6656 | * print link up message |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6657 | * @adapter: pointer to the device adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6658 | **/ |
| 6659 | static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter) |
| 6660 | { |
| 6661 | struct net_device *netdev = adapter->netdev; |
| 6662 | struct ixgbe_hw *hw = &adapter->hw; |
Emil Tantilov | cdc04dc | 2014-03-20 03:47:53 +0000 | [diff] [blame] | 6663 | struct net_device *upper; |
| 6664 | struct list_head *iter; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6665 | u32 link_speed = adapter->link_speed; |
Mark Rustad | 454adb0 | 2015-07-10 14:19:22 -0700 | [diff] [blame] | 6666 | const char *speed_str; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6667 | bool flow_rx, flow_tx; |
| 6668 | |
| 6669 | /* only continue if link was previously down */ |
| 6670 | if (netif_carrier_ok(netdev)) |
| 6671 | return; |
| 6672 | |
| 6673 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 6674 | |
| 6675 | switch (hw->mac.type) { |
| 6676 | case ixgbe_mac_82598EB: { |
| 6677 | u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 6678 | u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS); |
| 6679 | flow_rx = !!(frctl & IXGBE_FCTRL_RFCE); |
| 6680 | flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X); |
| 6681 | } |
| 6682 | break; |
| 6683 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6684 | case ixgbe_mac_X550: |
| 6685 | case ixgbe_mac_X550EM_x: |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6686 | case ixgbe_mac_82599EB: { |
| 6687 | u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN); |
| 6688 | u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG); |
| 6689 | flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE); |
| 6690 | flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X); |
| 6691 | } |
| 6692 | break; |
| 6693 | default: |
| 6694 | flow_tx = false; |
| 6695 | flow_rx = false; |
| 6696 | break; |
| 6697 | } |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 6698 | |
Jacob Keller | 6cb562d | 2012-12-05 07:24:41 +0000 | [diff] [blame] | 6699 | adapter->last_rx_ptp_check = jiffies; |
| 6700 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 6701 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6702 | ixgbe_ptp_start_cyclecounter(adapter); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 6703 | |
Mark Rustad | 454adb0 | 2015-07-10 14:19:22 -0700 | [diff] [blame] | 6704 | switch (link_speed) { |
| 6705 | case IXGBE_LINK_SPEED_10GB_FULL: |
| 6706 | speed_str = "10 Gbps"; |
| 6707 | break; |
| 6708 | case IXGBE_LINK_SPEED_2_5GB_FULL: |
| 6709 | speed_str = "2.5 Gbps"; |
| 6710 | break; |
| 6711 | case IXGBE_LINK_SPEED_1GB_FULL: |
| 6712 | speed_str = "1 Gbps"; |
| 6713 | break; |
| 6714 | case IXGBE_LINK_SPEED_100_FULL: |
| 6715 | speed_str = "100 Mbps"; |
| 6716 | break; |
| 6717 | default: |
| 6718 | speed_str = "unknown speed"; |
| 6719 | break; |
| 6720 | } |
| 6721 | 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] | 6722 | ((flow_rx && flow_tx) ? "RX/TX" : |
| 6723 | (flow_rx ? "RX" : |
| 6724 | (flow_tx ? "TX" : "None")))); |
| 6725 | |
| 6726 | netif_carrier_on(netdev); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6727 | ixgbe_check_vf_rate_limit(adapter); |
Alexander Duyck | befa2af | 2012-05-05 05:30:38 +0000 | [diff] [blame] | 6728 | |
Emil Tantilov | cdc04dc | 2014-03-20 03:47:53 +0000 | [diff] [blame] | 6729 | /* enable transmits */ |
| 6730 | netif_tx_wake_all_queues(adapter->netdev); |
| 6731 | |
| 6732 | /* enable any upper devices */ |
| 6733 | rtnl_lock(); |
| 6734 | netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) { |
| 6735 | if (netif_is_macvlan(upper)) { |
| 6736 | struct macvlan_dev *vlan = netdev_priv(upper); |
| 6737 | |
| 6738 | if (vlan->fwd_priv) |
| 6739 | netif_tx_wake_all_queues(upper); |
| 6740 | } |
| 6741 | } |
| 6742 | rtnl_unlock(); |
| 6743 | |
Alexander Duyck | 107d301 | 2012-10-02 00:17:03 +0000 | [diff] [blame] | 6744 | /* update the default user priority for VFs */ |
| 6745 | ixgbe_update_default_up(adapter); |
| 6746 | |
Alexander Duyck | befa2af | 2012-05-05 05:30:38 +0000 | [diff] [blame] | 6747 | /* ping all the active vfs to let them know link has changed */ |
| 6748 | ixgbe_ping_all_vfs(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6749 | } |
| 6750 | |
| 6751 | /** |
| 6752 | * ixgbe_watchdog_link_is_down - update netif_carrier status and |
| 6753 | * print link down message |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6754 | * @adapter: pointer to the adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6755 | **/ |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 6756 | static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6757 | { |
| 6758 | struct net_device *netdev = adapter->netdev; |
| 6759 | struct ixgbe_hw *hw = &adapter->hw; |
| 6760 | |
| 6761 | adapter->link_up = false; |
| 6762 | adapter->link_speed = 0; |
| 6763 | |
| 6764 | /* only continue if link was up previously */ |
| 6765 | if (!netif_carrier_ok(netdev)) |
| 6766 | return; |
| 6767 | |
| 6768 | /* poll for SFP+ cable when link is down */ |
| 6769 | if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB) |
| 6770 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 6771 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 6772 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6773 | ixgbe_ptp_start_cyclecounter(adapter); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 6774 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6775 | e_info(drv, "NIC Link is Down\n"); |
| 6776 | netif_carrier_off(netdev); |
Alexander Duyck | befa2af | 2012-05-05 05:30:38 +0000 | [diff] [blame] | 6777 | |
| 6778 | /* ping all the active vfs to let them know link has changed */ |
| 6779 | ixgbe_ping_all_vfs(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6780 | } |
| 6781 | |
Emil Tantilov | 07923c1 | 2014-08-12 07:12:08 +0000 | [diff] [blame] | 6782 | static bool ixgbe_ring_tx_pending(struct ixgbe_adapter *adapter) |
| 6783 | { |
| 6784 | int i; |
| 6785 | |
| 6786 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 6787 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 6788 | |
| 6789 | if (tx_ring->next_to_use != tx_ring->next_to_clean) |
| 6790 | return true; |
| 6791 | } |
| 6792 | |
| 6793 | return false; |
| 6794 | } |
| 6795 | |
| 6796 | static bool ixgbe_vf_tx_pending(struct ixgbe_adapter *adapter) |
| 6797 | { |
| 6798 | struct ixgbe_hw *hw = &adapter->hw; |
| 6799 | struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ]; |
| 6800 | u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask); |
| 6801 | |
| 6802 | int i, j; |
| 6803 | |
| 6804 | if (!adapter->num_vfs) |
| 6805 | return false; |
| 6806 | |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6807 | /* resetting the PF is only needed for MAC before X550 */ |
| 6808 | if (hw->mac.type >= ixgbe_mac_X550) |
| 6809 | return false; |
| 6810 | |
Emil Tantilov | 07923c1 | 2014-08-12 07:12:08 +0000 | [diff] [blame] | 6811 | for (i = 0; i < adapter->num_vfs; i++) { |
| 6812 | for (j = 0; j < q_per_pool; j++) { |
| 6813 | u32 h, t; |
| 6814 | |
| 6815 | h = IXGBE_READ_REG(hw, IXGBE_PVFTDHN(q_per_pool, i, j)); |
| 6816 | t = IXGBE_READ_REG(hw, IXGBE_PVFTDTN(q_per_pool, i, j)); |
| 6817 | |
| 6818 | if (h != t) |
| 6819 | return true; |
| 6820 | } |
| 6821 | } |
| 6822 | |
| 6823 | return false; |
| 6824 | } |
| 6825 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6826 | /** |
| 6827 | * ixgbe_watchdog_flush_tx - flush queues on link down |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6828 | * @adapter: pointer to the device adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6829 | **/ |
| 6830 | static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter) |
| 6831 | { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6832 | if (!netif_carrier_ok(adapter->netdev)) { |
Emil Tantilov | 07923c1 | 2014-08-12 07:12:08 +0000 | [diff] [blame] | 6833 | if (ixgbe_ring_tx_pending(adapter) || |
| 6834 | ixgbe_vf_tx_pending(adapter)) { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6835 | /* We've lost link, so the controller stops DMA, |
| 6836 | * but we've got queued Tx work that's never going |
| 6837 | * to get done, so reset controller to flush Tx. |
| 6838 | * (Do the reset outside of interrupt context). |
| 6839 | */ |
Jacob Keller | 12ff3f3 | 2012-12-01 07:57:17 +0000 | [diff] [blame] | 6840 | e_warn(drv, "initiating reset to clear Tx work after link loss\n"); |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6841 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6842 | } |
| 6843 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6844 | } |
| 6845 | |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 6846 | #ifdef CONFIG_PCI_IOV |
| 6847 | static inline void ixgbe_issue_vf_flr(struct ixgbe_adapter *adapter, |
| 6848 | struct pci_dev *vfdev) |
| 6849 | { |
| 6850 | if (!pci_wait_for_pending_transaction(vfdev)) |
| 6851 | e_dev_warn("Issuing VFLR with pending transactions\n"); |
| 6852 | |
| 6853 | e_dev_err("Issuing VFLR for VF %s\n", pci_name(vfdev)); |
| 6854 | pcie_capability_set_word(vfdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_BCR_FLR); |
| 6855 | |
| 6856 | msleep(100); |
| 6857 | } |
| 6858 | |
| 6859 | static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter) |
| 6860 | { |
| 6861 | struct ixgbe_hw *hw = &adapter->hw; |
| 6862 | struct pci_dev *pdev = adapter->pdev; |
Mark Rustad | 988d130 | 2015-10-30 15:29:34 -0700 | [diff] [blame] | 6863 | unsigned int vf; |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 6864 | u32 gpc; |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 6865 | |
| 6866 | if (!(netif_carrier_ok(adapter->netdev))) |
| 6867 | return; |
| 6868 | |
| 6869 | gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC); |
| 6870 | if (gpc) /* If incrementing then no need for the check below */ |
| 6871 | return; |
| 6872 | /* Check to see if a bad DMA write target from an errant or |
| 6873 | * malicious VF has caused a PCIe error. If so then we can |
| 6874 | * issue a VFLR to the offending VF(s) and then resume without |
| 6875 | * requesting a full slot reset. |
| 6876 | */ |
| 6877 | |
| 6878 | if (!pdev) |
| 6879 | return; |
| 6880 | |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 6881 | /* check status reg for all VFs owned by this PF */ |
Mark Rustad | 988d130 | 2015-10-30 15:29:34 -0700 | [diff] [blame] | 6882 | for (vf = 0; vf < adapter->num_vfs; ++vf) { |
| 6883 | struct pci_dev *vfdev = adapter->vfinfo[vf].vfdev; |
| 6884 | u16 status_reg; |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 6885 | |
Mark Rustad | 988d130 | 2015-10-30 15:29:34 -0700 | [diff] [blame] | 6886 | if (!vfdev) |
| 6887 | continue; |
| 6888 | pci_read_config_word(vfdev, PCI_STATUS, &status_reg); |
| 6889 | if (status_reg != IXGBE_FAILED_READ_CFG_WORD && |
| 6890 | status_reg & PCI_STATUS_REC_MASTER_ABORT) |
| 6891 | ixgbe_issue_vf_flr(adapter, vfdev); |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 6892 | } |
| 6893 | } |
| 6894 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6895 | static void ixgbe_spoof_check(struct ixgbe_adapter *adapter) |
| 6896 | { |
| 6897 | u32 ssvpc; |
| 6898 | |
Greg Rose | 0584d99 | 2012-08-08 00:00:58 +0000 | [diff] [blame] | 6899 | /* Do not perform spoof check for 82598 or if not in IOV mode */ |
| 6900 | if (adapter->hw.mac.type == ixgbe_mac_82598EB || |
| 6901 | adapter->num_vfs == 0) |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6902 | return; |
| 6903 | |
| 6904 | ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC); |
| 6905 | |
| 6906 | /* |
| 6907 | * ssvpc register is cleared on read, if zero then no |
| 6908 | * spoofed packets in the last interval. |
| 6909 | */ |
| 6910 | if (!ssvpc) |
| 6911 | return; |
| 6912 | |
Emil Tantilov | d6ea075 | 2012-08-08 06:28:37 +0000 | [diff] [blame] | 6913 | e_warn(drv, "%u Spoofed packets detected\n", ssvpc); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6914 | } |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 6915 | #else |
| 6916 | static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused *adapter) |
| 6917 | { |
| 6918 | } |
| 6919 | |
| 6920 | static void |
| 6921 | ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused *adapter) |
| 6922 | { |
| 6923 | } |
| 6924 | #endif /* CONFIG_PCI_IOV */ |
| 6925 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6926 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6927 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6928 | * ixgbe_watchdog_subtask - check and bring link up |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6929 | * @adapter: pointer to the device adapter structure |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6930 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6931 | static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6932 | { |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 6933 | /* if interface is down, removing or resetting, do nothing */ |
Emil Tantilov | 7edebf9 | 2011-08-27 07:18:37 +0000 | [diff] [blame] | 6934 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 6935 | test_bit(__IXGBE_REMOVING, &adapter->state) || |
Emil Tantilov | 7edebf9 | 2011-08-27 07:18:37 +0000 | [diff] [blame] | 6936 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6937 | return; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6938 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6939 | ixgbe_watchdog_update_link(adapter); |
John Fastabend | 10eec95 | 2010-02-03 14:23:32 +0000 | [diff] [blame] | 6940 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6941 | if (adapter->link_up) |
| 6942 | ixgbe_watchdog_link_is_up(adapter); |
| 6943 | else |
| 6944 | ixgbe_watchdog_link_is_down(adapter); |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 6945 | |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 6946 | ixgbe_check_for_bad_vf(adapter); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6947 | ixgbe_spoof_check(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6948 | ixgbe_update_stats(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6949 | |
| 6950 | ixgbe_watchdog_flush_tx(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6951 | } |
| 6952 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6953 | /** |
| 6954 | * ixgbe_sfp_detection_subtask - poll for SFP+ cable |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6955 | * @adapter: the ixgbe adapter structure |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6956 | **/ |
| 6957 | static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter) |
| 6958 | { |
| 6959 | struct ixgbe_hw *hw = &adapter->hw; |
| 6960 | s32 err; |
| 6961 | |
| 6962 | /* not searching for SFP so there is nothing to do here */ |
| 6963 | if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) && |
| 6964 | !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 6965 | return; |
| 6966 | |
Mark Rustad | 58e7cd2 | 2015-08-08 16:18:48 -0700 | [diff] [blame] | 6967 | if (adapter->sfp_poll_time && |
| 6968 | time_after(adapter->sfp_poll_time, jiffies)) |
| 6969 | return; /* If not yet time to poll for SFP */ |
| 6970 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6971 | /* someone else is in init, wait until next service event */ |
| 6972 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 6973 | return; |
| 6974 | |
Mark Rustad | 58e7cd2 | 2015-08-08 16:18:48 -0700 | [diff] [blame] | 6975 | adapter->sfp_poll_time = jiffies + IXGBE_SFP_POLL_JIFFIES - 1; |
| 6976 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6977 | err = hw->phy.ops.identify_sfp(hw); |
| 6978 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 6979 | goto sfp_out; |
| 6980 | |
| 6981 | if (err == IXGBE_ERR_SFP_NOT_PRESENT) { |
| 6982 | /* If no cable is present, then we need to reset |
| 6983 | * the next time we find a good cable. */ |
| 6984 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 6985 | } |
| 6986 | |
| 6987 | /* exit on error */ |
| 6988 | if (err) |
| 6989 | goto sfp_out; |
| 6990 | |
| 6991 | /* exit if reset not needed */ |
| 6992 | if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 6993 | goto sfp_out; |
| 6994 | |
| 6995 | adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 6996 | |
| 6997 | /* |
| 6998 | * A module may be identified correctly, but the EEPROM may not have |
| 6999 | * support for that module. setup_sfp() will fail in that case, so |
| 7000 | * we should not allow that module to load. |
| 7001 | */ |
| 7002 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 7003 | err = hw->phy.ops.reset(hw); |
| 7004 | else |
| 7005 | err = hw->mac.ops.setup_sfp(hw); |
| 7006 | |
| 7007 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 7008 | goto sfp_out; |
| 7009 | |
| 7010 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 7011 | e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type); |
| 7012 | |
| 7013 | sfp_out: |
| 7014 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 7015 | |
| 7016 | if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) && |
| 7017 | (adapter->netdev->reg_state == NETREG_REGISTERED)) { |
| 7018 | e_dev_err("failed to initialize because an unsupported " |
| 7019 | "SFP+ module type was detected.\n"); |
| 7020 | e_dev_err("Reload the driver after installing a " |
| 7021 | "supported module.\n"); |
| 7022 | unregister_netdev(adapter->netdev); |
| 7023 | } |
| 7024 | } |
| 7025 | |
| 7026 | /** |
| 7027 | * ixgbe_sfp_link_config_subtask - set up link SFP after module install |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7028 | * @adapter: the ixgbe adapter structure |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7029 | **/ |
| 7030 | static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter) |
| 7031 | { |
| 7032 | struct ixgbe_hw *hw = &adapter->hw; |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 7033 | u32 speed; |
| 7034 | bool autoneg = false; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7035 | |
| 7036 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG)) |
| 7037 | return; |
| 7038 | |
| 7039 | /* someone else is in init, wait until next service event */ |
| 7040 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 7041 | return; |
| 7042 | |
| 7043 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 7044 | |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 7045 | speed = hw->phy.autoneg_advertised; |
Emil Tantilov | ed33ff6 | 2013-08-30 07:55:24 +0000 | [diff] [blame] | 7046 | if ((!speed) && (hw->mac.ops.get_link_capabilities)) { |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 7047 | hw->mac.ops.get_link_capabilities(hw, &speed, &autoneg); |
Emil Tantilov | ed33ff6 | 2013-08-30 07:55:24 +0000 | [diff] [blame] | 7048 | |
| 7049 | /* setup the highest link when no autoneg */ |
| 7050 | if (!autoneg) { |
| 7051 | if (speed & IXGBE_LINK_SPEED_10GB_FULL) |
| 7052 | speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 7053 | } |
| 7054 | } |
| 7055 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7056 | if (hw->mac.ops.setup_link) |
Josh Hay | fd0326f | 2012-12-15 03:28:30 +0000 | [diff] [blame] | 7057 | hw->mac.ops.setup_link(hw, speed, true); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7058 | |
| 7059 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 7060 | adapter->link_check_timeout = jiffies; |
| 7061 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 7062 | } |
| 7063 | |
| 7064 | /** |
| 7065 | * ixgbe_service_timer - Timer Call-back |
| 7066 | * @data: pointer to adapter cast into an unsigned long |
| 7067 | **/ |
| 7068 | static void ixgbe_service_timer(unsigned long data) |
| 7069 | { |
| 7070 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
| 7071 | unsigned long next_event_offset; |
| 7072 | |
| 7073 | /* poll faster when waiting for link */ |
| 7074 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 7075 | next_event_offset = HZ / 10; |
| 7076 | else |
| 7077 | next_event_offset = HZ * 2; |
| 7078 | |
| 7079 | /* Reset the timer */ |
| 7080 | mod_timer(&adapter->service_timer, next_event_offset + jiffies); |
| 7081 | |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7082 | ixgbe_service_event_schedule(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7083 | } |
| 7084 | |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 7085 | static void ixgbe_phy_interrupt_subtask(struct ixgbe_adapter *adapter) |
| 7086 | { |
| 7087 | struct ixgbe_hw *hw = &adapter->hw; |
| 7088 | u32 status; |
| 7089 | |
| 7090 | if (!(adapter->flags2 & IXGBE_FLAG2_PHY_INTERRUPT)) |
| 7091 | return; |
| 7092 | |
| 7093 | adapter->flags2 &= ~IXGBE_FLAG2_PHY_INTERRUPT; |
| 7094 | |
| 7095 | if (!hw->phy.ops.handle_lasi) |
| 7096 | return; |
| 7097 | |
| 7098 | status = hw->phy.ops.handle_lasi(&adapter->hw); |
| 7099 | if (status != IXGBE_ERR_OVERTEMP) |
| 7100 | return; |
| 7101 | |
| 7102 | e_crit(drv, "%s\n", ixgbe_overheat_msg); |
| 7103 | } |
| 7104 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7105 | static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter) |
| 7106 | { |
| 7107 | if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED)) |
| 7108 | return; |
| 7109 | |
| 7110 | adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED; |
| 7111 | |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 7112 | /* If we're already down, removing or resetting, just bail */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7113 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 7114 | test_bit(__IXGBE_REMOVING, &adapter->state) || |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7115 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 7116 | return; |
| 7117 | |
| 7118 | ixgbe_dump(adapter); |
| 7119 | netdev_err(adapter->netdev, "Reset adapter\n"); |
| 7120 | adapter->tx_timeout_count++; |
| 7121 | |
John Fastabend | 8f4c5c9 | 2014-01-16 02:30:05 -0800 | [diff] [blame] | 7122 | rtnl_lock(); |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7123 | ixgbe_reinit_locked(adapter); |
John Fastabend | 8f4c5c9 | 2014-01-16 02:30:05 -0800 | [diff] [blame] | 7124 | rtnl_unlock(); |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7125 | } |
| 7126 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7127 | /** |
| 7128 | * ixgbe_service_task - manages and runs subtasks |
| 7129 | * @work: pointer to work_struct containing our data |
| 7130 | **/ |
| 7131 | static void ixgbe_service_task(struct work_struct *work) |
| 7132 | { |
| 7133 | struct ixgbe_adapter *adapter = container_of(work, |
| 7134 | struct ixgbe_adapter, |
| 7135 | service_task); |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 7136 | if (ixgbe_removed(adapter->hw.hw_addr)) { |
| 7137 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 7138 | rtnl_lock(); |
| 7139 | ixgbe_down(adapter); |
| 7140 | rtnl_unlock(); |
| 7141 | } |
| 7142 | ixgbe_service_event_complete(adapter); |
| 7143 | return; |
| 7144 | } |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7145 | #ifdef CONFIG_IXGBE_VXLAN |
| 7146 | if (adapter->flags2 & IXGBE_FLAG2_VXLAN_REREG_NEEDED) { |
| 7147 | adapter->flags2 &= ~IXGBE_FLAG2_VXLAN_REREG_NEEDED; |
| 7148 | vxlan_get_rx_port(adapter->netdev); |
| 7149 | } |
| 7150 | #endif /* CONFIG_IXGBE_VXLAN */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7151 | ixgbe_reset_subtask(adapter); |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 7152 | ixgbe_phy_interrupt_subtask(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7153 | ixgbe_sfp_detection_subtask(adapter); |
| 7154 | ixgbe_sfp_link_config_subtask(adapter); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 7155 | ixgbe_check_overtemp_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7156 | ixgbe_watchdog_subtask(adapter); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 7157 | ixgbe_fdir_reinit_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7158 | ixgbe_check_hang_subtask(adapter); |
Jacob Keller | 891dc08 | 2012-12-05 07:24:46 +0000 | [diff] [blame] | 7159 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 7160 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) { |
Jacob Keller | 891dc08 | 2012-12-05 07:24:46 +0000 | [diff] [blame] | 7161 | ixgbe_ptp_overflow_check(adapter); |
| 7162 | ixgbe_ptp_rx_hang(adapter); |
| 7163 | } |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7164 | |
| 7165 | ixgbe_service_event_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7166 | } |
| 7167 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7168 | static int ixgbe_tso(struct ixgbe_ring *tx_ring, |
| 7169 | struct ixgbe_tx_buffer *first, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7170 | u8 *hdr_len) |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7171 | { |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7172 | struct sk_buff *skb = first->skb; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7173 | u32 vlan_macip_lens, type_tucmd; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 7174 | u32 mss_l4len_idx, l4len; |
Francois Romieu | 2049e1f | 2014-03-30 03:14:27 +0000 | [diff] [blame] | 7175 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7176 | |
Alexander Duyck | 8f4fbb9 | 2012-10-30 06:01:40 +0000 | [diff] [blame] | 7177 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 7178 | return 0; |
| 7179 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7180 | if (!skb_is_gso(skb)) |
| 7181 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7182 | |
Francois Romieu | 2049e1f | 2014-03-30 03:14:27 +0000 | [diff] [blame] | 7183 | err = skb_cow_head(skb, 0); |
| 7184 | if (err < 0) |
| 7185 | return err; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 7186 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7187 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
| 7188 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 7189 | |
Joe Perches | a1108ff | 2014-03-13 05:19:25 +0000 | [diff] [blame] | 7190 | if (first->protocol == htons(ETH_P_IP)) { |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7191 | struct iphdr *iph = ip_hdr(skb); |
| 7192 | iph->tot_len = 0; |
| 7193 | iph->check = 0; |
| 7194 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 7195 | iph->daddr, 0, |
| 7196 | IPPROTO_TCP, |
| 7197 | 0); |
| 7198 | type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7199 | first->tx_flags |= IXGBE_TX_FLAGS_TSO | |
| 7200 | IXGBE_TX_FLAGS_CSUM | |
| 7201 | IXGBE_TX_FLAGS_IPV4; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7202 | } else if (skb_is_gso_v6(skb)) { |
| 7203 | ipv6_hdr(skb)->payload_len = 0; |
| 7204 | tcp_hdr(skb)->check = |
| 7205 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 7206 | &ipv6_hdr(skb)->daddr, |
| 7207 | 0, IPPROTO_TCP, 0); |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7208 | first->tx_flags |= IXGBE_TX_FLAGS_TSO | |
| 7209 | IXGBE_TX_FLAGS_CSUM; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7210 | } |
| 7211 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 7212 | /* compute header lengths */ |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7213 | l4len = tcp_hdrlen(skb); |
| 7214 | *hdr_len = skb_transport_offset(skb) + l4len; |
| 7215 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 7216 | /* update gso size and bytecount with header size */ |
| 7217 | first->gso_segs = skb_shinfo(skb)->gso_segs; |
| 7218 | first->bytecount += (first->gso_segs - 1) * *hdr_len; |
| 7219 | |
Alexander Duyck | c44f5f5 | 2012-10-30 06:01:45 +0000 | [diff] [blame] | 7220 | /* mss_l4len_id: use 0 as index for TSO */ |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7221 | mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT; |
| 7222 | mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7223 | |
| 7224 | /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */ |
| 7225 | vlan_macip_lens = skb_network_header_len(skb); |
| 7226 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7227 | vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7228 | |
| 7229 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7230 | mss_l4len_idx); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7231 | |
| 7232 | return 1; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 7233 | } |
| 7234 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7235 | static inline bool ixgbe_ipv6_csum_is_sctp(struct sk_buff *skb) |
| 7236 | { |
| 7237 | unsigned int offset = 0; |
| 7238 | |
| 7239 | ipv6_find_hdr(skb, &offset, IPPROTO_SCTP, NULL, NULL); |
| 7240 | |
| 7241 | return offset == skb_checksum_start_offset(skb); |
| 7242 | } |
| 7243 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7244 | static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring, |
| 7245 | struct ixgbe_tx_buffer *first) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7246 | { |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7247 | struct sk_buff *skb = first->skb; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7248 | u32 vlan_macip_lens = 0; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7249 | u32 type_tucmd = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7250 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7251 | if (skb->ip_summed != CHECKSUM_PARTIAL) { |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7252 | csum_failed: |
| 7253 | if (!(first->tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | |
| 7254 | IXGBE_TX_FLAGS_CC))) |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7255 | return; |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7256 | goto no_csum; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7257 | } |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 7258 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7259 | switch (skb->csum_offset) { |
| 7260 | case offsetof(struct tcphdr, check): |
| 7261 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 7262 | /* fall through */ |
| 7263 | case offsetof(struct udphdr, check): |
| 7264 | break; |
| 7265 | case offsetof(struct sctphdr, checksum): |
| 7266 | /* validate that this is actually an SCTP request */ |
| 7267 | if (((first->protocol == htons(ETH_P_IP)) && |
| 7268 | (ip_hdr(skb)->protocol == IPPROTO_SCTP)) || |
| 7269 | ((first->protocol == htons(ETH_P_IPV6)) && |
| 7270 | ixgbe_ipv6_csum_is_sctp(skb))) { |
| 7271 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
| 7272 | break; |
| 7273 | } |
| 7274 | /* fall through */ |
| 7275 | default: |
| 7276 | skb_checksum_help(skb); |
| 7277 | goto csum_failed; |
| 7278 | } |
| 7279 | |
| 7280 | /* update TX checksum flag */ |
| 7281 | first->tx_flags |= IXGBE_TX_FLAGS_CSUM; |
| 7282 | vlan_macip_lens = skb_checksum_start_offset(skb) - |
| 7283 | skb_network_offset(skb); |
Mark Rustad | 36a92d7 | 2015-11-18 09:21:28 -0800 | [diff] [blame] | 7284 | no_csum: |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7285 | /* vlan_macip_lens: MACLEN, VLAN tag */ |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7286 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7287 | vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7288 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7289 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, 0); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7290 | } |
| 7291 | |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7292 | #define IXGBE_SET_FLAG(_input, _flag, _result) \ |
| 7293 | ((_flag <= _result) ? \ |
| 7294 | ((u32)(_input & _flag) * (_result / _flag)) : \ |
| 7295 | ((u32)(_input & _flag) / (_flag / _result))) |
| 7296 | |
| 7297 | 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] | 7298 | { |
| 7299 | /* set type for advanced descriptor with frame checksum insertion */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7300 | u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA | |
| 7301 | IXGBE_ADVTXD_DCMD_DEXT | |
| 7302 | IXGBE_ADVTXD_DCMD_IFCS; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7303 | |
| 7304 | /* set HW vlan bit if vlan is present */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7305 | cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN, |
| 7306 | IXGBE_ADVTXD_DCMD_VLE); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7307 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7308 | /* set segmentation enable bits for TSO/FSO */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7309 | cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO, |
| 7310 | IXGBE_ADVTXD_DCMD_TSE); |
| 7311 | |
| 7312 | /* set timestamp bit if present */ |
| 7313 | cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP, |
| 7314 | IXGBE_ADVTXD_MAC_TSTAMP); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7315 | |
Alexander Duyck | 62748b7 | 2012-07-20 08:09:01 +0000 | [diff] [blame] | 7316 | /* insert frame checksum */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7317 | 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] | 7318 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7319 | return cmd_type; |
| 7320 | } |
| 7321 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7322 | static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc, |
| 7323 | u32 tx_flags, unsigned int paylen) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7324 | { |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7325 | u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7326 | |
| 7327 | /* enable L4 checksum for TSO and TX checksum offload */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7328 | olinfo_status |= IXGBE_SET_FLAG(tx_flags, |
| 7329 | IXGBE_TX_FLAGS_CSUM, |
| 7330 | IXGBE_ADVTXD_POPTS_TXSM); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7331 | |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 7332 | /* enble IPv4 checksum for TSO */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7333 | olinfo_status |= IXGBE_SET_FLAG(tx_flags, |
| 7334 | IXGBE_TX_FLAGS_IPV4, |
| 7335 | IXGBE_ADVTXD_POPTS_IXSM); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7336 | |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 7337 | /* |
| 7338 | * Check Context must be set if Tx switch is enabled, which it |
| 7339 | * always is for case where virtual functions are running |
| 7340 | */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7341 | olinfo_status |= IXGBE_SET_FLAG(tx_flags, |
| 7342 | IXGBE_TX_FLAGS_CC, |
| 7343 | IXGBE_ADVTXD_CC); |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 7344 | |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7345 | tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7346 | } |
| 7347 | |
Daniel Borkmann | 2367a17 | 2014-08-26 19:34:18 +0200 | [diff] [blame] | 7348 | static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size) |
| 7349 | { |
| 7350 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 7351 | |
| 7352 | /* Herbert's original patch had: |
| 7353 | * smp_mb__after_netif_stop_queue(); |
| 7354 | * but since that doesn't exist yet, just open code it. |
| 7355 | */ |
| 7356 | smp_mb(); |
| 7357 | |
| 7358 | /* We need to check again in a case another CPU has just |
| 7359 | * made room available. |
| 7360 | */ |
| 7361 | if (likely(ixgbe_desc_unused(tx_ring) < size)) |
| 7362 | return -EBUSY; |
| 7363 | |
| 7364 | /* A reprieve! - use start_queue because it doesn't call schedule */ |
| 7365 | netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 7366 | ++tx_ring->tx_stats.restart_queue; |
| 7367 | return 0; |
| 7368 | } |
| 7369 | |
| 7370 | static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size) |
| 7371 | { |
| 7372 | if (likely(ixgbe_desc_unused(tx_ring) >= size)) |
| 7373 | return 0; |
| 7374 | |
| 7375 | return __ixgbe_maybe_stop_tx(tx_ring, size); |
| 7376 | } |
| 7377 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7378 | #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \ |
| 7379 | IXGBE_TXD_CMD_RS) |
| 7380 | |
| 7381 | static void ixgbe_tx_map(struct ixgbe_ring *tx_ring, |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7382 | struct ixgbe_tx_buffer *first, |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7383 | const u8 hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7384 | { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7385 | struct sk_buff *skb = first->skb; |
| 7386 | struct ixgbe_tx_buffer *tx_buffer; |
| 7387 | union ixgbe_adv_tx_desc *tx_desc; |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7388 | struct skb_frag_struct *frag; |
| 7389 | dma_addr_t dma; |
| 7390 | unsigned int data_len, size; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7391 | u32 tx_flags = first->tx_flags; |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7392 | u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7393 | u16 i = tx_ring->next_to_use; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7394 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7395 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
| 7396 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7397 | ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len); |
| 7398 | |
| 7399 | size = skb_headlen(skb); |
| 7400 | data_len = skb->data_len; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7401 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7402 | #ifdef IXGBE_FCOE |
| 7403 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7404 | if (data_len < sizeof(struct fcoe_crc_eof)) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7405 | size -= sizeof(struct fcoe_crc_eof) - data_len; |
| 7406 | data_len = 0; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7407 | } else { |
| 7408 | data_len -= sizeof(struct fcoe_crc_eof); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 7409 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7410 | } |
| 7411 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7412 | #endif |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7413 | 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] | 7414 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7415 | tx_buffer = first; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7416 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7417 | for (frag = &skb_shinfo(skb)->frags[0];; frag++) { |
| 7418 | if (dma_mapping_error(tx_ring->dev, dma)) |
| 7419 | goto dma_error; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7420 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7421 | /* record length, and DMA address */ |
| 7422 | dma_unmap_len_set(tx_buffer, len, size); |
| 7423 | dma_unmap_addr_set(tx_buffer, dma, dma); |
| 7424 | |
| 7425 | tx_desc->read.buffer_addr = cpu_to_le64(dma); |
| 7426 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7427 | while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7428 | tx_desc->read.cmd_type_len = |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7429 | cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7430 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7431 | i++; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7432 | tx_desc++; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7433 | if (i == tx_ring->count) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 7434 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7435 | i = 0; |
| 7436 | } |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7437 | tx_desc->read.olinfo_status = 0; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7438 | |
| 7439 | dma += IXGBE_MAX_DATA_PER_TXD; |
| 7440 | size -= IXGBE_MAX_DATA_PER_TXD; |
| 7441 | |
| 7442 | tx_desc->read.buffer_addr = cpu_to_le64(dma); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7443 | } |
| 7444 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7445 | if (likely(!data_len)) |
| 7446 | break; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7447 | |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7448 | tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7449 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7450 | i++; |
| 7451 | tx_desc++; |
| 7452 | if (i == tx_ring->count) { |
| 7453 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
| 7454 | i = 0; |
| 7455 | } |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7456 | tx_desc->read.olinfo_status = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7457 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7458 | #ifdef IXGBE_FCOE |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 7459 | size = min_t(unsigned int, data_len, skb_frag_size(frag)); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7460 | #else |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 7461 | size = skb_frag_size(frag); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7462 | #endif |
| 7463 | data_len -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7464 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7465 | dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size, |
| 7466 | DMA_TO_DEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7467 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7468 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7469 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 7470 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7471 | /* write last descriptor with RS and EOP bits */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7472 | cmd_type |= size | IXGBE_TXD_CMD; |
| 7473 | tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7474 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 7475 | netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount); |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 7476 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7477 | /* set the timestamp */ |
| 7478 | first->time_stamp = jiffies; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7479 | |
| 7480 | /* |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7481 | * Force memory writes to complete before letting h/w know there |
| 7482 | * are new descriptors to fetch. (Only applicable for weak-ordered |
| 7483 | * memory model archs, such as IA-64). |
| 7484 | * |
| 7485 | * We also need this memory barrier to make certain all of the |
| 7486 | * status bits have been updated before next_to_watch is written. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7487 | */ |
| 7488 | wmb(); |
| 7489 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7490 | /* set next_to_watch value indicating a packet is present */ |
| 7491 | first->next_to_watch = tx_desc; |
| 7492 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7493 | i++; |
| 7494 | if (i == tx_ring->count) |
| 7495 | i = 0; |
| 7496 | |
| 7497 | tx_ring->next_to_use = i; |
| 7498 | |
Daniel Borkmann | 2367a17 | 2014-08-26 19:34:18 +0200 | [diff] [blame] | 7499 | ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED); |
| 7500 | |
| 7501 | if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) { |
Alexander Duyck | ad435ec | 2014-11-14 00:56:35 +0000 | [diff] [blame] | 7502 | writel(i, tx_ring->tail); |
| 7503 | |
| 7504 | /* we need this if more than one processor can write to our tail |
| 7505 | * at a time, it synchronizes IO on IA64/Altix systems |
| 7506 | */ |
| 7507 | mmiowb(); |
Daniel Borkmann | 9c938cd | 2014-08-24 15:42:16 +0200 | [diff] [blame] | 7508 | } |
Daniel Borkmann | 2367a17 | 2014-08-26 19:34:18 +0200 | [diff] [blame] | 7509 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7510 | return; |
| 7511 | dma_error: |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7512 | dev_err(tx_ring->dev, "TX DMA map failed\n"); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7513 | |
| 7514 | /* clear dma mappings for failed tx_buffer_info map */ |
| 7515 | for (;;) { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7516 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
| 7517 | ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer); |
| 7518 | if (tx_buffer == first) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7519 | break; |
| 7520 | if (i == 0) |
| 7521 | i = tx_ring->count; |
| 7522 | i--; |
| 7523 | } |
| 7524 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7525 | tx_ring->next_to_use = i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7526 | } |
| 7527 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7528 | static void ixgbe_atr(struct ixgbe_ring *ring, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7529 | struct ixgbe_tx_buffer *first) |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7530 | { |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7531 | struct ixgbe_q_vector *q_vector = ring->q_vector; |
| 7532 | union ixgbe_atr_hash_dword input = { .dword = 0 }; |
| 7533 | union ixgbe_atr_hash_dword common = { .dword = 0 }; |
| 7534 | union { |
| 7535 | unsigned char *network; |
| 7536 | struct iphdr *ipv4; |
| 7537 | struct ipv6hdr *ipv6; |
| 7538 | } hdr; |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 7539 | struct tcphdr *th; |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7540 | unsigned int hlen; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7541 | struct sk_buff *skb; |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 7542 | __be16 vlan_id; |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7543 | int l4_proto; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7544 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7545 | /* if ring doesn't have a interrupt vector, cannot perform ATR */ |
| 7546 | if (!q_vector) |
Guillaume Gaudonville | d3ead24 | 2010-06-29 18:29:00 +0000 | [diff] [blame] | 7547 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7548 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7549 | /* do nothing if sampling is disabled */ |
| 7550 | if (!ring->atr_sample_rate) |
| 7551 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7552 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7553 | ring->atr_count++; |
| 7554 | |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7555 | /* currently only IPv4/IPv6 with TCP is supported */ |
| 7556 | if ((first->protocol != htons(ETH_P_IP)) && |
| 7557 | (first->protocol != htons(ETH_P_IPV6))) |
| 7558 | return; |
| 7559 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7560 | /* snag network header to get L4 type and address */ |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7561 | skb = first->skb; |
| 7562 | hdr.network = skb_network_header(skb); |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7563 | #ifdef CONFIG_IXGBE_VXLAN |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 7564 | if (skb->encapsulation && |
| 7565 | first->protocol == htons(ETH_P_IP) && |
| 7566 | hdr.ipv4->protocol != IPPROTO_UDP) { |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7567 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7568 | |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 7569 | /* verify the port is recognized as VXLAN */ |
| 7570 | if (adapter->vxlan_port && |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7571 | udp_hdr(skb)->dest == adapter->vxlan_port) |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 7572 | hdr.network = skb_inner_network_header(skb); |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7573 | } |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 7574 | #endif /* CONFIG_IXGBE_VXLAN */ |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7575 | |
| 7576 | /* Currently only IPv4/IPv6 with TCP is supported */ |
| 7577 | switch (hdr.ipv4->version) { |
| 7578 | case IPVERSION: |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7579 | /* access ihl as u8 to avoid unaligned access on ia64 */ |
| 7580 | hlen = (hdr.network[0] & 0x0F) << 2; |
| 7581 | l4_proto = hdr.ipv4->protocol; |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7582 | break; |
| 7583 | case 6: |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7584 | hlen = hdr.network - skb->data; |
| 7585 | l4_proto = ipv6_find_hdr(skb, &hlen, IPPROTO_TCP, NULL, NULL); |
| 7586 | hlen -= hdr.network - skb->data; |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7587 | break; |
| 7588 | default: |
| 7589 | return; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7590 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7591 | |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7592 | if (l4_proto != IPPROTO_TCP) |
| 7593 | return; |
| 7594 | |
| 7595 | th = (struct tcphdr *)(hdr.network + hlen); |
| 7596 | |
| 7597 | /* skip this packet since the socket is closing */ |
| 7598 | if (th->fin) |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7599 | return; |
| 7600 | |
| 7601 | /* sample on all syn packets or once every atr sample count */ |
| 7602 | if (!th->syn && (ring->atr_count < ring->atr_sample_rate)) |
| 7603 | return; |
| 7604 | |
| 7605 | /* reset sample count */ |
| 7606 | ring->atr_count = 0; |
| 7607 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7608 | vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT); |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7609 | |
| 7610 | /* |
| 7611 | * src and dst are inverted, think how the receiver sees them |
| 7612 | * |
| 7613 | * The input is broken into two sections, a non-compressed section |
| 7614 | * containing vm_pool, vlan_id, and flow_type. The rest of the data |
| 7615 | * is XORed together and stored in the compressed dword. |
| 7616 | */ |
| 7617 | input.formatted.vlan_id = vlan_id; |
| 7618 | |
| 7619 | /* |
| 7620 | * since src port and flex bytes occupy the same word XOR them together |
| 7621 | * and write the value to source port portion of compressed dword |
| 7622 | */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7623 | 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] | 7624 | common.port.src ^= th->dest ^ htons(ETH_P_8021Q); |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7625 | else |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7626 | common.port.src ^= th->dest ^ first->protocol; |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7627 | common.port.dst ^= th->source; |
| 7628 | |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7629 | switch (hdr.ipv4->version) { |
| 7630 | case IPVERSION: |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7631 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4; |
| 7632 | common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr; |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7633 | break; |
| 7634 | case 6: |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7635 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6; |
| 7636 | common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^ |
| 7637 | hdr.ipv6->saddr.s6_addr32[1] ^ |
| 7638 | hdr.ipv6->saddr.s6_addr32[2] ^ |
| 7639 | hdr.ipv6->saddr.s6_addr32[3] ^ |
| 7640 | hdr.ipv6->daddr.s6_addr32[0] ^ |
| 7641 | hdr.ipv6->daddr.s6_addr32[1] ^ |
| 7642 | hdr.ipv6->daddr.s6_addr32[2] ^ |
| 7643 | hdr.ipv6->daddr.s6_addr32[3]; |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7644 | break; |
| 7645 | default: |
| 7646 | break; |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7647 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7648 | |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 7649 | if (hdr.network != skb_network_header(skb)) |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7650 | input.formatted.flow_type |= IXGBE_ATR_L4TYPE_TUNNEL_MASK; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7651 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7652 | /* 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] | 7653 | ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw, |
| 7654 | input, common, ring->queue_index); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7655 | } |
| 7656 | |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 7657 | 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] | 7658 | void *accel_priv, select_queue_fallback_t fallback) |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 7659 | { |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 7660 | struct ixgbe_fwd_adapter *fwd_adapter = accel_priv; |
| 7661 | #ifdef IXGBE_FCOE |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 7662 | struct ixgbe_adapter *adapter; |
| 7663 | struct ixgbe_ring_feature *f; |
| 7664 | int txq; |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 7665 | #endif |
| 7666 | |
| 7667 | if (fwd_adapter) |
| 7668 | return skb->queue_mapping + fwd_adapter->tx_base_queue; |
| 7669 | |
| 7670 | #ifdef IXGBE_FCOE |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 7671 | |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 7672 | /* |
| 7673 | * only execute the code below if protocol is FCoE |
| 7674 | * or FIP and we have FCoE enabled on the adapter |
| 7675 | */ |
| 7676 | switch (vlan_get_protocol(skb)) { |
Joe Perches | a1108ff | 2014-03-13 05:19:25 +0000 | [diff] [blame] | 7677 | case htons(ETH_P_FCOE): |
| 7678 | case htons(ETH_P_FIP): |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 7679 | adapter = netdev_priv(dev); |
Alexander Duyck | c087663 | 2012-05-10 00:01:46 +0000 | [diff] [blame] | 7680 | |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 7681 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 7682 | break; |
| 7683 | default: |
Daniel Borkmann | 99932d4 | 2014-02-16 15:55:20 +0100 | [diff] [blame] | 7684 | return fallback(dev, skb); |
Krishna Kumar | fdd3d63 | 2010-02-03 13:13:10 +0000 | [diff] [blame] | 7685 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7686 | |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 7687 | f = &adapter->ring_feature[RING_F_FCOE]; |
| 7688 | |
| 7689 | txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) : |
| 7690 | smp_processor_id(); |
| 7691 | |
| 7692 | while (txq >= f->indices) |
| 7693 | txq -= f->indices; |
| 7694 | |
| 7695 | return txq + f->offset; |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 7696 | #else |
Daniel Borkmann | 99932d4 | 2014-02-16 15:55:20 +0100 | [diff] [blame] | 7697 | return fallback(dev, skb); |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 7698 | #endif |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 7699 | } |
| 7700 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 7701 | netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb, |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 7702 | struct ixgbe_adapter *adapter, |
| 7703 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7704 | { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7705 | struct ixgbe_tx_buffer *first; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 7706 | int tso; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7707 | u32 tx_flags = 0; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7708 | unsigned short f; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7709 | u16 count = TXD_USE_COUNT(skb_headlen(skb)); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7710 | __be16 protocol = skb->protocol; |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 7711 | u8 hdr_len = 0; |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 7712 | |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7713 | /* |
| 7714 | * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD, |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 7715 | * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD, |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7716 | * + 2 desc gap to keep tail from touching head, |
| 7717 | * + 1 desc for context descriptor, |
| 7718 | * otherwise try next time |
| 7719 | */ |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7720 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) |
| 7721 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size); |
Alexander Duyck | 7f66162 | 2013-02-09 01:19:55 +0000 | [diff] [blame] | 7722 | |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7723 | if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) { |
| 7724 | tx_ring->tx_stats.tx_busy++; |
| 7725 | return NETDEV_TX_BUSY; |
| 7726 | } |
| 7727 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7728 | /* record the location of the first descriptor for this packet */ |
| 7729 | first = &tx_ring->tx_buffer_info[tx_ring->next_to_use]; |
| 7730 | first->skb = skb; |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 7731 | first->bytecount = skb->len; |
| 7732 | first->gso_segs = 1; |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7733 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7734 | /* 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] | 7735 | if (skb_vlan_tag_present(skb)) { |
| 7736 | tx_flags |= skb_vlan_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7737 | tx_flags |= IXGBE_TX_FLAGS_HW_VLAN; |
| 7738 | /* 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] | 7739 | } else if (protocol == htons(ETH_P_8021Q)) { |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7740 | struct vlan_hdr *vhdr, _vhdr; |
| 7741 | vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr); |
| 7742 | if (!vhdr) |
| 7743 | goto out_drop; |
| 7744 | |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 7745 | tx_flags |= ntohs(vhdr->h_vlan_TCI) << |
| 7746 | IXGBE_TX_FLAGS_VLAN_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7747 | tx_flags |= IXGBE_TX_FLAGS_SW_VLAN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7748 | } |
Toshiaki Makita | 0213668 | 2015-01-29 20:37:09 +0900 | [diff] [blame] | 7749 | protocol = vlan_get_protocol(skb); |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7750 | |
Mark Rustad | d523493 | 2014-08-09 07:02:09 +0000 | [diff] [blame] | 7751 | if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && |
| 7752 | adapter->ptp_clock && |
| 7753 | !test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS, |
| 7754 | &adapter->state)) { |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7755 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; |
| 7756 | tx_flags |= IXGBE_TX_FLAGS_TSTAMP; |
Jacob Keller | 891dc08 | 2012-12-05 07:24:46 +0000 | [diff] [blame] | 7757 | |
| 7758 | /* schedule check for Tx timestamp */ |
| 7759 | adapter->ptp_tx_skb = skb_get(skb); |
| 7760 | adapter->ptp_tx_start = jiffies; |
| 7761 | schedule_work(&adapter->ptp_tx_work); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7762 | } |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7763 | |
Jakub Kicinski | ff29a86 | 2014-03-15 14:55:16 +0000 | [diff] [blame] | 7764 | skb_tx_timestamp(skb); |
| 7765 | |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 7766 | #ifdef CONFIG_PCI_IOV |
| 7767 | /* |
| 7768 | * Use the l2switch_enable flag - would be false if the DMA |
| 7769 | * Tx switch had been disabled. |
| 7770 | */ |
| 7771 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7772 | tx_flags |= IXGBE_TX_FLAGS_CC; |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 7773 | |
| 7774 | #endif |
John Fastabend | 32701dc | 2011-09-27 03:51:56 +0000 | [diff] [blame] | 7775 | /* 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] | 7776 | if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && |
Alexander Duyck | 09dca47 | 2011-07-20 00:09:10 +0000 | [diff] [blame] | 7777 | ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) || |
| 7778 | (skb->priority != TC_PRIO_CONTROL))) { |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7779 | tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK; |
John Fastabend | 32701dc | 2011-09-27 03:51:56 +0000 | [diff] [blame] | 7780 | tx_flags |= (skb->priority & 0x7) << |
| 7781 | IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7782 | if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) { |
| 7783 | struct vlan_ethhdr *vhdr; |
Francois Romieu | 2049e1f | 2014-03-30 03:14:27 +0000 | [diff] [blame] | 7784 | |
| 7785 | if (skb_cow_head(skb, 0)) |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7786 | goto out_drop; |
| 7787 | vhdr = (struct vlan_ethhdr *)skb->data; |
| 7788 | vhdr->h_vlan_TCI = htons(tx_flags >> |
| 7789 | IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 7790 | } else { |
| 7791 | tx_flags |= IXGBE_TX_FLAGS_HW_VLAN; |
| 7792 | } |
| 7793 | } |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7794 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7795 | /* record initial flags and protocol */ |
| 7796 | first->tx_flags = tx_flags; |
| 7797 | first->protocol = protocol; |
| 7798 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7799 | #ifdef IXGBE_FCOE |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7800 | /* setup tx offload for FCoE */ |
Joe Perches | a1108ff | 2014-03-13 05:19:25 +0000 | [diff] [blame] | 7801 | if ((protocol == htons(ETH_P_FCOE)) && |
Alexander Duyck | a58915c | 2012-05-25 06:38:18 +0000 | [diff] [blame] | 7802 | (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) { |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7803 | tso = ixgbe_fso(tx_ring, first, &hdr_len); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7804 | if (tso < 0) |
| 7805 | goto out_drop; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7806 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7807 | goto xmit_fcoe; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 7808 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7809 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7810 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7811 | tso = ixgbe_tso(tx_ring, first, &hdr_len); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7812 | if (tso < 0) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7813 | goto out_drop; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7814 | else if (!tso) |
| 7815 | ixgbe_tx_csum(tx_ring, first); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7816 | |
| 7817 | /* add the ATR filter if ATR is on */ |
| 7818 | if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state)) |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7819 | ixgbe_atr(tx_ring, first); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7820 | |
| 7821 | #ifdef IXGBE_FCOE |
| 7822 | xmit_fcoe: |
| 7823 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7824 | ixgbe_tx_map(tx_ring, first, hdr_len); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7825 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7826 | return NETDEV_TX_OK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7827 | |
| 7828 | out_drop: |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7829 | dev_kfree_skb_any(first->skb); |
| 7830 | first->skb = NULL; |
| 7831 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7832 | return NETDEV_TX_OK; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7833 | } |
| 7834 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 7835 | static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb, |
| 7836 | struct net_device *netdev, |
| 7837 | struct ixgbe_ring *ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7838 | { |
| 7839 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7840 | struct ixgbe_ring *tx_ring; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7841 | |
Alexander Duyck | a50c29d | 2012-02-08 07:50:40 +0000 | [diff] [blame] | 7842 | /* |
| 7843 | * The minimum packet size for olinfo paylen is 17 so pad the skb |
| 7844 | * in order to meet this minimum size requirement. |
| 7845 | */ |
Alexander Duyck | a94d9e2 | 2014-12-03 08:17:39 -0800 | [diff] [blame] | 7846 | if (skb_put_padto(skb, 17)) |
| 7847 | return NETDEV_TX_OK; |
Alexander Duyck | a50c29d | 2012-02-08 07:50:40 +0000 | [diff] [blame] | 7848 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 7849 | tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping]; |
| 7850 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7851 | return ixgbe_xmit_frame_ring(skb, adapter, tx_ring); |
| 7852 | } |
| 7853 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 7854 | static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, |
| 7855 | struct net_device *netdev) |
| 7856 | { |
| 7857 | return __ixgbe_xmit_frame(skb, netdev, NULL); |
| 7858 | } |
| 7859 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7860 | /** |
| 7861 | * ixgbe_set_mac - Change the Ethernet Address of the NIC |
| 7862 | * @netdev: network interface device structure |
| 7863 | * @p: pointer to an address structure |
| 7864 | * |
| 7865 | * Returns 0 on success, negative on failure |
| 7866 | **/ |
| 7867 | static int ixgbe_set_mac(struct net_device *netdev, void *p) |
| 7868 | { |
| 7869 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7870 | struct ixgbe_hw *hw = &adapter->hw; |
| 7871 | struct sockaddr *addr = p; |
| 7872 | |
| 7873 | if (!is_valid_ether_addr(addr->sa_data)) |
| 7874 | return -EADDRNOTAVAIL; |
| 7875 | |
| 7876 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7877 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7878 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 7879 | ixgbe_mac_set_default_filter(adapter); |
| 7880 | |
| 7881 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7882 | } |
| 7883 | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7884 | static int |
| 7885 | ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr) |
| 7886 | { |
| 7887 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7888 | struct ixgbe_hw *hw = &adapter->hw; |
| 7889 | u16 value; |
| 7890 | int rc; |
| 7891 | |
| 7892 | if (prtad != hw->phy.mdio.prtad) |
| 7893 | return -EINVAL; |
| 7894 | rc = hw->phy.ops.read_reg(hw, addr, devad, &value); |
| 7895 | if (!rc) |
| 7896 | rc = value; |
| 7897 | return rc; |
| 7898 | } |
| 7899 | |
| 7900 | static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad, |
| 7901 | u16 addr, u16 value) |
| 7902 | { |
| 7903 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7904 | struct ixgbe_hw *hw = &adapter->hw; |
| 7905 | |
| 7906 | if (prtad != hw->phy.mdio.prtad) |
| 7907 | return -EINVAL; |
| 7908 | return hw->phy.ops.write_reg(hw, addr, devad, value); |
| 7909 | } |
| 7910 | |
| 7911 | static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd) |
| 7912 | { |
| 7913 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7914 | |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7915 | switch (cmd) { |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7916 | case SIOCSHWTSTAMP: |
Jacob Keller | 93501d4 | 2014-02-28 15:48:58 -0800 | [diff] [blame] | 7917 | return ixgbe_ptp_set_ts_config(adapter, req); |
| 7918 | case SIOCGHWTSTAMP: |
| 7919 | return ixgbe_ptp_get_ts_config(adapter, req); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7920 | default: |
| 7921 | return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd); |
| 7922 | } |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7923 | } |
| 7924 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7925 | /** |
| 7926 | * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 7927 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7928 | * @netdev: network interface device structure |
| 7929 | * |
| 7930 | * Returns non-zero on failure |
| 7931 | **/ |
| 7932 | static int ixgbe_add_sanmac_netdev(struct net_device *dev) |
| 7933 | { |
| 7934 | int err = 0; |
| 7935 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 7936 | struct ixgbe_hw *hw = &adapter->hw; |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7937 | |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 7938 | if (is_valid_ether_addr(hw->mac.san_addr)) { |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7939 | rtnl_lock(); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 7940 | 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] | 7941 | rtnl_unlock(); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 7942 | |
| 7943 | /* update SAN MAC vmdq pool selection */ |
| 7944 | hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0)); |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7945 | } |
| 7946 | return err; |
| 7947 | } |
| 7948 | |
| 7949 | /** |
| 7950 | * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 7951 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7952 | * @netdev: network interface device structure |
| 7953 | * |
| 7954 | * Returns non-zero on failure |
| 7955 | **/ |
| 7956 | static int ixgbe_del_sanmac_netdev(struct net_device *dev) |
| 7957 | { |
| 7958 | int err = 0; |
| 7959 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 7960 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 7961 | |
| 7962 | if (is_valid_ether_addr(mac->san_addr)) { |
| 7963 | rtnl_lock(); |
| 7964 | err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 7965 | rtnl_unlock(); |
| 7966 | } |
| 7967 | return err; |
| 7968 | } |
| 7969 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7970 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7971 | /* |
| 7972 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 7973 | * without having to re-enable interrupts. It's not called while |
| 7974 | * the interrupt routine is executing. |
| 7975 | */ |
| 7976 | static void ixgbe_netpoll(struct net_device *netdev) |
| 7977 | { |
| 7978 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 7979 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7980 | |
Alexander Duyck | 1a647bd | 2010-01-13 01:49:13 +0000 | [diff] [blame] | 7981 | /* if interface is down do nothing */ |
| 7982 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 7983 | return; |
| 7984 | |
Alexander Duyck | 856f606 | 2015-02-25 17:45:54 +0000 | [diff] [blame] | 7985 | /* loop through and schedule all active queues */ |
| 7986 | for (i = 0; i < adapter->num_q_vectors; i++) |
| 7987 | ixgbe_msix_clean_rings(0, adapter->q_vector[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7988 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7989 | |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 7990 | #endif |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7991 | static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev, |
| 7992 | struct rtnl_link_stats64 *stats) |
| 7993 | { |
| 7994 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7995 | int i; |
| 7996 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7997 | rcu_read_lock(); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7998 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7999 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8000 | u64 bytes, packets; |
| 8001 | unsigned int start; |
| 8002 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8003 | if (ring) { |
| 8004 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 8005 | start = u64_stats_fetch_begin_irq(&ring->syncp); |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8006 | packets = ring->stats.packets; |
| 8007 | bytes = ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 8008 | } while (u64_stats_fetch_retry_irq(&ring->syncp, start)); |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8009 | stats->rx_packets += packets; |
| 8010 | stats->rx_bytes += bytes; |
| 8011 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8012 | } |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 8013 | |
| 8014 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 8015 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]); |
| 8016 | u64 bytes, packets; |
| 8017 | unsigned int start; |
| 8018 | |
| 8019 | if (ring) { |
| 8020 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 8021 | start = u64_stats_fetch_begin_irq(&ring->syncp); |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 8022 | packets = ring->stats.packets; |
| 8023 | bytes = ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 8024 | } while (u64_stats_fetch_retry_irq(&ring->syncp, start)); |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 8025 | stats->tx_packets += packets; |
| 8026 | stats->tx_bytes += bytes; |
| 8027 | } |
| 8028 | } |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8029 | rcu_read_unlock(); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8030 | /* following stats updated by ixgbe_watchdog_task() */ |
| 8031 | stats->multicast = netdev->stats.multicast; |
| 8032 | stats->rx_errors = netdev->stats.rx_errors; |
| 8033 | stats->rx_length_errors = netdev->stats.rx_length_errors; |
| 8034 | stats->rx_crc_errors = netdev->stats.rx_crc_errors; |
| 8035 | stats->rx_missed_errors = netdev->stats.rx_missed_errors; |
| 8036 | return stats; |
| 8037 | } |
| 8038 | |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 8039 | #ifdef CONFIG_IXGBE_DCB |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 8040 | /** |
| 8041 | * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid. |
| 8042 | * @adapter: pointer to ixgbe_adapter |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8043 | * @tc: number of traffic classes currently enabled |
| 8044 | * |
| 8045 | * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm |
| 8046 | * 802.1Q priority maps to a packet buffer that exists. |
| 8047 | */ |
| 8048 | static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc) |
| 8049 | { |
| 8050 | struct ixgbe_hw *hw = &adapter->hw; |
| 8051 | u32 reg, rsave; |
| 8052 | int i; |
| 8053 | |
| 8054 | /* 82598 have a static priority to TC mapping that can not |
| 8055 | * be changed so no validation is needed. |
| 8056 | */ |
| 8057 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 8058 | return; |
| 8059 | |
| 8060 | reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC); |
| 8061 | rsave = reg; |
| 8062 | |
| 8063 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 8064 | u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT); |
| 8065 | |
| 8066 | /* If up2tc is out of bounds default to zero */ |
| 8067 | if (up2tc > tc) |
| 8068 | reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT); |
| 8069 | } |
| 8070 | |
| 8071 | if (reg != rsave) |
| 8072 | IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg); |
| 8073 | |
| 8074 | return; |
| 8075 | } |
| 8076 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 8077 | /** |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 8078 | * ixgbe_set_prio_tc_map - Configure netdev prio tc map |
| 8079 | * @adapter: Pointer to adapter struct |
| 8080 | * |
| 8081 | * Populate the netdev user priority to tc map |
| 8082 | */ |
| 8083 | static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter) |
| 8084 | { |
| 8085 | struct net_device *dev = adapter->netdev; |
| 8086 | struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg; |
| 8087 | struct ieee_ets *ets = adapter->ixgbe_ieee_ets; |
| 8088 | u8 prio; |
| 8089 | |
| 8090 | for (prio = 0; prio < MAX_USER_PRIORITY; prio++) { |
| 8091 | u8 tc = 0; |
| 8092 | |
| 8093 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) |
| 8094 | tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio); |
| 8095 | else if (ets) |
| 8096 | tc = ets->prio_tc[prio]; |
| 8097 | |
| 8098 | netdev_set_prio_tc_map(dev, prio, tc); |
| 8099 | } |
| 8100 | } |
| 8101 | |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 8102 | #endif /* CONFIG_IXGBE_DCB */ |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 8103 | /** |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 8104 | * ixgbe_setup_tc - configure net_device for multiple traffic classes |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8105 | * |
| 8106 | * @netdev: net device to configure |
| 8107 | * @tc: number of traffic classes to enable |
| 8108 | */ |
| 8109 | int ixgbe_setup_tc(struct net_device *dev, u8 tc) |
| 8110 | { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8111 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 8112 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8113 | bool pools; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8114 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8115 | /* Hardware supports up to 8 traffic classes */ |
Emil Tantilov | 7e3f5c8 | 2015-07-09 12:28:59 -0700 | [diff] [blame] | 8116 | if (tc > adapter->dcb_cfg.num_tcs.pg_tcs) |
| 8117 | return -EINVAL; |
| 8118 | |
| 8119 | if (hw->mac.type == ixgbe_mac_82598EB && tc && tc < MAX_TRAFFIC_CLASS) |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8120 | return -EINVAL; |
| 8121 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8122 | pools = (find_first_zero_bit(&adapter->fwd_bitmask, 32) > 1); |
| 8123 | if (tc && pools && adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS) |
| 8124 | return -EBUSY; |
| 8125 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8126 | /* Hardware has to reinitialize queues and interrupts to |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 8127 | * match packet buffer alignment. Unfortunately, the |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8128 | * hardware is not flexible enough to do this dynamically. |
| 8129 | */ |
| 8130 | if (netif_running(dev)) |
| 8131 | ixgbe_close(dev); |
Alexander Duyck | bf4d67d | 2015-10-20 13:28:17 -0700 | [diff] [blame] | 8132 | else |
| 8133 | ixgbe_reset(adapter); |
| 8134 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8135 | ixgbe_clear_interrupt_scheme(adapter); |
| 8136 | |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 8137 | #ifdef CONFIG_IXGBE_DCB |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8138 | if (tc) { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8139 | netdev_set_num_tc(dev, tc); |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 8140 | ixgbe_set_prio_tc_map(adapter); |
| 8141 | |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8142 | adapter->flags |= IXGBE_FLAG_DCB_ENABLED; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8143 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 8144 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 8145 | adapter->last_lfc_mode = adapter->hw.fc.requested_mode; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8146 | adapter->hw.fc.requested_mode = ixgbe_fc_none; |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 8147 | } |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8148 | } else { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8149 | netdev_reset_tc(dev); |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 8150 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 8151 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 8152 | adapter->hw.fc.requested_mode = adapter->last_lfc_mode; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8153 | |
| 8154 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8155 | |
| 8156 | adapter->temp_dcb_cfg.pfc_mode_enable = false; |
| 8157 | adapter->dcb_cfg.pfc_mode_enable = false; |
| 8158 | } |
| 8159 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8160 | ixgbe_validate_rtr(adapter, tc); |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 8161 | |
| 8162 | #endif /* CONFIG_IXGBE_DCB */ |
| 8163 | ixgbe_init_interrupt_scheme(adapter); |
| 8164 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8165 | if (netif_running(dev)) |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 8166 | return ixgbe_open(dev); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8167 | |
| 8168 | return 0; |
| 8169 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8170 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8171 | static int ixgbe_delete_clsu32(struct ixgbe_adapter *adapter, |
| 8172 | struct tc_cls_u32_offload *cls) |
| 8173 | { |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8174 | u32 uhtid = TC_U32_USERHTID(cls->knode.handle); |
| 8175 | u32 loc; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8176 | int err; |
| 8177 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8178 | if ((uhtid != 0x800) && (uhtid >= IXGBE_MAX_LINK_HANDLE)) |
| 8179 | return -EINVAL; |
| 8180 | |
| 8181 | loc = cls->knode.handle & 0xfffff; |
| 8182 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8183 | spin_lock(&adapter->fdir_perfect_lock); |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8184 | err = ixgbe_update_ethtool_fdir_entry(adapter, NULL, loc); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8185 | spin_unlock(&adapter->fdir_perfect_lock); |
| 8186 | return err; |
| 8187 | } |
| 8188 | |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8189 | static int ixgbe_configure_clsu32_add_hnode(struct ixgbe_adapter *adapter, |
| 8190 | __be16 protocol, |
| 8191 | struct tc_cls_u32_offload *cls) |
| 8192 | { |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8193 | u32 uhtid = TC_U32_USERHTID(cls->hnode.handle); |
| 8194 | |
| 8195 | if (uhtid >= IXGBE_MAX_LINK_HANDLE) |
| 8196 | return -EINVAL; |
| 8197 | |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8198 | /* This ixgbe devices do not support hash tables at the moment |
| 8199 | * so abort when given hash tables. |
| 8200 | */ |
| 8201 | if (cls->hnode.divisor > 0) |
| 8202 | return -EINVAL; |
| 8203 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8204 | set_bit(uhtid - 1, &adapter->tables); |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8205 | return 0; |
| 8206 | } |
| 8207 | |
| 8208 | static int ixgbe_configure_clsu32_del_hnode(struct ixgbe_adapter *adapter, |
| 8209 | struct tc_cls_u32_offload *cls) |
| 8210 | { |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8211 | u32 uhtid = TC_U32_USERHTID(cls->hnode.handle); |
| 8212 | |
| 8213 | if (uhtid >= IXGBE_MAX_LINK_HANDLE) |
| 8214 | return -EINVAL; |
| 8215 | |
| 8216 | clear_bit(uhtid - 1, &adapter->tables); |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8217 | return 0; |
| 8218 | } |
| 8219 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8220 | static int ixgbe_configure_clsu32(struct ixgbe_adapter *adapter, |
| 8221 | __be16 protocol, |
| 8222 | struct tc_cls_u32_offload *cls) |
| 8223 | { |
| 8224 | u32 loc = cls->knode.handle & 0xfffff; |
| 8225 | struct ixgbe_hw *hw = &adapter->hw; |
| 8226 | struct ixgbe_mat_field *field_ptr; |
| 8227 | struct ixgbe_fdir_filter *input; |
| 8228 | union ixgbe_atr_input mask; |
| 8229 | #ifdef CONFIG_NET_CLS_ACT |
| 8230 | const struct tc_action *a; |
| 8231 | #endif |
| 8232 | int i, err = 0; |
| 8233 | u8 queue; |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8234 | u32 uhtid, link_uhtid; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8235 | |
| 8236 | memset(&mask, 0, sizeof(union ixgbe_atr_input)); |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8237 | uhtid = TC_U32_USERHTID(cls->knode.handle); |
| 8238 | link_uhtid = TC_U32_USERHTID(cls->knode.link_handle); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8239 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8240 | /* At the moment cls_u32 jumps to network layer and skips past |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8241 | * L2 headers. The canonical method to match L2 frames is to use |
| 8242 | * negative values. However this is error prone at best but really |
| 8243 | * 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] | 8244 | * 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] | 8245 | * headers when needed. |
| 8246 | */ |
| 8247 | if (protocol != htons(ETH_P_IP)) |
| 8248 | return -EINVAL; |
| 8249 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8250 | if (link_uhtid) { |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8251 | struct ixgbe_nexthdr *nexthdr = ixgbe_ipv4_jumps; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8252 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8253 | if (link_uhtid >= IXGBE_MAX_LINK_HANDLE) |
| 8254 | return -EINVAL; |
| 8255 | |
| 8256 | if (!test_bit(link_uhtid - 1, &adapter->tables)) |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8257 | return -EINVAL; |
| 8258 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8259 | for (i = 0; nexthdr[i].jump; i++) { |
Amritha Nambiar | 4ae7834 | 2016-03-09 18:32:16 -0500 | [diff] [blame^] | 8260 | if (nexthdr[i].o != cls->knode.sel->offoff || |
| 8261 | nexthdr[i].s != cls->knode.sel->offshift || |
| 8262 | nexthdr[i].m != cls->knode.sel->offmask || |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8263 | /* do not support multiple key jumps its just mad */ |
| 8264 | cls->knode.sel->nkeys > 1) |
| 8265 | return -EINVAL; |
| 8266 | |
Amritha Nambiar | 4ae7834 | 2016-03-09 18:32:16 -0500 | [diff] [blame^] | 8267 | if (nexthdr[i].off == cls->knode.sel->keys[0].off && |
| 8268 | nexthdr[i].val == cls->knode.sel->keys[0].val && |
| 8269 | nexthdr[i].mask == cls->knode.sel->keys[0].mask) { |
| 8270 | adapter->jump_tables[link_uhtid] = |
| 8271 | nexthdr[i].jump; |
| 8272 | break; |
| 8273 | } |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8274 | } |
| 8275 | return 0; |
| 8276 | } |
| 8277 | |
| 8278 | if (loc >= ((1024 << adapter->fdir_pballoc) - 2)) { |
| 8279 | e_err(drv, "Location out of range\n"); |
| 8280 | return -EINVAL; |
| 8281 | } |
| 8282 | |
| 8283 | /* cls u32 is a graph starting at root node 0x800. The driver tracks |
| 8284 | * links and also the fields used to advance the parser across each |
| 8285 | * link (e.g. nexthdr/eat parameters from 'tc'). This way we can map |
| 8286 | * the u32 graph onto the hardware parse graph denoted in ixgbe_model.h |
| 8287 | * To add support for new nodes update ixgbe_model.h parse structures |
| 8288 | * this function _should_ be generic try not to hardcode values here. |
| 8289 | */ |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8290 | if (uhtid == 0x800) { |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8291 | field_ptr = adapter->jump_tables[0]; |
| 8292 | } else { |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8293 | if (uhtid >= IXGBE_MAX_LINK_HANDLE) |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8294 | return -EINVAL; |
| 8295 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8296 | field_ptr = adapter->jump_tables[uhtid]; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8297 | } |
| 8298 | |
| 8299 | if (!field_ptr) |
| 8300 | return -EINVAL; |
| 8301 | |
| 8302 | input = kzalloc(sizeof(*input), GFP_KERNEL); |
| 8303 | if (!input) |
| 8304 | return -ENOMEM; |
| 8305 | |
| 8306 | for (i = 0; i < cls->knode.sel->nkeys; i++) { |
| 8307 | int off = cls->knode.sel->keys[i].off; |
| 8308 | __be32 val = cls->knode.sel->keys[i].val; |
| 8309 | __be32 m = cls->knode.sel->keys[i].mask; |
| 8310 | bool found_entry = false; |
| 8311 | int j; |
| 8312 | |
| 8313 | for (j = 0; field_ptr[j].val; j++) { |
Sridhar Samudrala | ebd83ad | 2016-03-07 09:41:48 -0800 | [diff] [blame] | 8314 | if (field_ptr[j].off == off) { |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8315 | field_ptr[j].val(input, &mask, val, m); |
| 8316 | input->filter.formatted.flow_type |= |
| 8317 | field_ptr[j].type; |
| 8318 | found_entry = true; |
| 8319 | break; |
| 8320 | } |
| 8321 | } |
| 8322 | |
| 8323 | if (!found_entry) |
| 8324 | goto err_out; |
| 8325 | } |
| 8326 | |
| 8327 | mask.formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK | |
| 8328 | IXGBE_ATR_L4TYPE_MASK; |
| 8329 | |
| 8330 | if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4) |
| 8331 | mask.formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK; |
| 8332 | |
| 8333 | #ifdef CONFIG_NET_CLS_ACT |
| 8334 | if (list_empty(&cls->knode.exts->actions)) |
| 8335 | goto err_out; |
| 8336 | |
| 8337 | list_for_each_entry(a, &cls->knode.exts->actions, list) { |
| 8338 | if (!is_tcf_gact_shot(a)) |
| 8339 | goto err_out; |
| 8340 | } |
| 8341 | #endif |
| 8342 | |
| 8343 | input->action = IXGBE_FDIR_DROP_QUEUE; |
| 8344 | queue = IXGBE_FDIR_DROP_QUEUE; |
| 8345 | input->sw_idx = loc; |
| 8346 | |
| 8347 | spin_lock(&adapter->fdir_perfect_lock); |
| 8348 | |
| 8349 | if (hlist_empty(&adapter->fdir_filter_list)) { |
| 8350 | memcpy(&adapter->fdir_mask, &mask, sizeof(mask)); |
| 8351 | err = ixgbe_fdir_set_input_mask_82599(hw, &mask); |
| 8352 | if (err) |
| 8353 | goto err_out_w_lock; |
| 8354 | } else if (memcmp(&adapter->fdir_mask, &mask, sizeof(mask))) { |
| 8355 | err = -EINVAL; |
| 8356 | goto err_out_w_lock; |
| 8357 | } |
| 8358 | |
| 8359 | ixgbe_atr_compute_perfect_hash_82599(&input->filter, &mask); |
| 8360 | err = ixgbe_fdir_write_perfect_filter_82599(hw, &input->filter, |
| 8361 | input->sw_idx, queue); |
| 8362 | if (!err) |
| 8363 | ixgbe_update_ethtool_fdir_entry(adapter, input, input->sw_idx); |
| 8364 | spin_unlock(&adapter->fdir_perfect_lock); |
| 8365 | |
| 8366 | return err; |
| 8367 | err_out_w_lock: |
| 8368 | spin_unlock(&adapter->fdir_perfect_lock); |
| 8369 | err_out: |
| 8370 | kfree(input); |
| 8371 | return -EINVAL; |
| 8372 | } |
| 8373 | |
Emil Tantilov | 6e2a60b | 2016-02-17 15:55:06 -0800 | [diff] [blame] | 8374 | static int __ixgbe_setup_tc(struct net_device *dev, u32 handle, __be16 proto, |
| 8375 | struct tc_to_netdev *tc) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 8376 | { |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8377 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 8378 | |
| 8379 | if (TC_H_MAJ(handle) == TC_H_MAJ(TC_H_INGRESS) && |
| 8380 | tc->type == TC_SETUP_CLSU32) { |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8381 | switch (tc->cls_u32->command) { |
| 8382 | case TC_CLSU32_NEW_KNODE: |
| 8383 | case TC_CLSU32_REPLACE_KNODE: |
| 8384 | return ixgbe_configure_clsu32(adapter, |
| 8385 | proto, tc->cls_u32); |
| 8386 | case TC_CLSU32_DELETE_KNODE: |
| 8387 | return ixgbe_delete_clsu32(adapter, tc->cls_u32); |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8388 | case TC_CLSU32_NEW_HNODE: |
| 8389 | case TC_CLSU32_REPLACE_HNODE: |
| 8390 | return ixgbe_configure_clsu32_add_hnode(adapter, proto, |
| 8391 | tc->cls_u32); |
| 8392 | case TC_CLSU32_DELETE_HNODE: |
| 8393 | return ixgbe_configure_clsu32_del_hnode(adapter, |
| 8394 | tc->cls_u32); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8395 | default: |
| 8396 | return -EINVAL; |
| 8397 | } |
| 8398 | } |
| 8399 | |
John Fastabend | 5eb4dce | 2016-02-29 11:26:13 -0800 | [diff] [blame] | 8400 | if (tc->type != TC_SETUP_MQPRIO) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 8401 | return -EINVAL; |
| 8402 | |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 8403 | return ixgbe_setup_tc(dev, tc->tc); |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 8404 | } |
| 8405 | |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 8406 | #ifdef CONFIG_PCI_IOV |
| 8407 | void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter) |
| 8408 | { |
| 8409 | struct net_device *netdev = adapter->netdev; |
| 8410 | |
| 8411 | rtnl_lock(); |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 8412 | ixgbe_setup_tc(netdev, netdev_get_num_tc(netdev)); |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 8413 | rtnl_unlock(); |
| 8414 | } |
| 8415 | |
| 8416 | #endif |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8417 | void ixgbe_do_reset(struct net_device *netdev) |
| 8418 | { |
| 8419 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8420 | |
| 8421 | if (netif_running(netdev)) |
| 8422 | ixgbe_reinit_locked(adapter); |
| 8423 | else |
| 8424 | ixgbe_reset(adapter); |
| 8425 | } |
| 8426 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 8427 | static netdev_features_t ixgbe_fix_features(struct net_device *netdev, |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8428 | netdev_features_t features) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8429 | { |
| 8430 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8431 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8432 | /* If Rx checksum is disabled, then RSC/LRO should also be disabled */ |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8433 | if (!(features & NETIF_F_RXCSUM)) |
| 8434 | features &= ~NETIF_F_LRO; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8435 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8436 | /* Turn off LRO if not RSC capable */ |
| 8437 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) |
| 8438 | features &= ~NETIF_F_LRO; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 8439 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8440 | return features; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8441 | } |
| 8442 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 8443 | static int ixgbe_set_features(struct net_device *netdev, |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8444 | netdev_features_t features) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8445 | { |
| 8446 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8447 | netdev_features_t changed = netdev->features ^ features; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8448 | bool need_reset = false; |
| 8449 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8450 | /* Make sure RSC matches LRO, reset if change */ |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8451 | if (!(features & NETIF_F_LRO)) { |
| 8452 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8453 | need_reset = true; |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8454 | adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED; |
| 8455 | } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) && |
| 8456 | !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) { |
| 8457 | if (adapter->rx_itr_setting == 1 || |
| 8458 | adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) { |
| 8459 | adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED; |
| 8460 | need_reset = true; |
| 8461 | } else if ((changed ^ features) & NETIF_F_LRO) { |
| 8462 | e_info(probe, "rx-usecs set too low, " |
| 8463 | "disabling RSC\n"); |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8464 | } |
| 8465 | } |
| 8466 | |
| 8467 | /* |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8468 | * Check if Flow Director n-tuple support or hw_tc support was |
| 8469 | * enabled or disabled. If the state changed, we need to reset. |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8470 | */ |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8471 | if ((features & NETIF_F_NTUPLE) || (features & NETIF_F_HW_TC)) { |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8472 | /* turn off ATR, enable perfect filters and reset */ |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 8473 | if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) |
| 8474 | need_reset = true; |
| 8475 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8476 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 8477 | adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8478 | } else { |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 8479 | /* turn off perfect filters, enable ATR and reset */ |
| 8480 | if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 8481 | need_reset = true; |
| 8482 | |
| 8483 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 8484 | |
| 8485 | /* We cannot enable ATR if SR-IOV is enabled */ |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8486 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED || |
| 8487 | /* We cannot enable ATR if we have 2 or more tcs */ |
| 8488 | (netdev_get_num_tc(netdev) > 1) || |
| 8489 | /* We cannot enable ATR if RSS is disabled */ |
| 8490 | (adapter->ring_feature[RING_F_RSS].limit <= 1) || |
| 8491 | /* A sample rate of 0 indicates ATR disabled */ |
| 8492 | (!adapter->atr_sample_rate)) |
| 8493 | ; /* do nothing not supported */ |
| 8494 | else /* otherwise supported and set the flag */ |
| 8495 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8496 | } |
| 8497 | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 8498 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
John Fastabend | 146d4cc | 2012-05-15 05:59:26 +0000 | [diff] [blame] | 8499 | ixgbe_vlan_strip_enable(adapter); |
| 8500 | else |
| 8501 | ixgbe_vlan_strip_disable(adapter); |
| 8502 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 8503 | if (changed & NETIF_F_RXALL) |
| 8504 | need_reset = true; |
| 8505 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8506 | netdev->features = features; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8507 | |
| 8508 | #ifdef CONFIG_IXGBE_VXLAN |
| 8509 | if ((adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) { |
| 8510 | if (features & NETIF_F_RXCSUM) |
| 8511 | adapter->flags2 |= IXGBE_FLAG2_VXLAN_REREG_NEEDED; |
| 8512 | else |
| 8513 | ixgbe_clear_vxlan_port(adapter); |
| 8514 | } |
| 8515 | #endif /* CONFIG_IXGBE_VXLAN */ |
| 8516 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8517 | if (need_reset) |
| 8518 | ixgbe_do_reset(netdev); |
| 8519 | |
| 8520 | return 0; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8521 | } |
| 8522 | |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8523 | #ifdef CONFIG_IXGBE_VXLAN |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8524 | /** |
| 8525 | * ixgbe_add_vxlan_port - Get notifications about VXLAN ports that come up |
| 8526 | * @dev: The port's netdev |
| 8527 | * @sa_family: Socket Family that VXLAN is notifiying us about |
| 8528 | * @port: New UDP port number that VXLAN started listening to |
| 8529 | **/ |
| 8530 | static void ixgbe_add_vxlan_port(struct net_device *dev, sa_family_t sa_family, |
| 8531 | __be16 port) |
| 8532 | { |
| 8533 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 8534 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8535 | |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8536 | if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) |
| 8537 | return; |
| 8538 | |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8539 | if (sa_family == AF_INET6) |
| 8540 | return; |
| 8541 | |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 8542 | if (adapter->vxlan_port == port) |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8543 | return; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8544 | |
| 8545 | if (adapter->vxlan_port) { |
| 8546 | netdev_info(dev, |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8547 | "Hit Max num of VXLAN ports, not adding port %d\n", |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 8548 | ntohs(port)); |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8549 | return; |
| 8550 | } |
| 8551 | |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 8552 | adapter->vxlan_port = port; |
| 8553 | IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, ntohs(port)); |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8554 | } |
| 8555 | |
| 8556 | /** |
| 8557 | * ixgbe_del_vxlan_port - Get notifications about VXLAN ports that go away |
| 8558 | * @dev: The port's netdev |
| 8559 | * @sa_family: Socket Family that VXLAN is notifying us about |
| 8560 | * @port: UDP port number that VXLAN stopped listening to |
| 8561 | **/ |
| 8562 | static void ixgbe_del_vxlan_port(struct net_device *dev, sa_family_t sa_family, |
| 8563 | __be16 port) |
| 8564 | { |
| 8565 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8566 | |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8567 | if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) |
| 8568 | return; |
| 8569 | |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8570 | if (sa_family == AF_INET6) |
| 8571 | return; |
| 8572 | |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 8573 | if (adapter->vxlan_port != port) { |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8574 | netdev_info(dev, "Port %d was not found, not deleting\n", |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 8575 | ntohs(port)); |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8576 | return; |
| 8577 | } |
| 8578 | |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8579 | ixgbe_clear_vxlan_port(adapter); |
| 8580 | adapter->flags2 |= IXGBE_FLAG2_VXLAN_REREG_NEEDED; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8581 | } |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8582 | #endif /* CONFIG_IXGBE_VXLAN */ |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8583 | |
stephen hemminger | edc7d57 | 2012-10-01 12:32:33 +0000 | [diff] [blame] | 8584 | static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 8585 | struct net_device *dev, |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 8586 | const unsigned char *addr, u16 vid, |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 8587 | u16 flags) |
| 8588 | { |
Alexander Duyck | bcfd343 | 2014-07-17 02:11:22 +0000 | [diff] [blame] | 8589 | /* guarantee we can provide a unique filter for the unicast address */ |
Ben Hutchings | 46acc46 | 2012-11-01 09:11:11 +0000 | [diff] [blame] | 8590 | if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) { |
Alexander Duyck | 2f9be16 | 2015-10-22 16:26:42 -0700 | [diff] [blame] | 8591 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 8592 | u16 pool = VMDQ_P(0); |
| 8593 | |
| 8594 | if (netdev_uc_count(dev) >= ixgbe_available_rars(adapter, pool)) |
Alexander Duyck | bcfd343 | 2014-07-17 02:11:22 +0000 | [diff] [blame] | 8595 | return -ENOMEM; |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 8596 | } |
| 8597 | |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 8598 | return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags); |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 8599 | } |
| 8600 | |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 8601 | /** |
| 8602 | * ixgbe_configure_bridge_mode - set various bridge modes |
| 8603 | * @adapter - the private structure |
| 8604 | * @mode - requested bridge mode |
| 8605 | * |
| 8606 | * Configure some settings require for various bridge modes. |
| 8607 | **/ |
| 8608 | static int ixgbe_configure_bridge_mode(struct ixgbe_adapter *adapter, |
| 8609 | __u16 mode) |
| 8610 | { |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 8611 | struct ixgbe_hw *hw = &adapter->hw; |
| 8612 | unsigned int p, num_pools; |
| 8613 | u32 vmdctl; |
| 8614 | |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 8615 | switch (mode) { |
| 8616 | case BRIDGE_MODE_VEPA: |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 8617 | /* disable Tx loopback, rely on switch hairpin mode */ |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 8618 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, 0); |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 8619 | |
| 8620 | /* must enable Rx switching replication to allow multicast |
| 8621 | * packet reception on all VFs, and to enable source address |
| 8622 | * pruning. |
| 8623 | */ |
| 8624 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL); |
| 8625 | vmdctl |= IXGBE_VT_CTL_REPLEN; |
| 8626 | IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl); |
| 8627 | |
| 8628 | /* enable Rx source address pruning. Note, this requires |
| 8629 | * replication to be enabled or else it does nothing. |
| 8630 | */ |
| 8631 | num_pools = adapter->num_vfs + adapter->num_rx_pools; |
| 8632 | for (p = 0; p < num_pools; p++) { |
| 8633 | if (hw->mac.ops.set_source_address_pruning) |
| 8634 | hw->mac.ops.set_source_address_pruning(hw, |
| 8635 | true, |
| 8636 | p); |
| 8637 | } |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 8638 | break; |
| 8639 | case BRIDGE_MODE_VEB: |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 8640 | /* enable Tx loopback for internal VF/PF communication */ |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 8641 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, |
| 8642 | IXGBE_PFDTXGSWC_VT_LBEN); |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 8643 | |
| 8644 | /* disable Rx switching replication unless we have SR-IOV |
| 8645 | * virtual functions |
| 8646 | */ |
| 8647 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL); |
| 8648 | if (!adapter->num_vfs) |
| 8649 | vmdctl &= ~IXGBE_VT_CTL_REPLEN; |
| 8650 | IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl); |
| 8651 | |
| 8652 | /* disable Rx source address pruning, since we don't expect to |
| 8653 | * be receiving external loopback of our transmitted frames. |
| 8654 | */ |
| 8655 | num_pools = adapter->num_vfs + adapter->num_rx_pools; |
| 8656 | for (p = 0; p < num_pools; p++) { |
| 8657 | if (hw->mac.ops.set_source_address_pruning) |
| 8658 | hw->mac.ops.set_source_address_pruning(hw, |
| 8659 | false, |
| 8660 | p); |
| 8661 | } |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 8662 | break; |
| 8663 | default: |
| 8664 | return -EINVAL; |
| 8665 | } |
| 8666 | |
| 8667 | adapter->bridge_mode = mode; |
| 8668 | |
| 8669 | e_info(drv, "enabling bridge mode: %s\n", |
| 8670 | mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
| 8671 | |
| 8672 | return 0; |
| 8673 | } |
| 8674 | |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8675 | static int ixgbe_ndo_bridge_setlink(struct net_device *dev, |
Roopa Prabhu | add511b | 2015-01-29 22:40:12 -0800 | [diff] [blame] | 8676 | struct nlmsghdr *nlh, u16 flags) |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8677 | { |
| 8678 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 8679 | struct nlattr *attr, *br_spec; |
| 8680 | int rem; |
| 8681 | |
| 8682 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 8683 | return -EOPNOTSUPP; |
| 8684 | |
| 8685 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
Thomas Graf | 4ea85e8 | 2014-11-26 13:42:18 +0100 | [diff] [blame] | 8686 | if (!br_spec) |
| 8687 | return -EINVAL; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8688 | |
| 8689 | nla_for_each_nested(attr, br_spec, rem) { |
Mark Rustad | a1e869d | 2015-04-10 10:36:36 -0700 | [diff] [blame] | 8690 | int status; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8691 | __u16 mode; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8692 | |
| 8693 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 8694 | continue; |
| 8695 | |
Thomas Graf | b7c1a31 | 2014-11-26 13:42:17 +0100 | [diff] [blame] | 8696 | if (nla_len(attr) < sizeof(mode)) |
| 8697 | return -EINVAL; |
| 8698 | |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8699 | mode = nla_get_u16(attr); |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 8700 | status = ixgbe_configure_bridge_mode(adapter, mode); |
| 8701 | if (status) |
| 8702 | return status; |
Don Skidmore | aa2bacb | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 8703 | |
| 8704 | break; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8705 | } |
| 8706 | |
| 8707 | return 0; |
| 8708 | } |
| 8709 | |
| 8710 | 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] | 8711 | struct net_device *dev, |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 8712 | u32 filter_mask, int nlflags) |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8713 | { |
| 8714 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8715 | |
| 8716 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 8717 | return 0; |
| 8718 | |
Don Skidmore | aa2bacb | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 8719 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, |
Scott Feldman | 7d4f8d8 | 2015-06-22 00:27:17 -0700 | [diff] [blame] | 8720 | adapter->bridge_mode, 0, 0, nlflags, |
| 8721 | filter_mask, NULL); |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8722 | } |
| 8723 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8724 | static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev) |
| 8725 | { |
| 8726 | struct ixgbe_fwd_adapter *fwd_adapter = NULL; |
| 8727 | struct ixgbe_adapter *adapter = netdev_priv(pdev); |
Jacob Keller | aac2f1b | 2014-08-21 06:17:59 +0000 | [diff] [blame] | 8728 | int used_pools = adapter->num_vfs + adapter->num_rx_pools; |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 8729 | unsigned int limit; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8730 | int pool, err; |
| 8731 | |
Jacob Keller | aac2f1b | 2014-08-21 06:17:59 +0000 | [diff] [blame] | 8732 | /* Hardware has a limited number of available pools. Each VF, and the |
| 8733 | * PF require a pool. Check to ensure we don't attempt to use more |
| 8734 | * then the available number of pools. |
| 8735 | */ |
| 8736 | if (used_pools >= IXGBE_MAX_VF_FUNCTIONS) |
| 8737 | return ERR_PTR(-EINVAL); |
| 8738 | |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 8739 | #ifdef CONFIG_RPS |
| 8740 | if (vdev->num_rx_queues != vdev->num_tx_queues) { |
| 8741 | netdev_info(pdev, "%s: Only supports a single queue count for TX and RX\n", |
| 8742 | vdev->name); |
| 8743 | return ERR_PTR(-EINVAL); |
| 8744 | } |
| 8745 | #endif |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8746 | /* Check for hardware restriction on number of rx/tx queues */ |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 8747 | if (vdev->num_tx_queues > IXGBE_MAX_L2A_QUEUES || |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8748 | vdev->num_tx_queues == IXGBE_BAD_L2A_QUEUE) { |
| 8749 | netdev_info(pdev, |
| 8750 | "%s: Supports RX/TX Queue counts 1,2, and 4\n", |
| 8751 | pdev->name); |
| 8752 | return ERR_PTR(-EINVAL); |
| 8753 | } |
| 8754 | |
| 8755 | if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && |
| 8756 | adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS - 1) || |
| 8757 | (adapter->num_rx_pools > IXGBE_MAX_MACVLANS)) |
| 8758 | return ERR_PTR(-EBUSY); |
| 8759 | |
Maninder Singh | bc52f95 | 2015-06-19 09:37:55 +0530 | [diff] [blame] | 8760 | fwd_adapter = kzalloc(sizeof(*fwd_adapter), GFP_KERNEL); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8761 | if (!fwd_adapter) |
| 8762 | return ERR_PTR(-ENOMEM); |
| 8763 | |
| 8764 | pool = find_first_zero_bit(&adapter->fwd_bitmask, 32); |
| 8765 | adapter->num_rx_pools++; |
| 8766 | set_bit(pool, &adapter->fwd_bitmask); |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 8767 | limit = find_last_bit(&adapter->fwd_bitmask, 32); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8768 | |
| 8769 | /* Enable VMDq flag so device will be set in VM mode */ |
| 8770 | adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED | IXGBE_FLAG_SRIOV_ENABLED; |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 8771 | adapter->ring_feature[RING_F_VMDQ].limit = limit + 1; |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 8772 | adapter->ring_feature[RING_F_RSS].limit = vdev->num_tx_queues; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8773 | |
| 8774 | /* Force reinit of ring allocation with VMDQ enabled */ |
| 8775 | err = ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev)); |
| 8776 | if (err) |
| 8777 | goto fwd_add_err; |
| 8778 | fwd_adapter->pool = pool; |
| 8779 | fwd_adapter->real_adapter = adapter; |
| 8780 | err = ixgbe_fwd_ring_up(vdev, fwd_adapter); |
| 8781 | if (err) |
| 8782 | goto fwd_add_err; |
| 8783 | netif_tx_start_all_queues(vdev); |
| 8784 | return fwd_adapter; |
| 8785 | fwd_add_err: |
| 8786 | /* unwind counter and free adapter struct */ |
| 8787 | netdev_info(pdev, |
| 8788 | "%s: dfwd hardware acceleration failed\n", vdev->name); |
| 8789 | clear_bit(pool, &adapter->fwd_bitmask); |
| 8790 | adapter->num_rx_pools--; |
| 8791 | kfree(fwd_adapter); |
| 8792 | return ERR_PTR(err); |
| 8793 | } |
| 8794 | |
| 8795 | static void ixgbe_fwd_del(struct net_device *pdev, void *priv) |
| 8796 | { |
| 8797 | struct ixgbe_fwd_adapter *fwd_adapter = priv; |
| 8798 | struct ixgbe_adapter *adapter = fwd_adapter->real_adapter; |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 8799 | unsigned int limit; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8800 | |
| 8801 | clear_bit(fwd_adapter->pool, &adapter->fwd_bitmask); |
| 8802 | adapter->num_rx_pools--; |
| 8803 | |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 8804 | limit = find_last_bit(&adapter->fwd_bitmask, 32); |
| 8805 | adapter->ring_feature[RING_F_VMDQ].limit = limit + 1; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8806 | ixgbe_fwd_ring_down(fwd_adapter->netdev, fwd_adapter); |
| 8807 | ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev)); |
| 8808 | netdev_dbg(pdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n", |
| 8809 | fwd_adapter->pool, adapter->num_rx_pools, |
| 8810 | fwd_adapter->rx_base_queue, |
| 8811 | fwd_adapter->rx_base_queue + adapter->num_rx_queues_per_pool, |
| 8812 | adapter->fwd_bitmask); |
| 8813 | kfree(fwd_adapter); |
| 8814 | } |
| 8815 | |
Mark Rustad | f467bc0 | 2015-06-15 11:33:20 -0700 | [diff] [blame] | 8816 | #define IXGBE_MAX_TUNNEL_HDR_LEN 80 |
| 8817 | static netdev_features_t |
| 8818 | ixgbe_features_check(struct sk_buff *skb, struct net_device *dev, |
| 8819 | netdev_features_t features) |
| 8820 | { |
| 8821 | if (!skb->encapsulation) |
| 8822 | return features; |
| 8823 | |
| 8824 | if (unlikely(skb_inner_mac_header(skb) - skb_transport_header(skb) > |
| 8825 | IXGBE_MAX_TUNNEL_HDR_LEN)) |
Tom Herbert | a188222 | 2015-12-14 11:19:43 -0800 | [diff] [blame] | 8826 | return features & ~NETIF_F_CSUM_MASK; |
Mark Rustad | f467bc0 | 2015-06-15 11:33:20 -0700 | [diff] [blame] | 8827 | |
| 8828 | return features; |
| 8829 | } |
| 8830 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 8831 | static const struct net_device_ops ixgbe_netdev_ops = { |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 8832 | .ndo_open = ixgbe_open, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 8833 | .ndo_stop = ixgbe_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 8834 | .ndo_start_xmit = ixgbe_xmit_frame, |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 8835 | .ndo_select_queue = ixgbe_select_queue, |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 8836 | .ndo_set_rx_mode = ixgbe_set_rx_mode, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 8837 | .ndo_validate_addr = eth_validate_addr, |
| 8838 | .ndo_set_mac_address = ixgbe_set_mac, |
| 8839 | .ndo_change_mtu = ixgbe_change_mtu, |
| 8840 | .ndo_tx_timeout = ixgbe_tx_timeout, |
Rostislav Pehlivanov | c04f90e | 2016-01-27 18:33:30 +0000 | [diff] [blame] | 8841 | .ndo_set_tx_maxrate = ixgbe_tx_maxrate, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 8842 | .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid, |
| 8843 | .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid, |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 8844 | .ndo_do_ioctl = ixgbe_ioctl, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 8845 | .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac, |
| 8846 | .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan, |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 8847 | .ndo_set_vf_rate = ixgbe_ndo_set_vf_bw, |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 8848 | .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk, |
Vlad Zolotarov | e65ce0d | 2015-03-30 21:35:24 +0300 | [diff] [blame] | 8849 | .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] | 8850 | .ndo_set_vf_trust = ixgbe_ndo_set_vf_trust, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 8851 | .ndo_get_vf_config = ixgbe_ndo_get_vf_config, |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8852 | .ndo_get_stats64 = ixgbe_get_stats64, |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 8853 | .ndo_setup_tc = __ixgbe_setup_tc, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 8854 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 8855 | .ndo_poll_controller = ixgbe_netpoll, |
| 8856 | #endif |
Cong Wang | e0d1095 | 2013-08-01 11:10:25 +0800 | [diff] [blame] | 8857 | #ifdef CONFIG_NET_RX_BUSY_POLL |
Eliezer Tamir | 8b80cda | 2013-07-10 17:13:26 +0300 | [diff] [blame] | 8858 | .ndo_busy_poll = ixgbe_low_latency_recv, |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 8859 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 8860 | #ifdef IXGBE_FCOE |
| 8861 | .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get, |
Yi Zou | 68a683c | 2011-02-01 07:22:16 +0000 | [diff] [blame] | 8862 | .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 8863 | .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put, |
Yi Zou | 8450ff8 | 2009-08-31 12:32:14 +0000 | [diff] [blame] | 8864 | .ndo_fcoe_enable = ixgbe_fcoe_enable, |
| 8865 | .ndo_fcoe_disable = ixgbe_fcoe_disable, |
Yi Zou | 61a1fa1 | 2009-10-28 18:24:56 +0000 | [diff] [blame] | 8866 | .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn, |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 8867 | .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 8868 | #endif /* IXGBE_FCOE */ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8869 | .ndo_set_features = ixgbe_set_features, |
| 8870 | .ndo_fix_features = ixgbe_fix_features, |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 8871 | .ndo_fdb_add = ixgbe_ndo_fdb_add, |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8872 | .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink, |
| 8873 | .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink, |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8874 | .ndo_dfwd_add_station = ixgbe_fwd_add, |
| 8875 | .ndo_dfwd_del_station = ixgbe_fwd_del, |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8876 | #ifdef CONFIG_IXGBE_VXLAN |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8877 | .ndo_add_vxlan_port = ixgbe_add_vxlan_port, |
| 8878 | .ndo_del_vxlan_port = ixgbe_del_vxlan_port, |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8879 | #endif /* CONFIG_IXGBE_VXLAN */ |
Mark Rustad | f467bc0 | 2015-06-15 11:33:20 -0700 | [diff] [blame] | 8880 | .ndo_features_check = ixgbe_features_check, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 8881 | }; |
| 8882 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 8883 | /** |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 8884 | * ixgbe_enumerate_functions - Get the number of ports this device has |
| 8885 | * @adapter: adapter structure |
| 8886 | * |
| 8887 | * This function enumerates the phsyical functions co-located on a single slot, |
| 8888 | * in order to determine how many ports a device has. This is most useful in |
| 8889 | * determining the required GT/s of PCIe bandwidth necessary for optimal |
| 8890 | * performance. |
| 8891 | **/ |
| 8892 | static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter) |
| 8893 | { |
Jacob Keller | caafb95 | 2014-07-19 07:17:17 +0000 | [diff] [blame] | 8894 | struct pci_dev *entry, *pdev = adapter->pdev; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 8895 | int physfns = 0; |
| 8896 | |
Jacob Keller | f1f9657 | 2013-08-31 02:45:38 +0000 | [diff] [blame] | 8897 | /* Some cards can not use the generic count PCIe functions method, |
| 8898 | * because they are behind a parent switch, so we hardcode these with |
| 8899 | * the correct number of functions. |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 8900 | */ |
Jacob Keller | 8818970 | 2014-07-19 07:17:16 +0000 | [diff] [blame] | 8901 | if (ixgbe_pcie_from_parent(&adapter->hw)) |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 8902 | physfns = 4; |
Jacob Keller | 8818970 | 2014-07-19 07:17:16 +0000 | [diff] [blame] | 8903 | |
| 8904 | list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) { |
| 8905 | /* don't count virtual functions */ |
Jacob Keller | caafb95 | 2014-07-19 07:17:17 +0000 | [diff] [blame] | 8906 | if (entry->is_virtfn) |
| 8907 | continue; |
| 8908 | |
| 8909 | /* When the devices on the bus don't all match our device ID, |
| 8910 | * we can't reliably determine the correct number of |
| 8911 | * functions. This can occur if a function has been direct |
| 8912 | * attached to a virtual machine using VT-d, for example. In |
| 8913 | * this case, simply return -1 to indicate this. |
| 8914 | */ |
| 8915 | if ((entry->vendor != pdev->vendor) || |
| 8916 | (entry->device != pdev->device)) |
| 8917 | return -1; |
| 8918 | |
| 8919 | physfns++; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 8920 | } |
| 8921 | |
| 8922 | return physfns; |
| 8923 | } |
| 8924 | |
| 8925 | /** |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 8926 | * ixgbe_wol_supported - Check whether device supports WoL |
| 8927 | * @hw: hw specific details |
| 8928 | * @device_id: the device ID |
| 8929 | * @subdev_id: the subsystem device ID |
| 8930 | * |
| 8931 | * This function is used by probe and ethtool to determine |
| 8932 | * which devices have WoL support |
| 8933 | * |
| 8934 | **/ |
| 8935 | int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id, |
| 8936 | u16 subdevice_id) |
| 8937 | { |
| 8938 | struct ixgbe_hw *hw = &adapter->hw; |
| 8939 | u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK; |
| 8940 | int is_wol_supported = 0; |
| 8941 | |
| 8942 | switch (device_id) { |
| 8943 | case IXGBE_DEV_ID_82599_SFP: |
| 8944 | /* Only these subdevices could supports WOL */ |
| 8945 | switch (subdevice_id) { |
Mark Rustad | 8755744 | 2014-02-25 17:58:55 -0800 | [diff] [blame] | 8946 | case IXGBE_SUBDEV_ID_82599_SFP_WOL0: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 8947 | case IXGBE_SUBDEV_ID_82599_560FLR: |
| 8948 | /* only support first port */ |
| 8949 | if (hw->bus.func != 0) |
| 8950 | break; |
Emil Tantilov | 5700ff2 | 2013-04-18 08:18:55 +0000 | [diff] [blame] | 8951 | case IXGBE_SUBDEV_ID_82599_SP_560FLR: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 8952 | case IXGBE_SUBDEV_ID_82599_SFP: |
Don Skidmore | b6dfd93 | 2012-07-11 07:17:42 +0000 | [diff] [blame] | 8953 | case IXGBE_SUBDEV_ID_82599_RNDC: |
Emil Tantilov | f8a06c2 | 2012-08-16 08:13:07 +0000 | [diff] [blame] | 8954 | case IXGBE_SUBDEV_ID_82599_ECNA_DP: |
Jacob Keller | 979fe5f | 2013-04-03 04:41:37 +0000 | [diff] [blame] | 8955 | case IXGBE_SUBDEV_ID_82599_LOM_SFP: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 8956 | is_wol_supported = 1; |
| 8957 | break; |
| 8958 | } |
| 8959 | break; |
Don Skidmore | 5daebbb | 2013-04-05 05:49:34 +0000 | [diff] [blame] | 8960 | case IXGBE_DEV_ID_82599EN_SFP: |
| 8961 | /* Only this subdevice supports WOL */ |
| 8962 | switch (subdevice_id) { |
| 8963 | case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1: |
| 8964 | is_wol_supported = 1; |
| 8965 | break; |
| 8966 | } |
| 8967 | break; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 8968 | case IXGBE_DEV_ID_82599_COMBO_BACKPLANE: |
| 8969 | /* All except this subdevice support WOL */ |
| 8970 | if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ) |
| 8971 | is_wol_supported = 1; |
| 8972 | break; |
| 8973 | case IXGBE_DEV_ID_82599_KX4: |
| 8974 | is_wol_supported = 1; |
| 8975 | break; |
| 8976 | case IXGBE_DEV_ID_X540T: |
joshua.a.hay@intel.com | df376f0 | 2012-09-21 00:08:21 +0000 | [diff] [blame] | 8977 | case IXGBE_DEV_ID_X540T1: |
Don Skidmore | df8c26f | 2015-06-09 16:00:17 -0700 | [diff] [blame] | 8978 | case IXGBE_DEV_ID_X550T: |
| 8979 | case IXGBE_DEV_ID_X550EM_X_KX4: |
| 8980 | case IXGBE_DEV_ID_X550EM_X_KR: |
| 8981 | case IXGBE_DEV_ID_X550EM_X_10G_T: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 8982 | /* check eeprom to see if enabled wol */ |
| 8983 | if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) || |
| 8984 | ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) && |
| 8985 | (hw->bus.func == 0))) { |
| 8986 | is_wol_supported = 1; |
| 8987 | } |
| 8988 | break; |
| 8989 | } |
| 8990 | |
| 8991 | return is_wol_supported; |
| 8992 | } |
| 8993 | |
| 8994 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8995 | * ixgbe_probe - Device Initialization Routine |
| 8996 | * @pdev: PCI device information struct |
| 8997 | * @ent: entry in ixgbe_pci_tbl |
| 8998 | * |
| 8999 | * Returns 0 on success, negative on failure |
| 9000 | * |
| 9001 | * ixgbe_probe initializes an adapter identified by a pci_dev structure. |
| 9002 | * The OS initialization, configuring of the adapter private structure, |
| 9003 | * and a hardware reset occur. |
| 9004 | **/ |
Greg Kroah-Hartman | 1dd06ae | 2012-12-06 14:30:56 +0000 | [diff] [blame] | 9005 | 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] | 9006 | { |
| 9007 | struct net_device *netdev; |
| 9008 | struct ixgbe_adapter *adapter = NULL; |
| 9009 | struct ixgbe_hw *hw; |
| 9010 | const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data]; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 9011 | int i, err, pci_using_dac, expected_gts; |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 9012 | unsigned int indices = MAX_TX_QUEUES; |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 9013 | u8 part_str[IXGBE_PBANUM_LENGTH]; |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 9014 | bool disable_dev = false; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 9015 | #ifdef IXGBE_FCOE |
| 9016 | u16 device_caps; |
| 9017 | #endif |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 9018 | u32 eec; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9019 | |
Andy Gospodarek | bded64a | 2010-07-21 06:40:31 +0000 | [diff] [blame] | 9020 | /* Catch broken hardware that put the wrong VF device ID in |
| 9021 | * the PCIe SR-IOV capability. |
| 9022 | */ |
| 9023 | if (pdev->is_virtfn) { |
| 9024 | WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n", |
| 9025 | pci_name(pdev), pdev->vendor, pdev->device); |
| 9026 | return -EINVAL; |
| 9027 | } |
| 9028 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 9029 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9030 | if (err) |
| 9031 | return err; |
| 9032 | |
Russell King | f5f2eda | 2013-06-10 12:47:42 +0100 | [diff] [blame] | 9033 | if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9034 | pci_using_dac = 1; |
| 9035 | } else { |
Russell King | f5f2eda | 2013-06-10 12:47:42 +0100 | [diff] [blame] | 9036 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9037 | if (err) { |
Russell King | f5f2eda | 2013-06-10 12:47:42 +0100 | [diff] [blame] | 9038 | dev_err(&pdev->dev, |
| 9039 | "No usable DMA configuration, aborting\n"); |
| 9040 | goto err_dma; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9041 | } |
| 9042 | pci_using_dac = 0; |
| 9043 | } |
| 9044 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 9045 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 9046 | IORESOURCE_MEM), ixgbe_driver_name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9047 | if (err) { |
Dan Carpenter | b8bc042 | 2010-07-27 00:05:56 +0000 | [diff] [blame] | 9048 | dev_err(&pdev->dev, |
| 9049 | "pci_request_selected_regions failed 0x%x\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9050 | goto err_pci_reg; |
| 9051 | } |
| 9052 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 9053 | pci_enable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9054 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9055 | pci_set_master(pdev); |
Wendy Xiong | fb3b27b | 2008-04-23 11:09:24 -0700 | [diff] [blame] | 9056 | pci_save_state(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9057 | |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 9058 | if (ii->mac == ixgbe_mac_82598EB) { |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 9059 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 9060 | /* 8 TC w/ 4 queues per TC */ |
| 9061 | indices = 4 * MAX_TRAFFIC_CLASS; |
| 9062 | #else |
| 9063 | indices = IXGBE_MAX_RSS_INDICES; |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 9064 | #endif |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 9065 | } |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 9066 | |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 9067 | netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9068 | if (!netdev) { |
| 9069 | err = -ENOMEM; |
| 9070 | goto err_alloc_etherdev; |
| 9071 | } |
| 9072 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9073 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 9074 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9075 | adapter = netdev_priv(netdev); |
| 9076 | |
| 9077 | adapter->netdev = netdev; |
| 9078 | adapter->pdev = pdev; |
| 9079 | hw = &adapter->hw; |
| 9080 | hw->back = adapter; |
stephen hemminger | b3f4d59 | 2012-03-13 06:04:20 +0000 | [diff] [blame] | 9081 | adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9082 | |
Jeff Kirsher | 0585798 | 2008-09-11 19:57:00 -0700 | [diff] [blame] | 9083 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 9084 | pci_resource_len(pdev, 0)); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 9085 | adapter->io_addr = hw->hw_addr; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9086 | if (!hw->hw_addr) { |
| 9087 | err = -EIO; |
| 9088 | goto err_ioremap; |
| 9089 | } |
| 9090 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 9091 | netdev->netdev_ops = &ixgbe_netdev_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9092 | ixgbe_set_ethtool_ops(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9093 | netdev->watchdog_timeo = 5 * HZ; |
Mark Rustad | 339de30 | 2014-06-06 01:57:06 +0000 | [diff] [blame] | 9094 | strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9095 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9096 | /* Setup hw api */ |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 9097 | hw->mac.ops = *ii->mac_ops; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 9098 | hw->mac.type = ii->mac; |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 9099 | hw->mvals = ii->mvals; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9100 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9101 | /* EEPROM */ |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 9102 | hw->eeprom.ops = *ii->eeprom_ops; |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 9103 | eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw)); |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 9104 | if (ixgbe_removed(hw->hw_addr)) { |
| 9105 | err = -EIO; |
| 9106 | goto err_ioremap; |
| 9107 | } |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9108 | /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */ |
| 9109 | if (!(eec & (1 << 8))) |
| 9110 | hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic; |
| 9111 | |
| 9112 | /* PHY */ |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 9113 | hw->phy.ops = *ii->phy_ops; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 9114 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 9115 | /* ixgbe_identify_phy_generic will set prtad and mmds properly */ |
| 9116 | hw->phy.mdio.prtad = MDIO_PRTAD_NONE; |
| 9117 | hw->phy.mdio.mmds = 0; |
| 9118 | hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 9119 | hw->phy.mdio.dev = netdev; |
| 9120 | hw->phy.mdio.mdio_read = ixgbe_mdio_read; |
| 9121 | hw->phy.mdio.mdio_write = ixgbe_mdio_write; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 9122 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 9123 | ii->get_invariants(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9124 | |
| 9125 | /* setup the private structure */ |
| 9126 | err = ixgbe_sw_init(adapter); |
| 9127 | if (err) |
| 9128 | goto err_sw_init; |
| 9129 | |
Don Skidmore | dbd15b8 | 2016-03-09 16:45:00 -0500 | [diff] [blame] | 9130 | /* Make sure the SWFW semaphore is in a valid state */ |
| 9131 | if (hw->mac.ops.init_swfw_sync) |
| 9132 | hw->mac.ops.init_swfw_sync(hw); |
| 9133 | |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 9134 | /* Make it possible the adapter to be woken up via WOL */ |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 9135 | switch (adapter->hw.mac.type) { |
| 9136 | case ixgbe_mac_82599EB: |
| 9137 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 9138 | case ixgbe_mac_X550: |
| 9139 | case ixgbe_mac_X550EM_x: |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 9140 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 9141 | break; |
| 9142 | default: |
| 9143 | break; |
| 9144 | } |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 9145 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 9146 | /* |
| 9147 | * If there is a fan on this device and it has failed log the |
| 9148 | * failure. |
| 9149 | */ |
| 9150 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 9151 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 9152 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 9153 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 9154 | } |
| 9155 | |
Peter P Waskiewicz Jr | 8ef78ad | 2012-02-01 09:19:21 +0000 | [diff] [blame] | 9156 | if (allow_unsupported_sfp) |
| 9157 | hw->allow_unsupported_sfp = allow_unsupported_sfp; |
| 9158 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9159 | /* reset_hw fills in the perm_addr as well */ |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 9160 | hw->phy.reset_if_overtemp = true; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9161 | err = hw->mac.ops.reset_hw(hw); |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 9162 | hw->phy.reset_if_overtemp = false; |
Mark Rustad | 29a8dca | 2015-08-08 16:17:46 -0700 | [diff] [blame] | 9163 | if (err == IXGBE_ERR_SFP_NOT_PRESENT) { |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 9164 | err = 0; |
| 9165 | } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 1b1bf31 | 2013-07-31 05:27:04 +0000 | [diff] [blame] | 9166 | e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n"); |
| 9167 | e_dev_err("Reload the driver after installing a supported module.\n"); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 9168 | goto err_sw_init; |
| 9169 | } else if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 9170 | e_dev_err("HW Init failed: %d\n", err); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9171 | goto err_sw_init; |
| 9172 | } |
| 9173 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 9174 | #ifdef CONFIG_PCI_IOV |
Greg Rose | 60a1a68 | 2012-12-11 08:26:33 +0000 | [diff] [blame] | 9175 | /* SR-IOV not supported on the 82598 */ |
| 9176 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 9177 | goto skip_sriov; |
| 9178 | /* Mailbox */ |
| 9179 | ixgbe_init_mbx_params_pf(hw); |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 9180 | hw->mbx.ops = ii->mbx_ops; |
ethan.zhao | dcc23e3 | 2014-01-16 19:41:04 -0800 | [diff] [blame] | 9181 | pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT); |
ethan.zhao | 31ac910 | 2014-01-16 19:41:05 -0800 | [diff] [blame] | 9182 | ixgbe_enable_sriov(adapter); |
Greg Rose | 60a1a68 | 2012-12-11 08:26:33 +0000 | [diff] [blame] | 9183 | skip_sriov: |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 9184 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 9185 | #endif |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 9186 | netdev->features = NETIF_F_SG | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9187 | NETIF_F_TSO | |
| 9188 | NETIF_F_TSO6 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9189 | NETIF_F_RXHASH | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 9190 | NETIF_F_RXCSUM | |
| 9191 | NETIF_F_HW_CSUM | |
| 9192 | NETIF_F_HW_VLAN_CTAG_TX | |
| 9193 | NETIF_F_HW_VLAN_CTAG_RX; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9194 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 9195 | if (hw->mac.type >= ixgbe_mac_82599EB) |
Tom Herbert | 53692b1 | 2015-12-14 11:19:41 -0800 | [diff] [blame] | 9196 | netdev->features |= NETIF_F_SCTP_CRC; |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 9197 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 9198 | /* copy netdev features into list of user selectable features */ |
| 9199 | netdev->hw_features |= netdev->features; |
| 9200 | netdev->hw_features |= NETIF_F_RXALL | |
| 9201 | NETIF_F_HW_L2FW_DOFFLOAD; |
| 9202 | |
| 9203 | if (hw->mac.type >= ixgbe_mac_82599EB) |
| 9204 | netdev->hw_features |= NETIF_F_NTUPLE | |
| 9205 | NETIF_F_HW_TC; |
| 9206 | |
| 9207 | /* set this bit last since it cannot be part of hw_features */ |
Alexander Duyck | 87031c0 | 2015-04-09 22:03:24 -0700 | [diff] [blame] | 9208 | netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 9209 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 9210 | netdev->vlan_features |= NETIF_F_SG | |
| 9211 | NETIF_F_TSO | |
| 9212 | NETIF_F_TSO6 | |
| 9213 | NETIF_F_HW_CSUM | |
| 9214 | NETIF_F_SCTP_CRC; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 9215 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 9216 | netdev->mpls_features |= NETIF_F_HW_CSUM; |
| 9217 | netdev->hw_enc_features |= NETIF_F_HW_CSUM; |
Mark Rustad | f467bc0 | 2015-06-15 11:33:20 -0700 | [diff] [blame] | 9218 | |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 9219 | netdev->priv_flags |= IFF_UNICAST_FLT; |
Ben Greear | f43f313 | 2012-03-06 09:42:04 +0000 | [diff] [blame] | 9220 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 9221 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 9222 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 9223 | netdev->dcbnl_ops = &dcbnl_ops; |
| 9224 | #endif |
| 9225 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 9226 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 9227 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 9228 | unsigned int fcoe_l; |
| 9229 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 9230 | if (hw->mac.ops.get_device_caps) { |
| 9231 | hw->mac.ops.get_device_caps(hw, &device_caps); |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 9232 | if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS) |
| 9233 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 9234 | } |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 9235 | |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 9236 | |
| 9237 | fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus()); |
| 9238 | adapter->ring_feature[RING_F_FCOE].limit = fcoe_l; |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 9239 | |
Alexander Duyck | a58915c | 2012-05-25 06:38:18 +0000 | [diff] [blame] | 9240 | netdev->features |= NETIF_F_FSO | |
| 9241 | NETIF_F_FCOE_CRC; |
| 9242 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 9243 | netdev->vlan_features |= NETIF_F_FSO | |
| 9244 | NETIF_F_FCOE_CRC | |
| 9245 | NETIF_F_FCOE_MTU; |
Yi Zou | 5e09d7f | 2010-07-19 13:59:52 +0000 | [diff] [blame] | 9246 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 9247 | #endif /* IXGBE_FCOE */ |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 9248 | if (pci_using_dac) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9249 | netdev->features |= NETIF_F_HIGHDMA; |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 9250 | netdev->vlan_features |= NETIF_F_HIGHDMA; |
| 9251 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9252 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9253 | if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) |
| 9254 | netdev->hw_features |= NETIF_F_LRO; |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 9255 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 9256 | netdev->features |= NETIF_F_LRO; |
| 9257 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9258 | /* make sure the EEPROM is good */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9259 | if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 9260 | e_dev_err("The EEPROM Checksum Is Not Valid\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9261 | err = -EIO; |
Alexander Duyck | 35937c0 | 2012-02-08 07:51:37 +0000 | [diff] [blame] | 9262 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9263 | } |
| 9264 | |
Sowmini Varadhan | c7374b5 | 2016-01-12 19:32:30 -0800 | [diff] [blame] | 9265 | eth_platform_get_mac_address(&adapter->pdev->dev, |
| 9266 | adapter->hw.mac.perm_addr); |
Martin K Petersen | c762dff | 2014-11-15 14:24:51 +0000 | [diff] [blame] | 9267 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9268 | memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9269 | |
Jiri Pirko | aaeb6cd | 2013-01-08 01:38:26 +0000 | [diff] [blame] | 9270 | if (!is_valid_ether_addr(netdev->dev_addr)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 9271 | e_dev_err("invalid MAC address\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9272 | err = -EIO; |
Alexander Duyck | 35937c0 | 2012-02-08 07:51:37 +0000 | [diff] [blame] | 9273 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9274 | } |
| 9275 | |
Tushar Dave | 5676804 | 2016-01-07 14:17:03 -0800 | [diff] [blame] | 9276 | /* Set hw->mac.addr to permanent MAC address */ |
| 9277 | ether_addr_copy(hw->mac.addr, hw->mac.perm_addr); |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 9278 | ixgbe_mac_set_default_filter(adapter); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 9279 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 9280 | setup_timer(&adapter->service_timer, &ixgbe_service_timer, |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 9281 | (unsigned long) adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9282 | |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 9283 | if (ixgbe_removed(hw->hw_addr)) { |
| 9284 | err = -EIO; |
| 9285 | goto err_sw_init; |
| 9286 | } |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 9287 | INIT_WORK(&adapter->service_task, ixgbe_service_task); |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 9288 | set_bit(__IXGBE_SERVICE_INITED, &adapter->state); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 9289 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9290 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 9291 | err = ixgbe_init_interrupt_scheme(adapter); |
| 9292 | if (err) |
| 9293 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9294 | |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9295 | /* WOL not supported for all devices */ |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 9296 | adapter->wol = 0; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9297 | hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap); |
Jacob Keller | 6b92b0b | 2013-04-13 05:40:37 +0000 | [diff] [blame] | 9298 | hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device, |
Don Skidmore | b8f8363 | 2013-02-28 08:08:44 +0000 | [diff] [blame] | 9299 | pdev->subsystem_device); |
Jacob Keller | 6b92b0b | 2013-04-13 05:40:37 +0000 | [diff] [blame] | 9300 | if (hw->wol_enabled) |
Andy Gospodarek | 9417c46 | 2011-07-16 07:31:33 +0000 | [diff] [blame] | 9301 | adapter->wol = IXGBE_WUFC_MAG; |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 9302 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 9303 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 9304 | |
Emil Tantilov | 15e5209 | 2011-09-29 05:01:29 +0000 | [diff] [blame] | 9305 | /* save off EEPROM version number */ |
| 9306 | hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh); |
| 9307 | hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl); |
| 9308 | |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 9309 | /* pick up the PCI bus settings for reporting later */ |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 9310 | if (ixgbe_pcie_from_parent(hw)) |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 9311 | ixgbe_get_parent_bus_info(adapter); |
Don Skidmore | f9328bc | 2015-06-18 13:24:06 -0400 | [diff] [blame] | 9312 | else |
| 9313 | hw->mac.ops.get_bus_info(hw); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 9314 | |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 9315 | /* calculate the expected PCIe bandwidth required for optimal |
| 9316 | * performance. Note that some older parts will never have enough |
| 9317 | * bandwidth due to being older generation PCIe parts. We clamp these |
| 9318 | * parts to ensure no warning is displayed if it can't be fixed. |
| 9319 | */ |
| 9320 | switch (hw->mac.type) { |
| 9321 | case ixgbe_mac_82598EB: |
| 9322 | expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16); |
| 9323 | break; |
| 9324 | default: |
| 9325 | expected_gts = ixgbe_enumerate_functions(adapter) * 10; |
| 9326 | break; |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 9327 | } |
Jacob Keller | caafb95 | 2014-07-19 07:17:17 +0000 | [diff] [blame] | 9328 | |
| 9329 | /* don't check link if we failed to enumerate functions */ |
| 9330 | if (expected_gts > 0) |
| 9331 | ixgbe_check_minimum_link(adapter, expected_gts); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 9332 | |
Mark Rustad | 339de30 | 2014-06-06 01:57:06 +0000 | [diff] [blame] | 9333 | err = ixgbe_read_pba_string_generic(hw, part_str, sizeof(part_str)); |
Jacob Keller | 6a2aae5 | 2013-10-18 05:09:24 +0000 | [diff] [blame] | 9334 | if (err) |
Mark Rustad | 339de30 | 2014-06-06 01:57:06 +0000 | [diff] [blame] | 9335 | strlcpy(part_str, "Unknown", sizeof(part_str)); |
Jacob Keller | 6a2aae5 | 2013-10-18 05:09:24 +0000 | [diff] [blame] | 9336 | if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present) |
| 9337 | e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n", |
| 9338 | hw->mac.type, hw->phy.type, hw->phy.sfp_type, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 9339 | part_str); |
Jacob Keller | 6a2aae5 | 2013-10-18 05:09:24 +0000 | [diff] [blame] | 9340 | else |
| 9341 | e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n", |
| 9342 | hw->mac.type, hw->phy.type, part_str); |
| 9343 | |
| 9344 | e_dev_info("%pM\n", netdev->dev_addr); |
| 9345 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9346 | /* reset the hardware with the new settings */ |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 9347 | err = hw->mac.ops.start_hw(hw); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 9348 | if (err == IXGBE_ERR_EEPROM_VERSION) { |
| 9349 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 9350 | e_dev_warn("This device is a pre-production adapter/LOM. " |
| 9351 | "Please be aware there may be issues associated " |
| 9352 | "with your hardware. If you are experiencing " |
| 9353 | "problems please contact your Intel or hardware " |
| 9354 | "representative who provided you with this " |
| 9355 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 9356 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9357 | strcpy(netdev->name, "eth%d"); |
| 9358 | err = register_netdev(netdev); |
| 9359 | if (err) |
| 9360 | goto err_register; |
| 9361 | |
Emil Tantilov | 0fb6a55 | 2014-12-04 03:03:38 +0000 | [diff] [blame] | 9362 | pci_set_drvdata(pdev, adapter); |
| 9363 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 9364 | /* power down the optics for 82599 SFP+ fiber */ |
| 9365 | if (hw->mac.ops.disable_tx_laser) |
Emil Tantilov | 93d3ce8 | 2011-10-19 07:59:55 +0000 | [diff] [blame] | 9366 | hw->mac.ops.disable_tx_laser(hw); |
| 9367 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 9368 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 9369 | netif_carrier_off(netdev); |
| 9370 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 9371 | #ifdef CONFIG_IXGBE_DCA |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 9372 | if (dca_add_requester(&pdev->dev) == 0) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9373 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9374 | ixgbe_setup_dca(adapter); |
| 9375 | } |
| 9376 | #endif |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 9377 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 9378 | 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] | 9379 | for (i = 0; i < adapter->num_vfs; i++) |
| 9380 | ixgbe_vf_configuration(pdev, (i | 0x10000000)); |
| 9381 | } |
| 9382 | |
Jacob Keller | 2466dd9 | 2011-09-08 03:50:54 +0000 | [diff] [blame] | 9383 | /* firmware requires driver version to be 0xFFFFFFFF |
| 9384 | * since os does not support feature |
| 9385 | */ |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 9386 | if (hw->mac.ops.set_fw_drv_ver) |
Jacob Keller | 2466dd9 | 2011-09-08 03:50:54 +0000 | [diff] [blame] | 9387 | hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, |
| 9388 | 0xFF); |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 9389 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 9390 | /* add san mac addr to netdev */ |
| 9391 | ixgbe_add_sanmac_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9392 | |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 9393 | e_dev_info("%s\n", ixgbe_default_device_descr); |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 9394 | |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 9395 | #ifdef CONFIG_IXGBE_HWMON |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 9396 | if (ixgbe_sysfs_init(adapter)) |
| 9397 | e_err(probe, "failed to allocate sysfs resources\n"); |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 9398 | #endif /* CONFIG_IXGBE_HWMON */ |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 9399 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 9400 | ixgbe_dbg_adapter_init(adapter); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 9401 | |
Emil Tantilov | d1a35ee | 2014-05-13 08:24:00 +0000 | [diff] [blame] | 9402 | /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */ |
| 9403 | 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] | 9404 | hw->mac.ops.setup_link(hw, |
| 9405 | IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL, |
| 9406 | true); |
| 9407 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9408 | return 0; |
| 9409 | |
| 9410 | err_register: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 9411 | ixgbe_release_hw_control(adapter); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 9412 | ixgbe_clear_interrupt_scheme(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9413 | err_sw_init: |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 9414 | ixgbe_disable_sriov(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 9415 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 9416 | iounmap(adapter->io_addr); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 9417 | kfree(adapter->mac_table); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9418 | err_ioremap: |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 9419 | disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9420 | free_netdev(netdev); |
| 9421 | err_alloc_etherdev: |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 9422 | pci_release_selected_regions(pdev, |
| 9423 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9424 | err_pci_reg: |
| 9425 | err_dma: |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 9426 | if (!adapter || disable_dev) |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 9427 | pci_disable_device(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9428 | return err; |
| 9429 | } |
| 9430 | |
| 9431 | /** |
| 9432 | * ixgbe_remove - Device Removal Routine |
| 9433 | * @pdev: PCI device information struct |
| 9434 | * |
| 9435 | * ixgbe_remove is called by the PCI subsystem to alert the driver |
| 9436 | * that it should release a PCI device. The could be caused by a |
| 9437 | * Hot-Plug event, or because the driver is going to be removed from |
| 9438 | * memory. |
| 9439 | **/ |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 9440 | static void ixgbe_remove(struct pci_dev *pdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9441 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 9442 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
Emil Tantilov | 0fb6a55 | 2014-12-04 03:03:38 +0000 | [diff] [blame] | 9443 | struct net_device *netdev; |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 9444 | bool disable_dev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9445 | |
Emil Tantilov | 0fb6a55 | 2014-12-04 03:03:38 +0000 | [diff] [blame] | 9446 | /* if !adapter then we already cleaned up in probe */ |
| 9447 | if (!adapter) |
| 9448 | return; |
| 9449 | |
| 9450 | netdev = adapter->netdev; |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 9451 | ixgbe_dbg_adapter_exit(adapter); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 9452 | |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 9453 | set_bit(__IXGBE_REMOVING, &adapter->state); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 9454 | cancel_work_sync(&adapter->service_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9455 | |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 9456 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 9457 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9458 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 9459 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 9460 | dca_remove_requester(&pdev->dev); |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 9461 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 9462 | IXGBE_DCA_CTRL_DCA_DISABLE); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9463 | } |
| 9464 | |
| 9465 | #endif |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 9466 | #ifdef CONFIG_IXGBE_HWMON |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 9467 | ixgbe_sysfs_exit(adapter); |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 9468 | #endif /* CONFIG_IXGBE_HWMON */ |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 9469 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 9470 | /* remove the added san mac */ |
| 9471 | ixgbe_del_sanmac_netdev(netdev); |
| 9472 | |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 9473 | #ifdef CONFIG_PCI_IOV |
Alex Williamson | 7837e28 | 2015-07-10 15:31:34 -0600 | [diff] [blame] | 9474 | ixgbe_disable_sriov(adapter); |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 9475 | #endif |
Alex Williamson | 6b010e9 | 2015-07-29 14:38:21 -0600 | [diff] [blame] | 9476 | if (netdev->reg_state == NETREG_REGISTERED) |
| 9477 | unregister_netdev(netdev); |
| 9478 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 9479 | ixgbe_clear_interrupt_scheme(adapter); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 9480 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 9481 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9482 | |
Alexander Duyck | 2b1588c | 2012-03-17 02:39:16 +0000 | [diff] [blame] | 9483 | #ifdef CONFIG_DCB |
| 9484 | kfree(adapter->ixgbe_ieee_pfc); |
| 9485 | kfree(adapter->ixgbe_ieee_ets); |
| 9486 | |
| 9487 | #endif |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 9488 | iounmap(adapter->io_addr); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 9489 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 9490 | IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9491 | |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 9492 | e_dev_info("complete\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 9493 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 9494 | kfree(adapter->mac_table); |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 9495 | disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9496 | free_netdev(netdev); |
| 9497 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 9498 | pci_disable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9499 | |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 9500 | if (disable_dev) |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 9501 | pci_disable_device(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9502 | } |
| 9503 | |
| 9504 | /** |
| 9505 | * ixgbe_io_error_detected - called when PCI error is detected |
| 9506 | * @pdev: Pointer to PCI device |
| 9507 | * @state: The current pci connection state |
| 9508 | * |
| 9509 | * This function is called after a PCI bus error affecting |
| 9510 | * this device has been detected. |
| 9511 | */ |
| 9512 | 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] | 9513 | pci_channel_state_t state) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9514 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 9515 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 9516 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9517 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 9518 | #ifdef CONFIG_PCI_IOV |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 9519 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 9520 | struct pci_dev *bdev, *vfdev; |
| 9521 | u32 dw0, dw1, dw2, dw3; |
| 9522 | int vf, pos; |
| 9523 | u16 req_id, pf_func; |
| 9524 | |
| 9525 | if (adapter->hw.mac.type == ixgbe_mac_82598EB || |
| 9526 | adapter->num_vfs == 0) |
| 9527 | goto skip_bad_vf_detection; |
| 9528 | |
| 9529 | bdev = pdev->bus->self; |
Yijing Wang | 62f87c0 | 2012-07-24 17:20:03 +0800 | [diff] [blame] | 9530 | while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT)) |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 9531 | bdev = bdev->bus->self; |
| 9532 | |
| 9533 | if (!bdev) |
| 9534 | goto skip_bad_vf_detection; |
| 9535 | |
| 9536 | pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR); |
| 9537 | if (!pos) |
| 9538 | goto skip_bad_vf_detection; |
| 9539 | |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 9540 | dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG); |
| 9541 | dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4); |
| 9542 | dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8); |
| 9543 | dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12); |
| 9544 | if (ixgbe_removed(hw->hw_addr)) |
| 9545 | goto skip_bad_vf_detection; |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 9546 | |
| 9547 | req_id = dw1 >> 16; |
| 9548 | /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */ |
| 9549 | if (!(req_id & 0x0080)) |
| 9550 | goto skip_bad_vf_detection; |
| 9551 | |
| 9552 | pf_func = req_id & 0x01; |
| 9553 | if ((pf_func & 1) == (pdev->devfn & 1)) { |
| 9554 | unsigned int device_id; |
| 9555 | |
| 9556 | vf = (req_id & 0x7F) >> 1; |
| 9557 | e_dev_err("VF %d has caused a PCIe error\n", vf); |
| 9558 | e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: " |
| 9559 | "%8.8x\tdw3: %8.8x\n", |
| 9560 | dw0, dw1, dw2, dw3); |
| 9561 | switch (adapter->hw.mac.type) { |
| 9562 | case ixgbe_mac_82599EB: |
| 9563 | device_id = IXGBE_82599_VF_DEVICE_ID; |
| 9564 | break; |
| 9565 | case ixgbe_mac_X540: |
| 9566 | device_id = IXGBE_X540_VF_DEVICE_ID; |
| 9567 | break; |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 9568 | case ixgbe_mac_X550: |
| 9569 | device_id = IXGBE_DEV_ID_X550_VF; |
| 9570 | break; |
| 9571 | case ixgbe_mac_X550EM_x: |
| 9572 | device_id = IXGBE_DEV_ID_X550EM_X_VF; |
| 9573 | break; |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 9574 | default: |
| 9575 | device_id = 0; |
| 9576 | break; |
| 9577 | } |
| 9578 | |
| 9579 | /* Find the pci device of the offending VF */ |
Jon Mason | 36e9031 | 2012-07-19 21:02:09 +0000 | [diff] [blame] | 9580 | vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL); |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 9581 | while (vfdev) { |
| 9582 | if (vfdev->devfn == (req_id & 0xFF)) |
| 9583 | break; |
Jon Mason | 36e9031 | 2012-07-19 21:02:09 +0000 | [diff] [blame] | 9584 | vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 9585 | device_id, vfdev); |
| 9586 | } |
| 9587 | /* |
| 9588 | * There's a slim chance the VF could have been hot plugged, |
| 9589 | * so if it is no longer present we don't need to issue the |
| 9590 | * VFLR. Just clean up the AER in that case. |
| 9591 | */ |
| 9592 | if (vfdev) { |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 9593 | ixgbe_issue_vf_flr(adapter, vfdev); |
Greg Rose | b4fafbe | 2012-12-13 01:14:06 +0000 | [diff] [blame] | 9594 | /* Free device reference count */ |
| 9595 | pci_dev_put(vfdev); |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 9596 | } |
| 9597 | |
| 9598 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 9599 | } |
| 9600 | |
| 9601 | /* |
| 9602 | * Even though the error may have occurred on the other port |
| 9603 | * we still need to increment the vf error reference count for |
| 9604 | * both ports because the I/O resume function will be called |
| 9605 | * for both of them. |
| 9606 | */ |
| 9607 | adapter->vferr_refcount++; |
| 9608 | |
| 9609 | return PCI_ERS_RESULT_RECOVERED; |
| 9610 | |
| 9611 | skip_bad_vf_detection: |
| 9612 | #endif /* CONFIG_PCI_IOV */ |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 9613 | if (!test_bit(__IXGBE_SERVICE_INITED, &adapter->state)) |
| 9614 | return PCI_ERS_RESULT_DISCONNECT; |
| 9615 | |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 9616 | rtnl_lock(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9617 | netif_device_detach(netdev); |
| 9618 | |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 9619 | if (state == pci_channel_io_perm_failure) { |
| 9620 | rtnl_unlock(); |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 9621 | return PCI_ERS_RESULT_DISCONNECT; |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 9622 | } |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 9623 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9624 | if (netif_running(netdev)) |
| 9625 | ixgbe_down(adapter); |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 9626 | |
| 9627 | if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state)) |
| 9628 | pci_disable_device(pdev); |
| 9629 | rtnl_unlock(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9630 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 9631 | /* Request a slot reset. */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9632 | return PCI_ERS_RESULT_NEED_RESET; |
| 9633 | } |
| 9634 | |
| 9635 | /** |
| 9636 | * ixgbe_io_slot_reset - called after the pci bus has been reset. |
| 9637 | * @pdev: Pointer to PCI device |
| 9638 | * |
| 9639 | * Restart the card from scratch, as if from a cold-boot. |
| 9640 | */ |
| 9641 | static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev) |
| 9642 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 9643 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9644 | pci_ers_result_t result; |
| 9645 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9646 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 9647 | if (pci_enable_device_mem(pdev)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 9648 | 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] | 9649 | result = PCI_ERS_RESULT_DISCONNECT; |
| 9650 | } else { |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 9651 | smp_mb__before_atomic(); |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 9652 | clear_bit(__IXGBE_DISABLED, &adapter->state); |
Mark Rustad | 0391bbe | 2014-02-28 15:48:55 -0800 | [diff] [blame] | 9653 | adapter->hw.hw_addr = adapter->io_addr; |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9654 | pci_set_master(pdev); |
| 9655 | pci_restore_state(pdev); |
Breno Leitao | c0e1f68 | 2009-11-10 08:37:47 +0000 | [diff] [blame] | 9656 | pci_save_state(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9657 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 9658 | pci_wake_from_d3(pdev, false); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9659 | |
| 9660 | ixgbe_reset(adapter); |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 9661 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9662 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9663 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9664 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9665 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 9666 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 9667 | e_dev_err("pci_cleanup_aer_uncorrect_error_status " |
| 9668 | "failed 0x%0x\n", err); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9669 | /* non-fatal, continue */ |
| 9670 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9671 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9672 | return result; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9673 | } |
| 9674 | |
| 9675 | /** |
| 9676 | * ixgbe_io_resume - called when traffic can start flowing again. |
| 9677 | * @pdev: Pointer to PCI device |
| 9678 | * |
| 9679 | * This callback is called when the error recovery driver tells us that |
| 9680 | * its OK to resume normal operation. |
| 9681 | */ |
| 9682 | static void ixgbe_io_resume(struct pci_dev *pdev) |
| 9683 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 9684 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 9685 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9686 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 9687 | #ifdef CONFIG_PCI_IOV |
| 9688 | if (adapter->vferr_refcount) { |
| 9689 | e_info(drv, "Resuming after VF err\n"); |
| 9690 | adapter->vferr_refcount--; |
| 9691 | return; |
| 9692 | } |
| 9693 | |
| 9694 | #endif |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 9695 | if (netif_running(netdev)) |
| 9696 | ixgbe_up(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9697 | |
| 9698 | netif_device_attach(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9699 | } |
| 9700 | |
Stephen Hemminger | 3646f0e | 2012-09-07 09:33:15 -0700 | [diff] [blame] | 9701 | static const struct pci_error_handlers ixgbe_err_handler = { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9702 | .error_detected = ixgbe_io_error_detected, |
| 9703 | .slot_reset = ixgbe_io_slot_reset, |
| 9704 | .resume = ixgbe_io_resume, |
| 9705 | }; |
| 9706 | |
| 9707 | static struct pci_driver ixgbe_driver = { |
| 9708 | .name = ixgbe_driver_name, |
| 9709 | .id_table = ixgbe_pci_tbl, |
| 9710 | .probe = ixgbe_probe, |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 9711 | .remove = ixgbe_remove, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9712 | #ifdef CONFIG_PM |
| 9713 | .suspend = ixgbe_suspend, |
| 9714 | .resume = ixgbe_resume, |
| 9715 | #endif |
| 9716 | .shutdown = ixgbe_shutdown, |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 9717 | .sriov_configure = ixgbe_pci_sriov_configure, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9718 | .err_handler = &ixgbe_err_handler |
| 9719 | }; |
| 9720 | |
| 9721 | /** |
| 9722 | * ixgbe_init_module - Driver Registration Routine |
| 9723 | * |
| 9724 | * ixgbe_init_module is the first routine called when the driver is |
| 9725 | * loaded. All it does is register with the PCI subsystem. |
| 9726 | **/ |
| 9727 | static int __init ixgbe_init_module(void) |
| 9728 | { |
| 9729 | int ret; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 9730 | pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version); |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 9731 | pr_info("%s\n", ixgbe_copyright); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9732 | |
Mark Rustad | 780484d | 2015-10-21 17:21:10 -0700 | [diff] [blame] | 9733 | ixgbe_wq = create_singlethread_workqueue(ixgbe_driver_name); |
| 9734 | if (!ixgbe_wq) { |
| 9735 | pr_err("%s: Failed to create workqueue\n", ixgbe_driver_name); |
| 9736 | return -ENOMEM; |
| 9737 | } |
| 9738 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 9739 | ixgbe_dbg_init(); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 9740 | |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 9741 | ret = pci_register_driver(&ixgbe_driver); |
| 9742 | if (ret) { |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 9743 | ixgbe_dbg_exit(); |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 9744 | return ret; |
| 9745 | } |
| 9746 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 9747 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9748 | dca_register_notify(&dca_notifier); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9749 | #endif |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 9750 | |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 9751 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9752 | } |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 9753 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9754 | module_init(ixgbe_init_module); |
| 9755 | |
| 9756 | /** |
| 9757 | * ixgbe_exit_module - Driver Exit Cleanup Routine |
| 9758 | * |
| 9759 | * ixgbe_exit_module is called just before the driver is removed |
| 9760 | * from memory. |
| 9761 | **/ |
| 9762 | static void __exit ixgbe_exit_module(void) |
| 9763 | { |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 9764 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9765 | dca_unregister_notify(&dca_notifier); |
| 9766 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9767 | pci_unregister_driver(&ixgbe_driver); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 9768 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 9769 | ixgbe_dbg_exit(); |
Mark Rustad | 780484d | 2015-10-21 17:21:10 -0700 | [diff] [blame] | 9770 | if (ixgbe_wq) { |
| 9771 | destroy_workqueue(ixgbe_wq); |
| 9772 | ixgbe_wq = NULL; |
| 9773 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9774 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9775 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 9776 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9777 | static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 9778 | void *p) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9779 | { |
| 9780 | int ret_val; |
| 9781 | |
| 9782 | ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 9783 | __ixgbe_notify_dca); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9784 | |
| 9785 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; |
| 9786 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9787 | |
Alexander Duyck | b453368 | 2009-03-31 21:32:42 +0000 | [diff] [blame] | 9788 | #endif /* CONFIG_IXGBE_DCA */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 9789 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9790 | module_exit(ixgbe_exit_module); |
| 9791 | |
| 9792 | /* ixgbe_main.c */ |