Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel 10 Gigabit PCI Express Linux driver |
Mark Rustad | 0391bbe | 2014-02-28 15:48:55 -0800 | [diff] [blame] | 4 | Copyright(c) 1999 - 2014 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> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 54 | |
Martin K Petersen | c762dff | 2014-11-15 14:24:51 +0000 | [diff] [blame] | 55 | #ifdef CONFIG_OF |
| 56 | #include <linux/of_net.h> |
| 57 | #endif |
| 58 | |
| 59 | #ifdef CONFIG_SPARC |
| 60 | #include <asm/idprom.h> |
| 61 | #include <asm/prom.h> |
| 62 | #endif |
| 63 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 64 | #include "ixgbe.h" |
| 65 | #include "ixgbe_common.h" |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 66 | #include "ixgbe_dcb_82599.h" |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 67 | #include "ixgbe_sriov.h" |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 68 | |
| 69 | char ixgbe_driver_name[] = "ixgbe"; |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 70 | static const char ixgbe_driver_string[] = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 71 | "Intel(R) 10 Gigabit PCI Express Network Driver"; |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 72 | #ifdef IXGBE_FCOE |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 73 | char ixgbe_default_device_descr[] = |
| 74 | "Intel(R) 10 Gigabit Network Connection"; |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 75 | #else |
| 76 | static char ixgbe_default_device_descr[] = |
| 77 | "Intel(R) 10 Gigabit Network Connection"; |
| 78 | #endif |
Don Skidmore | 9be4a9b | 2014-11-29 05:22:58 +0000 | [diff] [blame] | 79 | #define DRV_VERSION "4.0.1-k" |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 80 | const char ixgbe_driver_version[] = DRV_VERSION; |
Don Skidmore | a52055e | 2011-02-23 09:58:39 +0000 | [diff] [blame] | 81 | static const char ixgbe_copyright[] = |
Mark Rustad | 0391bbe | 2014-02-28 15:48:55 -0800 | [diff] [blame] | 82 | "Copyright (c) 1999-2014 Intel Corporation."; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 83 | |
Don Skidmore | f44e751 | 2015-06-09 16:36:23 -0700 | [diff] [blame^] | 84 | 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"; |
| 85 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 86 | static const struct ixgbe_info *ixgbe_info_tbl[] = { |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 87 | [board_82598] = &ixgbe_82598_info, |
| 88 | [board_82599] = &ixgbe_82599_info, |
| 89 | [board_X540] = &ixgbe_X540_info, |
| 90 | [board_X550] = &ixgbe_X550_info, |
| 91 | [board_X550EM_x] = &ixgbe_X550EM_x_info, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | /* ixgbe_pci_tbl - PCI Device ID Table |
| 95 | * |
| 96 | * Wildcard entries (PCI_ANY_ID) should come last |
| 97 | * Last entry must be all 0s |
| 98 | * |
| 99 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 100 | * Class, Class Mask, private data (not used) } |
| 101 | */ |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 102 | static const struct pci_device_id ixgbe_pci_tbl[] = { |
Alexander Duyck | 54239c6 | 2011-07-15 03:06:06 +0000 | [diff] [blame] | 103 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 }, |
| 104 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 }, |
| 105 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 }, |
| 106 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 }, |
| 107 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 }, |
| 108 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 }, |
| 109 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 }, |
| 110 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 }, |
| 111 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 }, |
| 112 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 }, |
| 113 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 }, |
| 114 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 }, |
| 115 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 }, |
| 116 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 }, |
| 117 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 }, |
| 118 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 }, |
| 119 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 }, |
| 120 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 }, |
| 121 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 }, |
| 122 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 }, |
| 123 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 }, |
| 124 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 }, |
| 125 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 }, |
| 126 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 }, |
| 127 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 }, |
| 128 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 }, |
Don Skidmore | 8f58332 | 2013-07-27 06:25:38 +0000 | [diff] [blame] | 129 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_QSFP_SF_QP), board_82599 }, |
Emil Tantilov | 7d14528 | 2011-09-08 08:30:14 +0000 | [diff] [blame] | 130 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 }, |
Emil Tantilov | 9e791e4 | 2011-11-04 06:43:29 +0000 | [diff] [blame] | 131 | {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] | 132 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 }, |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 133 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T), board_X550}, |
| 134 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KX4), board_X550EM_x}, |
| 135 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KR), board_X550EM_x}, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 136 | /* required last entry */ |
| 137 | {0, } |
| 138 | }; |
| 139 | MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl); |
| 140 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 141 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 142 | static int ixgbe_notify_dca(struct notifier_block *, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 143 | void *p); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 144 | static struct notifier_block dca_notifier = { |
| 145 | .notifier_call = ixgbe_notify_dca, |
| 146 | .next = NULL, |
| 147 | .priority = 0 |
| 148 | }; |
| 149 | #endif |
| 150 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 151 | #ifdef CONFIG_PCI_IOV |
| 152 | static unsigned int max_vfs; |
| 153 | module_param(max_vfs, uint, 0); |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 154 | MODULE_PARM_DESC(max_vfs, |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 155 | "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] | 156 | #endif /* CONFIG_PCI_IOV */ |
| 157 | |
Peter P Waskiewicz Jr | 8ef78ad | 2012-02-01 09:19:21 +0000 | [diff] [blame] | 158 | static unsigned int allow_unsupported_sfp; |
| 159 | module_param(allow_unsupported_sfp, uint, 0); |
| 160 | MODULE_PARM_DESC(allow_unsupported_sfp, |
| 161 | "Allow unsupported and untested SFP+ modules on 82599-based adapters"); |
| 162 | |
stephen hemminger | b3f4d59 | 2012-03-13 06:04:20 +0000 | [diff] [blame] | 163 | #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK) |
| 164 | static int debug = -1; |
| 165 | module_param(debug, int, 0); |
| 166 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 167 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 168 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 169 | MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver"); |
| 170 | MODULE_LICENSE("GPL"); |
| 171 | MODULE_VERSION(DRV_VERSION); |
| 172 | |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 173 | static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev); |
| 174 | |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 175 | static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter *adapter, |
| 176 | u32 reg, u16 *value) |
| 177 | { |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 178 | struct pci_dev *parent_dev; |
| 179 | struct pci_bus *parent_bus; |
| 180 | |
| 181 | parent_bus = adapter->pdev->bus->parent; |
| 182 | if (!parent_bus) |
| 183 | return -1; |
| 184 | |
| 185 | parent_dev = parent_bus->self; |
| 186 | if (!parent_dev) |
| 187 | return -1; |
| 188 | |
Yijing Wang | c0798ed | 2013-09-04 17:30:08 +0000 | [diff] [blame] | 189 | if (!pci_is_pcie(parent_dev)) |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 190 | return -1; |
| 191 | |
Yijing Wang | c0798ed | 2013-09-04 17:30:08 +0000 | [diff] [blame] | 192 | pcie_capability_read_word(parent_dev, reg, value); |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 193 | if (*value == IXGBE_FAILED_READ_CFG_WORD && |
| 194 | ixgbe_check_cfg_remove(&adapter->hw, parent_dev)) |
| 195 | return -1; |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 196 | return 0; |
| 197 | } |
| 198 | |
| 199 | static s32 ixgbe_get_parent_bus_info(struct ixgbe_adapter *adapter) |
| 200 | { |
| 201 | struct ixgbe_hw *hw = &adapter->hw; |
| 202 | u16 link_status = 0; |
| 203 | int err; |
| 204 | |
| 205 | hw->bus.type = ixgbe_bus_type_pci_express; |
| 206 | |
| 207 | /* Get the negotiated link width and speed from PCI config space of the |
| 208 | * parent, as this device is behind a switch |
| 209 | */ |
| 210 | err = ixgbe_read_pci_cfg_word_parent(adapter, 18, &link_status); |
| 211 | |
| 212 | /* assume caller will handle error case */ |
| 213 | if (err) |
| 214 | return err; |
| 215 | |
| 216 | hw->bus.width = ixgbe_convert_bus_width(link_status); |
| 217 | hw->bus.speed = ixgbe_convert_bus_speed(link_status); |
| 218 | |
| 219 | return 0; |
| 220 | } |
| 221 | |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 222 | /** |
| 223 | * ixgbe_check_from_parent - Determine whether PCIe info should come from parent |
| 224 | * @hw: hw specific details |
| 225 | * |
| 226 | * This function is used by probe to determine whether a device's PCI-Express |
| 227 | * bandwidth details should be gathered from the parent bus instead of from the |
| 228 | * device. Used to ensure that various locations all have the correct device ID |
| 229 | * checks. |
| 230 | */ |
| 231 | static inline bool ixgbe_pcie_from_parent(struct ixgbe_hw *hw) |
| 232 | { |
| 233 | switch (hw->device_id) { |
| 234 | case IXGBE_DEV_ID_82599_SFP_SF_QP: |
Don Skidmore | 8f58332 | 2013-07-27 06:25:38 +0000 | [diff] [blame] | 235 | case IXGBE_DEV_ID_82599_QSFP_SF_QP: |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 236 | return true; |
| 237 | default: |
| 238 | return false; |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | static void ixgbe_check_minimum_link(struct ixgbe_adapter *adapter, |
| 243 | int expected_gts) |
| 244 | { |
| 245 | int max_gts = 0; |
| 246 | enum pci_bus_speed speed = PCI_SPEED_UNKNOWN; |
| 247 | enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN; |
| 248 | struct pci_dev *pdev; |
| 249 | |
| 250 | /* determine whether to use the the parent device |
| 251 | */ |
| 252 | if (ixgbe_pcie_from_parent(&adapter->hw)) |
| 253 | pdev = adapter->pdev->bus->parent->self; |
| 254 | else |
| 255 | pdev = adapter->pdev; |
| 256 | |
| 257 | if (pcie_get_minimum_link(pdev, &speed, &width) || |
| 258 | speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) { |
| 259 | e_dev_warn("Unable to determine PCI Express bandwidth.\n"); |
| 260 | return; |
| 261 | } |
| 262 | |
| 263 | switch (speed) { |
| 264 | case PCIE_SPEED_2_5GT: |
| 265 | /* 8b/10b encoding reduces max throughput by 20% */ |
| 266 | max_gts = 2 * width; |
| 267 | break; |
| 268 | case PCIE_SPEED_5_0GT: |
| 269 | /* 8b/10b encoding reduces max throughput by 20% */ |
| 270 | max_gts = 4 * width; |
| 271 | break; |
| 272 | case PCIE_SPEED_8_0GT: |
Jacob Keller | 9f0a433 | 2013-10-18 05:09:19 +0000 | [diff] [blame] | 273 | /* 128b/130b encoding reduces throughput by less than 2% */ |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 274 | max_gts = 8 * width; |
| 275 | break; |
| 276 | default: |
| 277 | e_dev_warn("Unable to determine PCI Express bandwidth.\n"); |
| 278 | return; |
| 279 | } |
| 280 | |
| 281 | e_dev_info("PCI Express bandwidth of %dGT/s available\n", |
| 282 | max_gts); |
| 283 | e_dev_info("(Speed:%s, Width: x%d, Encoding Loss:%s)\n", |
| 284 | (speed == PCIE_SPEED_8_0GT ? "8.0GT/s" : |
| 285 | speed == PCIE_SPEED_5_0GT ? "5.0GT/s" : |
| 286 | speed == PCIE_SPEED_2_5GT ? "2.5GT/s" : |
| 287 | "Unknown"), |
| 288 | width, |
| 289 | (speed == PCIE_SPEED_2_5GT ? "20%" : |
| 290 | speed == PCIE_SPEED_5_0GT ? "20%" : |
Jacob Keller | 9f0a433 | 2013-10-18 05:09:19 +0000 | [diff] [blame] | 291 | speed == PCIE_SPEED_8_0GT ? "<2%" : |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 292 | "Unknown")); |
| 293 | |
| 294 | if (max_gts < expected_gts) { |
| 295 | e_dev_warn("This is not sufficient for optimal performance of this card.\n"); |
| 296 | e_dev_warn("For optimal performance, at least %dGT/s of bandwidth is required.\n", |
| 297 | expected_gts); |
| 298 | e_dev_warn("A slot with more lanes and/or higher speed is suggested.\n"); |
| 299 | } |
| 300 | } |
| 301 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 302 | static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter) |
| 303 | { |
| 304 | if (!test_bit(__IXGBE_DOWN, &adapter->state) && |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 305 | !test_bit(__IXGBE_REMOVING, &adapter->state) && |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 306 | !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state)) |
| 307 | schedule_work(&adapter->service_task); |
| 308 | } |
| 309 | |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 310 | static void ixgbe_remove_adapter(struct ixgbe_hw *hw) |
| 311 | { |
| 312 | struct ixgbe_adapter *adapter = hw->back; |
| 313 | |
| 314 | if (!hw->hw_addr) |
| 315 | return; |
| 316 | hw->hw_addr = NULL; |
| 317 | e_dev_err("Adapter removed\n"); |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 318 | if (test_bit(__IXGBE_SERVICE_INITED, &adapter->state)) |
| 319 | ixgbe_service_event_schedule(adapter); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 320 | } |
| 321 | |
Mark Rustad | f8e2472 | 2014-03-18 07:03:40 +0000 | [diff] [blame] | 322 | static void ixgbe_check_remove(struct ixgbe_hw *hw, u32 reg) |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 323 | { |
| 324 | u32 value; |
| 325 | |
| 326 | /* The following check not only optimizes a bit by not |
| 327 | * performing a read on the status register when the |
| 328 | * register just read was a status register read that |
| 329 | * returned IXGBE_FAILED_READ_REG. It also blocks any |
| 330 | * potential recursion. |
| 331 | */ |
| 332 | if (reg == IXGBE_STATUS) { |
| 333 | ixgbe_remove_adapter(hw); |
| 334 | return; |
| 335 | } |
| 336 | value = ixgbe_read_reg(hw, IXGBE_STATUS); |
| 337 | if (value == IXGBE_FAILED_READ_REG) |
| 338 | ixgbe_remove_adapter(hw); |
| 339 | } |
| 340 | |
Mark Rustad | f8e2472 | 2014-03-18 07:03:40 +0000 | [diff] [blame] | 341 | /** |
| 342 | * ixgbe_read_reg - Read from device register |
| 343 | * @hw: hw specific details |
| 344 | * @reg: offset of register to read |
| 345 | * |
| 346 | * Returns : value read or IXGBE_FAILED_READ_REG if removed |
| 347 | * |
| 348 | * This function is used to read device registers. It checks for device |
| 349 | * removal by confirming any read that returns all ones by checking the |
| 350 | * status register value for all ones. This function avoids reading from |
| 351 | * the hardware if a removal was previously detected in which case it |
| 352 | * returns IXGBE_FAILED_READ_REG (all ones). |
| 353 | */ |
| 354 | u32 ixgbe_read_reg(struct ixgbe_hw *hw, u32 reg) |
| 355 | { |
| 356 | u8 __iomem *reg_addr = ACCESS_ONCE(hw->hw_addr); |
| 357 | u32 value; |
| 358 | |
| 359 | if (ixgbe_removed(reg_addr)) |
| 360 | return IXGBE_FAILED_READ_REG; |
| 361 | value = readl(reg_addr + reg); |
| 362 | if (unlikely(value == IXGBE_FAILED_READ_REG)) |
| 363 | ixgbe_check_remove(hw, reg); |
| 364 | return value; |
| 365 | } |
| 366 | |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 367 | static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev) |
| 368 | { |
| 369 | u16 value; |
| 370 | |
| 371 | pci_read_config_word(pdev, PCI_VENDOR_ID, &value); |
| 372 | if (value == IXGBE_FAILED_READ_CFG_WORD) { |
| 373 | ixgbe_remove_adapter(hw); |
| 374 | return true; |
| 375 | } |
| 376 | return false; |
| 377 | } |
| 378 | |
| 379 | u16 ixgbe_read_pci_cfg_word(struct ixgbe_hw *hw, u32 reg) |
| 380 | { |
| 381 | struct ixgbe_adapter *adapter = hw->back; |
| 382 | u16 value; |
| 383 | |
| 384 | if (ixgbe_removed(hw->hw_addr)) |
| 385 | return IXGBE_FAILED_READ_CFG_WORD; |
| 386 | pci_read_config_word(adapter->pdev, reg, &value); |
| 387 | if (value == IXGBE_FAILED_READ_CFG_WORD && |
| 388 | ixgbe_check_cfg_remove(hw, adapter->pdev)) |
| 389 | return IXGBE_FAILED_READ_CFG_WORD; |
| 390 | return value; |
| 391 | } |
| 392 | |
| 393 | #ifdef CONFIG_PCI_IOV |
| 394 | static u32 ixgbe_read_pci_cfg_dword(struct ixgbe_hw *hw, u32 reg) |
| 395 | { |
| 396 | struct ixgbe_adapter *adapter = hw->back; |
| 397 | u32 value; |
| 398 | |
| 399 | if (ixgbe_removed(hw->hw_addr)) |
| 400 | return IXGBE_FAILED_READ_CFG_DWORD; |
| 401 | pci_read_config_dword(adapter->pdev, reg, &value); |
| 402 | if (value == IXGBE_FAILED_READ_CFG_DWORD && |
| 403 | ixgbe_check_cfg_remove(hw, adapter->pdev)) |
| 404 | return IXGBE_FAILED_READ_CFG_DWORD; |
| 405 | return value; |
| 406 | } |
| 407 | #endif /* CONFIG_PCI_IOV */ |
| 408 | |
Jacob Keller | ed19231 | 2014-02-22 01:23:53 +0000 | [diff] [blame] | 409 | void ixgbe_write_pci_cfg_word(struct ixgbe_hw *hw, u32 reg, u16 value) |
| 410 | { |
| 411 | struct ixgbe_adapter *adapter = hw->back; |
| 412 | |
| 413 | if (ixgbe_removed(hw->hw_addr)) |
| 414 | return; |
| 415 | pci_write_config_word(adapter->pdev, reg, value); |
| 416 | } |
| 417 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 418 | static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter) |
| 419 | { |
| 420 | BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state)); |
| 421 | |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 422 | /* flush memory to make sure state is correct before next watchdog */ |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 423 | smp_mb__before_atomic(); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 424 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
| 425 | } |
| 426 | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 427 | struct ixgbe_reg_info { |
| 428 | u32 ofs; |
| 429 | char *name; |
| 430 | }; |
| 431 | |
| 432 | static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = { |
| 433 | |
| 434 | /* General Registers */ |
| 435 | {IXGBE_CTRL, "CTRL"}, |
| 436 | {IXGBE_STATUS, "STATUS"}, |
| 437 | {IXGBE_CTRL_EXT, "CTRL_EXT"}, |
| 438 | |
| 439 | /* Interrupt Registers */ |
| 440 | {IXGBE_EICR, "EICR"}, |
| 441 | |
| 442 | /* RX Registers */ |
| 443 | {IXGBE_SRRCTL(0), "SRRCTL"}, |
| 444 | {IXGBE_DCA_RXCTRL(0), "DRXCTL"}, |
| 445 | {IXGBE_RDLEN(0), "RDLEN"}, |
| 446 | {IXGBE_RDH(0), "RDH"}, |
| 447 | {IXGBE_RDT(0), "RDT"}, |
| 448 | {IXGBE_RXDCTL(0), "RXDCTL"}, |
| 449 | {IXGBE_RDBAL(0), "RDBAL"}, |
| 450 | {IXGBE_RDBAH(0), "RDBAH"}, |
| 451 | |
| 452 | /* TX Registers */ |
| 453 | {IXGBE_TDBAL(0), "TDBAL"}, |
| 454 | {IXGBE_TDBAH(0), "TDBAH"}, |
| 455 | {IXGBE_TDLEN(0), "TDLEN"}, |
| 456 | {IXGBE_TDH(0), "TDH"}, |
| 457 | {IXGBE_TDT(0), "TDT"}, |
| 458 | {IXGBE_TXDCTL(0), "TXDCTL"}, |
| 459 | |
| 460 | /* List Terminator */ |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 461 | { .name = NULL } |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 462 | }; |
| 463 | |
| 464 | |
| 465 | /* |
| 466 | * ixgbe_regdump - register printout routine |
| 467 | */ |
| 468 | static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo) |
| 469 | { |
| 470 | int i = 0, j = 0; |
| 471 | char rname[16]; |
| 472 | u32 regs[64]; |
| 473 | |
| 474 | switch (reginfo->ofs) { |
| 475 | case IXGBE_SRRCTL(0): |
| 476 | for (i = 0; i < 64; i++) |
| 477 | regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i)); |
| 478 | break; |
| 479 | case IXGBE_DCA_RXCTRL(0): |
| 480 | for (i = 0; i < 64; i++) |
| 481 | regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i)); |
| 482 | break; |
| 483 | case IXGBE_RDLEN(0): |
| 484 | for (i = 0; i < 64; i++) |
| 485 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i)); |
| 486 | break; |
| 487 | case IXGBE_RDH(0): |
| 488 | for (i = 0; i < 64; i++) |
| 489 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i)); |
| 490 | break; |
| 491 | case IXGBE_RDT(0): |
| 492 | for (i = 0; i < 64; i++) |
| 493 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i)); |
| 494 | break; |
| 495 | case IXGBE_RXDCTL(0): |
| 496 | for (i = 0; i < 64; i++) |
| 497 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i)); |
| 498 | break; |
| 499 | case IXGBE_RDBAL(0): |
| 500 | for (i = 0; i < 64; i++) |
| 501 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i)); |
| 502 | break; |
| 503 | case IXGBE_RDBAH(0): |
| 504 | for (i = 0; i < 64; i++) |
| 505 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i)); |
| 506 | break; |
| 507 | case IXGBE_TDBAL(0): |
| 508 | for (i = 0; i < 64; i++) |
| 509 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i)); |
| 510 | break; |
| 511 | case IXGBE_TDBAH(0): |
| 512 | for (i = 0; i < 64; i++) |
| 513 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i)); |
| 514 | break; |
| 515 | case IXGBE_TDLEN(0): |
| 516 | for (i = 0; i < 64; i++) |
| 517 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i)); |
| 518 | break; |
| 519 | case IXGBE_TDH(0): |
| 520 | for (i = 0; i < 64; i++) |
| 521 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i)); |
| 522 | break; |
| 523 | case IXGBE_TDT(0): |
| 524 | for (i = 0; i < 64; i++) |
| 525 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i)); |
| 526 | break; |
| 527 | case IXGBE_TXDCTL(0): |
| 528 | for (i = 0; i < 64; i++) |
| 529 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i)); |
| 530 | break; |
| 531 | default: |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 532 | pr_info("%-15s %08x\n", reginfo->name, |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 533 | IXGBE_READ_REG(hw, reginfo->ofs)); |
| 534 | return; |
| 535 | } |
| 536 | |
| 537 | for (i = 0; i < 8; i++) { |
| 538 | 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] | 539 | pr_err("%-15s", rname); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 540 | for (j = 0; j < 8; j++) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 541 | pr_cont(" %08x", regs[i*8+j]); |
| 542 | pr_cont("\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | } |
| 546 | |
| 547 | /* |
| 548 | * ixgbe_dump - Print registers, tx-rings and rx-rings |
| 549 | */ |
| 550 | static void ixgbe_dump(struct ixgbe_adapter *adapter) |
| 551 | { |
| 552 | struct net_device *netdev = adapter->netdev; |
| 553 | struct ixgbe_hw *hw = &adapter->hw; |
| 554 | struct ixgbe_reg_info *reginfo; |
| 555 | int n = 0; |
| 556 | struct ixgbe_ring *tx_ring; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 557 | struct ixgbe_tx_buffer *tx_buffer; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 558 | union ixgbe_adv_tx_desc *tx_desc; |
| 559 | struct my_u0 { u64 a; u64 b; } *u0; |
| 560 | struct ixgbe_ring *rx_ring; |
| 561 | union ixgbe_adv_rx_desc *rx_desc; |
| 562 | struct ixgbe_rx_buffer *rx_buffer_info; |
| 563 | u32 staterr; |
| 564 | int i = 0; |
| 565 | |
| 566 | if (!netif_msg_hw(adapter)) |
| 567 | return; |
| 568 | |
| 569 | /* Print netdevice Info */ |
| 570 | if (netdev) { |
| 571 | dev_info(&adapter->pdev->dev, "Net device Info\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 572 | pr_info("Device Name state " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 573 | "trans_start last_rx\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 574 | pr_info("%-15s %016lX %016lX %016lX\n", |
| 575 | netdev->name, |
| 576 | netdev->state, |
| 577 | netdev->trans_start, |
| 578 | netdev->last_rx); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | /* Print Registers */ |
| 582 | dev_info(&adapter->pdev->dev, "Register Dump\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 583 | pr_info(" Register Name Value\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 584 | for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl; |
| 585 | reginfo->name; reginfo++) { |
| 586 | ixgbe_regdump(hw, reginfo); |
| 587 | } |
| 588 | |
| 589 | /* Print TX Ring Summary */ |
| 590 | if (!netdev || !netif_running(netdev)) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 591 | return; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 592 | |
| 593 | dev_info(&adapter->pdev->dev, "TX Rings Summary\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 594 | pr_info(" %s %s %s %s\n", |
| 595 | "Queue [NTU] [NTC] [bi(ntc)->dma ]", |
| 596 | "leng", "ntw", "timestamp"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 597 | for (n = 0; n < adapter->num_tx_queues; n++) { |
| 598 | tx_ring = adapter->tx_ring[n]; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 599 | tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean]; |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 600 | pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n", |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 601 | n, tx_ring->next_to_use, tx_ring->next_to_clean, |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 602 | (u64)dma_unmap_addr(tx_buffer, dma), |
| 603 | dma_unmap_len(tx_buffer, len), |
| 604 | tx_buffer->next_to_watch, |
| 605 | (u64)tx_buffer->time_stamp); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | /* Print TX Rings */ |
| 609 | if (!netif_msg_tx_done(adapter)) |
| 610 | goto rx_ring_summary; |
| 611 | |
| 612 | dev_info(&adapter->pdev->dev, "TX Rings Dump\n"); |
| 613 | |
| 614 | /* Transmit Descriptor Formats |
| 615 | * |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 616 | * 82598 Advanced Transmit Descriptor |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 617 | * +--------------------------------------------------------------+ |
| 618 | * 0 | Buffer Address [63:0] | |
| 619 | * +--------------------------------------------------------------+ |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 620 | * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 621 | * +--------------------------------------------------------------+ |
| 622 | * 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] | 623 | * |
| 624 | * 82598 Advanced Transmit Descriptor (Write-Back Format) |
| 625 | * +--------------------------------------------------------------+ |
| 626 | * 0 | RSV [63:0] | |
| 627 | * +--------------------------------------------------------------+ |
| 628 | * 8 | RSV | STA | NXTSEQ | |
| 629 | * +--------------------------------------------------------------+ |
| 630 | * 63 36 35 32 31 0 |
| 631 | * |
| 632 | * 82599+ Advanced Transmit Descriptor |
| 633 | * +--------------------------------------------------------------+ |
| 634 | * 0 | Buffer Address [63:0] | |
| 635 | * +--------------------------------------------------------------+ |
| 636 | * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN | |
| 637 | * +--------------------------------------------------------------+ |
| 638 | * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0 |
| 639 | * |
| 640 | * 82599+ Advanced Transmit Descriptor (Write-Back Format) |
| 641 | * +--------------------------------------------------------------+ |
| 642 | * 0 | RSV [63:0] | |
| 643 | * +--------------------------------------------------------------+ |
| 644 | * 8 | RSV | STA | RSV | |
| 645 | * +--------------------------------------------------------------+ |
| 646 | * 63 36 35 32 31 0 |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 647 | */ |
| 648 | |
| 649 | for (n = 0; n < adapter->num_tx_queues; n++) { |
| 650 | tx_ring = adapter->tx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 651 | pr_info("------------------------------------\n"); |
| 652 | pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index); |
| 653 | pr_info("------------------------------------\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 654 | pr_info("%s%s %s %s %s %s\n", |
| 655 | "T [desc] [address 63:0 ] ", |
| 656 | "[PlPOIdStDDt Ln] [bi->dma ] ", |
| 657 | "leng", "ntw", "timestamp", "bi->skb"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 658 | |
| 659 | for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 660 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 661 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 662 | u0 = (struct my_u0 *)tx_desc; |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 663 | if (dma_unmap_len(tx_buffer, len) > 0) { |
| 664 | pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p", |
| 665 | i, |
| 666 | le64_to_cpu(u0->a), |
| 667 | le64_to_cpu(u0->b), |
| 668 | (u64)dma_unmap_addr(tx_buffer, dma), |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 669 | dma_unmap_len(tx_buffer, len), |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 670 | tx_buffer->next_to_watch, |
| 671 | (u64)tx_buffer->time_stamp, |
| 672 | tx_buffer->skb); |
| 673 | if (i == tx_ring->next_to_use && |
| 674 | i == tx_ring->next_to_clean) |
| 675 | pr_cont(" NTC/U\n"); |
| 676 | else if (i == tx_ring->next_to_use) |
| 677 | pr_cont(" NTU\n"); |
| 678 | else if (i == tx_ring->next_to_clean) |
| 679 | pr_cont(" NTC\n"); |
| 680 | else |
| 681 | pr_cont("\n"); |
| 682 | |
| 683 | if (netif_msg_pktdata(adapter) && |
| 684 | tx_buffer->skb) |
| 685 | print_hex_dump(KERN_INFO, "", |
| 686 | DUMP_PREFIX_ADDRESS, 16, 1, |
| 687 | tx_buffer->skb->data, |
| 688 | dma_unmap_len(tx_buffer, len), |
| 689 | true); |
| 690 | } |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 691 | } |
| 692 | } |
| 693 | |
| 694 | /* Print RX Rings Summary */ |
| 695 | rx_ring_summary: |
| 696 | dev_info(&adapter->pdev->dev, "RX Rings Summary\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 697 | pr_info("Queue [NTU] [NTC]\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 698 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 699 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 700 | pr_info("%5d %5X %5X\n", |
| 701 | n, rx_ring->next_to_use, rx_ring->next_to_clean); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | /* Print RX Rings */ |
| 705 | if (!netif_msg_rx_status(adapter)) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 706 | return; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 707 | |
| 708 | dev_info(&adapter->pdev->dev, "RX Rings Dump\n"); |
| 709 | |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 710 | /* Receive Descriptor Formats |
| 711 | * |
| 712 | * 82598 Advanced Receive Descriptor (Read) Format |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 713 | * 63 1 0 |
| 714 | * +-----------------------------------------------------+ |
| 715 | * 0 | Packet Buffer Address [63:1] |A0/NSE| |
| 716 | * +----------------------------------------------+------+ |
| 717 | * 8 | Header Buffer Address [63:1] | DD | |
| 718 | * +-----------------------------------------------------+ |
| 719 | * |
| 720 | * |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 721 | * 82598 Advanced Receive Descriptor (Write-Back) Format |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 722 | * |
| 723 | * 63 48 47 32 31 30 21 20 16 15 4 3 0 |
| 724 | * +------------------------------------------------------+ |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 725 | * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS | |
| 726 | * | Packet | IP | | | | Type | Type | |
| 727 | * | Checksum | Ident | | | | | | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 728 | * +------------------------------------------------------+ |
| 729 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | |
| 730 | * +------------------------------------------------------+ |
| 731 | * 63 48 47 32 31 20 19 0 |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 732 | * |
| 733 | * 82599+ Advanced Receive Descriptor (Read) Format |
| 734 | * 63 1 0 |
| 735 | * +-----------------------------------------------------+ |
| 736 | * 0 | Packet Buffer Address [63:1] |A0/NSE| |
| 737 | * +----------------------------------------------+------+ |
| 738 | * 8 | Header Buffer Address [63:1] | DD | |
| 739 | * +-----------------------------------------------------+ |
| 740 | * |
| 741 | * |
| 742 | * 82599+ Advanced Receive Descriptor (Write-Back) Format |
| 743 | * |
| 744 | * 63 48 47 32 31 30 21 20 17 16 4 3 0 |
| 745 | * +------------------------------------------------------+ |
| 746 | * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS | |
| 747 | * |/ RTT / PCoE_PARAM | | | CNT | Type | Type | |
| 748 | * |/ Flow Dir Flt ID | | | | | | |
| 749 | * +------------------------------------------------------+ |
| 750 | * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP | |
| 751 | * +------------------------------------------------------+ |
| 752 | * 63 48 47 32 31 20 19 0 |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 753 | */ |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 754 | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 755 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 756 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 757 | pr_info("------------------------------------\n"); |
| 758 | pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index); |
| 759 | pr_info("------------------------------------\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 760 | pr_info("%s%s%s", |
| 761 | "R [desc] [ PktBuf A0] ", |
| 762 | "[ HeadBuf DD] [bi->dma ] [bi->skb ] ", |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 763 | "<-- Adv Rx Read format\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 764 | pr_info("%s%s%s", |
| 765 | "RWB[desc] [PcsmIpSHl PtRs] ", |
| 766 | "[vl er S cks ln] ---------------- [bi->skb ] ", |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 767 | "<-- Adv Rx Write-Back format\n"); |
| 768 | |
| 769 | for (i = 0; i < rx_ring->count; i++) { |
| 770 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 771 | rx_desc = IXGBE_RX_DESC(rx_ring, i); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 772 | u0 = (struct my_u0 *)rx_desc; |
| 773 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 774 | if (staterr & IXGBE_RXD_STAT_DD) { |
| 775 | /* Descriptor Done */ |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 776 | pr_info("RWB[0x%03X] %016llX " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 777 | "%016llX ---------------- %p", i, |
| 778 | le64_to_cpu(u0->a), |
| 779 | le64_to_cpu(u0->b), |
| 780 | rx_buffer_info->skb); |
| 781 | } else { |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 782 | pr_info("R [0x%03X] %016llX " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 783 | "%016llX %016llX %p", i, |
| 784 | le64_to_cpu(u0->a), |
| 785 | le64_to_cpu(u0->b), |
| 786 | (u64)rx_buffer_info->dma, |
| 787 | rx_buffer_info->skb); |
| 788 | |
Emil Tantilov | 9c50c03 | 2012-07-26 01:21:24 +0000 | [diff] [blame] | 789 | if (netif_msg_pktdata(adapter) && |
| 790 | rx_buffer_info->dma) { |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 791 | print_hex_dump(KERN_INFO, "", |
| 792 | DUMP_PREFIX_ADDRESS, 16, 1, |
Emil Tantilov | 9c50c03 | 2012-07-26 01:21:24 +0000 | [diff] [blame] | 793 | page_address(rx_buffer_info->page) + |
| 794 | rx_buffer_info->page_offset, |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 795 | ixgbe_rx_bufsz(rx_ring), true); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 796 | } |
| 797 | } |
| 798 | |
| 799 | if (i == rx_ring->next_to_use) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 800 | pr_cont(" NTU\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 801 | else if (i == rx_ring->next_to_clean) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 802 | pr_cont(" NTC\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 803 | else |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 804 | pr_cont("\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 805 | |
| 806 | } |
| 807 | } |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 808 | } |
| 809 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 810 | static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter) |
| 811 | { |
| 812 | u32 ctrl_ext; |
| 813 | |
| 814 | /* Let firmware take over control of h/w */ |
| 815 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 816 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 817 | ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter) |
| 821 | { |
| 822 | u32 ctrl_ext; |
| 823 | |
| 824 | /* Let firmware know the driver has taken over */ |
| 825 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 826 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 827 | ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 828 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 829 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 830 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 831 | * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors |
| 832 | * @adapter: pointer to adapter struct |
| 833 | * @direction: 0 for Rx, 1 for Tx, -1 for other causes |
| 834 | * @queue: queue to map the corresponding interrupt to |
| 835 | * @msix_vector: the vector to map to the corresponding queue |
| 836 | * |
| 837 | */ |
| 838 | static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 839 | u8 queue, u8 msix_vector) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 840 | { |
| 841 | u32 ivar, index; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 842 | struct ixgbe_hw *hw = &adapter->hw; |
| 843 | switch (hw->mac.type) { |
| 844 | case ixgbe_mac_82598EB: |
| 845 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 846 | if (direction == -1) |
| 847 | direction = 0; |
| 848 | index = (((direction * 64) + queue) >> 2) & 0x1F; |
| 849 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index)); |
| 850 | ivar &= ~(0xFF << (8 * (queue & 0x3))); |
| 851 | ivar |= (msix_vector << (8 * (queue & 0x3))); |
| 852 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar); |
| 853 | break; |
| 854 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 855 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 856 | case ixgbe_mac_X550: |
| 857 | case ixgbe_mac_X550EM_x: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 858 | if (direction == -1) { |
| 859 | /* other causes */ |
| 860 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 861 | index = ((queue & 1) * 8); |
| 862 | ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC); |
| 863 | ivar &= ~(0xFF << index); |
| 864 | ivar |= (msix_vector << index); |
| 865 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar); |
| 866 | break; |
| 867 | } else { |
| 868 | /* tx or rx causes */ |
| 869 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 870 | index = ((16 * (queue & 1)) + (8 * direction)); |
| 871 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1)); |
| 872 | ivar &= ~(0xFF << index); |
| 873 | ivar |= (msix_vector << index); |
| 874 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar); |
| 875 | break; |
| 876 | } |
| 877 | default: |
| 878 | break; |
| 879 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 880 | } |
| 881 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 882 | static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 883 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 884 | { |
| 885 | u32 mask; |
| 886 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 887 | switch (adapter->hw.mac.type) { |
| 888 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 889 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 890 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 891 | break; |
| 892 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 893 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 894 | case ixgbe_mac_X550: |
| 895 | case ixgbe_mac_X550EM_x: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 896 | mask = (qmask & 0xFFFFFFFF); |
| 897 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask); |
| 898 | mask = (qmask >> 32); |
| 899 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 900 | break; |
| 901 | default: |
| 902 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 903 | } |
| 904 | } |
| 905 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 906 | void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *ring, |
| 907 | struct ixgbe_tx_buffer *tx_buffer) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 908 | { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 909 | if (tx_buffer->skb) { |
| 910 | dev_kfree_skb_any(tx_buffer->skb); |
| 911 | if (dma_unmap_len(tx_buffer, len)) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 912 | dma_unmap_single(ring->dev, |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 913 | dma_unmap_addr(tx_buffer, dma), |
| 914 | dma_unmap_len(tx_buffer, len), |
| 915 | DMA_TO_DEVICE); |
| 916 | } else if (dma_unmap_len(tx_buffer, len)) { |
| 917 | dma_unmap_page(ring->dev, |
| 918 | dma_unmap_addr(tx_buffer, dma), |
| 919 | dma_unmap_len(tx_buffer, len), |
| 920 | DMA_TO_DEVICE); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 921 | } |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 922 | tx_buffer->next_to_watch = NULL; |
| 923 | tx_buffer->skb = NULL; |
| 924 | dma_unmap_len_set(tx_buffer, len, 0); |
| 925 | /* tx_buffer must be completely set up in the transmit path */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 926 | } |
| 927 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 928 | static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter) |
| 929 | { |
| 930 | struct ixgbe_hw *hw = &adapter->hw; |
| 931 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
| 932 | int i; |
| 933 | u32 data; |
| 934 | |
| 935 | if ((hw->fc.current_mode != ixgbe_fc_full) && |
| 936 | (hw->fc.current_mode != ixgbe_fc_rx_pause)) |
| 937 | return; |
| 938 | |
| 939 | switch (hw->mac.type) { |
| 940 | case ixgbe_mac_82598EB: |
| 941 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); |
| 942 | break; |
| 943 | default: |
| 944 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); |
| 945 | } |
| 946 | hwstats->lxoffrxc += data; |
| 947 | |
| 948 | /* refill credits (no tx hang) if we received xoff */ |
| 949 | if (!data) |
| 950 | return; |
| 951 | |
| 952 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 953 | clear_bit(__IXGBE_HANG_CHECK_ARMED, |
| 954 | &adapter->tx_ring[i]->state); |
| 955 | } |
| 956 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 957 | static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 958 | { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 959 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 960 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 961 | u32 xoff[8] = {0}; |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 962 | u8 tc; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 963 | int i; |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 964 | bool pfc_en = adapter->dcb_cfg.pfc_mode_enable; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 965 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 966 | if (adapter->ixgbe_ieee_pfc) |
| 967 | pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 968 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 969 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) { |
| 970 | ixgbe_update_xoff_rx_lfc(adapter); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 971 | return; |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 972 | } |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 973 | |
| 974 | /* update stats for each tc, only valid with PFC enabled */ |
| 975 | for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) { |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 976 | u32 pxoffrxc; |
| 977 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 978 | switch (hw->mac.type) { |
| 979 | case ixgbe_mac_82598EB: |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 980 | pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i)); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 981 | break; |
| 982 | default: |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 983 | pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i)); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 984 | } |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 985 | hwstats->pxoffrxc[i] += pxoffrxc; |
| 986 | /* Get the TC for given UP */ |
| 987 | tc = netdev_get_prio_tc_map(adapter->netdev, i); |
| 988 | xoff[tc] += pxoffrxc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 989 | } |
| 990 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 991 | /* disarm tx queues that have received xoff frames */ |
| 992 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 993 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 994 | |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 995 | tc = tx_ring->dcb_tc; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 996 | if (xoff[tc]) |
| 997 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
| 998 | } |
| 999 | } |
| 1000 | |
| 1001 | static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring) |
| 1002 | { |
Alexander Duyck | 7d7ce68 | 2012-02-08 07:50:51 +0000 | [diff] [blame] | 1003 | return ring->stats.packets; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring) |
| 1007 | { |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 1008 | struct ixgbe_adapter *adapter; |
| 1009 | struct ixgbe_hw *hw; |
| 1010 | u32 head, tail; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1011 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 1012 | if (ring->l2_accel_priv) |
| 1013 | adapter = ring->l2_accel_priv->real_adapter; |
| 1014 | else |
| 1015 | adapter = netdev_priv(ring->netdev); |
| 1016 | |
| 1017 | hw = &adapter->hw; |
| 1018 | head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx)); |
| 1019 | tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx)); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1020 | |
| 1021 | if (head != tail) |
| 1022 | return (head < tail) ? |
| 1023 | tail - head : (tail + ring->count - head); |
| 1024 | |
| 1025 | return 0; |
| 1026 | } |
| 1027 | |
| 1028 | static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring) |
| 1029 | { |
| 1030 | u32 tx_done = ixgbe_get_tx_completed(tx_ring); |
| 1031 | u32 tx_done_old = tx_ring->tx_stats.tx_done_old; |
| 1032 | u32 tx_pending = ixgbe_get_tx_pending(tx_ring); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1033 | |
| 1034 | clear_check_for_tx_hang(tx_ring); |
| 1035 | |
| 1036 | /* |
| 1037 | * Check for a hung queue, but be thorough. This verifies |
| 1038 | * that a transmit has been completed since the previous |
| 1039 | * check AND there is at least one packet pending. The |
| 1040 | * ARMED bit is set to indicate a potential hang. The |
| 1041 | * bit is cleared if a pause frame is received to remove |
| 1042 | * false hang detection due to PFC or 802.3x frames. By |
| 1043 | * requiring this to fail twice we avoid races with |
| 1044 | * pfc clearing the ARMED bit and conditions where we |
| 1045 | * run the check_tx_hang logic with a transmit completion |
| 1046 | * pending but without time to complete it yet. |
| 1047 | */ |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 1048 | if (tx_done_old == tx_done && tx_pending) |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1049 | /* make sure it is true for two checks in a row */ |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 1050 | return test_and_set_bit(__IXGBE_HANG_CHECK_ARMED, |
| 1051 | &tx_ring->state); |
| 1052 | /* update completed stats and continue */ |
| 1053 | tx_ring->tx_stats.tx_done_old = tx_done; |
| 1054 | /* reset the countdown */ |
| 1055 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1056 | |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 1057 | return false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1058 | } |
| 1059 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 1060 | /** |
| 1061 | * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout |
| 1062 | * @adapter: driver private struct |
| 1063 | **/ |
| 1064 | static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter) |
| 1065 | { |
| 1066 | |
| 1067 | /* Do the reset outside of interrupt context */ |
| 1068 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1069 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; |
Jacob Keller | 12ff3f3 | 2012-12-01 07:57:17 +0000 | [diff] [blame] | 1070 | e_warn(drv, "initiating reset due to tx timeout\n"); |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 1071 | ixgbe_service_event_schedule(adapter); |
| 1072 | } |
| 1073 | } |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1074 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1075 | /** |
| 1076 | * ixgbe_clean_tx_irq - Reclaim resources after transmit completes |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1077 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1078 | * @tx_ring: tx ring to clean |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1079 | **/ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1080 | static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1081 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1082 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1083 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1084 | struct ixgbe_tx_buffer *tx_buffer; |
| 1085 | union ixgbe_adv_tx_desc *tx_desc; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1086 | unsigned int total_bytes = 0, total_packets = 0; |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 1087 | unsigned int budget = q_vector->tx.work_limit; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1088 | unsigned int i = tx_ring->next_to_clean; |
| 1089 | |
| 1090 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1091 | return true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1092 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1093 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1094 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1095 | i -= tx_ring->count; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 1096 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1097 | do { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1098 | union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1099 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1100 | /* if next_to_watch is not set then there is no work pending */ |
| 1101 | if (!eop_desc) |
| 1102 | break; |
| 1103 | |
Alexander Duyck | 7f83a9e | 2012-02-08 07:49:23 +0000 | [diff] [blame] | 1104 | /* prevent any other reads prior to eop_desc */ |
Alexander Duyck | 7e63bf4 | 2013-01-08 07:00:58 +0000 | [diff] [blame] | 1105 | read_barrier_depends(); |
Alexander Duyck | 7f83a9e | 2012-02-08 07:49:23 +0000 | [diff] [blame] | 1106 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1107 | /* if DD is not set pending work has not been completed */ |
| 1108 | if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD))) |
| 1109 | break; |
| 1110 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1111 | /* clear next_to_watch to prevent false hangs */ |
| 1112 | tx_buffer->next_to_watch = NULL; |
| 1113 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 1114 | /* update the statistics for this packet */ |
| 1115 | total_bytes += tx_buffer->bytecount; |
| 1116 | total_packets += tx_buffer->gso_segs; |
| 1117 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1118 | /* free the skb */ |
Rick Jones | fe1f2a9 | 2014-09-12 17:44:06 +0000 | [diff] [blame] | 1119 | dev_consume_skb_any(tx_buffer->skb); |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1120 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1121 | /* unmap skb header data */ |
| 1122 | dma_unmap_single(tx_ring->dev, |
| 1123 | dma_unmap_addr(tx_buffer, dma), |
| 1124 | dma_unmap_len(tx_buffer, len), |
| 1125 | DMA_TO_DEVICE); |
| 1126 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1127 | /* clear tx_buffer data */ |
| 1128 | tx_buffer->skb = NULL; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1129 | dma_unmap_len_set(tx_buffer, len, 0); |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1130 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1131 | /* unmap remaining buffers */ |
| 1132 | while (tx_desc != eop_desc) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1133 | tx_buffer++; |
| 1134 | tx_desc++; |
| 1135 | i++; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1136 | if (unlikely(!i)) { |
| 1137 | i -= tx_ring->count; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1138 | tx_buffer = tx_ring->tx_buffer_info; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1139 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1140 | } |
| 1141 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1142 | /* unmap any remaining paged data */ |
| 1143 | if (dma_unmap_len(tx_buffer, len)) { |
| 1144 | dma_unmap_page(tx_ring->dev, |
| 1145 | dma_unmap_addr(tx_buffer, dma), |
| 1146 | dma_unmap_len(tx_buffer, len), |
| 1147 | DMA_TO_DEVICE); |
| 1148 | dma_unmap_len_set(tx_buffer, len, 0); |
| 1149 | } |
| 1150 | } |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 1151 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1152 | /* move us one more past the eop_desc for start of next pkt */ |
| 1153 | tx_buffer++; |
| 1154 | tx_desc++; |
| 1155 | i++; |
| 1156 | if (unlikely(!i)) { |
| 1157 | i -= tx_ring->count; |
| 1158 | tx_buffer = tx_ring->tx_buffer_info; |
| 1159 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
| 1160 | } |
| 1161 | |
| 1162 | /* issue prefetch for next Tx descriptor */ |
| 1163 | prefetch(tx_desc); |
| 1164 | |
| 1165 | /* update budget accounting */ |
| 1166 | budget--; |
| 1167 | } while (likely(budget)); |
| 1168 | |
| 1169 | i += tx_ring->count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1170 | tx_ring->next_to_clean = i; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1171 | u64_stats_update_begin(&tx_ring->syncp); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1172 | tx_ring->stats.bytes += total_bytes; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1173 | tx_ring->stats.packets += total_packets; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1174 | u64_stats_update_end(&tx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1175 | q_vector->tx.total_bytes += total_bytes; |
| 1176 | q_vector->tx.total_packets += total_packets; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1177 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1178 | 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] | 1179 | /* schedule immediate reset if we believe we hung */ |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1180 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1181 | e_err(drv, "Detected Tx Unit Hang\n" |
| 1182 | " Tx Queue <%d>\n" |
| 1183 | " TDH, TDT <%x>, <%x>\n" |
| 1184 | " next_to_use <%x>\n" |
| 1185 | " next_to_clean <%x>\n" |
| 1186 | "tx_buffer_info[next_to_clean]\n" |
| 1187 | " time_stamp <%lx>\n" |
| 1188 | " jiffies <%lx>\n", |
| 1189 | tx_ring->queue_index, |
| 1190 | IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)), |
| 1191 | IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)), |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1192 | tx_ring->next_to_use, i, |
| 1193 | tx_ring->tx_buffer_info[i].time_stamp, jiffies); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1194 | |
| 1195 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 1196 | |
| 1197 | e_info(probe, |
| 1198 | "tx hang %d detected on queue %d, resetting adapter\n", |
| 1199 | adapter->tx_timeout_count + 1, tx_ring->queue_index); |
| 1200 | |
| 1201 | /* schedule immediate reset if we believe we hung */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 1202 | ixgbe_tx_timeout_reset(adapter); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1203 | |
| 1204 | /* the adapter is about to reset, no point in enabling stuff */ |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 1205 | return true; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1206 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1207 | |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 1208 | netdev_tx_completed_queue(txring_txq(tx_ring), |
| 1209 | total_packets, total_bytes); |
| 1210 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 1211 | #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) |
Alexander Duyck | 30065e6 | 2011-07-15 03:05:14 +0000 | [diff] [blame] | 1212 | if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) && |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 1213 | (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 1214 | /* Make sure that anybody stopping the queue after this |
| 1215 | * sees the new next_to_clean. |
| 1216 | */ |
| 1217 | smp_mb(); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1218 | if (__netif_subqueue_stopped(tx_ring->netdev, |
| 1219 | tx_ring->queue_index) |
| 1220 | && !test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1221 | netif_wake_subqueue(tx_ring->netdev, |
| 1222 | tx_ring->queue_index); |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 1223 | ++tx_ring->tx_stats.restart_queue; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 1224 | } |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 1225 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1226 | |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 1227 | return !!budget; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1228 | } |
| 1229 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1230 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1231 | static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter, |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1232 | struct ixgbe_ring *tx_ring, |
| 1233 | int cpu) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1234 | { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 1235 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1236 | u32 txctrl = dca3_get_tag(tx_ring->dev, cpu); |
| 1237 | u16 reg_offset; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1238 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1239 | switch (hw->mac.type) { |
| 1240 | case ixgbe_mac_82598EB: |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1241 | reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1242 | break; |
| 1243 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1244 | case ixgbe_mac_X540: |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1245 | reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx); |
| 1246 | txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599; |
| 1247 | break; |
| 1248 | default: |
| 1249 | /* for unknown hardware do not write register */ |
| 1250 | return; |
| 1251 | } |
| 1252 | |
| 1253 | /* |
| 1254 | * We can enable relaxed ordering for reads, but not writes when |
| 1255 | * DCA is enabled. This is due to a known issue in some chipsets |
| 1256 | * which will cause the DCA tag to be cleared. |
| 1257 | */ |
| 1258 | txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN | |
| 1259 | IXGBE_DCA_TXCTRL_DATA_RRO_EN | |
| 1260 | IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
| 1261 | |
| 1262 | IXGBE_WRITE_REG(hw, reg_offset, txctrl); |
| 1263 | } |
| 1264 | |
| 1265 | static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter, |
| 1266 | struct ixgbe_ring *rx_ring, |
| 1267 | int cpu) |
| 1268 | { |
| 1269 | struct ixgbe_hw *hw = &adapter->hw; |
| 1270 | u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu); |
| 1271 | u8 reg_idx = rx_ring->reg_idx; |
| 1272 | |
| 1273 | |
| 1274 | switch (hw->mac.type) { |
| 1275 | case ixgbe_mac_82599EB: |
| 1276 | case ixgbe_mac_X540: |
| 1277 | rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1278 | break; |
| 1279 | default: |
| 1280 | break; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1281 | } |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1282 | |
| 1283 | /* |
| 1284 | * We can enable relaxed ordering for reads, but not writes when |
| 1285 | * DCA is enabled. This is due to a known issue in some chipsets |
| 1286 | * which will cause the DCA tag to be cleared. |
| 1287 | */ |
| 1288 | rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN | |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1289 | IXGBE_DCA_RXCTRL_DESC_DCA_EN; |
| 1290 | |
| 1291 | IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector) |
| 1295 | { |
| 1296 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1297 | struct ixgbe_ring *ring; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1298 | int cpu = get_cpu(); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1299 | |
| 1300 | if (q_vector->cpu == cpu) |
| 1301 | goto out_no_update; |
| 1302 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 1303 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1304 | ixgbe_update_tx_dca(adapter, ring, cpu); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1305 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 1306 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1307 | ixgbe_update_rx_dca(adapter, ring, cpu); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1308 | |
| 1309 | q_vector->cpu = cpu; |
| 1310 | out_no_update: |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1311 | put_cpu(); |
| 1312 | } |
| 1313 | |
| 1314 | static void ixgbe_setup_dca(struct ixgbe_adapter *adapter) |
| 1315 | { |
| 1316 | int i; |
| 1317 | |
| 1318 | if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED)) |
| 1319 | return; |
| 1320 | |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 1321 | /* always use CB2 mode, difference is masked in the CB driver */ |
| 1322 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2); |
| 1323 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 1324 | for (i = 0; i < adapter->num_q_vectors; i++) { |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1325 | adapter->q_vector[i]->cpu = -1; |
| 1326 | ixgbe_update_dca(adapter->q_vector[i]); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1327 | } |
| 1328 | } |
| 1329 | |
| 1330 | static int __ixgbe_notify_dca(struct device *dev, void *data) |
| 1331 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 1332 | struct ixgbe_adapter *adapter = dev_get_drvdata(dev); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1333 | unsigned long event = *(unsigned long *)data; |
| 1334 | |
Don Skidmore | 2a72c31 | 2011-07-20 02:27:05 +0000 | [diff] [blame] | 1335 | if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE)) |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1336 | return 0; |
| 1337 | |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1338 | switch (event) { |
| 1339 | case DCA_PROVIDER_ADD: |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 1340 | /* if we're already enabled, don't do it again */ |
| 1341 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1342 | break; |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 1343 | if (dca_add_requester(dev) == 0) { |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 1344 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1345 | ixgbe_setup_dca(adapter); |
| 1346 | break; |
| 1347 | } |
| 1348 | /* Fall Through since DCA is disabled. */ |
| 1349 | case DCA_PROVIDER_REMOVE: |
| 1350 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 1351 | dca_remove_requester(dev); |
| 1352 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 1353 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 1354 | } |
| 1355 | break; |
| 1356 | } |
| 1357 | |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 1358 | return 0; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1359 | } |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1360 | |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1361 | #endif /* CONFIG_IXGBE_DCA */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1362 | static inline void ixgbe_rx_hash(struct ixgbe_ring *ring, |
| 1363 | union ixgbe_adv_rx_desc *rx_desc, |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1364 | struct sk_buff *skb) |
| 1365 | { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1366 | if (ring->netdev->features & NETIF_F_RXHASH) |
Tom Herbert | 38da985 | 2013-12-18 16:47:04 +0000 | [diff] [blame] | 1367 | skb_set_hash(skb, |
| 1368 | le32_to_cpu(rx_desc->wb.lower.hi_dword.rss), |
| 1369 | PKT_HASH_TYPE_L3); |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1370 | } |
| 1371 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1372 | #ifdef IXGBE_FCOE |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1373 | /** |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1374 | * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1375 | * @ring: structure containing ring specific data |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1376 | * @rx_desc: advanced rx descriptor |
| 1377 | * |
| 1378 | * Returns : true if it is FCoE pkt |
| 1379 | */ |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1380 | static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring, |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1381 | union ixgbe_adv_rx_desc *rx_desc) |
| 1382 | { |
| 1383 | __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 1384 | |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1385 | return test_bit(__IXGBE_RX_FCOE, &ring->state) && |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1386 | ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) == |
| 1387 | (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE << |
| 1388 | IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT))); |
| 1389 | } |
| 1390 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1391 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1392 | /** |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1393 | * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1394 | * @ring: structure containing ring specific data |
| 1395 | * @rx_desc: current Rx descriptor being processed |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1396 | * @skb: skb currently being received and modified |
| 1397 | **/ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1398 | static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring, |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1399 | union ixgbe_adv_rx_desc *rx_desc, |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1400 | struct sk_buff *skb) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1401 | { |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1402 | __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 1403 | __le16 hdr_info = rx_desc->wb.lower.lo_dword.hs_rss.hdr_info; |
| 1404 | bool encap_pkt = false; |
| 1405 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1406 | skb_checksum_none_assert(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1407 | |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 1408 | /* Rx csum disabled */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1409 | if (!(ring->netdev->features & NETIF_F_RXCSUM)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1410 | return; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1411 | |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1412 | if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_VXLAN)) && |
| 1413 | (hdr_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_TUNNEL >> 16))) { |
| 1414 | encap_pkt = true; |
| 1415 | skb->encapsulation = 1; |
| 1416 | skb->ip_summed = CHECKSUM_NONE; |
| 1417 | } |
| 1418 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1419 | /* if IP and error */ |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1420 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) && |
| 1421 | ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1422 | ring->rx_stats.csum_err++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1423 | return; |
| 1424 | } |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1425 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1426 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS)) |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1427 | return; |
| 1428 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1429 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) { |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1430 | /* |
| 1431 | * 82599 errata, UDP frames with a 0 checksum can be marked as |
| 1432 | * checksum errors. |
| 1433 | */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1434 | if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) && |
| 1435 | test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state)) |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1436 | return; |
| 1437 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1438 | ring->rx_stats.csum_err++; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1439 | return; |
| 1440 | } |
| 1441 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1442 | /* It must be a TCP or UDP packet with a valid checksum */ |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1443 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1444 | if (encap_pkt) { |
| 1445 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_OUTERIPCS)) |
| 1446 | return; |
| 1447 | |
| 1448 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_OUTERIPER)) { |
| 1449 | ring->rx_stats.csum_err++; |
| 1450 | return; |
| 1451 | } |
| 1452 | /* If we checked the outer header let the stack know */ |
| 1453 | skb->csum_level = 1; |
| 1454 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1455 | } |
| 1456 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1457 | static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring, |
| 1458 | struct ixgbe_rx_buffer *bi) |
| 1459 | { |
| 1460 | struct page *page = bi->page; |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1461 | dma_addr_t dma; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1462 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1463 | /* since we are recycling buffers we should seldom need to alloc */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1464 | if (likely(page)) |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1465 | return true; |
| 1466 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1467 | /* alloc new page for storage */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1468 | page = dev_alloc_pages(ixgbe_rx_pg_order(rx_ring)); |
| 1469 | if (unlikely(!page)) { |
| 1470 | rx_ring->rx_stats.alloc_rx_page_failed++; |
| 1471 | return false; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1472 | } |
| 1473 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1474 | /* map page for use */ |
| 1475 | dma = dma_map_page(rx_ring->dev, page, 0, |
| 1476 | ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1477 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1478 | /* |
| 1479 | * if mapping failed free memory back to system since |
| 1480 | * there isn't much point in holding memory we can't use |
| 1481 | */ |
| 1482 | if (dma_mapping_error(rx_ring->dev, dma)) { |
Alexander Duyck | dd411ec | 2012-04-06 04:24:50 +0000 | [diff] [blame] | 1483 | __free_pages(page, ixgbe_rx_pg_order(rx_ring)); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1484 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1485 | rx_ring->rx_stats.alloc_rx_page_failed++; |
| 1486 | return false; |
| 1487 | } |
| 1488 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1489 | bi->dma = dma; |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1490 | bi->page = page; |
Alexander Duyck | afaa945 | 2012-07-20 08:08:12 +0000 | [diff] [blame] | 1491 | bi->page_offset = 0; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1492 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1493 | return true; |
| 1494 | } |
| 1495 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1496 | /** |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1497 | * ixgbe_alloc_rx_buffers - Replace used receive buffers |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1498 | * @rx_ring: ring to place buffers on |
| 1499 | * @cleaned_count: number of buffers to replace |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1500 | **/ |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1501 | 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] | 1502 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1503 | union ixgbe_adv_rx_desc *rx_desc; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1504 | struct ixgbe_rx_buffer *bi; |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1505 | u16 i = rx_ring->next_to_use; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1506 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1507 | /* nothing to do */ |
| 1508 | if (!cleaned_count) |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1509 | return; |
| 1510 | |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1511 | rx_desc = IXGBE_RX_DESC(rx_ring, i); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1512 | bi = &rx_ring->rx_buffer_info[i]; |
| 1513 | i -= rx_ring->count; |
| 1514 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1515 | do { |
| 1516 | if (!ixgbe_alloc_mapped_page(rx_ring, bi)) |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1517 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1518 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1519 | /* |
| 1520 | * Refresh the desc even if buffer_addrs didn't change |
| 1521 | * because each write-back erases this info. |
| 1522 | */ |
| 1523 | 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] | 1524 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1525 | rx_desc++; |
| 1526 | bi++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1527 | i++; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1528 | if (unlikely(!i)) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1529 | rx_desc = IXGBE_RX_DESC(rx_ring, 0); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1530 | bi = rx_ring->rx_buffer_info; |
| 1531 | i -= rx_ring->count; |
| 1532 | } |
| 1533 | |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1534 | /* clear the status bits for the next_to_use descriptor */ |
| 1535 | rx_desc->wb.upper.status_error = 0; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1536 | |
| 1537 | cleaned_count--; |
| 1538 | } while (cleaned_count); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1539 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1540 | i += rx_ring->count; |
| 1541 | |
Alexander Duyck | ad435ec | 2014-11-14 00:56:35 +0000 | [diff] [blame] | 1542 | if (rx_ring->next_to_use != i) { |
| 1543 | rx_ring->next_to_use = i; |
| 1544 | |
| 1545 | /* update next to alloc since we have filled the ring */ |
| 1546 | rx_ring->next_to_alloc = i; |
| 1547 | |
| 1548 | /* Force memory writes to complete before letting h/w |
| 1549 | * know there are new descriptors to fetch. (Only |
| 1550 | * applicable for weak-ordered memory model archs, |
| 1551 | * such as IA-64). |
| 1552 | */ |
| 1553 | wmb(); |
| 1554 | writel(i, rx_ring->tail); |
| 1555 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1556 | } |
| 1557 | |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1558 | static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring, |
| 1559 | struct sk_buff *skb) |
| 1560 | { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1561 | u16 hdr_len = skb_headlen(skb); |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1562 | |
| 1563 | /* set gso_size to avoid messing up TCP MSS */ |
| 1564 | skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len), |
| 1565 | IXGBE_CB(skb)->append_cnt); |
Alexander Duyck | 96be80a | 2013-02-12 09:45:44 +0000 | [diff] [blame] | 1566 | skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4; |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1567 | } |
| 1568 | |
| 1569 | static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring, |
| 1570 | struct sk_buff *skb) |
| 1571 | { |
| 1572 | /* if append_cnt is 0 then frame is not RSC */ |
| 1573 | if (!IXGBE_CB(skb)->append_cnt) |
| 1574 | return; |
| 1575 | |
| 1576 | rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt; |
| 1577 | rx_ring->rx_stats.rsc_flush++; |
| 1578 | |
| 1579 | ixgbe_set_rsc_gso_size(rx_ring, skb); |
| 1580 | |
| 1581 | /* gso_size is computed using append_cnt so always clear it last */ |
| 1582 | IXGBE_CB(skb)->append_cnt = 0; |
| 1583 | } |
| 1584 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1585 | /** |
| 1586 | * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor |
| 1587 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1588 | * @rx_desc: pointer to the EOP Rx descriptor |
| 1589 | * @skb: pointer to current skb being populated |
| 1590 | * |
| 1591 | * This function checks the ring, descriptor, and packet information in |
| 1592 | * order to populate the hash, checksum, VLAN, timestamp, protocol, and |
| 1593 | * other fields within the skb. |
| 1594 | **/ |
| 1595 | static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring, |
| 1596 | union ixgbe_adv_rx_desc *rx_desc, |
| 1597 | struct sk_buff *skb) |
| 1598 | { |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1599 | struct net_device *dev = rx_ring->netdev; |
| 1600 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1601 | ixgbe_update_rsc_stats(rx_ring, skb); |
| 1602 | |
| 1603 | ixgbe_rx_hash(rx_ring, rx_desc, skb); |
| 1604 | |
| 1605 | ixgbe_rx_checksum(rx_ring, rx_desc, skb); |
| 1606 | |
Jakub Kicinski | eda183c | 2014-04-02 10:33:28 +0000 | [diff] [blame] | 1607 | if (unlikely(ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_STAT_TS))) |
| 1608 | ixgbe_ptp_rx_hwtstamp(rx_ring->q_vector->adapter, skb); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 1609 | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 1610 | if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) && |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1611 | ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1612 | u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan); |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 1613 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid); |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1614 | } |
| 1615 | |
| 1616 | skb_record_rx_queue(skb, rx_ring->queue_index); |
| 1617 | |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1618 | skb->protocol = eth_type_trans(skb, dev); |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1619 | } |
| 1620 | |
| 1621 | static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector, |
| 1622 | struct sk_buff *skb) |
| 1623 | { |
Jacob Keller | b464003 | 2013-10-01 04:33:54 -0700 | [diff] [blame] | 1624 | if (ixgbe_qv_busy_polling(q_vector)) |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 1625 | netif_receive_skb(skb); |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1626 | else |
Alexander Duyck | 856f606 | 2015-02-25 17:45:54 +0000 | [diff] [blame] | 1627 | napi_gro_receive(&q_vector->napi, skb); |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1628 | } |
Mallikarjuna R Chilakala | 43634e8 | 2010-02-25 23:14:37 +0000 | [diff] [blame] | 1629 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1630 | /** |
| 1631 | * ixgbe_is_non_eop - process handling of non-EOP buffers |
| 1632 | * @rx_ring: Rx ring being processed |
| 1633 | * @rx_desc: Rx descriptor for current buffer |
| 1634 | * @skb: Current socket buffer containing buffer in progress |
| 1635 | * |
| 1636 | * This function updates next to clean. If the buffer is an EOP buffer |
| 1637 | * this function exits returning false, otherwise it will place the |
| 1638 | * sk_buff in the next buffer to be chained and return true indicating |
| 1639 | * that this is in fact a non-EOP buffer. |
| 1640 | **/ |
| 1641 | static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring, |
| 1642 | union ixgbe_adv_rx_desc *rx_desc, |
| 1643 | struct sk_buff *skb) |
| 1644 | { |
| 1645 | u32 ntc = rx_ring->next_to_clean + 1; |
| 1646 | |
| 1647 | /* fetch, update, and store next to clean */ |
| 1648 | ntc = (ntc < rx_ring->count) ? ntc : 0; |
| 1649 | rx_ring->next_to_clean = ntc; |
| 1650 | |
| 1651 | prefetch(IXGBE_RX_DESC(rx_ring, ntc)); |
| 1652 | |
Alexander Duyck | 5a02cbd | 2012-07-20 08:08:51 +0000 | [diff] [blame] | 1653 | /* update RSC append count if present */ |
| 1654 | if (ring_is_rsc_enabled(rx_ring)) { |
| 1655 | __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data & |
| 1656 | cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK); |
| 1657 | |
| 1658 | if (unlikely(rsc_enabled)) { |
| 1659 | u32 rsc_cnt = le32_to_cpu(rsc_enabled); |
| 1660 | |
| 1661 | rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT; |
| 1662 | IXGBE_CB(skb)->append_cnt += rsc_cnt - 1; |
| 1663 | |
| 1664 | /* update ntc based on RSC value */ |
| 1665 | ntc = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 1666 | ntc &= IXGBE_RXDADV_NEXTP_MASK; |
| 1667 | ntc >>= IXGBE_RXDADV_NEXTP_SHIFT; |
| 1668 | } |
| 1669 | } |
| 1670 | |
| 1671 | /* 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] | 1672 | if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))) |
| 1673 | return false; |
| 1674 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1675 | /* place skb in next buffer to be received */ |
| 1676 | rx_ring->rx_buffer_info[ntc].skb = skb; |
| 1677 | rx_ring->rx_stats.non_eop_descs++; |
| 1678 | |
| 1679 | return true; |
| 1680 | } |
| 1681 | |
| 1682 | /** |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1683 | * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail |
| 1684 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1685 | * @skb: pointer to current skb being adjusted |
| 1686 | * |
| 1687 | * This function is an ixgbe specific version of __pskb_pull_tail. The |
| 1688 | * main difference between this version and the original function is that |
| 1689 | * this function can make several assumptions about the state of things |
| 1690 | * that allow for significant optimizations versus the standard function. |
| 1691 | * As a result we can do things like drop a frag and maintain an accurate |
| 1692 | * truesize for the skb. |
| 1693 | */ |
| 1694 | static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring, |
| 1695 | struct sk_buff *skb) |
| 1696 | { |
| 1697 | struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0]; |
| 1698 | unsigned char *va; |
| 1699 | unsigned int pull_len; |
| 1700 | |
| 1701 | /* |
| 1702 | * it is valid to use page_address instead of kmap since we are |
| 1703 | * working with pages allocated out of the lomem pool per |
| 1704 | * alloc_page(GFP_ATOMIC) |
| 1705 | */ |
| 1706 | va = skb_frag_address(frag); |
| 1707 | |
| 1708 | /* |
| 1709 | * we need the header to contain the greater of either ETH_HLEN or |
| 1710 | * 60 bytes if the skb->len is less than 60 for skb_pad. |
| 1711 | */ |
Alexander Duyck | 8496e33 | 2014-09-05 19:22:18 -0400 | [diff] [blame] | 1712 | pull_len = eth_get_headlen(va, IXGBE_RX_HDR_SIZE); |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1713 | |
| 1714 | /* align pull length to size of long to optimize memcpy performance */ |
| 1715 | skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long))); |
| 1716 | |
| 1717 | /* update all of the pointers */ |
| 1718 | skb_frag_size_sub(frag, pull_len); |
| 1719 | frag->page_offset += pull_len; |
| 1720 | skb->data_len -= pull_len; |
| 1721 | skb->tail += pull_len; |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1722 | } |
| 1723 | |
| 1724 | /** |
Alexander Duyck | 42073d9 | 2012-07-20 08:08:28 +0000 | [diff] [blame] | 1725 | * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB |
| 1726 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1727 | * @skb: pointer to current skb being updated |
| 1728 | * |
| 1729 | * This function provides a basic DMA sync up for the first fragment of an |
| 1730 | * skb. The reason for doing this is that the first fragment cannot be |
| 1731 | * unmapped until we have reached the end of packet descriptor for a buffer |
| 1732 | * chain. |
| 1733 | */ |
| 1734 | static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring, |
| 1735 | struct sk_buff *skb) |
| 1736 | { |
| 1737 | /* if the page was released unmap it, else just sync our portion */ |
| 1738 | if (unlikely(IXGBE_CB(skb)->page_released)) { |
| 1739 | dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma, |
| 1740 | ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE); |
| 1741 | IXGBE_CB(skb)->page_released = false; |
| 1742 | } else { |
| 1743 | struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0]; |
| 1744 | |
| 1745 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 1746 | IXGBE_CB(skb)->dma, |
| 1747 | frag->page_offset, |
| 1748 | ixgbe_rx_bufsz(rx_ring), |
| 1749 | DMA_FROM_DEVICE); |
| 1750 | } |
| 1751 | IXGBE_CB(skb)->dma = 0; |
| 1752 | } |
| 1753 | |
| 1754 | /** |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1755 | * ixgbe_cleanup_headers - Correct corrupted or empty headers |
| 1756 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1757 | * @rx_desc: pointer to the EOP Rx descriptor |
| 1758 | * @skb: pointer to current skb being fixed |
| 1759 | * |
| 1760 | * Check for corrupted packet headers caused by senders on the local L2 |
| 1761 | * embedded NIC switch not setting up their Tx Descriptors right. These |
| 1762 | * should be very rare. |
| 1763 | * |
| 1764 | * Also address the case where we are pulling data in on pages only |
| 1765 | * and as such no data is present in the skb header. |
| 1766 | * |
| 1767 | * In addition if skb is not at least 60 bytes we need to pad it so that |
| 1768 | * it is large enough to qualify as a valid Ethernet frame. |
| 1769 | * |
| 1770 | * Returns true if an error was encountered and skb was freed. |
| 1771 | **/ |
| 1772 | static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring, |
| 1773 | union ixgbe_adv_rx_desc *rx_desc, |
| 1774 | struct sk_buff *skb) |
| 1775 | { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1776 | struct net_device *netdev = rx_ring->netdev; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1777 | |
| 1778 | /* verify that the packet does not have any known errors */ |
| 1779 | if (unlikely(ixgbe_test_staterr(rx_desc, |
| 1780 | IXGBE_RXDADV_ERR_FRAME_ERR_MASK) && |
| 1781 | !(netdev->features & NETIF_F_RXALL))) { |
| 1782 | dev_kfree_skb_any(skb); |
| 1783 | return true; |
| 1784 | } |
| 1785 | |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1786 | /* place header in linear portion of buffer */ |
Alexander Duyck | cf3fe7a | 2012-07-20 08:08:39 +0000 | [diff] [blame] | 1787 | if (skb_is_nonlinear(skb)) |
| 1788 | ixgbe_pull_tail(rx_ring, skb); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1789 | |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1790 | #ifdef IXGBE_FCOE |
| 1791 | /* do not attempt to pad FCoE Frames as this will disrupt DDP */ |
| 1792 | if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) |
| 1793 | return false; |
| 1794 | |
| 1795 | #endif |
Alexander Duyck | a94d9e2 | 2014-12-03 08:17:39 -0800 | [diff] [blame] | 1796 | /* if eth_skb_pad returns an error the skb was freed */ |
| 1797 | if (eth_skb_pad(skb)) |
| 1798 | return true; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1799 | |
| 1800 | return false; |
| 1801 | } |
| 1802 | |
| 1803 | /** |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1804 | * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring |
| 1805 | * @rx_ring: rx descriptor ring to store buffers on |
| 1806 | * @old_buff: donor buffer to have page reused |
| 1807 | * |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1808 | * Synchronizes page for reuse by the adapter |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1809 | **/ |
| 1810 | static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring, |
| 1811 | struct ixgbe_rx_buffer *old_buff) |
| 1812 | { |
| 1813 | struct ixgbe_rx_buffer *new_buff; |
| 1814 | u16 nta = rx_ring->next_to_alloc; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1815 | |
| 1816 | new_buff = &rx_ring->rx_buffer_info[nta]; |
| 1817 | |
| 1818 | /* update, and store next to alloc */ |
| 1819 | nta++; |
| 1820 | rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0; |
| 1821 | |
| 1822 | /* transfer page from old buffer to new buffer */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1823 | *new_buff = *old_buff; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1824 | |
| 1825 | /* sync the buffer for use by the device */ |
| 1826 | dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma, |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1827 | new_buff->page_offset, |
| 1828 | ixgbe_rx_bufsz(rx_ring), |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1829 | DMA_FROM_DEVICE); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1830 | } |
| 1831 | |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1832 | static inline bool ixgbe_page_is_reserved(struct page *page) |
| 1833 | { |
| 1834 | return (page_to_nid(page) != numa_mem_id()) || page->pfmemalloc; |
| 1835 | } |
| 1836 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1837 | /** |
| 1838 | * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff |
| 1839 | * @rx_ring: rx descriptor ring to transact packets on |
| 1840 | * @rx_buffer: buffer containing page to add |
| 1841 | * @rx_desc: descriptor containing length of buffer written by hardware |
| 1842 | * @skb: sk_buff to place the data into |
| 1843 | * |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1844 | * This function will add the data contained in rx_buffer->page to the skb. |
| 1845 | * This is done either through a direct copy if the data in the buffer is |
| 1846 | * less than the skb header size, otherwise it will just attach the page as |
| 1847 | * a frag to the skb. |
| 1848 | * |
| 1849 | * The function will then update the page offset if necessary and return |
| 1850 | * true if the buffer can be reused by the adapter. |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1851 | **/ |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1852 | static bool ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring, |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1853 | struct ixgbe_rx_buffer *rx_buffer, |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1854 | union ixgbe_adv_rx_desc *rx_desc, |
| 1855 | struct sk_buff *skb) |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1856 | { |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1857 | struct page *page = rx_buffer->page; |
| 1858 | unsigned int size = le16_to_cpu(rx_desc->wb.upper.length); |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1859 | #if (PAGE_SIZE < 8192) |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1860 | unsigned int truesize = ixgbe_rx_bufsz(rx_ring); |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1861 | #else |
| 1862 | unsigned int truesize = ALIGN(size, L1_CACHE_BYTES); |
| 1863 | unsigned int last_offset = ixgbe_rx_pg_size(rx_ring) - |
| 1864 | ixgbe_rx_bufsz(rx_ring); |
| 1865 | #endif |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1866 | |
Alexander Duyck | cf3fe7a | 2012-07-20 08:08:39 +0000 | [diff] [blame] | 1867 | if ((size <= IXGBE_RX_HDR_SIZE) && !skb_is_nonlinear(skb)) { |
| 1868 | unsigned char *va = page_address(page) + rx_buffer->page_offset; |
| 1869 | |
| 1870 | memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long))); |
| 1871 | |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1872 | /* page is not reserved, we can reuse buffer as-is */ |
| 1873 | if (likely(!ixgbe_page_is_reserved(page))) |
Alexander Duyck | cf3fe7a | 2012-07-20 08:08:39 +0000 | [diff] [blame] | 1874 | return true; |
| 1875 | |
| 1876 | /* this page cannot be reused so discard it */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1877 | __free_pages(page, ixgbe_rx_pg_order(rx_ring)); |
Alexander Duyck | cf3fe7a | 2012-07-20 08:08:39 +0000 | [diff] [blame] | 1878 | return false; |
| 1879 | } |
| 1880 | |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1881 | skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page, |
| 1882 | rx_buffer->page_offset, size, truesize); |
| 1883 | |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1884 | /* avoid re-using remote pages */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1885 | if (unlikely(ixgbe_page_is_reserved(page))) |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1886 | return false; |
| 1887 | |
| 1888 | #if (PAGE_SIZE < 8192) |
| 1889 | /* if we are only owner of page we can reuse it */ |
| 1890 | if (unlikely(page_count(page) != 1)) |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1891 | return false; |
| 1892 | |
| 1893 | /* flip page offset to other buffer */ |
| 1894 | rx_buffer->page_offset ^= truesize; |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1895 | #else |
| 1896 | /* move offset up to the next cache line */ |
| 1897 | rx_buffer->page_offset += truesize; |
| 1898 | |
| 1899 | if (rx_buffer->page_offset > last_offset) |
| 1900 | return false; |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1901 | #endif |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1902 | |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1903 | /* Even if we own the page, we are not allowed to use atomic_set() |
| 1904 | * This would break get_page_unless_zero() users. |
| 1905 | */ |
| 1906 | atomic_inc(&page->_count); |
| 1907 | |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1908 | return true; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1909 | } |
| 1910 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 1911 | static struct sk_buff *ixgbe_fetch_rx_buffer(struct ixgbe_ring *rx_ring, |
| 1912 | union ixgbe_adv_rx_desc *rx_desc) |
| 1913 | { |
| 1914 | struct ixgbe_rx_buffer *rx_buffer; |
| 1915 | struct sk_buff *skb; |
| 1916 | struct page *page; |
| 1917 | |
| 1918 | rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean]; |
| 1919 | page = rx_buffer->page; |
| 1920 | prefetchw(page); |
| 1921 | |
| 1922 | skb = rx_buffer->skb; |
| 1923 | |
| 1924 | if (likely(!skb)) { |
| 1925 | void *page_addr = page_address(page) + |
| 1926 | rx_buffer->page_offset; |
| 1927 | |
| 1928 | /* prefetch first cache line of first page */ |
| 1929 | prefetch(page_addr); |
| 1930 | #if L1_CACHE_BYTES < 128 |
| 1931 | prefetch(page_addr + L1_CACHE_BYTES); |
| 1932 | #endif |
| 1933 | |
| 1934 | /* allocate a skb to store the frags */ |
Alexander Duyck | 67fd893 | 2014-12-09 19:40:56 -0800 | [diff] [blame] | 1935 | skb = napi_alloc_skb(&rx_ring->q_vector->napi, |
| 1936 | IXGBE_RX_HDR_SIZE); |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 1937 | if (unlikely(!skb)) { |
| 1938 | rx_ring->rx_stats.alloc_rx_buff_failed++; |
| 1939 | return NULL; |
| 1940 | } |
| 1941 | |
| 1942 | /* |
| 1943 | * we will be copying header into skb->data in |
| 1944 | * pskb_may_pull so it is in our interest to prefetch |
| 1945 | * it now to avoid a possible cache miss |
| 1946 | */ |
| 1947 | prefetchw(skb->data); |
| 1948 | |
| 1949 | /* |
| 1950 | * Delay unmapping of the first packet. It carries the |
| 1951 | * header information, HW may still access the header |
| 1952 | * after the writeback. Only unmap it when EOP is |
| 1953 | * reached |
| 1954 | */ |
| 1955 | if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))) |
| 1956 | goto dma_sync; |
| 1957 | |
| 1958 | IXGBE_CB(skb)->dma = rx_buffer->dma; |
| 1959 | } else { |
| 1960 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)) |
| 1961 | ixgbe_dma_sync_frag(rx_ring, skb); |
| 1962 | |
| 1963 | dma_sync: |
| 1964 | /* we are reusing so sync this buffer for CPU use */ |
| 1965 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 1966 | rx_buffer->dma, |
| 1967 | rx_buffer->page_offset, |
| 1968 | ixgbe_rx_bufsz(rx_ring), |
| 1969 | DMA_FROM_DEVICE); |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1970 | |
| 1971 | rx_buffer->skb = NULL; |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 1972 | } |
| 1973 | |
| 1974 | /* pull page into skb */ |
| 1975 | if (ixgbe_add_rx_frag(rx_ring, rx_buffer, rx_desc, skb)) { |
| 1976 | /* hand second half of page back to the ring */ |
| 1977 | ixgbe_reuse_rx_page(rx_ring, rx_buffer); |
| 1978 | } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) { |
| 1979 | /* the page has been released from the ring */ |
| 1980 | IXGBE_CB(skb)->page_released = true; |
| 1981 | } else { |
| 1982 | /* we are not reusing the buffer so unmap it */ |
| 1983 | dma_unmap_page(rx_ring->dev, rx_buffer->dma, |
| 1984 | ixgbe_rx_pg_size(rx_ring), |
| 1985 | DMA_FROM_DEVICE); |
| 1986 | } |
| 1987 | |
| 1988 | /* clear contents of buffer_info */ |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 1989 | rx_buffer->page = NULL; |
| 1990 | |
| 1991 | return skb; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1992 | } |
| 1993 | |
| 1994 | /** |
| 1995 | * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf |
| 1996 | * @q_vector: structure containing interrupt and ring information |
| 1997 | * @rx_ring: rx descriptor ring to transact packets on |
| 1998 | * @budget: Total limit on number of packets to process |
| 1999 | * |
| 2000 | * This function provides a "bounce buffer" approach to Rx interrupt |
| 2001 | * processing. The advantage to this is that on systems that have |
| 2002 | * expensive overhead for IOMMU access this provides a means of avoiding |
| 2003 | * it by maintaining the mapping of the page to the syste. |
| 2004 | * |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2005 | * Returns amount of work completed |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2006 | **/ |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2007 | static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2008 | struct ixgbe_ring *rx_ring, |
Alexander Duyck | f4de00e | 2012-09-25 00:29:37 +0000 | [diff] [blame] | 2009 | const int budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2010 | { |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 2011 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 2012 | #ifdef IXGBE_FCOE |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2013 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Mark Rustad | 4ffdf91 | 2012-07-18 06:05:50 +0000 | [diff] [blame] | 2014 | int ddp_bytes; |
| 2015 | unsigned int mss = 0; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 2016 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2017 | u16 cleaned_count = ixgbe_desc_unused(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2018 | |
Eric W. Biederman | fdabfc8a | 2014-03-14 18:00:41 -0700 | [diff] [blame] | 2019 | while (likely(total_rx_packets < budget)) { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2020 | union ixgbe_adv_rx_desc *rx_desc; |
| 2021 | struct sk_buff *skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2022 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2023 | /* return some buffers to hardware, one at a time is too slow */ |
| 2024 | if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) { |
| 2025 | ixgbe_alloc_rx_buffers(rx_ring, cleaned_count); |
| 2026 | cleaned_count = 0; |
| 2027 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2028 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2029 | rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2030 | |
Alexander Duyck | 124b74c | 2014-12-11 15:02:28 -0800 | [diff] [blame] | 2031 | if (!rx_desc->wb.upper.status_error) |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2032 | break; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 2033 | |
Alexander Duyck | 124b74c | 2014-12-11 15:02:28 -0800 | [diff] [blame] | 2034 | /* This memory barrier is needed to keep us from reading |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2035 | * any other fields out of the rx_desc until we know the |
Alexander Duyck | 124b74c | 2014-12-11 15:02:28 -0800 | [diff] [blame] | 2036 | * descriptor has been written back |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2037 | */ |
Alexander Duyck | 124b74c | 2014-12-11 15:02:28 -0800 | [diff] [blame] | 2038 | dma_rmb(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2039 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2040 | /* retrieve a buffer from the ring */ |
| 2041 | skb = ixgbe_fetch_rx_buffer(rx_ring, rx_desc); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2042 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2043 | /* exit if we failed to retrieve a buffer */ |
| 2044 | if (!skb) |
| 2045 | break; |
Alexander Duyck | 4c1975d | 2012-01-31 02:59:23 +0000 | [diff] [blame] | 2046 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2047 | cleaned_count++; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2048 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2049 | /* place incomplete frames back on ring for completion */ |
| 2050 | if (ixgbe_is_non_eop(rx_ring, rx_desc, skb)) |
| 2051 | continue; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2052 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2053 | /* verify the packet layout is correct */ |
| 2054 | if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb)) |
| 2055 | continue; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 2056 | |
| 2057 | /* probably a little skewed due to removing CRC */ |
| 2058 | total_rx_bytes += skb->len; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 2059 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 2060 | /* populate checksum, timestamp, VLAN, and protocol */ |
| 2061 | ixgbe_process_skb_fields(rx_ring, rx_desc, skb); |
| 2062 | |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 2063 | #ifdef IXGBE_FCOE |
| 2064 | /* if ddp, not passing to ULD unless for FCP_RSP or error */ |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 2065 | if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) { |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 2066 | ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb); |
Mark Rustad | 4ffdf91 | 2012-07-18 06:05:50 +0000 | [diff] [blame] | 2067 | /* include DDPed FCoE data */ |
| 2068 | if (ddp_bytes > 0) { |
| 2069 | if (!mss) { |
| 2070 | mss = rx_ring->netdev->mtu - |
| 2071 | sizeof(struct fcoe_hdr) - |
| 2072 | sizeof(struct fc_frame_header) - |
| 2073 | sizeof(struct fcoe_crc_eof); |
| 2074 | if (mss > 512) |
| 2075 | mss &= ~511; |
| 2076 | } |
| 2077 | total_rx_bytes += ddp_bytes; |
| 2078 | total_rx_packets += DIV_ROUND_UP(ddp_bytes, |
| 2079 | mss); |
| 2080 | } |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 2081 | if (!ddp_bytes) { |
| 2082 | dev_kfree_skb_any(skb); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2083 | continue; |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 2084 | } |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 2085 | } |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2086 | |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 2087 | #endif /* IXGBE_FCOE */ |
Eliezer Tamir | 8b80cda | 2013-07-10 17:13:26 +0300 | [diff] [blame] | 2088 | skb_mark_napi_id(skb, &q_vector->napi); |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 2089 | ixgbe_rx_skb(q_vector, skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2090 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2091 | /* update budget accounting */ |
Alexander Duyck | f4de00e | 2012-09-25 00:29:37 +0000 | [diff] [blame] | 2092 | total_rx_packets++; |
Eric W. Biederman | fdabfc8a | 2014-03-14 18:00:41 -0700 | [diff] [blame] | 2093 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2094 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 2095 | u64_stats_update_begin(&rx_ring->syncp); |
| 2096 | rx_ring->stats.packets += total_rx_packets; |
| 2097 | rx_ring->stats.bytes += total_rx_bytes; |
| 2098 | u64_stats_update_end(&rx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2099 | q_vector->rx.total_packets += total_rx_packets; |
| 2100 | q_vector->rx.total_bytes += total_rx_bytes; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2101 | |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2102 | return total_rx_packets; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2103 | } |
| 2104 | |
Cong Wang | e0d1095 | 2013-08-01 11:10:25 +0800 | [diff] [blame] | 2105 | #ifdef CONFIG_NET_RX_BUSY_POLL |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2106 | /* must be called with local_bh_disable()d */ |
| 2107 | static int ixgbe_low_latency_recv(struct napi_struct *napi) |
| 2108 | { |
| 2109 | struct ixgbe_q_vector *q_vector = |
| 2110 | container_of(napi, struct ixgbe_q_vector, napi); |
| 2111 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 2112 | struct ixgbe_ring *ring; |
| 2113 | int found = 0; |
| 2114 | |
| 2115 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2116 | return LL_FLUSH_FAILED; |
| 2117 | |
| 2118 | if (!ixgbe_qv_lock_poll(q_vector)) |
| 2119 | return LL_FLUSH_BUSY; |
| 2120 | |
| 2121 | ixgbe_for_each_ring(ring, q_vector->rx) { |
| 2122 | found = ixgbe_clean_rx_irq(q_vector, ring, 4); |
Jacob Keller | b464003 | 2013-10-01 04:33:54 -0700 | [diff] [blame] | 2123 | #ifdef BP_EXTENDED_STATS |
Eliezer Tamir | 7e15b90 | 2013-06-10 11:40:31 +0300 | [diff] [blame] | 2124 | if (found) |
| 2125 | ring->stats.cleaned += found; |
| 2126 | else |
| 2127 | ring->stats.misses++; |
| 2128 | #endif |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2129 | if (found) |
| 2130 | break; |
| 2131 | } |
| 2132 | |
| 2133 | ixgbe_qv_unlock_poll(q_vector); |
| 2134 | |
| 2135 | return found; |
| 2136 | } |
Cong Wang | e0d1095 | 2013-08-01 11:10:25 +0800 | [diff] [blame] | 2137 | #endif /* CONFIG_NET_RX_BUSY_POLL */ |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2138 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2139 | /** |
| 2140 | * ixgbe_configure_msix - Configure MSI-X hardware |
| 2141 | * @adapter: board private structure |
| 2142 | * |
| 2143 | * ixgbe_configure_msix sets up the hardware to properly generate MSI-X |
| 2144 | * interrupts. |
| 2145 | **/ |
| 2146 | static void ixgbe_configure_msix(struct ixgbe_adapter *adapter) |
| 2147 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2148 | struct ixgbe_q_vector *q_vector; |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2149 | int v_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2150 | u32 mask; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2151 | |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 2152 | /* Populate MSIX to EITR Select */ |
| 2153 | if (adapter->num_vfs > 32) { |
| 2154 | u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1; |
| 2155 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel); |
| 2156 | } |
| 2157 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 2158 | /* |
| 2159 | * Populate the IVAR table and set the ITR values to the |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2160 | * corresponding register. |
| 2161 | */ |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2162 | for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) { |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2163 | struct ixgbe_ring *ring; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2164 | q_vector = adapter->q_vector[v_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2165 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 2166 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2167 | ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2168 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 2169 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2170 | ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2171 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2172 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2173 | } |
| 2174 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2175 | switch (adapter->hw.mac.type) { |
| 2176 | case ixgbe_mac_82598EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2177 | ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2178 | v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2179 | break; |
| 2180 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2181 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2182 | case ixgbe_mac_X550: |
| 2183 | case ixgbe_mac_X550EM_x: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2184 | ixgbe_set_ivar(adapter, -1, 1, v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2185 | break; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2186 | default: |
| 2187 | break; |
| 2188 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2189 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2190 | |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 2191 | /* set up to autoclear timer, and the vectors */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2192 | mask = IXGBE_EIMS_ENABLE_MASK; |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2193 | mask &= ~(IXGBE_EIMS_OTHER | |
| 2194 | IXGBE_EIMS_MAILBOX | |
| 2195 | IXGBE_EIMS_LSC); |
| 2196 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2197 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2198 | } |
| 2199 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2200 | enum latency_range { |
| 2201 | lowest_latency = 0, |
| 2202 | low_latency = 1, |
| 2203 | bulk_latency = 2, |
| 2204 | latency_invalid = 255 |
| 2205 | }; |
| 2206 | |
| 2207 | /** |
| 2208 | * ixgbe_update_itr - update the dynamic ITR value based on statistics |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2209 | * @q_vector: structure containing interrupt and ring information |
| 2210 | * @ring_container: structure containing ring performance data |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2211 | * |
| 2212 | * Stores a new ITR value based on packets and byte |
| 2213 | * counts during the last interrupt. The advantage of per interrupt |
| 2214 | * computation is faster updates and more accurate ITR for the current |
| 2215 | * traffic pattern. Constants in this function were computed |
| 2216 | * based on theoretical maximum wire speed and thresholds were set based |
| 2217 | * on testing data as well as attempting to minimize response time |
| 2218 | * while increasing bulk throughput. |
| 2219 | * this functionality is controlled by the InterruptThrottleRate module |
| 2220 | * parameter (see ixgbe_param.c) |
| 2221 | **/ |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2222 | static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector, |
| 2223 | struct ixgbe_ring_container *ring_container) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2224 | { |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2225 | int bytes = ring_container->total_bytes; |
| 2226 | int packets = ring_container->total_packets; |
| 2227 | u32 timepassed_us; |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2228 | u64 bytes_perint; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2229 | u8 itr_setting = ring_container->itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2230 | |
| 2231 | if (packets == 0) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2232 | return; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2233 | |
| 2234 | /* simple throttlerate management |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2235 | * 0-10MB/s lowest (100000 ints/s) |
| 2236 | * 10-20MB/s low (20000 ints/s) |
| 2237 | * 20-1249MB/s bulk (8000 ints/s) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2238 | */ |
| 2239 | /* what was last interrupt timeslice? */ |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2240 | timepassed_us = q_vector->itr >> 2; |
Don Skidmore | bdbeefe | 2013-03-02 07:17:37 +0000 | [diff] [blame] | 2241 | if (timepassed_us == 0) |
| 2242 | return; |
| 2243 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2244 | bytes_perint = bytes / timepassed_us; /* bytes/usec */ |
| 2245 | |
| 2246 | switch (itr_setting) { |
| 2247 | case lowest_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2248 | if (bytes_perint > 10) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2249 | itr_setting = low_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2250 | break; |
| 2251 | case low_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2252 | if (bytes_perint > 20) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2253 | itr_setting = bulk_latency; |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2254 | else if (bytes_perint <= 10) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2255 | itr_setting = lowest_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2256 | break; |
| 2257 | case bulk_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2258 | if (bytes_perint <= 20) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2259 | itr_setting = low_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2260 | break; |
| 2261 | } |
| 2262 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2263 | /* clear work counters since we have the values we need */ |
| 2264 | ring_container->total_bytes = 0; |
| 2265 | ring_container->total_packets = 0; |
| 2266 | |
| 2267 | /* write updated itr to ring container */ |
| 2268 | ring_container->itr = itr_setting; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2269 | } |
| 2270 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2271 | /** |
| 2272 | * ixgbe_write_eitr - write EITR register in hardware specific way |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2273 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2274 | * |
| 2275 | * This function is made to be called by ethtool and by the driver |
| 2276 | * when it needs to update EITR registers at runtime. Hardware |
| 2277 | * specific quirks/differences are taken care of here. |
| 2278 | */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2279 | void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector) |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2280 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2281 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2282 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2283 | int v_idx = q_vector->v_idx; |
Alexander Duyck | 5d967eb | 2012-02-08 07:49:43 +0000 | [diff] [blame] | 2284 | u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2285 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2286 | switch (adapter->hw.mac.type) { |
| 2287 | case ixgbe_mac_82598EB: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2288 | /* must write high and low 16 bits to reset counter */ |
| 2289 | itr_reg |= (itr_reg << 16); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2290 | break; |
| 2291 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2292 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2293 | case ixgbe_mac_X550: |
| 2294 | case ixgbe_mac_X550EM_x: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2295 | /* |
| 2296 | * set the WDIS bit to not clear the timer bits and cause an |
| 2297 | * immediate assertion of the interrupt |
| 2298 | */ |
| 2299 | itr_reg |= IXGBE_EITR_CNT_WDIS; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2300 | break; |
| 2301 | default: |
| 2302 | break; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2303 | } |
| 2304 | IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg); |
| 2305 | } |
| 2306 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2307 | static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2308 | { |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2309 | u32 new_itr = q_vector->itr; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2310 | u8 current_itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2311 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2312 | ixgbe_update_itr(q_vector, &q_vector->tx); |
| 2313 | ixgbe_update_itr(q_vector, &q_vector->rx); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2314 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2315 | current_itr = max(q_vector->rx.itr, q_vector->tx.itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2316 | |
| 2317 | switch (current_itr) { |
| 2318 | /* counts and packets in update_itr are dependent on these numbers */ |
| 2319 | case lowest_latency: |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2320 | new_itr = IXGBE_100K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2321 | break; |
| 2322 | case low_latency: |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2323 | new_itr = IXGBE_20K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2324 | break; |
| 2325 | case bulk_latency: |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2326 | new_itr = IXGBE_8K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2327 | break; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2328 | default: |
| 2329 | break; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2330 | } |
| 2331 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2332 | if (new_itr != q_vector->itr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2333 | /* do an exponential smoothing */ |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2334 | new_itr = (10 * new_itr * q_vector->itr) / |
| 2335 | ((9 * new_itr) + q_vector->itr); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2336 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2337 | /* save the algorithm value here */ |
Alexander Duyck | 5d967eb | 2012-02-08 07:49:43 +0000 | [diff] [blame] | 2338 | q_vector->itr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2339 | |
| 2340 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2341 | } |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2342 | } |
| 2343 | |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2344 | /** |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2345 | * ixgbe_check_overtemp_subtask - check for over temperature |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2346 | * @adapter: pointer to adapter |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2347 | **/ |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2348 | static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter) |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2349 | { |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2350 | struct ixgbe_hw *hw = &adapter->hw; |
| 2351 | u32 eicr = adapter->interrupt_event; |
| 2352 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2353 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2354 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2355 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2356 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) && |
| 2357 | !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT)) |
| 2358 | return; |
| 2359 | |
| 2360 | adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2361 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2362 | switch (hw->device_id) { |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2363 | case IXGBE_DEV_ID_82599_T3_LOM: |
| 2364 | /* |
| 2365 | * Since the warning interrupt is for both ports |
| 2366 | * we don't have to check if: |
| 2367 | * - This interrupt wasn't for our port. |
| 2368 | * - We may have missed the interrupt so always have to |
| 2369 | * check if we got a LSC |
| 2370 | */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2371 | if (!(eicr & IXGBE_EICR_GPI_SDP0_8259X) && |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2372 | !(eicr & IXGBE_EICR_LSC)) |
| 2373 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2374 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2375 | if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) { |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 2376 | u32 speed; |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2377 | bool link_up = false; |
| 2378 | |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 2379 | hw->mac.ops.check_link(hw, &speed, &link_up, false); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2380 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2381 | if (link_up) |
| 2382 | return; |
| 2383 | } |
| 2384 | |
| 2385 | /* Check if this is not due to overtemp */ |
| 2386 | if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP) |
| 2387 | return; |
| 2388 | |
| 2389 | break; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2390 | default: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2391 | if (!(eicr & IXGBE_EICR_GPI_SDP0(hw))) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2392 | return; |
| 2393 | break; |
| 2394 | } |
Don Skidmore | f44e751 | 2015-06-09 16:36:23 -0700 | [diff] [blame^] | 2395 | e_crit(drv, "%s\n", ixgbe_overheat_msg); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2396 | |
| 2397 | adapter->interrupt_event = 0; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2398 | } |
| 2399 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2400 | static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr) |
| 2401 | { |
| 2402 | struct ixgbe_hw *hw = &adapter->hw; |
| 2403 | |
| 2404 | if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) && |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2405 | (eicr & IXGBE_EICR_GPI_SDP1(hw))) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2406 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2407 | /* write to clear the interrupt */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2408 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw)); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2409 | } |
| 2410 | } |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2411 | |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2412 | static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 2413 | { |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2414 | struct ixgbe_hw *hw = &adapter->hw; |
| 2415 | |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2416 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)) |
| 2417 | return; |
| 2418 | |
| 2419 | switch (adapter->hw.mac.type) { |
| 2420 | case ixgbe_mac_82599EB: |
| 2421 | /* |
| 2422 | * Need to check link state so complete overtemp check |
| 2423 | * on service task |
| 2424 | */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2425 | if (((eicr & IXGBE_EICR_GPI_SDP0(hw)) || |
| 2426 | (eicr & IXGBE_EICR_LSC)) && |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2427 | (!test_bit(__IXGBE_DOWN, &adapter->state))) { |
| 2428 | adapter->interrupt_event = eicr; |
| 2429 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2430 | ixgbe_service_event_schedule(adapter); |
| 2431 | return; |
| 2432 | } |
| 2433 | return; |
| 2434 | case ixgbe_mac_X540: |
| 2435 | if (!(eicr & IXGBE_EICR_TS)) |
| 2436 | return; |
| 2437 | break; |
| 2438 | default: |
| 2439 | return; |
| 2440 | } |
| 2441 | |
Don Skidmore | f44e751 | 2015-06-09 16:36:23 -0700 | [diff] [blame^] | 2442 | e_crit(drv, "%s\n", ixgbe_overheat_msg); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2443 | } |
| 2444 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2445 | static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 2446 | { |
| 2447 | struct ixgbe_hw *hw = &adapter->hw; |
| 2448 | |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2449 | if (eicr & IXGBE_EICR_GPI_SDP2(hw)) { |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2450 | /* Clear the interrupt */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2451 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2(hw)); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2452 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2453 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 2454 | ixgbe_service_event_schedule(adapter); |
| 2455 | } |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2456 | } |
| 2457 | |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2458 | if (eicr & IXGBE_EICR_GPI_SDP1(hw)) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2459 | /* Clear the interrupt */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2460 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw)); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2461 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2462 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 2463 | ixgbe_service_event_schedule(adapter); |
| 2464 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2465 | } |
| 2466 | } |
| 2467 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2468 | static void ixgbe_check_lsc(struct ixgbe_adapter *adapter) |
| 2469 | { |
| 2470 | struct ixgbe_hw *hw = &adapter->hw; |
| 2471 | |
| 2472 | adapter->lsc_int++; |
| 2473 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 2474 | adapter->link_check_timeout = jiffies; |
| 2475 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2476 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC); |
Nelson, Shannon | 8a0717f | 2009-11-12 18:47:11 +0000 | [diff] [blame] | 2477 | IXGBE_WRITE_FLUSH(hw); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 2478 | ixgbe_service_event_schedule(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2479 | } |
| 2480 | } |
| 2481 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2482 | static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter, |
| 2483 | u64 qmask) |
| 2484 | { |
| 2485 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2486 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2487 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2488 | switch (hw->mac.type) { |
| 2489 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2490 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2491 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask); |
| 2492 | break; |
| 2493 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2494 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2495 | case ixgbe_mac_X550: |
| 2496 | case ixgbe_mac_X550EM_x: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2497 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2498 | if (mask) |
| 2499 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2500 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2501 | if (mask) |
| 2502 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask); |
| 2503 | break; |
| 2504 | default: |
| 2505 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2506 | } |
| 2507 | /* skip the flush */ |
| 2508 | } |
| 2509 | |
| 2510 | static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2511 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2512 | { |
| 2513 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2514 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2515 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2516 | switch (hw->mac.type) { |
| 2517 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2518 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2519 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask); |
| 2520 | break; |
| 2521 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2522 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2523 | case ixgbe_mac_X550: |
| 2524 | case ixgbe_mac_X550EM_x: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2525 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2526 | if (mask) |
| 2527 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2528 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2529 | if (mask) |
| 2530 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask); |
| 2531 | break; |
| 2532 | default: |
| 2533 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2534 | } |
| 2535 | /* skip the flush */ |
| 2536 | } |
| 2537 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2538 | /** |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2539 | * ixgbe_irq_enable - Enable default interrupt generation settings |
| 2540 | * @adapter: board private structure |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2541 | **/ |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2542 | static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues, |
| 2543 | bool flush) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2544 | { |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2545 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2546 | u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE); |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 2547 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2548 | /* don't reenable LSC while waiting for link */ |
| 2549 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 2550 | mask &= ~IXGBE_EIMS_LSC; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2551 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2552 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2553 | switch (adapter->hw.mac.type) { |
| 2554 | case ixgbe_mac_82599EB: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2555 | mask |= IXGBE_EIMS_GPI_SDP0(hw); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2556 | break; |
| 2557 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2558 | case ixgbe_mac_X550: |
| 2559 | case ixgbe_mac_X550EM_x: |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2560 | mask |= IXGBE_EIMS_TS; |
| 2561 | break; |
| 2562 | default: |
| 2563 | break; |
| 2564 | } |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2565 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2566 | mask |= IXGBE_EIMS_GPI_SDP1(hw); |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2567 | switch (adapter->hw.mac.type) { |
| 2568 | case ixgbe_mac_82599EB: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2569 | mask |= IXGBE_EIMS_GPI_SDP1(hw); |
| 2570 | mask |= IXGBE_EIMS_GPI_SDP2(hw); |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2571 | /* fall through */ |
Don Skidmore | 858bc08 | 2011-08-04 09:28:30 +0000 | [diff] [blame] | 2572 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2573 | case ixgbe_mac_X550: |
| 2574 | case ixgbe_mac_X550EM_x: |
Don Skidmore | 858bc08 | 2011-08-04 09:28:30 +0000 | [diff] [blame] | 2575 | mask |= IXGBE_EIMS_ECC; |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2576 | mask |= IXGBE_EIMS_MAILBOX; |
| 2577 | break; |
| 2578 | default: |
| 2579 | break; |
| 2580 | } |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2581 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2582 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) && |
| 2583 | !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 2584 | mask |= IXGBE_EIMS_FLOW_DIR; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2585 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2586 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
| 2587 | if (queues) |
| 2588 | ixgbe_irq_enable_queues(adapter, ~0); |
| 2589 | if (flush) |
| 2590 | IXGBE_WRITE_FLUSH(&adapter->hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2591 | } |
| 2592 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2593 | static irqreturn_t ixgbe_msix_other(int irq, void *data) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2594 | { |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2595 | struct ixgbe_adapter *adapter = data; |
| 2596 | struct ixgbe_hw *hw = &adapter->hw; |
| 2597 | u32 eicr; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2598 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2599 | /* |
| 2600 | * Workaround for Silicon errata. Use clear-by-write instead |
| 2601 | * of clear-by-read. Reading with EICS will return the |
| 2602 | * interrupt causes without clearing, which later be done |
| 2603 | * with the write to EICR. |
| 2604 | */ |
| 2605 | eicr = IXGBE_READ_REG(hw, IXGBE_EICS); |
Jacob Keller | d87d830 | 2013-03-02 07:51:42 +0000 | [diff] [blame] | 2606 | |
| 2607 | /* The lower 16bits of the EICR register are for the queue interrupts |
Joe Perches | dbedd44 | 2015-03-06 20:49:12 -0800 | [diff] [blame] | 2608 | * 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] | 2609 | * the bits are high when ixgbe_msix_other is called. There is a race |
| 2610 | * condition otherwise which results in possible performance loss |
| 2611 | * especially if the ixgbe_msix_other interrupt is triggering |
| 2612 | * consistently (as it would when PPS is turned on for the X540 device) |
| 2613 | */ |
| 2614 | eicr &= 0xFFFF0000; |
| 2615 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2616 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2617 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2618 | if (eicr & IXGBE_EICR_LSC) |
| 2619 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2620 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2621 | if (eicr & IXGBE_EICR_MAILBOX) |
| 2622 | ixgbe_msg_task(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2623 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2624 | switch (hw->mac.type) { |
| 2625 | case ixgbe_mac_82599EB: |
| 2626 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2627 | case ixgbe_mac_X550: |
| 2628 | case ixgbe_mac_X550EM_x: |
Don Skidmore | d773ce2 | 2014-02-25 17:58:53 -0800 | [diff] [blame] | 2629 | if (eicr & IXGBE_EICR_ECC) { |
| 2630 | e_info(link, "Received ECC Err, initiating reset\n"); |
| 2631 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; |
| 2632 | ixgbe_service_event_schedule(adapter); |
| 2633 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC); |
| 2634 | } |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2635 | /* Handle Flow Director Full threshold interrupt */ |
| 2636 | if (eicr & IXGBE_EICR_FLOW_DIR) { |
| 2637 | int reinit_count = 0; |
| 2638 | int i; |
| 2639 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2640 | struct ixgbe_ring *ring = adapter->tx_ring[i]; |
| 2641 | if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE, |
| 2642 | &ring->state)) |
| 2643 | reinit_count++; |
| 2644 | } |
| 2645 | if (reinit_count) { |
| 2646 | /* no more flow director interrupts until after init */ |
| 2647 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR); |
| 2648 | adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 2649 | ixgbe_service_event_schedule(adapter); |
| 2650 | } |
| 2651 | } |
| 2652 | ixgbe_check_sfp_event(adapter, eicr); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2653 | ixgbe_check_overtemp_event(adapter, eicr); |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2654 | break; |
| 2655 | default: |
| 2656 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2657 | } |
| 2658 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2659 | ixgbe_check_fan_failure(adapter, eicr); |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2660 | |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2661 | if (unlikely(eicr & IXGBE_EICR_TIMESYNC)) |
| 2662 | ixgbe_ptp_check_pps_event(adapter, eicr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2663 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2664 | /* re-enable the original interrupt state, no lsc, no queues */ |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2665 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2666 | ixgbe_irq_enable(adapter, false, false); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2667 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2668 | return IRQ_HANDLED; |
| 2669 | } |
| 2670 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2671 | static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2672 | { |
| 2673 | struct ixgbe_q_vector *q_vector = data; |
| 2674 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2675 | /* EIAM disabled interrupts (on this vector) for us */ |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2676 | |
| 2677 | if (q_vector->rx.ring || q_vector->tx.ring) |
| 2678 | napi_schedule(&q_vector->napi); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2679 | |
| 2680 | return IRQ_HANDLED; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2681 | } |
| 2682 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2683 | /** |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2684 | * ixgbe_poll - NAPI Rx polling callback |
| 2685 | * @napi: structure for representing this polling device |
| 2686 | * @budget: how many packets driver is allowed to clean |
| 2687 | * |
| 2688 | * This function is used for legacy and MSI, NAPI mode |
| 2689 | **/ |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 2690 | int ixgbe_poll(struct napi_struct *napi, int budget) |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2691 | { |
| 2692 | struct ixgbe_q_vector *q_vector = |
| 2693 | container_of(napi, struct ixgbe_q_vector, napi); |
| 2694 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 2695 | struct ixgbe_ring *ring; |
| 2696 | int per_ring_budget; |
| 2697 | bool clean_complete = true; |
| 2698 | |
| 2699 | #ifdef CONFIG_IXGBE_DCA |
| 2700 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 2701 | ixgbe_update_dca(q_vector); |
| 2702 | #endif |
| 2703 | |
| 2704 | ixgbe_for_each_ring(ring, q_vector->tx) |
| 2705 | clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring); |
| 2706 | |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2707 | if (!ixgbe_qv_lock_napi(q_vector)) |
| 2708 | return budget; |
| 2709 | |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2710 | /* attempt to distribute budget to each queue fairly, but don't allow |
| 2711 | * the budget to go below 1 because we'll exit polling */ |
| 2712 | if (q_vector->rx.count > 1) |
| 2713 | per_ring_budget = max(budget/q_vector->rx.count, 1); |
| 2714 | else |
| 2715 | per_ring_budget = budget; |
| 2716 | |
| 2717 | ixgbe_for_each_ring(ring, q_vector->rx) |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2718 | clean_complete &= (ixgbe_clean_rx_irq(q_vector, ring, |
| 2719 | per_ring_budget) < per_ring_budget); |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2720 | |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2721 | ixgbe_qv_unlock_napi(q_vector); |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2722 | /* If all work not completed, return budget and keep polling */ |
| 2723 | if (!clean_complete) |
| 2724 | return budget; |
| 2725 | |
| 2726 | /* all work done, exit the polling mode */ |
| 2727 | napi_complete(napi); |
| 2728 | if (adapter->rx_itr_setting & 1) |
| 2729 | ixgbe_set_itr(q_vector); |
| 2730 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2731 | ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx)); |
| 2732 | |
| 2733 | return 0; |
| 2734 | } |
| 2735 | |
| 2736 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2737 | * ixgbe_request_msix_irqs - Initialize MSI-X interrupts |
| 2738 | * @adapter: board private structure |
| 2739 | * |
| 2740 | * ixgbe_request_msix_irqs allocates MSI-X vectors and requests |
| 2741 | * interrupts from the kernel. |
| 2742 | **/ |
| 2743 | static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter) |
| 2744 | { |
| 2745 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2746 | int vector, err; |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2747 | int ri = 0, ti = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2748 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2749 | for (vector = 0; vector < adapter->num_q_vectors; vector++) { |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2750 | struct ixgbe_q_vector *q_vector = adapter->q_vector[vector]; |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2751 | struct msix_entry *entry = &adapter->msix_entries[vector]; |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 2752 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2753 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 2754 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2755 | "%s-%s-%d", netdev->name, "TxRx", ri++); |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2756 | ti++; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2757 | } else if (q_vector->rx.ring) { |
| 2758 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2759 | "%s-%s-%d", netdev->name, "rx", ri++); |
| 2760 | } else if (q_vector->tx.ring) { |
| 2761 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2762 | "%s-%s-%d", netdev->name, "tx", ti++); |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2763 | } else { |
| 2764 | /* skip this unused q_vector */ |
| 2765 | continue; |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2766 | } |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2767 | err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0, |
| 2768 | q_vector->name, q_vector); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2769 | if (err) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2770 | e_err(probe, "request_irq failed for MSIX interrupt " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 2771 | "Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2772 | goto free_queue_irqs; |
| 2773 | } |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2774 | /* If Flow Director is enabled, set interrupt affinity */ |
| 2775 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 2776 | /* assign the mask for this irq */ |
| 2777 | irq_set_affinity_hint(entry->vector, |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2778 | &q_vector->affinity_mask); |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2779 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2780 | } |
| 2781 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2782 | err = request_irq(adapter->msix_entries[vector].vector, |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2783 | ixgbe_msix_other, 0, netdev->name, adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2784 | if (err) { |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2785 | e_err(probe, "request_irq for msix_other failed: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2786 | goto free_queue_irqs; |
| 2787 | } |
| 2788 | |
| 2789 | return 0; |
| 2790 | |
| 2791 | free_queue_irqs: |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2792 | while (vector) { |
| 2793 | vector--; |
| 2794 | irq_set_affinity_hint(adapter->msix_entries[vector].vector, |
| 2795 | NULL); |
| 2796 | free_irq(adapter->msix_entries[vector].vector, |
| 2797 | adapter->q_vector[vector]); |
| 2798 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2799 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 2800 | pci_disable_msix(adapter->pdev); |
| 2801 | kfree(adapter->msix_entries); |
| 2802 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2803 | return err; |
| 2804 | } |
| 2805 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 2806 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2807 | * ixgbe_intr - legacy mode Interrupt Handler |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2808 | * @irq: interrupt number |
| 2809 | * @data: pointer to a network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2810 | **/ |
| 2811 | static irqreturn_t ixgbe_intr(int irq, void *data) |
| 2812 | { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2813 | struct ixgbe_adapter *adapter = data; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2814 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2815 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2816 | u32 eicr; |
| 2817 | |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 2818 | /* |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 2819 | * Workaround for silicon errata #26 on 82598. Mask the interrupt |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 2820 | * before the read of EICR. |
| 2821 | */ |
| 2822 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); |
| 2823 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2824 | /* 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] | 2825 | * therefore no explicit interrupt disable is necessary */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2826 | eicr = IXGBE_READ_REG(hw, IXGBE_EICR); |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2827 | if (!eicr) { |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2828 | /* |
| 2829 | * shared interrupt alert! |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2830 | * make sure interrupts are enabled because the read will |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2831 | * have disabled interrupts due to EIAM |
| 2832 | * finish the workaround of silicon errata on 82598. Unmask |
| 2833 | * the interrupt that we masked before the EICR read. |
| 2834 | */ |
| 2835 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2836 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2837 | return IRQ_NONE; /* Not our interrupt */ |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2838 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2839 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2840 | if (eicr & IXGBE_EICR_LSC) |
| 2841 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2842 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2843 | switch (hw->mac.type) { |
| 2844 | case ixgbe_mac_82599EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2845 | ixgbe_check_sfp_event(adapter, eicr); |
Don Skidmore | 0ccb974 | 2011-08-04 02:07:48 +0000 | [diff] [blame] | 2846 | /* Fall through */ |
| 2847 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2848 | case ixgbe_mac_X550: |
| 2849 | case ixgbe_mac_X550EM_x: |
Don Skidmore | d773ce2 | 2014-02-25 17:58:53 -0800 | [diff] [blame] | 2850 | if (eicr & IXGBE_EICR_ECC) { |
| 2851 | e_info(link, "Received ECC Err, initiating reset\n"); |
| 2852 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; |
| 2853 | ixgbe_service_event_schedule(adapter); |
| 2854 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC); |
| 2855 | } |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2856 | ixgbe_check_overtemp_event(adapter, eicr); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2857 | break; |
| 2858 | default: |
| 2859 | break; |
| 2860 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2861 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2862 | ixgbe_check_fan_failure(adapter, eicr); |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2863 | if (unlikely(eicr & IXGBE_EICR_TIMESYNC)) |
| 2864 | ixgbe_ptp_check_pps_event(adapter, eicr); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2865 | |
Alexander Duyck | b9f6ed2 | 2012-02-08 07:49:54 +0000 | [diff] [blame] | 2866 | /* would disable interrupts here but EIAM disabled it */ |
| 2867 | napi_schedule(&q_vector->napi); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2868 | |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2869 | /* |
| 2870 | * re-enable link(maybe) and non-queue interrupts, no flush. |
| 2871 | * ixgbe_poll will re-enable the queue interrupts |
| 2872 | */ |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2873 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2874 | ixgbe_irq_enable(adapter, false, false); |
| 2875 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2876 | return IRQ_HANDLED; |
| 2877 | } |
| 2878 | |
| 2879 | /** |
| 2880 | * ixgbe_request_irq - initialize interrupts |
| 2881 | * @adapter: board private structure |
| 2882 | * |
| 2883 | * Attempts to configure interrupts using the best available |
| 2884 | * capabilities of the hardware and kernel. |
| 2885 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2886 | static int ixgbe_request_irq(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2887 | { |
| 2888 | struct net_device *netdev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2889 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2890 | |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 2891 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2892 | err = ixgbe_request_msix_irqs(adapter); |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 2893 | else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2894 | err = request_irq(adapter->pdev->irq, ixgbe_intr, 0, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2895 | netdev->name, adapter); |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 2896 | else |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2897 | err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2898 | netdev->name, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2899 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2900 | if (err) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2901 | e_err(probe, "request_irq failed, Error %d\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2902 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2903 | return err; |
| 2904 | } |
| 2905 | |
| 2906 | static void ixgbe_free_irq(struct ixgbe_adapter *adapter) |
| 2907 | { |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2908 | int vector; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2909 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2910 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2911 | free_irq(adapter->pdev->irq, adapter); |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2912 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2913 | } |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2914 | |
| 2915 | for (vector = 0; vector < adapter->num_q_vectors; vector++) { |
| 2916 | struct ixgbe_q_vector *q_vector = adapter->q_vector[vector]; |
| 2917 | struct msix_entry *entry = &adapter->msix_entries[vector]; |
| 2918 | |
| 2919 | /* free only the irqs that were actually requested */ |
| 2920 | if (!q_vector->rx.ring && !q_vector->tx.ring) |
| 2921 | continue; |
| 2922 | |
| 2923 | /* clear the affinity_mask in the IRQ descriptor */ |
| 2924 | irq_set_affinity_hint(entry->vector, NULL); |
| 2925 | |
| 2926 | free_irq(entry->vector, q_vector); |
| 2927 | } |
| 2928 | |
| 2929 | free_irq(adapter->msix_entries[vector++].vector, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2930 | } |
| 2931 | |
| 2932 | /** |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2933 | * ixgbe_irq_disable - Mask off interrupt generation on the NIC |
| 2934 | * @adapter: board private structure |
| 2935 | **/ |
| 2936 | static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter) |
| 2937 | { |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2938 | switch (adapter->hw.mac.type) { |
| 2939 | case ixgbe_mac_82598EB: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 2940 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2941 | break; |
| 2942 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2943 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2944 | case ixgbe_mac_X550: |
| 2945 | case ixgbe_mac_X550EM_x: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 2946 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000); |
| 2947 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2948 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2949 | break; |
| 2950 | default: |
| 2951 | break; |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2952 | } |
| 2953 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 2954 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2955 | int vector; |
| 2956 | |
| 2957 | for (vector = 0; vector < adapter->num_q_vectors; vector++) |
| 2958 | synchronize_irq(adapter->msix_entries[vector].vector); |
| 2959 | |
| 2960 | synchronize_irq(adapter->msix_entries[vector++].vector); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2961 | } else { |
| 2962 | synchronize_irq(adapter->pdev->irq); |
| 2963 | } |
| 2964 | } |
| 2965 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2966 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2967 | * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts |
| 2968 | * |
| 2969 | **/ |
| 2970 | static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter) |
| 2971 | { |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2972 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2973 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2974 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2975 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2976 | ixgbe_set_ivar(adapter, 0, 0, 0); |
| 2977 | ixgbe_set_ivar(adapter, 1, 0, 0); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2978 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2979 | e_info(hw, "Legacy interrupt IVAR setup done\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2980 | } |
| 2981 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2982 | /** |
| 2983 | * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset |
| 2984 | * @adapter: board private structure |
| 2985 | * @ring: structure containing ring specific data |
| 2986 | * |
| 2987 | * Configure the Tx descriptor ring after a reset. |
| 2988 | **/ |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 2989 | void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter, |
| 2990 | struct ixgbe_ring *ring) |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2991 | { |
| 2992 | struct ixgbe_hw *hw = &adapter->hw; |
| 2993 | u64 tdba = ring->dma; |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2994 | int wait_loop = 10; |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2995 | u32 txdctl = IXGBE_TXDCTL_ENABLE; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2996 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2997 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2998 | /* disable queue to avoid issues while updating state */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2999 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3000 | IXGBE_WRITE_FLUSH(hw); |
| 3001 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3002 | IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3003 | (tdba & DMA_BIT_MASK(32))); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3004 | IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32)); |
| 3005 | IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx), |
| 3006 | ring->count * sizeof(union ixgbe_adv_tx_desc)); |
| 3007 | IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0); |
| 3008 | IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 3009 | ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3010 | |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3011 | /* |
| 3012 | * set WTHRESH to encourage burst writeback, it should not be set |
Emil Tantilov | 67da097 | 2013-01-25 06:19:20 +0000 | [diff] [blame] | 3013 | * higher than 1 when: |
| 3014 | * - ITR is 0 as it could cause false TX hangs |
| 3015 | * - ITR is set to > 100k int/sec and BQL is enabled |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3016 | * |
| 3017 | * In order to avoid issues WTHRESH + PTHRESH should always be equal |
| 3018 | * to or less than the number of on chip descriptors, which is |
| 3019 | * currently 40. |
| 3020 | */ |
Emil Tantilov | 67da097 | 2013-01-25 06:19:20 +0000 | [diff] [blame] | 3021 | if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR)) |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3022 | txdctl |= (1 << 16); /* WTHRESH = 1 */ |
| 3023 | else |
| 3024 | txdctl |= (8 << 16); /* WTHRESH = 8 */ |
| 3025 | |
Alexander Duyck | e954b37 | 2012-02-08 07:49:38 +0000 | [diff] [blame] | 3026 | /* |
| 3027 | * Setting PTHRESH to 32 both improves performance |
| 3028 | * and avoids a TX hang with DFP enabled |
| 3029 | */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3030 | txdctl |= (1 << 8) | /* HTHRESH = 1 */ |
| 3031 | 32; /* PTHRESH = 32 */ |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3032 | |
| 3033 | /* reinitialize flowdirector state */ |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 3034 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 3035 | ring->atr_sample_rate = adapter->atr_sample_rate; |
| 3036 | ring->atr_count = 0; |
| 3037 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state); |
| 3038 | } else { |
| 3039 | ring->atr_sample_rate = 0; |
| 3040 | } |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3041 | |
Alexander Duyck | fd786b7 | 2013-01-12 06:33:31 +0000 | [diff] [blame] | 3042 | /* initialize XPS */ |
| 3043 | if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) { |
| 3044 | struct ixgbe_q_vector *q_vector = ring->q_vector; |
| 3045 | |
| 3046 | if (q_vector) |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 3047 | netif_set_xps_queue(ring->netdev, |
Alexander Duyck | fd786b7 | 2013-01-12 06:33:31 +0000 | [diff] [blame] | 3048 | &q_vector->affinity_mask, |
| 3049 | ring->queue_index); |
| 3050 | } |
| 3051 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 3052 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state); |
| 3053 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3054 | /* enable queue */ |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3055 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl); |
| 3056 | |
| 3057 | /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 3058 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 3059 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 3060 | return; |
| 3061 | |
| 3062 | /* poll to verify queue is enabled */ |
| 3063 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 3064 | usleep_range(1000, 2000); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3065 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx)); |
| 3066 | } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE)); |
| 3067 | if (!wait_loop) |
| 3068 | e_err(drv, "Could not enable Tx Queue %d\n", reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3069 | } |
| 3070 | |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 3071 | static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter) |
| 3072 | { |
| 3073 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3074 | u32 rttdcs, mtqc; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3075 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 3076 | |
| 3077 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3078 | return; |
| 3079 | |
| 3080 | /* disable the arbiter while setting MTQC */ |
| 3081 | rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS); |
| 3082 | rttdcs |= IXGBE_RTTDCS_ARBDIS; |
| 3083 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 3084 | |
| 3085 | /* set transmit pool layout */ |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3086 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 3087 | mtqc = IXGBE_MTQC_VT_ENA; |
| 3088 | if (tcs > 4) |
| 3089 | mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ; |
| 3090 | else if (tcs > 1) |
| 3091 | mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ; |
| 3092 | else if (adapter->ring_feature[RING_F_RSS].indices == 4) |
| 3093 | mtqc |= IXGBE_MTQC_32VF; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3094 | else |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3095 | mtqc |= IXGBE_MTQC_64VF; |
| 3096 | } else { |
| 3097 | if (tcs > 4) |
| 3098 | mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ; |
| 3099 | else if (tcs > 1) |
| 3100 | mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ; |
| 3101 | else |
| 3102 | mtqc = IXGBE_MTQC_64Q_1PB; |
| 3103 | } |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3104 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3105 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3106 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3107 | /* Enable Security TX Buffer IFG for multiple pb */ |
| 3108 | if (tcs) { |
| 3109 | u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG); |
| 3110 | sectx |= IXGBE_SECTX_DCB; |
| 3111 | IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx); |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 3112 | } |
| 3113 | |
| 3114 | /* re-enable the arbiter */ |
| 3115 | rttdcs &= ~IXGBE_RTTDCS_ARBDIS; |
| 3116 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 3117 | } |
| 3118 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3119 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3120 | * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3121 | * @adapter: board private structure |
| 3122 | * |
| 3123 | * Configure the Tx unit of the MAC after a reset. |
| 3124 | **/ |
| 3125 | static void ixgbe_configure_tx(struct ixgbe_adapter *adapter) |
| 3126 | { |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3127 | struct ixgbe_hw *hw = &adapter->hw; |
| 3128 | u32 dmatxctl; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3129 | u32 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3130 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3131 | ixgbe_setup_mtqc(adapter); |
| 3132 | |
| 3133 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 3134 | /* DMATXCTL.EN must be before Tx queues are enabled */ |
| 3135 | dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); |
| 3136 | dmatxctl |= IXGBE_DMATXCTL_TE; |
| 3137 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl); |
| 3138 | } |
| 3139 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3140 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3141 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 3142 | ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3143 | } |
| 3144 | |
Alexander Duyck | 3ebe8fd | 2012-04-25 04:36:38 +0000 | [diff] [blame] | 3145 | static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter, |
| 3146 | struct ixgbe_ring *ring) |
| 3147 | { |
| 3148 | struct ixgbe_hw *hw = &adapter->hw; |
| 3149 | u8 reg_idx = ring->reg_idx; |
| 3150 | u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx)); |
| 3151 | |
| 3152 | srrctl |= IXGBE_SRRCTL_DROP_EN; |
| 3153 | |
| 3154 | IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl); |
| 3155 | } |
| 3156 | |
| 3157 | static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter, |
| 3158 | struct ixgbe_ring *ring) |
| 3159 | { |
| 3160 | struct ixgbe_hw *hw = &adapter->hw; |
| 3161 | u8 reg_idx = ring->reg_idx; |
| 3162 | u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx)); |
| 3163 | |
| 3164 | srrctl &= ~IXGBE_SRRCTL_DROP_EN; |
| 3165 | |
| 3166 | IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl); |
| 3167 | } |
| 3168 | |
| 3169 | #ifdef CONFIG_IXGBE_DCB |
| 3170 | void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter) |
| 3171 | #else |
| 3172 | static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter) |
| 3173 | #endif |
| 3174 | { |
| 3175 | int i; |
| 3176 | bool pfc_en = adapter->dcb_cfg.pfc_mode_enable; |
| 3177 | |
| 3178 | if (adapter->ixgbe_ieee_pfc) |
| 3179 | pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en); |
| 3180 | |
| 3181 | /* |
| 3182 | * We should set the drop enable bit if: |
| 3183 | * SR-IOV is enabled |
| 3184 | * or |
| 3185 | * Number of Rx queues > 1 and flow control is disabled |
| 3186 | * |
| 3187 | * This allows us to avoid head of line blocking for security |
| 3188 | * and performance reasons. |
| 3189 | */ |
| 3190 | if (adapter->num_vfs || (adapter->num_rx_queues > 1 && |
| 3191 | !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) { |
| 3192 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3193 | ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]); |
| 3194 | } else { |
| 3195 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3196 | ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]); |
| 3197 | } |
| 3198 | } |
| 3199 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3200 | #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3201 | |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 3202 | static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3203 | struct ixgbe_ring *rx_ring) |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3204 | { |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3205 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3206 | u32 srrctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3207 | u8 reg_idx = rx_ring->reg_idx; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3208 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3209 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 3210 | u16 mask = adapter->ring_feature[RING_F_RSS].mask; |
| 3211 | |
| 3212 | /* |
| 3213 | * if VMDq is not active we must program one srrctl register |
| 3214 | * per RSS queue since we have enabled RDRXCTL.MVMEN |
| 3215 | */ |
| 3216 | reg_idx &= mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3217 | } |
| 3218 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3219 | /* configure header buffer length, needed for RSC */ |
| 3220 | srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3221 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3222 | /* configure the packet buffer length */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 3223 | srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3224 | |
| 3225 | /* configure descriptor type */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 3226 | srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3227 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3228 | IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3229 | } |
| 3230 | |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3231 | /** |
| 3232 | * Return a number of entries in the RSS indirection table |
| 3233 | * |
| 3234 | * @adapter: device handle |
| 3235 | * |
| 3236 | * - 82598/82599/X540: 128 |
| 3237 | * - X550(non-SRIOV mode): 512 |
| 3238 | * - X550(SRIOV mode): 64 |
| 3239 | */ |
Vlad Zolotarov | 7f276ef | 2015-03-30 21:18:58 +0300 | [diff] [blame] | 3240 | u32 ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3241 | { |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3242 | if (adapter->hw.mac.type < ixgbe_mac_X550) |
| 3243 | return 128; |
| 3244 | else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 3245 | return 64; |
| 3246 | else |
| 3247 | return 512; |
| 3248 | } |
| 3249 | |
| 3250 | /** |
| 3251 | * Write the RETA table to HW |
| 3252 | * |
| 3253 | * @adapter: device handle |
| 3254 | * |
| 3255 | * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW. |
| 3256 | */ |
| 3257 | static void ixgbe_store_reta(struct ixgbe_adapter *adapter) |
| 3258 | { |
| 3259 | u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter); |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3260 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3261 | u32 reta = 0; |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3262 | u32 indices_multi; |
| 3263 | u8 *indir_tbl = adapter->rss_indir_tbl; |
John Fastabend | 86b4db3 | 2011-04-26 07:26:19 +0000 | [diff] [blame] | 3264 | |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3265 | /* Fill out the redirection table as follows: |
| 3266 | * - 82598: 8 bit wide entries containing pair of 4 bit RSS |
| 3267 | * indices. |
| 3268 | * - 82599/X540: 8 bit wide entries containing 4 bit RSS index |
| 3269 | * - X550: 8 bit wide entries containing 6 bit RSS index |
| 3270 | */ |
| 3271 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 3272 | indices_multi = 0x11; |
| 3273 | else |
| 3274 | indices_multi = 0x1; |
| 3275 | |
| 3276 | /* Write redirection table to HW */ |
| 3277 | for (i = 0; i < reta_entries; i++) { |
| 3278 | reta |= indices_multi * indir_tbl[i] << (i & 0x3) * 8; |
| 3279 | if ((i & 3) == 3) { |
| 3280 | if (i < 128) |
| 3281 | IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); |
| 3282 | else |
| 3283 | IXGBE_WRITE_REG(hw, IXGBE_ERETA((i >> 2) - 32), |
| 3284 | reta); |
| 3285 | reta = 0; |
| 3286 | } |
| 3287 | } |
| 3288 | } |
| 3289 | |
| 3290 | /** |
| 3291 | * Write the RETA table to HW (for x550 devices in SRIOV mode) |
| 3292 | * |
| 3293 | * @adapter: device handle |
| 3294 | * |
| 3295 | * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW. |
| 3296 | */ |
| 3297 | static void ixgbe_store_vfreta(struct ixgbe_adapter *adapter) |
| 3298 | { |
| 3299 | u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter); |
| 3300 | struct ixgbe_hw *hw = &adapter->hw; |
| 3301 | u32 vfreta = 0; |
| 3302 | unsigned int pf_pool = adapter->num_vfs; |
| 3303 | |
| 3304 | /* Write redirection table to HW */ |
| 3305 | for (i = 0; i < reta_entries; i++) { |
| 3306 | vfreta |= (u32)adapter->rss_indir_tbl[i] << (i & 0x3) * 8; |
| 3307 | if ((i & 3) == 3) { |
| 3308 | IXGBE_WRITE_REG(hw, IXGBE_PFVFRETA(i >> 2, pf_pool), |
| 3309 | vfreta); |
| 3310 | vfreta = 0; |
| 3311 | } |
| 3312 | } |
| 3313 | } |
| 3314 | |
| 3315 | static void ixgbe_setup_reta(struct ixgbe_adapter *adapter) |
| 3316 | { |
| 3317 | struct ixgbe_hw *hw = &adapter->hw; |
| 3318 | u32 i, j; |
| 3319 | u32 reta_entries = ixgbe_rss_indir_tbl_entries(adapter); |
| 3320 | u16 rss_i = adapter->ring_feature[RING_F_RSS].indices; |
| 3321 | |
| 3322 | /* 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] | 3323 | * make full use of any rings they may have. We will use the |
| 3324 | * PSRTYPE register to control how many rings we use within the PF. |
| 3325 | */ |
| 3326 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 2)) |
| 3327 | rss_i = 2; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3328 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3329 | /* Fill out hash function seeds */ |
| 3330 | for (i = 0; i < 10; i++) |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3331 | IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), adapter->rss_key[i]); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3332 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3333 | /* Fill out redirection table */ |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3334 | memset(adapter->rss_indir_tbl, 0, sizeof(adapter->rss_indir_tbl)); |
| 3335 | |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3336 | for (i = 0, j = 0; i < reta_entries; i++, j++) { |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3337 | if (j == rss_i) |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3338 | j = 0; |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3339 | |
| 3340 | adapter->rss_indir_tbl[i] = j; |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3341 | } |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3342 | |
| 3343 | ixgbe_store_reta(adapter); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3344 | } |
| 3345 | |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3346 | static void ixgbe_setup_vfreta(struct ixgbe_adapter *adapter) |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3347 | { |
| 3348 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3349 | u16 rss_i = adapter->ring_feature[RING_F_RSS].indices; |
| 3350 | unsigned int pf_pool = adapter->num_vfs; |
| 3351 | int i, j; |
| 3352 | |
| 3353 | /* Fill out hash function seeds */ |
| 3354 | for (i = 0; i < 10; i++) |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3355 | IXGBE_WRITE_REG(hw, IXGBE_PFVFRSSRK(i, pf_pool), |
| 3356 | adapter->rss_key[i]); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3357 | |
| 3358 | /* Fill out the redirection table */ |
| 3359 | for (i = 0, j = 0; i < 64; i++, j++) { |
| 3360 | if (j == rss_i) |
| 3361 | j = 0; |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3362 | |
| 3363 | adapter->rss_indir_tbl[i] = j; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3364 | } |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3365 | |
| 3366 | ixgbe_store_vfreta(adapter); |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3367 | } |
| 3368 | |
| 3369 | static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter) |
| 3370 | { |
| 3371 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3372 | u32 mrqc = 0, rss_field = 0, vfmrqc = 0; |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3373 | u32 rxcsum; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3374 | |
| 3375 | /* Disable indicating checksum in descriptor, enables RSS hash */ |
| 3376 | rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); |
| 3377 | rxcsum |= IXGBE_RXCSUM_PCSD; |
| 3378 | IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); |
| 3379 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3380 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 3381 | if (adapter->ring_feature[RING_F_RSS].mask) |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3382 | mrqc = IXGBE_MRQC_RSSEN; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3383 | } else { |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3384 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3385 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3386 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 3387 | if (tcs > 4) |
| 3388 | mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */ |
| 3389 | else if (tcs > 1) |
| 3390 | mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */ |
| 3391 | else if (adapter->ring_feature[RING_F_RSS].indices == 4) |
| 3392 | mrqc = IXGBE_MRQC_VMDQRSS32EN; |
| 3393 | else |
| 3394 | mrqc = IXGBE_MRQC_VMDQRSS64EN; |
| 3395 | } else { |
| 3396 | if (tcs > 4) |
| 3397 | mrqc = IXGBE_MRQC_RTRSS8TCEN; |
| 3398 | else if (tcs > 1) |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3399 | mrqc = IXGBE_MRQC_RTRSS4TCEN; |
| 3400 | else |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3401 | mrqc = IXGBE_MRQC_RSSEN; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3402 | } |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3403 | } |
| 3404 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3405 | /* Perform hash on these packet types */ |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3406 | rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4 | |
| 3407 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP | |
| 3408 | IXGBE_MRQC_RSS_FIELD_IPV6 | |
| 3409 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3410 | |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 3411 | if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP) |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3412 | rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP; |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 3413 | if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP) |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3414 | rss_field |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP; |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 3415 | |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3416 | netdev_rss_key_fill(adapter->rss_key, sizeof(adapter->rss_key)); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3417 | if ((hw->mac.type >= ixgbe_mac_X550) && |
| 3418 | (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) { |
| 3419 | unsigned int pf_pool = adapter->num_vfs; |
| 3420 | |
| 3421 | /* Enable VF RSS mode */ |
| 3422 | mrqc |= IXGBE_MRQC_MULTIPLE_RSS; |
| 3423 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
| 3424 | |
| 3425 | /* Setup RSS through the VF registers */ |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3426 | ixgbe_setup_vfreta(adapter); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3427 | vfmrqc = IXGBE_MRQC_RSSEN; |
| 3428 | vfmrqc |= rss_field; |
| 3429 | IXGBE_WRITE_REG(hw, IXGBE_PFVFMRQC(pf_pool), vfmrqc); |
| 3430 | } else { |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3431 | ixgbe_setup_reta(adapter); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3432 | mrqc |= rss_field; |
| 3433 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
| 3434 | } |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3435 | } |
| 3436 | |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3437 | /** |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3438 | * ixgbe_configure_rscctl - enable RSC for the indicated ring |
| 3439 | * @adapter: address of board private structure |
| 3440 | * @index: index of ring to set |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3441 | **/ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 3442 | static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3443 | struct ixgbe_ring *ring) |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3444 | { |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3445 | struct ixgbe_hw *hw = &adapter->hw; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3446 | u32 rscctrl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3447 | u8 reg_idx = ring->reg_idx; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3448 | |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3449 | if (!ring_is_rsc_enabled(ring)) |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3450 | return; |
| 3451 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3452 | rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx)); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3453 | rscctrl |= IXGBE_RSCCTL_RSCEN; |
| 3454 | /* |
| 3455 | * we must limit the number of descriptors so that the |
| 3456 | * total size of max desc * buf_len is not greater |
Alexander Duyck | 642c680 | 2011-11-10 09:09:17 +0000 | [diff] [blame] | 3457 | * than 65536 |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3458 | */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 3459 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3460 | IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3461 | } |
| 3462 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3463 | #define IXGBE_MAX_RX_DESC_POLL 10 |
| 3464 | static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter, |
| 3465 | struct ixgbe_ring *ring) |
| 3466 | { |
| 3467 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3468 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 3469 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3470 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3471 | |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 3472 | if (ixgbe_removed(hw->hw_addr)) |
| 3473 | return; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3474 | /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 3475 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 3476 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 3477 | return; |
| 3478 | |
| 3479 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 3480 | usleep_range(1000, 2000); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3481 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 3482 | } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 3483 | |
| 3484 | if (!wait_loop) { |
| 3485 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within " |
| 3486 | "the polling period\n", reg_idx); |
| 3487 | } |
| 3488 | } |
| 3489 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 3490 | void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter, |
| 3491 | struct ixgbe_ring *ring) |
| 3492 | { |
| 3493 | struct ixgbe_hw *hw = &adapter->hw; |
| 3494 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 3495 | u32 rxdctl; |
| 3496 | u8 reg_idx = ring->reg_idx; |
| 3497 | |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 3498 | if (ixgbe_removed(hw->hw_addr)) |
| 3499 | return; |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 3500 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 3501 | rxdctl &= ~IXGBE_RXDCTL_ENABLE; |
| 3502 | |
| 3503 | /* write value back with RXDCTL.ENABLE bit cleared */ |
| 3504 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 3505 | |
| 3506 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 3507 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 3508 | return; |
| 3509 | |
| 3510 | /* the hardware may take up to 100us to really disable the rx queue */ |
| 3511 | do { |
| 3512 | udelay(10); |
| 3513 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 3514 | } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 3515 | |
| 3516 | if (!wait_loop) { |
| 3517 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within " |
| 3518 | "the polling period\n", reg_idx); |
| 3519 | } |
| 3520 | } |
| 3521 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 3522 | void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter, |
| 3523 | struct ixgbe_ring *ring) |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3524 | { |
| 3525 | struct ixgbe_hw *hw = &adapter->hw; |
| 3526 | u64 rdba = ring->dma; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3527 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3528 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3529 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3530 | /* disable queue to avoid issues while updating state */ |
| 3531 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 3532 | ixgbe_disable_rx_queue(adapter, ring); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3533 | |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3534 | IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32))); |
| 3535 | IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32)); |
| 3536 | IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx), |
| 3537 | ring->count * sizeof(union ixgbe_adv_rx_desc)); |
| 3538 | IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0); |
| 3539 | IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 3540 | ring->tail = adapter->io_addr + IXGBE_RDT(reg_idx); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3541 | |
| 3542 | ixgbe_configure_srrctl(adapter, ring); |
| 3543 | ixgbe_configure_rscctl(adapter, ring); |
| 3544 | |
| 3545 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 3546 | /* |
| 3547 | * enable cache line friendly hardware writes: |
| 3548 | * PTHRESH=32 descriptors (half the internal cache), |
| 3549 | * this also removes ugly rx_no_buffer_count increment |
| 3550 | * HTHRESH=4 descriptors (to minimize latency on fetch) |
| 3551 | * WTHRESH=8 burst writeback up to two cache lines |
| 3552 | */ |
| 3553 | rxdctl &= ~0x3FFFFF; |
| 3554 | rxdctl |= 0x080420; |
| 3555 | } |
| 3556 | |
| 3557 | /* enable receive descriptor ring */ |
| 3558 | rxdctl |= IXGBE_RXDCTL_ENABLE; |
| 3559 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 3560 | |
| 3561 | ixgbe_rx_desc_queue_enable(adapter, ring); |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 3562 | ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring)); |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3563 | } |
| 3564 | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3565 | static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter) |
| 3566 | { |
| 3567 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 3568 | int rss_i = adapter->ring_feature[RING_F_RSS].indices; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 3569 | u16 pool; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3570 | |
| 3571 | /* PSRTYPE must be initialized in non 82598 adapters */ |
| 3572 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3573 | IXGBE_PSRTYPE_UDPHDR | |
| 3574 | IXGBE_PSRTYPE_IPV4HDR | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3575 | IXGBE_PSRTYPE_L2HDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3576 | IXGBE_PSRTYPE_IPV6HDR; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3577 | |
| 3578 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3579 | return; |
| 3580 | |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 3581 | if (rss_i > 3) |
| 3582 | psrtype |= 2 << 29; |
| 3583 | else if (rss_i > 1) |
| 3584 | psrtype |= 1 << 29; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3585 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 3586 | for_each_set_bit(pool, &adapter->fwd_bitmask, 32) |
| 3587 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype); |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3588 | } |
| 3589 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3590 | static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter) |
| 3591 | { |
| 3592 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3593 | u32 reg_offset, vf_shift; |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3594 | u32 gcr_ext, vmdctl; |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 3595 | int i; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3596 | |
| 3597 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 3598 | return; |
| 3599 | |
| 3600 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL); |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3601 | vmdctl |= IXGBE_VMD_CTL_VMDQ_EN; |
| 3602 | vmdctl &= ~IXGBE_VT_CTL_POOL_MASK; |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3603 | vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT; |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3604 | vmdctl |= IXGBE_VT_CTL_REPLEN; |
| 3605 | IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3606 | |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3607 | vf_shift = VMDQ_P(0) % 32; |
| 3608 | reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3609 | |
| 3610 | /* Enable only the PF's pool for Tx/Rx */ |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3611 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (~0) << vf_shift); |
| 3612 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1); |
| 3613 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (~0) << vf_shift); |
| 3614 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1); |
Don Skidmore | aa2bacb | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 3615 | if (adapter->bridge_mode == BRIDGE_MODE_VEB) |
Greg Rose | 9b73598 | 2012-11-08 02:41:35 +0000 | [diff] [blame] | 3616 | IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3617 | |
| 3618 | /* 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] | 3619 | hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0)); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3620 | |
| 3621 | /* |
| 3622 | * Set up VF register offsets for selected VT Mode, |
| 3623 | * i.e. 32 or 64 VFs for SR-IOV |
| 3624 | */ |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 3625 | switch (adapter->ring_feature[RING_F_VMDQ].mask) { |
| 3626 | case IXGBE_82599_VMDQ_8Q_MASK: |
| 3627 | gcr_ext = IXGBE_GCR_EXT_VT_MODE_16; |
| 3628 | break; |
| 3629 | case IXGBE_82599_VMDQ_4Q_MASK: |
| 3630 | gcr_ext = IXGBE_GCR_EXT_VT_MODE_32; |
| 3631 | break; |
| 3632 | default: |
| 3633 | gcr_ext = IXGBE_GCR_EXT_VT_MODE_64; |
| 3634 | break; |
| 3635 | } |
| 3636 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3637 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext); |
| 3638 | |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3639 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 3640 | /* Enable MAC Anti-Spoofing */ |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3641 | hw->mac.ops.set_mac_anti_spoofing(hw, (adapter->num_vfs != 0), |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 3642 | adapter->num_vfs); |
Don Skidmore | 5b7f000 | 2015-01-28 07:03:38 +0000 | [diff] [blame] | 3643 | |
| 3644 | /* Ensure LLDP is set for Ethertype Antispoofing if we will be |
| 3645 | * calling set_ethertype_anti_spoofing for each VF in loop below |
| 3646 | */ |
| 3647 | if (hw->mac.ops.set_ethertype_anti_spoofing) |
| 3648 | IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_LLDP), |
| 3649 | (IXGBE_ETQF_FILTER_EN | /* enable filter */ |
| 3650 | IXGBE_ETQF_TX_ANTISPOOF | /* tx antispoof */ |
| 3651 | IXGBE_ETH_P_LLDP)); /* LLDP eth type */ |
| 3652 | |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 3653 | /* For VFs that have spoof checking turned off */ |
| 3654 | for (i = 0; i < adapter->num_vfs; i++) { |
| 3655 | if (!adapter->vfinfo[i].spoofchk_enabled) |
| 3656 | ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false); |
Don Skidmore | 5b7f000 | 2015-01-28 07:03:38 +0000 | [diff] [blame] | 3657 | |
| 3658 | /* enable ethertype anti spoofing if hw supports it */ |
| 3659 | if (hw->mac.ops.set_ethertype_anti_spoofing) |
| 3660 | hw->mac.ops.set_ethertype_anti_spoofing(hw, true, i); |
Vlad Zolotarov | e65ce0d | 2015-03-30 21:35:24 +0300 | [diff] [blame] | 3661 | |
| 3662 | /* Enable/Disable RSS query feature */ |
| 3663 | ixgbe_ndo_set_vf_rss_query_en(adapter->netdev, i, |
| 3664 | adapter->vfinfo[i].rss_query_enabled); |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 3665 | } |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3666 | } |
| 3667 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3668 | static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3669 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3670 | struct ixgbe_hw *hw = &adapter->hw; |
| 3671 | struct net_device *netdev = adapter->netdev; |
| 3672 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3673 | struct ixgbe_ring *rx_ring; |
| 3674 | int i; |
| 3675 | u32 mhadd, hlreg0; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3676 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3677 | #ifdef IXGBE_FCOE |
| 3678 | /* adjust max frame to be able to do baby jumbo for FCoE */ |
| 3679 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 3680 | (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE)) |
| 3681 | max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 3682 | |
| 3683 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 3684 | |
| 3685 | /* adjust max frame to be at least the size of a standard frame */ |
| 3686 | if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN)) |
| 3687 | max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN); |
| 3688 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3689 | mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD); |
| 3690 | if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) { |
| 3691 | mhadd &= ~IXGBE_MHADD_MFS_MASK; |
| 3692 | mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT; |
| 3693 | |
| 3694 | IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3695 | } |
| 3696 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3697 | hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3698 | /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */ |
| 3699 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3700 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0); |
| 3701 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3702 | /* |
| 3703 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3704 | * the Base and Length of the Rx Descriptor Ring |
| 3705 | */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3706 | for (i = 0; i < adapter->num_rx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3707 | rx_ring = adapter->rx_ring[i]; |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3708 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
| 3709 | set_ring_rsc_enabled(rx_ring); |
| 3710 | else |
| 3711 | clear_ring_rsc_enabled(rx_ring); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3712 | } |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3713 | } |
| 3714 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3715 | static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter) |
| 3716 | { |
| 3717 | struct ixgbe_hw *hw = &adapter->hw; |
| 3718 | u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 3719 | |
| 3720 | switch (hw->mac.type) { |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 3721 | case ixgbe_mac_X550: |
| 3722 | case ixgbe_mac_X550EM_x: |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3723 | case ixgbe_mac_82598EB: |
| 3724 | /* |
| 3725 | * For VMDq support of different descriptor types or |
| 3726 | * buffer sizes through the use of multiple SRRCTL |
| 3727 | * registers, RDRXCTL.MVMEN must be set to 1 |
| 3728 | * |
| 3729 | * also, the manual doesn't mention it clearly but DCA hints |
| 3730 | * will only use queue 0's tags unless this bit is set. Side |
| 3731 | * effects of setting this bit are only that SRRCTL must be |
| 3732 | * fully programmed [0..15] |
| 3733 | */ |
| 3734 | rdrxctl |= IXGBE_RDRXCTL_MVMEN; |
| 3735 | break; |
| 3736 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3737 | case ixgbe_mac_X540: |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3738 | /* Disable RSC for ACK packets */ |
| 3739 | IXGBE_WRITE_REG(hw, IXGBE_RSCDBU, |
| 3740 | (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU))); |
| 3741 | rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE; |
| 3742 | /* hardware requires some bits to be set by default */ |
| 3743 | rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX); |
| 3744 | rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP; |
| 3745 | break; |
| 3746 | default: |
| 3747 | /* We should do nothing since we don't know this hardware */ |
| 3748 | return; |
| 3749 | } |
| 3750 | |
| 3751 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
| 3752 | } |
| 3753 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3754 | /** |
| 3755 | * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset |
| 3756 | * @adapter: board private structure |
| 3757 | * |
| 3758 | * Configure the Rx unit of the MAC after a reset. |
| 3759 | **/ |
| 3760 | static void ixgbe_configure_rx(struct ixgbe_adapter *adapter) |
| 3761 | { |
| 3762 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3763 | int i; |
Jacob Keller | 6dcc28b | 2013-07-17 02:53:23 +0000 | [diff] [blame] | 3764 | u32 rxctrl, rfctl; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3765 | |
| 3766 | /* disable receives while setting up the descriptors */ |
Don Skidmore | 1f9ac57 | 2015-03-13 13:54:30 -0700 | [diff] [blame] | 3767 | hw->mac.ops.disable_rx(hw); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3768 | |
| 3769 | ixgbe_setup_psrtype(adapter); |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3770 | ixgbe_setup_rdrxctl(adapter); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3771 | |
Jacob Keller | 6dcc28b | 2013-07-17 02:53:23 +0000 | [diff] [blame] | 3772 | /* RSC Setup */ |
| 3773 | rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL); |
| 3774 | rfctl &= ~IXGBE_RFCTL_RSC_DIS; |
| 3775 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) |
| 3776 | rfctl |= IXGBE_RFCTL_RSC_DIS; |
| 3777 | IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl); |
| 3778 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3779 | /* Program registers for the distribution of queues */ |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3780 | ixgbe_setup_mrqc(adapter); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3781 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3782 | /* set_rx_buffer_len must be called before ring initialization */ |
| 3783 | ixgbe_set_rx_buffer_len(adapter); |
| 3784 | |
| 3785 | /* |
| 3786 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3787 | * the Base and Length of the Rx Descriptor Ring |
| 3788 | */ |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3789 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3790 | ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3791 | |
Don Skidmore | 1f9ac57 | 2015-03-13 13:54:30 -0700 | [diff] [blame] | 3792 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3793 | /* disable drop enable for 82598 parts */ |
| 3794 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3795 | rxctrl |= IXGBE_RXCTRL_DMBYPS; |
| 3796 | |
| 3797 | /* enable all receives */ |
| 3798 | rxctrl |= IXGBE_RXCTRL_RXEN; |
| 3799 | hw->mac.ops.enable_rx_dma(hw, rxctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3800 | } |
| 3801 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 3802 | static int ixgbe_vlan_rx_add_vid(struct net_device *netdev, |
| 3803 | __be16 proto, u16 vid) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3804 | { |
| 3805 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3806 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3807 | |
| 3808 | /* add VID to filter table */ |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3809 | hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3810 | set_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 3811 | |
| 3812 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3813 | } |
| 3814 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 3815 | static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev, |
| 3816 | __be16 proto, u16 vid) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3817 | { |
| 3818 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3819 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3820 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3821 | /* remove VID from filter table */ |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3822 | hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), false); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3823 | clear_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 3824 | |
| 3825 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3826 | } |
| 3827 | |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3828 | /** |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3829 | * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping |
| 3830 | * @adapter: driver data |
| 3831 | */ |
| 3832 | static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter) |
| 3833 | { |
| 3834 | struct ixgbe_hw *hw = &adapter->hw; |
| 3835 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3836 | int i, j; |
| 3837 | |
| 3838 | switch (hw->mac.type) { |
| 3839 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3840 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3841 | vlnctrl &= ~IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3842 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3843 | break; |
| 3844 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3845 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 3846 | case ixgbe_mac_X550: |
| 3847 | case ixgbe_mac_X550EM_x: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3848 | for (i = 0; i < adapter->num_rx_queues; i++) { |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 3849 | struct ixgbe_ring *ring = adapter->rx_ring[i]; |
| 3850 | |
| 3851 | if (ring->l2_accel_priv) |
| 3852 | continue; |
| 3853 | j = ring->reg_idx; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3854 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 3855 | vlnctrl &= ~IXGBE_RXDCTL_VME; |
| 3856 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 3857 | } |
| 3858 | break; |
| 3859 | default: |
| 3860 | break; |
| 3861 | } |
| 3862 | } |
| 3863 | |
| 3864 | /** |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3865 | * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3866 | * @adapter: driver data |
| 3867 | */ |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3868 | static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3869 | { |
| 3870 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3871 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3872 | int i, j; |
| 3873 | |
| 3874 | switch (hw->mac.type) { |
| 3875 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3876 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3877 | vlnctrl |= IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3878 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3879 | break; |
| 3880 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3881 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 3882 | case ixgbe_mac_X550: |
| 3883 | case ixgbe_mac_X550EM_x: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3884 | for (i = 0; i < adapter->num_rx_queues; i++) { |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 3885 | struct ixgbe_ring *ring = adapter->rx_ring[i]; |
| 3886 | |
| 3887 | if (ring->l2_accel_priv) |
| 3888 | continue; |
| 3889 | j = ring->reg_idx; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3890 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 3891 | vlnctrl |= IXGBE_RXDCTL_VME; |
| 3892 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 3893 | } |
| 3894 | break; |
| 3895 | default: |
| 3896 | break; |
| 3897 | } |
| 3898 | } |
| 3899 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3900 | static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter) |
| 3901 | { |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3902 | u16 vid; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3903 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 3904 | ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3905 | |
| 3906 | for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID) |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 3907 | ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3908 | } |
| 3909 | |
| 3910 | /** |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 3911 | * ixgbe_write_mc_addr_list - write multicast addresses to MTA |
| 3912 | * @netdev: network interface device structure |
| 3913 | * |
| 3914 | * Writes multicast address list to the MTA hash table. |
| 3915 | * Returns: -ENOMEM on failure |
| 3916 | * 0 on no addresses written |
| 3917 | * X on writing X addresses to MTA |
| 3918 | **/ |
| 3919 | static int ixgbe_write_mc_addr_list(struct net_device *netdev) |
| 3920 | { |
| 3921 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3922 | struct ixgbe_hw *hw = &adapter->hw; |
| 3923 | |
| 3924 | if (!netif_running(netdev)) |
| 3925 | return 0; |
| 3926 | |
| 3927 | if (hw->mac.ops.update_mc_addr_list) |
| 3928 | hw->mac.ops.update_mc_addr_list(hw, netdev); |
| 3929 | else |
| 3930 | return -ENOMEM; |
| 3931 | |
| 3932 | #ifdef CONFIG_PCI_IOV |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 3933 | ixgbe_restore_vf_multicasts(adapter); |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 3934 | #endif |
| 3935 | |
| 3936 | return netdev_mc_count(netdev); |
| 3937 | } |
| 3938 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 3939 | #ifdef CONFIG_PCI_IOV |
| 3940 | void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter) |
| 3941 | { |
| 3942 | struct ixgbe_hw *hw = &adapter->hw; |
| 3943 | int i; |
| 3944 | for (i = 0; i < hw->mac.num_rar_entries; i++) { |
| 3945 | if (adapter->mac_table[i].state & IXGBE_MAC_STATE_IN_USE) |
| 3946 | hw->mac.ops.set_rar(hw, i, adapter->mac_table[i].addr, |
| 3947 | adapter->mac_table[i].queue, |
| 3948 | IXGBE_RAH_AV); |
| 3949 | else |
| 3950 | hw->mac.ops.clear_rar(hw, i); |
| 3951 | |
| 3952 | adapter->mac_table[i].state &= ~(IXGBE_MAC_STATE_MODIFIED); |
| 3953 | } |
| 3954 | } |
| 3955 | #endif |
| 3956 | |
| 3957 | static void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter) |
| 3958 | { |
| 3959 | struct ixgbe_hw *hw = &adapter->hw; |
| 3960 | int i; |
| 3961 | for (i = 0; i < hw->mac.num_rar_entries; i++) { |
| 3962 | if (adapter->mac_table[i].state & IXGBE_MAC_STATE_MODIFIED) { |
| 3963 | if (adapter->mac_table[i].state & |
| 3964 | IXGBE_MAC_STATE_IN_USE) |
| 3965 | hw->mac.ops.set_rar(hw, i, |
| 3966 | adapter->mac_table[i].addr, |
| 3967 | adapter->mac_table[i].queue, |
| 3968 | IXGBE_RAH_AV); |
| 3969 | else |
| 3970 | hw->mac.ops.clear_rar(hw, i); |
| 3971 | |
| 3972 | adapter->mac_table[i].state &= |
| 3973 | ~(IXGBE_MAC_STATE_MODIFIED); |
| 3974 | } |
| 3975 | } |
| 3976 | } |
| 3977 | |
| 3978 | static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter) |
| 3979 | { |
| 3980 | int i; |
| 3981 | struct ixgbe_hw *hw = &adapter->hw; |
| 3982 | |
| 3983 | for (i = 0; i < hw->mac.num_rar_entries; i++) { |
| 3984 | adapter->mac_table[i].state |= IXGBE_MAC_STATE_MODIFIED; |
| 3985 | adapter->mac_table[i].state &= ~IXGBE_MAC_STATE_IN_USE; |
Joe Perches | c7bf716 | 2015-03-02 19:54:47 -0800 | [diff] [blame] | 3986 | eth_zero_addr(adapter->mac_table[i].addr); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 3987 | adapter->mac_table[i].queue = 0; |
| 3988 | } |
| 3989 | ixgbe_sync_mac_table(adapter); |
| 3990 | } |
| 3991 | |
| 3992 | static int ixgbe_available_rars(struct ixgbe_adapter *adapter) |
| 3993 | { |
| 3994 | struct ixgbe_hw *hw = &adapter->hw; |
| 3995 | int i, count = 0; |
| 3996 | |
| 3997 | for (i = 0; i < hw->mac.num_rar_entries; i++) { |
| 3998 | if (adapter->mac_table[i].state == 0) |
| 3999 | count++; |
| 4000 | } |
| 4001 | return count; |
| 4002 | } |
| 4003 | |
| 4004 | /* this function destroys the first RAR entry */ |
| 4005 | static void ixgbe_mac_set_default_filter(struct ixgbe_adapter *adapter, |
| 4006 | u8 *addr) |
| 4007 | { |
| 4008 | struct ixgbe_hw *hw = &adapter->hw; |
| 4009 | |
| 4010 | memcpy(&adapter->mac_table[0].addr, addr, ETH_ALEN); |
| 4011 | adapter->mac_table[0].queue = VMDQ_P(0); |
| 4012 | adapter->mac_table[0].state = (IXGBE_MAC_STATE_DEFAULT | |
| 4013 | IXGBE_MAC_STATE_IN_USE); |
| 4014 | hw->mac.ops.set_rar(hw, 0, adapter->mac_table[0].addr, |
| 4015 | adapter->mac_table[0].queue, |
| 4016 | IXGBE_RAH_AV); |
| 4017 | } |
| 4018 | |
| 4019 | int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter, u8 *addr, u16 queue) |
| 4020 | { |
| 4021 | struct ixgbe_hw *hw = &adapter->hw; |
| 4022 | int i; |
| 4023 | |
| 4024 | if (is_zero_ether_addr(addr)) |
| 4025 | return -EINVAL; |
| 4026 | |
| 4027 | for (i = 0; i < hw->mac.num_rar_entries; i++) { |
| 4028 | if (adapter->mac_table[i].state & IXGBE_MAC_STATE_IN_USE) |
| 4029 | continue; |
| 4030 | adapter->mac_table[i].state |= (IXGBE_MAC_STATE_MODIFIED | |
| 4031 | IXGBE_MAC_STATE_IN_USE); |
| 4032 | ether_addr_copy(adapter->mac_table[i].addr, addr); |
| 4033 | adapter->mac_table[i].queue = queue; |
| 4034 | ixgbe_sync_mac_table(adapter); |
| 4035 | return i; |
| 4036 | } |
| 4037 | return -ENOMEM; |
| 4038 | } |
| 4039 | |
| 4040 | int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter, u8 *addr, u16 queue) |
| 4041 | { |
| 4042 | /* search table for addr, if found, set to 0 and sync */ |
| 4043 | int i; |
| 4044 | struct ixgbe_hw *hw = &adapter->hw; |
| 4045 | |
| 4046 | if (is_zero_ether_addr(addr)) |
| 4047 | return -EINVAL; |
| 4048 | |
| 4049 | for (i = 0; i < hw->mac.num_rar_entries; i++) { |
| 4050 | if (ether_addr_equal(addr, adapter->mac_table[i].addr) && |
| 4051 | adapter->mac_table[i].queue == queue) { |
| 4052 | adapter->mac_table[i].state |= IXGBE_MAC_STATE_MODIFIED; |
| 4053 | adapter->mac_table[i].state &= ~IXGBE_MAC_STATE_IN_USE; |
Joe Perches | c7bf716 | 2015-03-02 19:54:47 -0800 | [diff] [blame] | 4054 | eth_zero_addr(adapter->mac_table[i].addr); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4055 | adapter->mac_table[i].queue = 0; |
| 4056 | ixgbe_sync_mac_table(adapter); |
| 4057 | return 0; |
| 4058 | } |
| 4059 | } |
| 4060 | return -ENOMEM; |
| 4061 | } |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4062 | /** |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4063 | * ixgbe_write_uc_addr_list - write unicast addresses to RAR table |
| 4064 | * @netdev: network interface device structure |
| 4065 | * |
| 4066 | * Writes unicast address list to the RAR table. |
| 4067 | * Returns: -ENOMEM on failure/insufficient address space |
| 4068 | * 0 on no addresses written |
| 4069 | * X on writing X addresses to the RAR table |
| 4070 | **/ |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4071 | 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] | 4072 | { |
| 4073 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4074 | int count = 0; |
| 4075 | |
| 4076 | /* return ENOMEM indicating insufficient memory for addresses */ |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4077 | if (netdev_uc_count(netdev) > ixgbe_available_rars(adapter)) |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4078 | return -ENOMEM; |
| 4079 | |
John Fastabend | 9544746 | 2012-05-31 12:42:26 +0000 | [diff] [blame] | 4080 | if (!netdev_uc_empty(netdev)) { |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4081 | struct netdev_hw_addr *ha; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4082 | netdev_for_each_uc_addr(ha, netdev) { |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4083 | ixgbe_del_mac_filter(adapter, ha->addr, vfn); |
| 4084 | ixgbe_add_mac_filter(adapter, ha->addr, vfn); |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4085 | count++; |
| 4086 | } |
| 4087 | } |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4088 | return count; |
| 4089 | } |
| 4090 | |
| 4091 | /** |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 4092 | * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4093 | * @netdev: network interface device structure |
| 4094 | * |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 4095 | * The set_rx_method entry point is called whenever the unicast/multicast |
| 4096 | * address list or the network interface flags are updated. This routine is |
| 4097 | * responsible for configuring the hardware for proper unicast, multicast and |
| 4098 | * promiscuous mode. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4099 | **/ |
Greg Rose | 7f87047 | 2010-01-09 02:25:29 +0000 | [diff] [blame] | 4100 | void ixgbe_set_rx_mode(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4101 | { |
| 4102 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4103 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4104 | u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE; |
Jacob Keller | a9b8943 | 2014-03-25 07:45:26 +0000 | [diff] [blame] | 4105 | u32 vlnctrl; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4106 | int count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4107 | |
| 4108 | /* Check for Promiscuous and All Multicast modes */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4109 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
Jacob Keller | a9b8943 | 2014-03-25 07:45:26 +0000 | [diff] [blame] | 4110 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4111 | |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 4112 | /* set all bits that we expect to always be set */ |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 4113 | fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */ |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 4114 | fctrl |= IXGBE_FCTRL_BAM; |
| 4115 | fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */ |
| 4116 | fctrl |= IXGBE_FCTRL_PMCF; |
| 4117 | |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4118 | /* clear the bits we are changing the status of */ |
| 4119 | fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Jacob Keller | a9b8943 | 2014-03-25 07:45:26 +0000 | [diff] [blame] | 4120 | vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4121 | if (netdev->flags & IFF_PROMISC) { |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 4122 | hw->addr_ctrl.user_set_promisc = true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4123 | fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4124 | vmolr |= IXGBE_VMOLR_MPE; |
Greg Rose | 670224f | 2013-02-22 02:14:39 +0000 | [diff] [blame] | 4125 | /* Only disable hardware filter vlans in promiscuous mode |
| 4126 | * if SR-IOV and VMDQ are disabled - otherwise ensure |
| 4127 | * that hardware VLAN filters remain enabled. |
| 4128 | */ |
Vlad Yasevich | 4556dc5 | 2014-11-21 23:52:52 -0800 | [diff] [blame] | 4129 | if (adapter->flags & (IXGBE_FLAG_VMDQ_ENABLED | |
| 4130 | IXGBE_FLAG_SRIOV_ENABLED)) |
Jacob Keller | a9b8943 | 2014-03-25 07:45:26 +0000 | [diff] [blame] | 4131 | vlnctrl |= (IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4132 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 4133 | if (netdev->flags & IFF_ALLMULTI) { |
| 4134 | fctrl |= IXGBE_FCTRL_MPE; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4135 | vmolr |= IXGBE_VMOLR_MPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 4136 | } |
Jacob Keller | a9b8943 | 2014-03-25 07:45:26 +0000 | [diff] [blame] | 4137 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 4138 | hw->addr_ctrl.user_set_promisc = false; |
John Fastabend | 9dcb373 | 2012-04-15 06:44:25 +0000 | [diff] [blame] | 4139 | } |
| 4140 | |
| 4141 | /* |
| 4142 | * Write addresses to available RAR registers, if there is not |
| 4143 | * sufficient space to store all the addresses then enable |
| 4144 | * unicast promiscuous mode |
| 4145 | */ |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4146 | count = ixgbe_write_uc_addr_list(netdev, VMDQ_P(0)); |
John Fastabend | 9dcb373 | 2012-04-15 06:44:25 +0000 | [diff] [blame] | 4147 | if (count < 0) { |
| 4148 | fctrl |= IXGBE_FCTRL_UPE; |
| 4149 | vmolr |= IXGBE_VMOLR_ROPE; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4150 | } |
| 4151 | |
Emil Tantilov | cf78959 | 2013-10-26 08:13:20 +0000 | [diff] [blame] | 4152 | /* Write addresses to the MTA, if the attempt fails |
| 4153 | * then we should just turn on promiscuous mode so |
| 4154 | * that we can at least receive multicast traffic |
| 4155 | */ |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4156 | count = ixgbe_write_mc_addr_list(netdev); |
| 4157 | if (count < 0) { |
| 4158 | fctrl |= IXGBE_FCTRL_MPE; |
| 4159 | vmolr |= IXGBE_VMOLR_MPE; |
| 4160 | } else if (count) { |
| 4161 | vmolr |= IXGBE_VMOLR_ROMPE; |
| 4162 | } |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 4163 | |
| 4164 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 4165 | vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) & |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4166 | ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE | |
| 4167 | IXGBE_VMOLR_ROPE); |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 4168 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4169 | } |
| 4170 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 4171 | /* This is useful for sniffing bad packets. */ |
| 4172 | if (adapter->netdev->features & NETIF_F_RXALL) { |
| 4173 | /* UPE and MPE will be handled by normal PROMISC logic |
| 4174 | * in e1000e_set_rx_mode */ |
| 4175 | fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */ |
| 4176 | IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */ |
| 4177 | IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */ |
| 4178 | |
| 4179 | fctrl &= ~(IXGBE_FCTRL_DPF); |
| 4180 | /* NOTE: VLAN filtering is disabled by setting PROMISC */ |
| 4181 | } |
| 4182 | |
Jacob Keller | a9b8943 | 2014-03-25 07:45:26 +0000 | [diff] [blame] | 4183 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4184 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4185 | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 4186 | if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX) |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4187 | ixgbe_vlan_strip_enable(adapter); |
| 4188 | else |
| 4189 | ixgbe_vlan_strip_disable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4190 | } |
| 4191 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4192 | static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter) |
| 4193 | { |
| 4194 | int q_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4195 | |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 4196 | for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) { |
| 4197 | ixgbe_qv_init_lock(adapter->q_vector[q_idx]); |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 4198 | napi_enable(&adapter->q_vector[q_idx]->napi); |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 4199 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4200 | } |
| 4201 | |
| 4202 | static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter) |
| 4203 | { |
| 4204 | int q_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4205 | |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 4206 | for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) { |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 4207 | napi_disable(&adapter->q_vector[q_idx]->napi); |
Jacob Keller | 27d9ce4 | 2013-09-21 05:05:44 +0000 | [diff] [blame] | 4208 | while (!ixgbe_qv_disable(adapter->q_vector[q_idx])) { |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 4209 | pr_info("QV %d locked\n", q_idx); |
Jacob Keller | 27d9ce4 | 2013-09-21 05:05:44 +0000 | [diff] [blame] | 4210 | usleep_range(1000, 20000); |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 4211 | } |
| 4212 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4213 | } |
| 4214 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 4215 | #ifdef CONFIG_IXGBE_DCB |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4216 | /** |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4217 | * ixgbe_configure_dcb - Configure DCB hardware |
| 4218 | * @adapter: ixgbe adapter struct |
| 4219 | * |
| 4220 | * This is called by the driver on open to configure the DCB hardware. |
| 4221 | * This is also called by the gennetlink interface when reconfiguring |
| 4222 | * the DCB state. |
| 4223 | */ |
| 4224 | static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter) |
| 4225 | { |
| 4226 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 9806307 | 2010-10-28 00:59:57 +0000 | [diff] [blame] | 4227 | int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4228 | |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 4229 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) { |
| 4230 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4231 | netif_set_gso_max_size(adapter->netdev, 65536); |
| 4232 | return; |
| 4233 | } |
| 4234 | |
| 4235 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4236 | netif_set_gso_max_size(adapter->netdev, 32768); |
| 4237 | |
John Fastabend | b120818 | 2011-10-15 05:00:10 +0000 | [diff] [blame] | 4238 | #ifdef IXGBE_FCOE |
| 4239 | if (adapter->netdev->features & NETIF_F_FCOE_MTU) |
| 4240 | max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE); |
| 4241 | #endif |
| 4242 | |
Alexander Duyck | 01fa7d9 | 2010-11-16 19:26:53 -0800 | [diff] [blame] | 4243 | /* reconfigure the hardware */ |
John Fastabend | 6f70f6a | 2011-04-26 07:26:25 +0000 | [diff] [blame] | 4244 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) { |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 4245 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 4246 | DCB_TX_CONFIG); |
| 4247 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 4248 | DCB_RX_CONFIG); |
| 4249 | ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg); |
John Fastabend | b120818 | 2011-10-15 05:00:10 +0000 | [diff] [blame] | 4250 | } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) { |
| 4251 | ixgbe_dcb_hw_ets(&adapter->hw, |
| 4252 | adapter->ixgbe_ieee_ets, |
| 4253 | max_frame); |
| 4254 | ixgbe_dcb_hw_pfc_config(&adapter->hw, |
| 4255 | adapter->ixgbe_ieee_pfc->pfc_en, |
| 4256 | adapter->ixgbe_ieee_ets->prio_tc); |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 4257 | } |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 4258 | |
| 4259 | /* Enable RSS Hash per TC */ |
| 4260 | if (hw->mac.type != ixgbe_mac_82598EB) { |
Alexander Duyck | 4ae6373 | 2012-06-22 06:46:33 +0000 | [diff] [blame] | 4261 | u32 msb = 0; |
| 4262 | u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1; |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 4263 | |
Alexander Duyck | d411a93 | 2012-06-30 00:14:01 +0000 | [diff] [blame] | 4264 | while (rss_i) { |
| 4265 | msb++; |
| 4266 | rss_i >>= 1; |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 4267 | } |
Alexander Duyck | d411a93 | 2012-06-30 00:14:01 +0000 | [diff] [blame] | 4268 | |
Alexander Duyck | 4ae6373 | 2012-06-22 06:46:33 +0000 | [diff] [blame] | 4269 | /* write msb to all 8 TCs in one write */ |
| 4270 | IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111); |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 4271 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4272 | } |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4273 | #endif |
| 4274 | |
| 4275 | /* Additional bittime to account for IXGBE framing */ |
| 4276 | #define IXGBE_ETH_FRAMING 20 |
| 4277 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4278 | /** |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4279 | * ixgbe_hpbthresh - calculate high water mark for flow control |
| 4280 | * |
| 4281 | * @adapter: board private structure to calculate for |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4282 | * @pb: packet buffer to calculate |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4283 | */ |
| 4284 | static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb) |
| 4285 | { |
| 4286 | struct ixgbe_hw *hw = &adapter->hw; |
| 4287 | struct net_device *dev = adapter->netdev; |
| 4288 | int link, tc, kb, marker; |
| 4289 | u32 dv_id, rx_pba; |
| 4290 | |
| 4291 | /* Calculate max LAN frame size */ |
| 4292 | tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING; |
| 4293 | |
| 4294 | #ifdef IXGBE_FCOE |
| 4295 | /* FCoE traffic class uses FCOE jumbo frames */ |
Alexander Duyck | 800bd60 | 2012-06-02 00:11:02 +0000 | [diff] [blame] | 4296 | if ((dev->features & NETIF_F_FCOE_MTU) && |
| 4297 | (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) && |
| 4298 | (pb == ixgbe_fcoe_get_tc(adapter))) |
| 4299 | tc = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4300 | #endif |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4301 | |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4302 | /* Calculate delay value for device */ |
| 4303 | switch (hw->mac.type) { |
| 4304 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 4305 | case ixgbe_mac_X550: |
| 4306 | case ixgbe_mac_X550EM_x: |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4307 | dv_id = IXGBE_DV_X540(link, tc); |
| 4308 | break; |
| 4309 | default: |
| 4310 | dv_id = IXGBE_DV(link, tc); |
| 4311 | break; |
| 4312 | } |
| 4313 | |
| 4314 | /* Loopback switch introduces additional latency */ |
| 4315 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 4316 | dv_id += IXGBE_B2BT(tc); |
| 4317 | |
| 4318 | /* Delay value is calculated in bit times convert to KB */ |
| 4319 | kb = IXGBE_BT2KB(dv_id); |
| 4320 | rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10; |
| 4321 | |
| 4322 | marker = rx_pba - kb; |
| 4323 | |
| 4324 | /* It is possible that the packet buffer is not large enough |
| 4325 | * to provide required headroom. In this case throw an error |
| 4326 | * to user and a do the best we can. |
| 4327 | */ |
| 4328 | if (marker < 0) { |
| 4329 | e_warn(drv, "Packet Buffer(%i) can not provide enough" |
| 4330 | "headroom to support flow control." |
| 4331 | "Decrease MTU or number of traffic classes\n", pb); |
| 4332 | marker = tc + 1; |
| 4333 | } |
| 4334 | |
| 4335 | return marker; |
| 4336 | } |
| 4337 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4338 | /** |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4339 | * ixgbe_lpbthresh - calculate low water mark for for flow control |
| 4340 | * |
| 4341 | * @adapter: board private structure to calculate for |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4342 | * @pb: packet buffer to calculate |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4343 | */ |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4344 | static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb) |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4345 | { |
| 4346 | struct ixgbe_hw *hw = &adapter->hw; |
| 4347 | struct net_device *dev = adapter->netdev; |
| 4348 | int tc; |
| 4349 | u32 dv_id; |
| 4350 | |
| 4351 | /* Calculate max LAN frame size */ |
| 4352 | tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN; |
| 4353 | |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4354 | #ifdef IXGBE_FCOE |
| 4355 | /* FCoE traffic class uses FCOE jumbo frames */ |
| 4356 | if ((dev->features & NETIF_F_FCOE_MTU) && |
| 4357 | (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) && |
| 4358 | (pb == netdev_get_prio_tc_map(dev, adapter->fcoe.up))) |
| 4359 | tc = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 4360 | #endif |
| 4361 | |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4362 | /* Calculate delay value for device */ |
| 4363 | switch (hw->mac.type) { |
| 4364 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 4365 | case ixgbe_mac_X550: |
| 4366 | case ixgbe_mac_X550EM_x: |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4367 | dv_id = IXGBE_LOW_DV_X540(tc); |
| 4368 | break; |
| 4369 | default: |
| 4370 | dv_id = IXGBE_LOW_DV(tc); |
| 4371 | break; |
| 4372 | } |
| 4373 | |
| 4374 | /* Delay value is calculated in bit times convert to KB */ |
| 4375 | return IXGBE_BT2KB(dv_id); |
| 4376 | } |
| 4377 | |
| 4378 | /* |
| 4379 | * ixgbe_pbthresh_setup - calculate and setup high low water marks |
| 4380 | */ |
| 4381 | static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter) |
| 4382 | { |
| 4383 | struct ixgbe_hw *hw = &adapter->hw; |
| 4384 | int num_tc = netdev_get_num_tc(adapter->netdev); |
| 4385 | int i; |
| 4386 | |
| 4387 | if (!num_tc) |
| 4388 | num_tc = 1; |
| 4389 | |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4390 | for (i = 0; i < num_tc; i++) { |
| 4391 | hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i); |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4392 | hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i); |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4393 | |
| 4394 | /* Low water marks must not be larger than high water marks */ |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4395 | if (hw->fc.low_water[i] > hw->fc.high_water[i]) |
| 4396 | hw->fc.low_water[i] = 0; |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4397 | } |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4398 | |
| 4399 | for (; i < MAX_TRAFFIC_CLASS; i++) |
| 4400 | hw->fc.high_water[i] = 0; |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4401 | } |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4402 | |
| 4403 | static void ixgbe_configure_pb(struct ixgbe_adapter *adapter) |
| 4404 | { |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4405 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 4406 | int hdrm; |
| 4407 | u8 tc = netdev_get_num_tc(adapter->netdev); |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4408 | |
| 4409 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 4410 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 4411 | hdrm = 32 << adapter->fdir_pballoc; |
| 4412 | else |
| 4413 | hdrm = 0; |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4414 | |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 4415 | hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL); |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4416 | ixgbe_pbthresh_setup(adapter); |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4417 | } |
| 4418 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4419 | static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter) |
| 4420 | { |
| 4421 | struct ixgbe_hw *hw = &adapter->hw; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 4422 | struct hlist_node *node2; |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4423 | struct ixgbe_fdir_filter *filter; |
| 4424 | |
| 4425 | spin_lock(&adapter->fdir_perfect_lock); |
| 4426 | |
| 4427 | if (!hlist_empty(&adapter->fdir_filter_list)) |
| 4428 | ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask); |
| 4429 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 4430 | hlist_for_each_entry_safe(filter, node2, |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4431 | &adapter->fdir_filter_list, fdir_node) { |
| 4432 | ixgbe_fdir_write_perfect_filter_82599(hw, |
Alexander Duyck | 1f4d518 | 2011-05-14 01:16:02 +0000 | [diff] [blame] | 4433 | &filter->filter, |
| 4434 | filter->sw_idx, |
| 4435 | (filter->action == IXGBE_FDIR_DROP_QUEUE) ? |
| 4436 | IXGBE_FDIR_DROP_QUEUE : |
| 4437 | adapter->rx_ring[filter->action]->reg_idx); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4438 | } |
| 4439 | |
| 4440 | spin_unlock(&adapter->fdir_perfect_lock); |
| 4441 | } |
| 4442 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4443 | static void ixgbe_macvlan_set_rx_mode(struct net_device *dev, unsigned int pool, |
| 4444 | struct ixgbe_adapter *adapter) |
| 4445 | { |
| 4446 | struct ixgbe_hw *hw = &adapter->hw; |
| 4447 | u32 vmolr; |
| 4448 | |
| 4449 | /* No unicast promiscuous support for VMDQ devices. */ |
| 4450 | vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(pool)); |
| 4451 | vmolr |= (IXGBE_VMOLR_ROMPE | IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE); |
| 4452 | |
| 4453 | /* clear the affected bit */ |
| 4454 | vmolr &= ~IXGBE_VMOLR_MPE; |
| 4455 | |
| 4456 | if (dev->flags & IFF_ALLMULTI) { |
| 4457 | vmolr |= IXGBE_VMOLR_MPE; |
| 4458 | } else { |
| 4459 | vmolr |= IXGBE_VMOLR_ROMPE; |
| 4460 | hw->mac.ops.update_mc_addr_list(hw, dev); |
| 4461 | } |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4462 | ixgbe_write_uc_addr_list(adapter->netdev, pool); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4463 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(pool), vmolr); |
| 4464 | } |
| 4465 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4466 | static void ixgbe_fwd_psrtype(struct ixgbe_fwd_adapter *vadapter) |
| 4467 | { |
| 4468 | struct ixgbe_adapter *adapter = vadapter->real_adapter; |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 4469 | int rss_i = adapter->num_rx_queues_per_pool; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4470 | struct ixgbe_hw *hw = &adapter->hw; |
| 4471 | u16 pool = vadapter->pool; |
| 4472 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
| 4473 | IXGBE_PSRTYPE_UDPHDR | |
| 4474 | IXGBE_PSRTYPE_IPV4HDR | |
| 4475 | IXGBE_PSRTYPE_L2HDR | |
| 4476 | IXGBE_PSRTYPE_IPV6HDR; |
| 4477 | |
| 4478 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4479 | return; |
| 4480 | |
| 4481 | if (rss_i > 3) |
| 4482 | psrtype |= 2 << 29; |
| 4483 | else if (rss_i > 1) |
| 4484 | psrtype |= 1 << 29; |
| 4485 | |
| 4486 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype); |
| 4487 | } |
| 4488 | |
| 4489 | /** |
| 4490 | * ixgbe_clean_rx_ring - Free Rx Buffers per Queue |
| 4491 | * @rx_ring: ring to free buffers from |
| 4492 | **/ |
| 4493 | static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring) |
| 4494 | { |
| 4495 | struct device *dev = rx_ring->dev; |
| 4496 | unsigned long size; |
| 4497 | u16 i; |
| 4498 | |
| 4499 | /* ring already cleared, nothing to do */ |
| 4500 | if (!rx_ring->rx_buffer_info) |
| 4501 | return; |
| 4502 | |
| 4503 | /* Free all the Rx ring sk_buffs */ |
| 4504 | for (i = 0; i < rx_ring->count; i++) { |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 4505 | struct ixgbe_rx_buffer *rx_buffer = &rx_ring->rx_buffer_info[i]; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4506 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4507 | if (rx_buffer->skb) { |
| 4508 | struct sk_buff *skb = rx_buffer->skb; |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 4509 | if (IXGBE_CB(skb)->page_released) |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4510 | dma_unmap_page(dev, |
| 4511 | IXGBE_CB(skb)->dma, |
| 4512 | ixgbe_rx_bufsz(rx_ring), |
| 4513 | DMA_FROM_DEVICE); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4514 | dev_kfree_skb(skb); |
Junwei Zhang | 4d2fcfb | 2014-10-22 15:29:03 +0000 | [diff] [blame] | 4515 | rx_buffer->skb = NULL; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4516 | } |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 4517 | |
| 4518 | if (!rx_buffer->page) |
| 4519 | continue; |
| 4520 | |
| 4521 | dma_unmap_page(dev, rx_buffer->dma, |
| 4522 | ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE); |
| 4523 | __free_pages(rx_buffer->page, ixgbe_rx_pg_order(rx_ring)); |
| 4524 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4525 | rx_buffer->page = NULL; |
| 4526 | } |
| 4527 | |
| 4528 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 4529 | memset(rx_ring->rx_buffer_info, 0, size); |
| 4530 | |
| 4531 | /* Zero out the descriptor ring */ |
| 4532 | memset(rx_ring->desc, 0, rx_ring->size); |
| 4533 | |
| 4534 | rx_ring->next_to_alloc = 0; |
| 4535 | rx_ring->next_to_clean = 0; |
| 4536 | rx_ring->next_to_use = 0; |
| 4537 | } |
| 4538 | |
| 4539 | static void ixgbe_disable_fwd_ring(struct ixgbe_fwd_adapter *vadapter, |
| 4540 | struct ixgbe_ring *rx_ring) |
| 4541 | { |
| 4542 | struct ixgbe_adapter *adapter = vadapter->real_adapter; |
| 4543 | int index = rx_ring->queue_index + vadapter->rx_base_queue; |
| 4544 | |
| 4545 | /* shutdown specific queue receive and wait for dma to settle */ |
| 4546 | ixgbe_disable_rx_queue(adapter, rx_ring); |
| 4547 | usleep_range(10000, 20000); |
| 4548 | ixgbe_irq_disable_queues(adapter, ((u64)1 << index)); |
| 4549 | ixgbe_clean_rx_ring(rx_ring); |
| 4550 | rx_ring->l2_accel_priv = NULL; |
| 4551 | } |
| 4552 | |
John Fastabend | ae72c8d | 2013-11-09 07:11:26 +0000 | [diff] [blame] | 4553 | static int ixgbe_fwd_ring_down(struct net_device *vdev, |
| 4554 | struct ixgbe_fwd_adapter *accel) |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4555 | { |
| 4556 | struct ixgbe_adapter *adapter = accel->real_adapter; |
| 4557 | unsigned int rxbase = accel->rx_base_queue; |
| 4558 | unsigned int txbase = accel->tx_base_queue; |
| 4559 | int i; |
| 4560 | |
| 4561 | netif_tx_stop_all_queues(vdev); |
| 4562 | |
| 4563 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 4564 | ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]); |
| 4565 | adapter->rx_ring[rxbase + i]->netdev = adapter->netdev; |
| 4566 | } |
| 4567 | |
| 4568 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 4569 | adapter->tx_ring[txbase + i]->l2_accel_priv = NULL; |
| 4570 | adapter->tx_ring[txbase + i]->netdev = adapter->netdev; |
| 4571 | } |
| 4572 | |
| 4573 | |
| 4574 | return 0; |
| 4575 | } |
| 4576 | |
| 4577 | static int ixgbe_fwd_ring_up(struct net_device *vdev, |
| 4578 | struct ixgbe_fwd_adapter *accel) |
| 4579 | { |
| 4580 | struct ixgbe_adapter *adapter = accel->real_adapter; |
| 4581 | unsigned int rxbase, txbase, queues; |
| 4582 | int i, baseq, err = 0; |
| 4583 | |
| 4584 | if (!test_bit(accel->pool, &adapter->fwd_bitmask)) |
| 4585 | return 0; |
| 4586 | |
| 4587 | baseq = accel->pool * adapter->num_rx_queues_per_pool; |
| 4588 | netdev_dbg(vdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n", |
| 4589 | accel->pool, adapter->num_rx_pools, |
| 4590 | baseq, baseq + adapter->num_rx_queues_per_pool, |
| 4591 | adapter->fwd_bitmask); |
| 4592 | |
| 4593 | accel->netdev = vdev; |
| 4594 | accel->rx_base_queue = rxbase = baseq; |
| 4595 | accel->tx_base_queue = txbase = baseq; |
| 4596 | |
| 4597 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) |
| 4598 | ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]); |
| 4599 | |
| 4600 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 4601 | adapter->rx_ring[rxbase + i]->netdev = vdev; |
| 4602 | adapter->rx_ring[rxbase + i]->l2_accel_priv = accel; |
| 4603 | ixgbe_configure_rx_ring(adapter, adapter->rx_ring[rxbase + i]); |
| 4604 | } |
| 4605 | |
| 4606 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 4607 | adapter->tx_ring[txbase + i]->netdev = vdev; |
| 4608 | adapter->tx_ring[txbase + i]->l2_accel_priv = accel; |
| 4609 | } |
| 4610 | |
| 4611 | queues = min_t(unsigned int, |
| 4612 | adapter->num_rx_queues_per_pool, vdev->num_tx_queues); |
| 4613 | err = netif_set_real_num_tx_queues(vdev, queues); |
| 4614 | if (err) |
| 4615 | goto fwd_queue_err; |
| 4616 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4617 | err = netif_set_real_num_rx_queues(vdev, queues); |
| 4618 | if (err) |
| 4619 | goto fwd_queue_err; |
| 4620 | |
| 4621 | if (is_valid_ether_addr(vdev->dev_addr)) |
| 4622 | ixgbe_add_mac_filter(adapter, vdev->dev_addr, accel->pool); |
| 4623 | |
| 4624 | ixgbe_fwd_psrtype(accel); |
| 4625 | ixgbe_macvlan_set_rx_mode(vdev, accel->pool, adapter); |
| 4626 | return err; |
| 4627 | fwd_queue_err: |
| 4628 | ixgbe_fwd_ring_down(vdev, accel); |
| 4629 | return err; |
| 4630 | } |
| 4631 | |
| 4632 | static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter) |
| 4633 | { |
| 4634 | struct net_device *upper; |
| 4635 | struct list_head *iter; |
| 4636 | int err; |
| 4637 | |
| 4638 | netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) { |
| 4639 | if (netif_is_macvlan(upper)) { |
| 4640 | struct macvlan_dev *dfwd = netdev_priv(upper); |
| 4641 | struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv; |
| 4642 | |
| 4643 | if (dfwd->fwd_priv) { |
| 4644 | err = ixgbe_fwd_ring_up(upper, vadapter); |
| 4645 | if (err) |
| 4646 | continue; |
| 4647 | } |
| 4648 | } |
| 4649 | } |
| 4650 | } |
| 4651 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4652 | static void ixgbe_configure(struct ixgbe_adapter *adapter) |
| 4653 | { |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 4654 | struct ixgbe_hw *hw = &adapter->hw; |
| 4655 | |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4656 | ixgbe_configure_pb(adapter); |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 4657 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 4658 | ixgbe_configure_dcb(adapter); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4659 | #endif |
Alexander Duyck | b35d4d4 | 2012-05-23 05:39:25 +0000 | [diff] [blame] | 4660 | /* |
| 4661 | * We must restore virtualization before VLANs or else |
| 4662 | * the VLVF registers will not be populated |
| 4663 | */ |
| 4664 | ixgbe_configure_virtualization(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4665 | |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 4666 | ixgbe_set_rx_mode(adapter->netdev); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4667 | ixgbe_restore_vlan(adapter); |
| 4668 | |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 4669 | switch (hw->mac.type) { |
| 4670 | case ixgbe_mac_82599EB: |
| 4671 | case ixgbe_mac_X540: |
| 4672 | hw->mac.ops.disable_rx_buff(hw); |
| 4673 | break; |
| 4674 | default: |
| 4675 | break; |
| 4676 | } |
| 4677 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4678 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 4679 | ixgbe_init_fdir_signature_82599(&adapter->hw, |
| 4680 | adapter->fdir_pballoc); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4681 | } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) { |
| 4682 | ixgbe_init_fdir_perfect_82599(&adapter->hw, |
| 4683 | adapter->fdir_pballoc); |
| 4684 | ixgbe_fdir_filter_restore(adapter); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4685 | } |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 4686 | |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 4687 | switch (hw->mac.type) { |
| 4688 | case ixgbe_mac_82599EB: |
| 4689 | case ixgbe_mac_X540: |
| 4690 | hw->mac.ops.enable_rx_buff(hw); |
| 4691 | break; |
| 4692 | default: |
| 4693 | break; |
| 4694 | } |
| 4695 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 4696 | #ifdef IXGBE_FCOE |
| 4697 | /* configure FCoE L2 filters, redirection table, and Rx control */ |
| 4698 | ixgbe_configure_fcoe(adapter); |
| 4699 | |
| 4700 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4701 | ixgbe_configure_tx(adapter); |
| 4702 | ixgbe_configure_rx(adapter); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4703 | ixgbe_configure_dfwd(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4704 | } |
| 4705 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4706 | static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw) |
| 4707 | { |
| 4708 | switch (hw->phy.type) { |
| 4709 | case ixgbe_phy_sfp_avago: |
| 4710 | case ixgbe_phy_sfp_ftl: |
| 4711 | case ixgbe_phy_sfp_intel: |
| 4712 | case ixgbe_phy_sfp_unknown: |
Don Skidmore | ea0a04d | 2010-05-18 16:00:13 +0000 | [diff] [blame] | 4713 | case ixgbe_phy_sfp_passive_tyco: |
| 4714 | case ixgbe_phy_sfp_passive_unknown: |
| 4715 | case ixgbe_phy_sfp_active_unknown: |
| 4716 | case ixgbe_phy_sfp_ftl_active: |
Emil Tantilov | 987e1d5 | 2013-08-14 07:12:27 +0000 | [diff] [blame] | 4717 | case ixgbe_phy_qsfp_passive_unknown: |
| 4718 | case ixgbe_phy_qsfp_active_unknown: |
| 4719 | case ixgbe_phy_qsfp_intel: |
| 4720 | case ixgbe_phy_qsfp_unknown: |
Emil Tantilov | d9cd46c | 2014-05-15 07:16:53 +0000 | [diff] [blame] | 4721 | /* ixgbe_phy_none is set when no SFP module is present */ |
| 4722 | case ixgbe_phy_none: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4723 | return true; |
Alexander Duyck | 8917b44 | 2011-07-21 00:40:51 +0000 | [diff] [blame] | 4724 | case ixgbe_phy_nl: |
| 4725 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4726 | return true; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4727 | default: |
| 4728 | return false; |
| 4729 | } |
| 4730 | } |
| 4731 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 4732 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4733 | * ixgbe_sfp_link_config - set up SFP+ link |
| 4734 | * @adapter: pointer to private adapter struct |
| 4735 | **/ |
| 4736 | static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter) |
| 4737 | { |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4738 | /* |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 4739 | * We are assuming the worst case scenario here, and that |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4740 | * is that an SFP was inserted/removed after the reset |
| 4741 | * but before SFP detection was enabled. As such the best |
| 4742 | * solution is to just start searching as soon as we start |
| 4743 | */ |
| 4744 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 4745 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4746 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4747 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4748 | } |
| 4749 | |
| 4750 | /** |
| 4751 | * ixgbe_non_sfp_link_config - set up non-SFP+ link |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 4752 | * @hw: pointer to private hardware struct |
| 4753 | * |
| 4754 | * Returns 0 on success, negative on failure |
| 4755 | **/ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4756 | 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] | 4757 | { |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 4758 | u32 speed; |
| 4759 | bool autoneg, link_up = false; |
Mark Rustad | a1e869d | 2015-04-10 10:36:36 -0700 | [diff] [blame] | 4760 | int ret = IXGBE_ERR_LINK_SETUP; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 4761 | |
| 4762 | if (hw->mac.ops.check_link) |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 4763 | 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] | 4764 | |
| 4765 | if (ret) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 4766 | return ret; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 4767 | |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 4768 | speed = hw->phy.autoneg_advertised; |
| 4769 | if ((!speed) && (hw->mac.ops.get_link_capabilities)) |
| 4770 | ret = hw->mac.ops.get_link_capabilities(hw, &speed, |
| 4771 | &autoneg); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 4772 | if (ret) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 4773 | return ret; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 4774 | |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 4775 | if (hw->mac.ops.setup_link) |
Josh Hay | fd0326f | 2012-12-15 03:28:30 +0000 | [diff] [blame] | 4776 | ret = hw->mac.ops.setup_link(hw, speed, link_up); |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 4777 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 4778 | return ret; |
| 4779 | } |
| 4780 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 4781 | static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4782 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4783 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 4784 | u32 gpie = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4785 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 4786 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 4787 | gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT | |
| 4788 | IXGBE_GPIE_OCD; |
| 4789 | gpie |= IXGBE_GPIE_EIAME; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 4790 | /* |
| 4791 | * use EIAM to auto-mask when MSI-X interrupt is asserted |
| 4792 | * this saves a register write for every interrupt |
| 4793 | */ |
| 4794 | switch (hw->mac.type) { |
| 4795 | case ixgbe_mac_82598EB: |
| 4796 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
| 4797 | break; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 4798 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4799 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 4800 | case ixgbe_mac_X550: |
| 4801 | case ixgbe_mac_X550EM_x: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4802 | default: |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 4803 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF); |
| 4804 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF); |
| 4805 | break; |
| 4806 | } |
| 4807 | } else { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4808 | /* legacy interrupts, use EIAM to auto-mask when reading EICR, |
| 4809 | * specifically only auto mask tx and rx interrupts */ |
| 4810 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4811 | } |
| 4812 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 4813 | /* XXX: to interrupt immediately for EICS writes, enable this */ |
| 4814 | /* gpie |= IXGBE_GPIE_EIMEN; */ |
| 4815 | |
| 4816 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 4817 | gpie &= ~IXGBE_GPIE_VTMODE_MASK; |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 4818 | |
| 4819 | switch (adapter->ring_feature[RING_F_VMDQ].mask) { |
| 4820 | case IXGBE_82599_VMDQ_8Q_MASK: |
| 4821 | gpie |= IXGBE_GPIE_VTMODE_16; |
| 4822 | break; |
| 4823 | case IXGBE_82599_VMDQ_4Q_MASK: |
| 4824 | gpie |= IXGBE_GPIE_VTMODE_32; |
| 4825 | break; |
| 4826 | default: |
| 4827 | gpie |= IXGBE_GPIE_VTMODE_64; |
| 4828 | break; |
| 4829 | } |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 4830 | } |
| 4831 | |
Alexander Duyck | 5fdd31f | 2011-07-21 00:40:45 +0000 | [diff] [blame] | 4832 | /* Enable Thermal over heat sensor interrupt */ |
Don Skidmore | f3df98e | 2011-08-17 10:15:21 +0000 | [diff] [blame] | 4833 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) { |
| 4834 | switch (adapter->hw.mac.type) { |
| 4835 | case ixgbe_mac_82599EB: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 4836 | gpie |= IXGBE_SDP0_GPIEN_8259X; |
Don Skidmore | f3df98e | 2011-08-17 10:15:21 +0000 | [diff] [blame] | 4837 | break; |
| 4838 | case ixgbe_mac_X540: |
| 4839 | gpie |= IXGBE_EIMS_TS; |
| 4840 | break; |
| 4841 | default: |
| 4842 | break; |
| 4843 | } |
| 4844 | } |
Alexander Duyck | 5fdd31f | 2011-07-21 00:40:45 +0000 | [diff] [blame] | 4845 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 4846 | /* Enable fan failure interrupt */ |
| 4847 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 4848 | gpie |= IXGBE_SDP1_GPIEN(hw); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 4849 | |
Don Skidmore | 2698b20 | 2011-04-13 07:01:52 +0000 | [diff] [blame] | 4850 | if (hw->mac.type == ixgbe_mac_82599EB) { |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 4851 | gpie |= IXGBE_SDP1_GPIEN_8259X; |
| 4852 | gpie |= IXGBE_SDP2_GPIEN_8259X; |
Don Skidmore | 2698b20 | 2011-04-13 07:01:52 +0000 | [diff] [blame] | 4853 | } |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 4854 | |
| 4855 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 4856 | } |
| 4857 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 4858 | static void ixgbe_up_complete(struct ixgbe_adapter *adapter) |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 4859 | { |
| 4860 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 4861 | int err; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 4862 | u32 ctrl_ext; |
| 4863 | |
| 4864 | ixgbe_get_hw_control(adapter); |
| 4865 | ixgbe_setup_gpie(adapter); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4866 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4867 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 4868 | ixgbe_configure_msix(adapter); |
| 4869 | else |
| 4870 | ixgbe_configure_msi_and_legacy(adapter); |
| 4871 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 4872 | /* enable the optics for 82599 SFP+ fiber */ |
| 4873 | if (hw->mac.ops.enable_tx_laser) |
Peter Waskiewicz | 61fac74 | 2010-04-27 00:38:15 +0000 | [diff] [blame] | 4874 | hw->mac.ops.enable_tx_laser(hw); |
| 4875 | |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 4876 | if (hw->phy.ops.set_phy_power) |
| 4877 | hw->phy.ops.set_phy_power(hw, true); |
| 4878 | |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 4879 | smp_mb__before_atomic(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4880 | clear_bit(__IXGBE_DOWN, &adapter->state); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4881 | ixgbe_napi_enable_all(adapter); |
| 4882 | |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 4883 | if (ixgbe_is_sfp(hw)) { |
| 4884 | ixgbe_sfp_link_config(adapter); |
| 4885 | } else { |
| 4886 | err = ixgbe_non_sfp_link_config(hw); |
| 4887 | if (err) |
| 4888 | e_err(probe, "link_config FAILED %d\n", err); |
| 4889 | } |
| 4890 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4891 | /* clear any pending interrupts, may auto mask */ |
| 4892 | IXGBE_READ_REG(hw, IXGBE_EICR); |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 4893 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4894 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4895 | /* |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 4896 | * If this adapter has a fan, check to see if we had a failure |
| 4897 | * before we enabled the interrupt. |
| 4898 | */ |
| 4899 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 4900 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 4901 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 4902 | e_crit(drv, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 4903 | } |
| 4904 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4905 | /* bring the link up in the watchdog, this could race with our first |
| 4906 | * link up interrupt but shouldn't be a problem */ |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4907 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 4908 | adapter->link_check_timeout = jiffies; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4909 | mod_timer(&adapter->service_timer, jiffies); |
Greg Rose | c920569 | 2010-01-22 22:46:22 +0000 | [diff] [blame] | 4910 | |
| 4911 | /* Set PF Reset Done bit so PF/VF Mail Ops can work */ |
| 4912 | ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); |
| 4913 | ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD; |
| 4914 | IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4915 | } |
| 4916 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4917 | void ixgbe_reinit_locked(struct ixgbe_adapter *adapter) |
| 4918 | { |
| 4919 | WARN_ON(in_interrupt()); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4920 | /* put off any impending NetWatchDogTimeout */ |
| 4921 | adapter->netdev->trans_start = jiffies; |
| 4922 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4923 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 4924 | usleep_range(1000, 2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4925 | ixgbe_down(adapter); |
Greg Rose | 5809a1a | 2010-03-24 09:36:08 +0000 | [diff] [blame] | 4926 | /* |
| 4927 | * If SR-IOV enabled then wait a bit before bringing the adapter |
| 4928 | * back up to give the VFs time to respond to the reset. The |
| 4929 | * two second wait is based upon the watchdog timer cycle in |
| 4930 | * the VF driver. |
| 4931 | */ |
| 4932 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 4933 | msleep(2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4934 | ixgbe_up(adapter); |
| 4935 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
| 4936 | } |
| 4937 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 4938 | void ixgbe_up(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4939 | { |
| 4940 | /* hardware has been reset, we need to reload some things */ |
| 4941 | ixgbe_configure(adapter); |
| 4942 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 4943 | ixgbe_up_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4944 | } |
| 4945 | |
| 4946 | void ixgbe_reset(struct ixgbe_adapter *adapter) |
| 4947 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4948 | struct ixgbe_hw *hw = &adapter->hw; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4949 | struct net_device *netdev = adapter->netdev; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 4950 | int err; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4951 | u8 old_addr[ETH_ALEN]; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 4952 | |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 4953 | if (ixgbe_removed(hw->hw_addr)) |
| 4954 | return; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4955 | /* lock SFP init bit to prevent race conditions with the watchdog */ |
| 4956 | while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 4957 | usleep_range(1000, 2000); |
| 4958 | |
| 4959 | /* clear all SFP and link config related flags while holding SFP_INIT */ |
| 4960 | adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP | |
| 4961 | IXGBE_FLAG2_SFP_NEEDS_RESET); |
| 4962 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 4963 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 4964 | err = hw->mac.ops.init_hw(hw); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 4965 | switch (err) { |
| 4966 | case 0: |
| 4967 | case IXGBE_ERR_SFP_NOT_PRESENT: |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4968 | case IXGBE_ERR_SFP_NOT_SUPPORTED: |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 4969 | break; |
| 4970 | case IXGBE_ERR_MASTER_REQUESTS_PENDING: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4971 | e_dev_err("master disable timed out\n"); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 4972 | break; |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 4973 | case IXGBE_ERR_EEPROM_VERSION: |
| 4974 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4975 | e_dev_warn("This device is a pre-production adapter/LOM. " |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 4976 | "Please be aware there may be issues associated with " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4977 | "your hardware. If you are experiencing problems " |
| 4978 | "please contact your Intel or hardware " |
| 4979 | "representative who provided you with this " |
| 4980 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 4981 | break; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 4982 | default: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4983 | e_dev_err("Hardware Error: %d\n", err); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 4984 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4985 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4986 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4987 | /* do not flush user set addresses */ |
| 4988 | memcpy(old_addr, &adapter->mac_table[0].addr, netdev->addr_len); |
| 4989 | ixgbe_flush_sw_mac_table(adapter); |
| 4990 | ixgbe_mac_set_default_filter(adapter, old_addr); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 4991 | |
| 4992 | /* update SAN MAC vmdq pool selection */ |
| 4993 | if (hw->mac.san_mac_rar_index) |
| 4994 | hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0)); |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 4995 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 4996 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 4997 | ixgbe_ptp_reset(adapter); |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 4998 | |
| 4999 | if (hw->phy.ops.set_phy_power) { |
| 5000 | if (!netif_running(adapter->netdev) && !adapter->wol) |
| 5001 | hw->phy.ops.set_phy_power(hw, false); |
| 5002 | else |
| 5003 | hw->phy.ops.set_phy_power(hw, true); |
| 5004 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5005 | } |
| 5006 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5007 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5008 | * ixgbe_clean_tx_ring - Free Tx Buffers |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5009 | * @tx_ring: ring to be cleaned |
| 5010 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5011 | static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5012 | { |
| 5013 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 5014 | unsigned long size; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5015 | u16 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5016 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 5017 | /* ring already cleared, nothing to do */ |
| 5018 | if (!tx_ring->tx_buffer_info) |
| 5019 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5020 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 5021 | /* Free all the Tx ring sk_buffs */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5022 | for (i = 0; i < tx_ring->count; i++) { |
| 5023 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5024 | ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5025 | } |
| 5026 | |
John Fastabend | dad8a3b | 2012-04-23 12:22:39 +0000 | [diff] [blame] | 5027 | netdev_tx_reset_queue(txring_txq(tx_ring)); |
| 5028 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5029 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 5030 | memset(tx_ring->tx_buffer_info, 0, size); |
| 5031 | |
| 5032 | /* Zero out the descriptor ring */ |
| 5033 | memset(tx_ring->desc, 0, tx_ring->size); |
| 5034 | |
| 5035 | tx_ring->next_to_use = 0; |
| 5036 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5037 | } |
| 5038 | |
| 5039 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5040 | * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues |
| 5041 | * @adapter: board private structure |
| 5042 | **/ |
| 5043 | static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter) |
| 5044 | { |
| 5045 | int i; |
| 5046 | |
| 5047 | for (i = 0; i < adapter->num_rx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5048 | ixgbe_clean_rx_ring(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5049 | } |
| 5050 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5051 | /** |
| 5052 | * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues |
| 5053 | * @adapter: board private structure |
| 5054 | **/ |
| 5055 | static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter) |
| 5056 | { |
| 5057 | int i; |
| 5058 | |
| 5059 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5060 | ixgbe_clean_tx_ring(adapter->tx_ring[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5061 | } |
| 5062 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5063 | static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter) |
| 5064 | { |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 5065 | struct hlist_node *node2; |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5066 | struct ixgbe_fdir_filter *filter; |
| 5067 | |
| 5068 | spin_lock(&adapter->fdir_perfect_lock); |
| 5069 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 5070 | hlist_for_each_entry_safe(filter, node2, |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5071 | &adapter->fdir_filter_list, fdir_node) { |
| 5072 | hlist_del(&filter->fdir_node); |
| 5073 | kfree(filter); |
| 5074 | } |
| 5075 | adapter->fdir_filter_count = 0; |
| 5076 | |
| 5077 | spin_unlock(&adapter->fdir_perfect_lock); |
| 5078 | } |
| 5079 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5080 | void ixgbe_down(struct ixgbe_adapter *adapter) |
| 5081 | { |
| 5082 | struct net_device *netdev = adapter->netdev; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5083 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5084 | struct net_device *upper; |
| 5085 | struct list_head *iter; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 5086 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5087 | |
| 5088 | /* signal that we are down to the interrupt handler */ |
Mark Rustad | c3049c8 | 2014-01-14 18:53:12 -0800 | [diff] [blame] | 5089 | if (test_and_set_bit(__IXGBE_DOWN, &adapter->state)) |
| 5090 | return; /* do nothing if already down */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5091 | |
| 5092 | /* disable receives */ |
Don Skidmore | 1f9ac57 | 2015-03-13 13:54:30 -0700 | [diff] [blame] | 5093 | hw->mac.ops.disable_rx(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5094 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 5095 | /* disable all enabled rx queues */ |
| 5096 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 5097 | /* this call also flushes the previous write */ |
| 5098 | ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]); |
| 5099 | |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 5100 | usleep_range(10000, 20000); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5101 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5102 | netif_tx_stop_all_queues(netdev); |
| 5103 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5104 | /* call carrier off first to avoid false dev_watchdog timeouts */ |
John Fastabend | c0dfb90 | 2010-04-27 02:13:39 +0000 | [diff] [blame] | 5105 | netif_carrier_off(netdev); |
| 5106 | netif_tx_disable(netdev); |
| 5107 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5108 | /* disable any upper devices */ |
| 5109 | netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) { |
| 5110 | if (netif_is_macvlan(upper)) { |
| 5111 | struct macvlan_dev *vlan = netdev_priv(upper); |
| 5112 | |
| 5113 | if (vlan->fwd_priv) { |
| 5114 | netif_tx_stop_all_queues(upper); |
| 5115 | netif_carrier_off(upper); |
| 5116 | netif_tx_disable(upper); |
| 5117 | } |
| 5118 | } |
| 5119 | } |
| 5120 | |
John Fastabend | c0dfb90 | 2010-04-27 02:13:39 +0000 | [diff] [blame] | 5121 | ixgbe_irq_disable(adapter); |
| 5122 | |
| 5123 | ixgbe_napi_disable_all(adapter); |
| 5124 | |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 5125 | adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT | |
| 5126 | IXGBE_FLAG2_RESET_REQUESTED); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5127 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 5128 | |
| 5129 | del_timer_sync(&adapter->service_timer); |
| 5130 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 5131 | if (adapter->num_vfs) { |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 5132 | /* Clear EITR Select mapping */ |
| 5133 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0); |
| 5134 | |
| 5135 | /* Mark all the VFs as inactive */ |
| 5136 | for (i = 0 ; i < adapter->num_vfs; i++) |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 5137 | adapter->vfinfo[i].clear_to_send = false; |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 5138 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 5139 | /* 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] | 5140 | ixgbe_ping_all_vfs(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5141 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5142 | /* Disable all VFTE/VFRE TX/RX */ |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 5143 | ixgbe_disable_tx_rx(adapter); |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 5144 | } |
| 5145 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5146 | /* disable transmits in the hardware now that interrupts are off */ |
| 5147 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 5148 | u8 reg_idx = adapter->tx_ring[i]->reg_idx; |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 5149 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5150 | } |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 5151 | |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5152 | /* Disable the Tx DMA engine on 82599 and later MAC */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5153 | switch (hw->mac.type) { |
| 5154 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5155 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5156 | case ixgbe_mac_X550: |
| 5157 | case ixgbe_mac_X550EM_x: |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 5158 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 5159 | (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) & |
| 5160 | ~IXGBE_DMATXCTL_TE)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5161 | break; |
| 5162 | default: |
| 5163 | break; |
| 5164 | } |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5165 | |
Paul Larson | 6f4a0e4 | 2008-06-24 17:00:56 -0700 | [diff] [blame] | 5166 | if (!pci_channel_offline(adapter->pdev)) |
| 5167 | ixgbe_reset(adapter); |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 5168 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 5169 | /* power down the optics for 82599 SFP+ fiber */ |
| 5170 | if (hw->mac.ops.disable_tx_laser) |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 5171 | hw->mac.ops.disable_tx_laser(hw); |
| 5172 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5173 | ixgbe_clean_all_tx_rings(adapter); |
| 5174 | ixgbe_clean_all_rx_rings(adapter); |
| 5175 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 5176 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 5177 | /* since we reset the hardware DCA settings were cleared */ |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 5178 | ixgbe_setup_dca(adapter); |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 5179 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5180 | } |
| 5181 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5182 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5183 | * ixgbe_tx_timeout - Respond to a Tx Hang |
| 5184 | * @netdev: network interface device structure |
| 5185 | **/ |
| 5186 | static void ixgbe_tx_timeout(struct net_device *netdev) |
| 5187 | { |
| 5188 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5189 | |
| 5190 | /* Do the reset outside of interrupt context */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 5191 | ixgbe_tx_timeout_reset(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5192 | } |
| 5193 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 5194 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5195 | * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter) |
| 5196 | * @adapter: board private structure to initialize |
| 5197 | * |
| 5198 | * ixgbe_sw_init initializes the Adapter private data structure. |
| 5199 | * Fields are initialized based on PCI device information and |
| 5200 | * OS network device settings (MTU size). |
| 5201 | **/ |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 5202 | static int ixgbe_sw_init(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5203 | { |
| 5204 | struct ixgbe_hw *hw = &adapter->hw; |
| 5205 | struct pci_dev *pdev = adapter->pdev; |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 5206 | unsigned int rss, fdir; |
Jacob Keller | cb6d0f5 | 2012-12-04 06:03:14 +0000 | [diff] [blame] | 5207 | u32 fwsm; |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5208 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5209 | int j; |
| 5210 | struct tc_configuration *tc; |
| 5211 | #endif |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5212 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5213 | /* PCI config space info */ |
| 5214 | |
| 5215 | hw->vendor_id = pdev->vendor; |
| 5216 | hw->device_id = pdev->device; |
| 5217 | hw->revision_id = pdev->revision; |
| 5218 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 5219 | hw->subsystem_device_id = pdev->subsystem_device; |
| 5220 | |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5221 | /* Set common capability flags and settings */ |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 5222 | rss = min_t(int, ixgbe_max_rss_indices(adapter), num_online_cpus()); |
Alexander Duyck | c087663 | 2012-05-10 00:01:46 +0000 | [diff] [blame] | 5223 | adapter->ring_feature[RING_F_RSS].limit = rss; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5224 | adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE; |
| 5225 | adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5226 | adapter->max_q_vectors = MAX_Q_VECTORS_82599; |
| 5227 | adapter->atr_sample_rate = 20; |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 5228 | fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus()); |
| 5229 | adapter->ring_feature[RING_F_FDIR].limit = fdir; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5230 | adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K; |
| 5231 | #ifdef CONFIG_IXGBE_DCA |
| 5232 | adapter->flags |= IXGBE_FLAG_DCA_CAPABLE; |
| 5233 | #endif |
| 5234 | #ifdef IXGBE_FCOE |
| 5235 | adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE; |
| 5236 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 5237 | #ifdef CONFIG_IXGBE_DCB |
| 5238 | /* Default traffic class to use for FCoE */ |
| 5239 | adapter->fcoe.up = IXGBE_FCOE_DEFTC; |
| 5240 | #endif /* CONFIG_IXGBE_DCB */ |
| 5241 | #endif /* IXGBE_FCOE */ |
| 5242 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 5243 | adapter->mac_table = kzalloc(sizeof(struct ixgbe_mac_addr) * |
| 5244 | hw->mac.num_rar_entries, |
| 5245 | GFP_ATOMIC); |
| 5246 | |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5247 | /* Set MAC specific capability flags and exceptions */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5248 | switch (hw->mac.type) { |
| 5249 | case ixgbe_mac_82598EB: |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5250 | adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE; |
| 5251 | adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED; |
| 5252 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5253 | if (hw->device_id == IXGBE_DEV_ID_82598AT) |
| 5254 | adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5255 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 5256 | adapter->max_q_vectors = MAX_Q_VECTORS_82598; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5257 | adapter->ring_feature[RING_F_FDIR].limit = 0; |
| 5258 | adapter->atr_sample_rate = 0; |
| 5259 | adapter->fdir_pballoc = 0; |
| 5260 | #ifdef IXGBE_FCOE |
| 5261 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
| 5262 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 5263 | #ifdef CONFIG_IXGBE_DCB |
| 5264 | adapter->fcoe.up = 0; |
| 5265 | #endif /* IXGBE_DCB */ |
| 5266 | #endif /* IXGBE_FCOE */ |
| 5267 | break; |
| 5268 | case ixgbe_mac_82599EB: |
| 5269 | if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM) |
| 5270 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5271 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5272 | case ixgbe_mac_X540: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 5273 | fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw)); |
Jacob Keller | cb6d0f5 | 2012-12-04 06:03:14 +0000 | [diff] [blame] | 5274 | if (fwsm & IXGBE_FWSM_TS_ENABLED) |
| 5275 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5276 | break; |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5277 | case ixgbe_mac_X550EM_x: |
| 5278 | case ixgbe_mac_X550: |
| 5279 | #ifdef CONFIG_IXGBE_DCA |
| 5280 | adapter->flags &= ~IXGBE_FLAG_DCA_CAPABLE; |
| 5281 | #endif |
| 5282 | break; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5283 | default: |
| 5284 | break; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5285 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5286 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 5287 | #ifdef IXGBE_FCOE |
| 5288 | /* FCoE support exists, always init the FCoE lock */ |
| 5289 | spin_lock_init(&adapter->fcoe.lock); |
| 5290 | |
| 5291 | #endif |
Alexander Duyck | 1fc5f03 | 2011-06-02 04:28:39 +0000 | [diff] [blame] | 5292 | /* n-tuple support exists, always init our spinlock */ |
| 5293 | spin_lock_init(&adapter->fdir_perfect_lock); |
| 5294 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5295 | #ifdef CONFIG_IXGBE_DCB |
John Fastabend | 4de2a02 | 2011-09-27 03:52:01 +0000 | [diff] [blame] | 5296 | switch (hw->mac.type) { |
| 5297 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5298 | case ixgbe_mac_X550: |
| 5299 | case ixgbe_mac_X550EM_x: |
John Fastabend | 4de2a02 | 2011-09-27 03:52:01 +0000 | [diff] [blame] | 5300 | adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS; |
| 5301 | adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS; |
| 5302 | break; |
| 5303 | default: |
| 5304 | adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS; |
| 5305 | adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS; |
| 5306 | break; |
| 5307 | } |
| 5308 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5309 | /* Configure DCB traffic classes */ |
| 5310 | for (j = 0; j < MAX_TRAFFIC_CLASS; j++) { |
| 5311 | tc = &adapter->dcb_cfg.tc_config[j]; |
| 5312 | tc->path[DCB_TX_CONFIG].bwg_id = 0; |
| 5313 | tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1); |
| 5314 | tc->path[DCB_RX_CONFIG].bwg_id = 0; |
| 5315 | tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1); |
| 5316 | tc->dcb_pfc = pfc_disabled; |
| 5317 | } |
John Fastabend | 4de2a02 | 2011-09-27 03:52:01 +0000 | [diff] [blame] | 5318 | |
| 5319 | /* Initialize default user to priority mapping, UPx->TC0 */ |
| 5320 | tc = &adapter->dcb_cfg.tc_config[0]; |
| 5321 | tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF; |
| 5322 | tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF; |
| 5323 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5324 | adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100; |
| 5325 | adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100; |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 5326 | adapter->dcb_cfg.pfc_mode_enable = false; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5327 | adapter->dcb_set_bitmap = 0x00; |
John Fastabend | 3032309 | 2011-03-01 05:25:35 +0000 | [diff] [blame] | 5328 | adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE; |
John Fastabend | f525c6d2 | 2012-04-18 22:42:27 +0000 | [diff] [blame] | 5329 | memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg, |
| 5330 | sizeof(adapter->temp_dcb_cfg)); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5331 | |
| 5332 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5333 | |
| 5334 | /* default flow control settings */ |
Don Skidmore | cd7664f | 2009-03-31 21:33:44 +0000 | [diff] [blame] | 5335 | hw->fc.requested_mode = ixgbe_fc_full; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 5336 | hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */ |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5337 | ixgbe_pbthresh_setup(adapter); |
Jesse Brandeburg | 2b9ade9 | 2008-08-26 04:27:10 -0700 | [diff] [blame] | 5338 | hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE; |
| 5339 | hw->fc.send_xon = true; |
Don Skidmore | 73d80953d | 2013-07-31 02:19:24 +0000 | [diff] [blame] | 5340 | hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5341 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 5342 | #ifdef CONFIG_PCI_IOV |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 5343 | if (max_vfs > 0) |
| 5344 | 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] | 5345 | |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 5346 | /* assign number of SR-IOV VFs */ |
| 5347 | if (hw->mac.type != ixgbe_mac_82598EB) { |
ethan.zhao | dcc23e3 | 2014-01-16 19:41:04 -0800 | [diff] [blame] | 5348 | if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) { |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 5349 | adapter->num_vfs = 0; |
| 5350 | e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n"); |
| 5351 | } else { |
| 5352 | adapter->num_vfs = max_vfs; |
| 5353 | } |
| 5354 | } |
| 5355 | #endif /* CONFIG_PCI_IOV */ |
| 5356 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5357 | /* enable itr by default in dynamic mode */ |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 5358 | adapter->rx_itr_setting = 1; |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 5359 | adapter->tx_itr_setting = 1; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5360 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5361 | /* set default ring sizes */ |
| 5362 | adapter->tx_ring_count = IXGBE_DEFAULT_TXD; |
| 5363 | adapter->rx_ring_count = IXGBE_DEFAULT_RXD; |
| 5364 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 5365 | /* set default work limits */ |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 5366 | adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 5367 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5368 | /* initialize eeprom parameters */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5369 | if (ixgbe_init_eeprom_params_generic(hw)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5370 | e_dev_err("EEPROM initialization failed\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5371 | return -EIO; |
| 5372 | } |
| 5373 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5374 | /* PF holds first pool slot */ |
| 5375 | set_bit(0, &adapter->fwd_bitmask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5376 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 5377 | |
| 5378 | return 0; |
| 5379 | } |
| 5380 | |
| 5381 | /** |
| 5382 | * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5383 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5384 | * |
| 5385 | * Return 0 on success, negative on failure |
| 5386 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5387 | int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5388 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5389 | struct device *dev = tx_ring->dev; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5390 | int orig_node = dev_to_node(dev); |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5391 | int ring_node = -1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5392 | int size; |
| 5393 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5394 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5395 | |
| 5396 | if (tx_ring->q_vector) |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5397 | ring_node = tx_ring->q_vector->numa_node; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5398 | |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5399 | tx_ring->tx_buffer_info = vzalloc_node(size, ring_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5400 | if (!tx_ring->tx_buffer_info) |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5401 | tx_ring->tx_buffer_info = vzalloc(size); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5402 | if (!tx_ring->tx_buffer_info) |
| 5403 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5404 | |
John Stultz | 827da44 | 2013-10-07 15:51:58 -0700 | [diff] [blame] | 5405 | u64_stats_init(&tx_ring->syncp); |
| 5406 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5407 | /* round up to nearest 4K */ |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 5408 | tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5409 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5410 | |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5411 | set_dev_node(dev, ring_node); |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5412 | tx_ring->desc = dma_alloc_coherent(dev, |
| 5413 | tx_ring->size, |
| 5414 | &tx_ring->dma, |
| 5415 | GFP_KERNEL); |
| 5416 | set_dev_node(dev, orig_node); |
| 5417 | if (!tx_ring->desc) |
| 5418 | tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size, |
| 5419 | &tx_ring->dma, GFP_KERNEL); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5420 | if (!tx_ring->desc) |
| 5421 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5422 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5423 | tx_ring->next_to_use = 0; |
| 5424 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5425 | return 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5426 | |
| 5427 | err: |
| 5428 | vfree(tx_ring->tx_buffer_info); |
| 5429 | tx_ring->tx_buffer_info = NULL; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5430 | 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] | 5431 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5432 | } |
| 5433 | |
| 5434 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5435 | * ixgbe_setup_all_tx_resources - allocate all queues Tx resources |
| 5436 | * @adapter: board private structure |
| 5437 | * |
| 5438 | * If this function returns with an error, then it's possible one or |
| 5439 | * more of the rings is populated (while the rest are not). It is the |
| 5440 | * callers duty to clean those orphaned rings. |
| 5441 | * |
| 5442 | * Return 0 on success, negative on failure |
| 5443 | **/ |
| 5444 | static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) |
| 5445 | { |
| 5446 | int i, err = 0; |
| 5447 | |
| 5448 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5449 | err = ixgbe_setup_tx_resources(adapter->tx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5450 | if (!err) |
| 5451 | continue; |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5452 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5453 | e_err(probe, "Allocation for Tx Queue %u failed\n", i); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5454 | goto err_setup_tx; |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5455 | } |
| 5456 | |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5457 | return 0; |
| 5458 | err_setup_tx: |
| 5459 | /* rewind the index freeing the rings as we go */ |
| 5460 | while (i--) |
| 5461 | ixgbe_free_tx_resources(adapter->tx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5462 | return err; |
| 5463 | } |
| 5464 | |
| 5465 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5466 | * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5467 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5468 | * |
| 5469 | * Returns 0 on success, negative on failure |
| 5470 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5471 | int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5472 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5473 | struct device *dev = rx_ring->dev; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5474 | int orig_node = dev_to_node(dev); |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5475 | int ring_node = -1; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5476 | int size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5477 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5478 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5479 | |
| 5480 | if (rx_ring->q_vector) |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5481 | ring_node = rx_ring->q_vector->numa_node; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5482 | |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5483 | rx_ring->rx_buffer_info = vzalloc_node(size, ring_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5484 | if (!rx_ring->rx_buffer_info) |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5485 | rx_ring->rx_buffer_info = vzalloc(size); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5486 | if (!rx_ring->rx_buffer_info) |
| 5487 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5488 | |
John Stultz | 827da44 | 2013-10-07 15:51:58 -0700 | [diff] [blame] | 5489 | u64_stats_init(&rx_ring->syncp); |
| 5490 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5491 | /* Round up to nearest 4K */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5492 | rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); |
| 5493 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5494 | |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5495 | set_dev_node(dev, ring_node); |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5496 | rx_ring->desc = dma_alloc_coherent(dev, |
| 5497 | rx_ring->size, |
| 5498 | &rx_ring->dma, |
| 5499 | GFP_KERNEL); |
| 5500 | set_dev_node(dev, orig_node); |
| 5501 | if (!rx_ring->desc) |
| 5502 | rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size, |
| 5503 | &rx_ring->dma, GFP_KERNEL); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5504 | if (!rx_ring->desc) |
| 5505 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5506 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5507 | rx_ring->next_to_clean = 0; |
| 5508 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5509 | |
| 5510 | return 0; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5511 | err: |
| 5512 | vfree(rx_ring->rx_buffer_info); |
| 5513 | rx_ring->rx_buffer_info = NULL; |
| 5514 | 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] | 5515 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5516 | } |
| 5517 | |
| 5518 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5519 | * ixgbe_setup_all_rx_resources - allocate all queues Rx resources |
| 5520 | * @adapter: board private structure |
| 5521 | * |
| 5522 | * If this function returns with an error, then it's possible one or |
| 5523 | * more of the rings is populated (while the rest are not). It is the |
| 5524 | * callers duty to clean those orphaned rings. |
| 5525 | * |
| 5526 | * Return 0 on success, negative on failure |
| 5527 | **/ |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5528 | static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) |
| 5529 | { |
| 5530 | int i, err = 0; |
| 5531 | |
| 5532 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5533 | err = ixgbe_setup_rx_resources(adapter->rx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5534 | if (!err) |
| 5535 | continue; |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5536 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5537 | e_err(probe, "Allocation for Rx Queue %u failed\n", i); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5538 | goto err_setup_rx; |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5539 | } |
| 5540 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 5541 | #ifdef IXGBE_FCOE |
| 5542 | err = ixgbe_setup_fcoe_ddp_resources(adapter); |
| 5543 | if (!err) |
| 5544 | #endif |
| 5545 | return 0; |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5546 | err_setup_rx: |
| 5547 | /* rewind the index freeing the rings as we go */ |
| 5548 | while (i--) |
| 5549 | ixgbe_free_rx_resources(adapter->rx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5550 | return err; |
| 5551 | } |
| 5552 | |
| 5553 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5554 | * ixgbe_free_tx_resources - Free Tx Resources per Queue |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5555 | * @tx_ring: Tx descriptor ring for a specific queue |
| 5556 | * |
| 5557 | * Free all transmit software resources |
| 5558 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5559 | void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5560 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5561 | ixgbe_clean_tx_ring(tx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5562 | |
| 5563 | vfree(tx_ring->tx_buffer_info); |
| 5564 | tx_ring->tx_buffer_info = NULL; |
| 5565 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5566 | /* if not set, then don't free */ |
| 5567 | if (!tx_ring->desc) |
| 5568 | return; |
| 5569 | |
| 5570 | dma_free_coherent(tx_ring->dev, tx_ring->size, |
| 5571 | tx_ring->desc, tx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5572 | |
| 5573 | tx_ring->desc = NULL; |
| 5574 | } |
| 5575 | |
| 5576 | /** |
| 5577 | * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues |
| 5578 | * @adapter: board private structure |
| 5579 | * |
| 5580 | * Free all transmit software resources |
| 5581 | **/ |
| 5582 | static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter) |
| 5583 | { |
| 5584 | int i; |
| 5585 | |
| 5586 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5587 | if (adapter->tx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5588 | ixgbe_free_tx_resources(adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5589 | } |
| 5590 | |
| 5591 | /** |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5592 | * ixgbe_free_rx_resources - Free Rx Resources |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5593 | * @rx_ring: ring to clean the resources from |
| 5594 | * |
| 5595 | * Free all receive software resources |
| 5596 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5597 | void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5598 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5599 | ixgbe_clean_rx_ring(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5600 | |
| 5601 | vfree(rx_ring->rx_buffer_info); |
| 5602 | rx_ring->rx_buffer_info = NULL; |
| 5603 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5604 | /* if not set, then don't free */ |
| 5605 | if (!rx_ring->desc) |
| 5606 | return; |
| 5607 | |
| 5608 | dma_free_coherent(rx_ring->dev, rx_ring->size, |
| 5609 | rx_ring->desc, rx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5610 | |
| 5611 | rx_ring->desc = NULL; |
| 5612 | } |
| 5613 | |
| 5614 | /** |
| 5615 | * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues |
| 5616 | * @adapter: board private structure |
| 5617 | * |
| 5618 | * Free all receive software resources |
| 5619 | **/ |
| 5620 | static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter) |
| 5621 | { |
| 5622 | int i; |
| 5623 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 5624 | #ifdef IXGBE_FCOE |
| 5625 | ixgbe_free_fcoe_ddp_resources(adapter); |
| 5626 | |
| 5627 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5628 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5629 | if (adapter->rx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5630 | ixgbe_free_rx_resources(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5631 | } |
| 5632 | |
| 5633 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5634 | * ixgbe_change_mtu - Change the Maximum Transfer Unit |
| 5635 | * @netdev: network interface device structure |
| 5636 | * @new_mtu: new value for maximum frame size |
| 5637 | * |
| 5638 | * Returns 0 on success, negative on failure |
| 5639 | **/ |
| 5640 | static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu) |
| 5641 | { |
| 5642 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5643 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 5644 | |
Jesse Brandeburg | 42c783c | 2008-09-11 19:56:28 -0700 | [diff] [blame] | 5645 | /* MTU < 68 is an error and causes problems on some kernels */ |
Alexander Duyck | 655309e | 2012-02-08 07:50:35 +0000 | [diff] [blame] | 5646 | if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) |
| 5647 | return -EINVAL; |
| 5648 | |
| 5649 | /* |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 5650 | * For 82599EB we cannot allow legacy VFs to enable their receive |
| 5651 | * paths when MTU greater than 1500 is configured. So display a |
| 5652 | * warning that legacy VFs will be disabled. |
Alexander Duyck | 655309e | 2012-02-08 07:50:35 +0000 | [diff] [blame] | 5653 | */ |
| 5654 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && |
| 5655 | (adapter->hw.mac.type == ixgbe_mac_82599EB) && |
Alexander Duyck | c560451 | 2013-01-09 08:50:42 +0000 | [diff] [blame] | 5656 | (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN))) |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 5657 | e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5658 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5659 | 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] | 5660 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5661 | /* must set new MTU before calling down or up */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5662 | netdev->mtu = new_mtu; |
| 5663 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5664 | if (netif_running(netdev)) |
| 5665 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5666 | |
| 5667 | return 0; |
| 5668 | } |
| 5669 | |
| 5670 | /** |
| 5671 | * ixgbe_open - Called when a network interface is made active |
| 5672 | * @netdev: network interface device structure |
| 5673 | * |
| 5674 | * Returns 0 on success, negative value on failure |
| 5675 | * |
| 5676 | * The open entry point is called when a network interface is made |
| 5677 | * active by the system (IFF_UP). At this point all resources needed |
| 5678 | * for transmit and receive operations are allocated, the interrupt |
| 5679 | * handler is registered with the OS, the watchdog timer is started, |
| 5680 | * and the stack is notified that the interface is ready. |
| 5681 | **/ |
| 5682 | static int ixgbe_open(struct net_device *netdev) |
| 5683 | { |
| 5684 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 5685 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5686 | int err, queues; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5687 | |
Auke Kok | 4bebfaa | 2008-02-11 09:26:01 -0800 | [diff] [blame] | 5688 | /* disallow open during test */ |
| 5689 | if (test_bit(__IXGBE_TESTING, &adapter->state)) |
| 5690 | return -EBUSY; |
| 5691 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 5692 | netif_carrier_off(netdev); |
| 5693 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5694 | /* allocate transmit descriptors */ |
| 5695 | err = ixgbe_setup_all_tx_resources(adapter); |
| 5696 | if (err) |
| 5697 | goto err_setup_tx; |
| 5698 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5699 | /* allocate receive descriptors */ |
| 5700 | err = ixgbe_setup_all_rx_resources(adapter); |
| 5701 | if (err) |
| 5702 | goto err_setup_rx; |
| 5703 | |
| 5704 | ixgbe_configure(adapter); |
| 5705 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5706 | err = ixgbe_request_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5707 | if (err) |
| 5708 | goto err_req_irq; |
| 5709 | |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 5710 | /* Notify the stack of the actual queue counts. */ |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5711 | if (adapter->num_rx_pools > 1) |
| 5712 | queues = adapter->num_rx_queues_per_pool; |
| 5713 | else |
| 5714 | queues = adapter->num_tx_queues; |
| 5715 | |
| 5716 | err = netif_set_real_num_tx_queues(netdev, queues); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 5717 | if (err) |
| 5718 | goto err_set_queues; |
| 5719 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5720 | if (adapter->num_rx_pools > 1 && |
| 5721 | adapter->num_rx_queues > IXGBE_MAX_L2A_QUEUES) |
| 5722 | queues = IXGBE_MAX_L2A_QUEUES; |
| 5723 | else |
| 5724 | queues = adapter->num_rx_queues; |
| 5725 | err = netif_set_real_num_rx_queues(netdev, queues); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 5726 | if (err) |
| 5727 | goto err_set_queues; |
| 5728 | |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 5729 | ixgbe_ptp_init(adapter); |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 5730 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 5731 | ixgbe_up_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5732 | |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 5733 | #if IS_ENABLED(CONFIG_IXGBE_VXLAN) |
| 5734 | vxlan_get_rx_port(netdev); |
| 5735 | |
| 5736 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5737 | return 0; |
| 5738 | |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 5739 | err_set_queues: |
| 5740 | ixgbe_free_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5741 | err_req_irq: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 5742 | ixgbe_free_all_rx_resources(adapter); |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 5743 | if (hw->phy.ops.set_phy_power && !adapter->wol) |
| 5744 | hw->phy.ops.set_phy_power(&adapter->hw, false); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5745 | err_setup_rx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 5746 | ixgbe_free_all_tx_resources(adapter); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5747 | err_setup_tx: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5748 | ixgbe_reset(adapter); |
| 5749 | |
| 5750 | return err; |
| 5751 | } |
| 5752 | |
Jacob Keller | a0cccce | 2014-05-16 05:12:29 +0000 | [diff] [blame] | 5753 | static void ixgbe_close_suspend(struct ixgbe_adapter *adapter) |
| 5754 | { |
| 5755 | ixgbe_ptp_suspend(adapter); |
| 5756 | |
| 5757 | ixgbe_down(adapter); |
| 5758 | ixgbe_free_irq(adapter); |
| 5759 | |
| 5760 | ixgbe_free_all_tx_resources(adapter); |
| 5761 | ixgbe_free_all_rx_resources(adapter); |
| 5762 | } |
| 5763 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5764 | /** |
| 5765 | * ixgbe_close - Disables a network interface |
| 5766 | * @netdev: network interface device structure |
| 5767 | * |
| 5768 | * Returns 0, this is not allowed to fail |
| 5769 | * |
| 5770 | * The close entry point is called when an interface is de-activated |
| 5771 | * by the OS. The hardware is still under the drivers control, but |
| 5772 | * needs to be disabled. A global MAC reset is issued to stop the |
| 5773 | * hardware, and all transmit and receive resources are freed. |
| 5774 | **/ |
| 5775 | static int ixgbe_close(struct net_device *netdev) |
| 5776 | { |
| 5777 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5778 | |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 5779 | ixgbe_ptp_stop(adapter); |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 5780 | |
Jacob Keller | a0cccce | 2014-05-16 05:12:29 +0000 | [diff] [blame] | 5781 | ixgbe_close_suspend(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5782 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5783 | ixgbe_fdir_filter_exit(adapter); |
| 5784 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 5785 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5786 | |
| 5787 | return 0; |
| 5788 | } |
| 5789 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5790 | #ifdef CONFIG_PM |
| 5791 | static int ixgbe_resume(struct pci_dev *pdev) |
| 5792 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5793 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 5794 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5795 | u32 err; |
| 5796 | |
Mark Rustad | 0391bbe | 2014-02-28 15:48:55 -0800 | [diff] [blame] | 5797 | adapter->hw.hw_addr = adapter->io_addr; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5798 | pci_set_power_state(pdev, PCI_D0); |
| 5799 | pci_restore_state(pdev); |
Don Skidmore | 656ab81 | 2009-12-23 21:19:19 -0800 | [diff] [blame] | 5800 | /* |
| 5801 | * pci_restore_state clears dev->state_saved so call |
| 5802 | * pci_save_state to restore it. |
| 5803 | */ |
| 5804 | pci_save_state(pdev); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5805 | |
| 5806 | err = pci_enable_device_mem(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5807 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5808 | e_dev_err("Cannot enable PCI device from suspend\n"); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5809 | return err; |
| 5810 | } |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 5811 | smp_mb__before_atomic(); |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 5812 | clear_bit(__IXGBE_DISABLED, &adapter->state); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5813 | pci_set_master(pdev); |
| 5814 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 5815 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5816 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5817 | ixgbe_reset(adapter); |
| 5818 | |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 5819 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
| 5820 | |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 5821 | rtnl_lock(); |
| 5822 | err = ixgbe_init_interrupt_scheme(adapter); |
| 5823 | if (!err && netif_running(netdev)) |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5824 | err = ixgbe_open(netdev); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 5825 | |
| 5826 | rtnl_unlock(); |
| 5827 | |
| 5828 | if (err) |
| 5829 | return err; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5830 | |
| 5831 | netif_device_attach(netdev); |
| 5832 | |
| 5833 | return 0; |
| 5834 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5835 | #endif /* CONFIG_PM */ |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5836 | |
| 5837 | static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5838 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5839 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 5840 | struct net_device *netdev = adapter->netdev; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5841 | struct ixgbe_hw *hw = &adapter->hw; |
| 5842 | u32 ctrl, fctrl; |
| 5843 | u32 wufc = adapter->wol; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5844 | #ifdef CONFIG_PM |
| 5845 | int retval = 0; |
| 5846 | #endif |
| 5847 | |
| 5848 | netif_device_detach(netdev); |
| 5849 | |
akepner | 499ab5c | 2013-03-13 14:54:58 +0000 | [diff] [blame] | 5850 | rtnl_lock(); |
Jacob Keller | a0cccce | 2014-05-16 05:12:29 +0000 | [diff] [blame] | 5851 | if (netif_running(netdev)) |
| 5852 | ixgbe_close_suspend(adapter); |
akepner | 499ab5c | 2013-03-13 14:54:58 +0000 | [diff] [blame] | 5853 | rtnl_unlock(); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5854 | |
Alexander Duyck | 5f5ae6f | 2010-11-16 19:26:52 -0800 | [diff] [blame] | 5855 | ixgbe_clear_interrupt_scheme(adapter); |
| 5856 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5857 | #ifdef CONFIG_PM |
| 5858 | retval = pci_save_state(pdev); |
| 5859 | if (retval) |
| 5860 | return retval; |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 5861 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5862 | #endif |
Jacob Keller | f4f1040 | 2013-06-25 07:59:23 +0000 | [diff] [blame] | 5863 | if (hw->mac.ops.stop_link_on_d3) |
| 5864 | hw->mac.ops.stop_link_on_d3(hw); |
| 5865 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5866 | if (wufc) { |
| 5867 | ixgbe_set_rx_mode(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5868 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 5869 | /* enable the optics for 82599 SFP+ fiber as we can WoL */ |
| 5870 | if (hw->mac.ops.enable_tx_laser) |
Don Skidmore | c509e75 | 2012-04-05 08:12:05 +0000 | [diff] [blame] | 5871 | hw->mac.ops.enable_tx_laser(hw); |
| 5872 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5873 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 5874 | if (wufc & IXGBE_WUFC_MC) { |
| 5875 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 5876 | fctrl |= IXGBE_FCTRL_MPE; |
| 5877 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
| 5878 | } |
| 5879 | |
| 5880 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 5881 | ctrl |= IXGBE_CTRL_GIO_DIS; |
| 5882 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); |
| 5883 | |
| 5884 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc); |
| 5885 | } else { |
| 5886 | IXGBE_WRITE_REG(hw, IXGBE_WUC, 0); |
| 5887 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0); |
| 5888 | } |
| 5889 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5890 | switch (hw->mac.type) { |
| 5891 | case ixgbe_mac_82598EB: |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 5892 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5893 | break; |
| 5894 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5895 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5896 | case ixgbe_mac_X550: |
| 5897 | case ixgbe_mac_X550EM_x: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5898 | pci_wake_from_d3(pdev, !!wufc); |
| 5899 | break; |
| 5900 | default: |
| 5901 | break; |
| 5902 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5903 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5904 | *enable_wake = !!wufc; |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 5905 | if (hw->phy.ops.set_phy_power && !*enable_wake) |
| 5906 | hw->phy.ops.set_phy_power(hw, false); |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5907 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5908 | ixgbe_release_hw_control(adapter); |
| 5909 | |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 5910 | if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state)) |
| 5911 | pci_disable_device(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5912 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5913 | return 0; |
| 5914 | } |
| 5915 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5916 | #ifdef CONFIG_PM |
| 5917 | static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state) |
| 5918 | { |
| 5919 | int retval; |
| 5920 | bool wake; |
| 5921 | |
| 5922 | retval = __ixgbe_shutdown(pdev, &wake); |
| 5923 | if (retval) |
| 5924 | return retval; |
| 5925 | |
| 5926 | if (wake) { |
| 5927 | pci_prepare_to_sleep(pdev); |
| 5928 | } else { |
| 5929 | pci_wake_from_d3(pdev, false); |
| 5930 | pci_set_power_state(pdev, PCI_D3hot); |
| 5931 | } |
| 5932 | |
| 5933 | return 0; |
| 5934 | } |
| 5935 | #endif /* CONFIG_PM */ |
| 5936 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5937 | static void ixgbe_shutdown(struct pci_dev *pdev) |
| 5938 | { |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5939 | bool wake; |
| 5940 | |
| 5941 | __ixgbe_shutdown(pdev, &wake); |
| 5942 | |
| 5943 | if (system_state == SYSTEM_POWER_OFF) { |
| 5944 | pci_wake_from_d3(pdev, wake); |
| 5945 | pci_set_power_state(pdev, PCI_D3hot); |
| 5946 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5947 | } |
| 5948 | |
| 5949 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5950 | * ixgbe_update_stats - Update the board statistics counters. |
| 5951 | * @adapter: board private structure |
| 5952 | **/ |
| 5953 | void ixgbe_update_stats(struct ixgbe_adapter *adapter) |
| 5954 | { |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 5955 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5956 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5957 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5958 | u64 total_mpc = 0; |
| 5959 | u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5960 | u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0; |
| 5961 | u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 5962 | u64 bytes = 0, packets = 0, hw_csum_rx_error = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5963 | |
Don Skidmore | d08935c | 2010-06-11 13:20:29 +0000 | [diff] [blame] | 5964 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 5965 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 5966 | return; |
| 5967 | |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5968 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5969 | u64 rsc_count = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5970 | u64 rsc_flush = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5971 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5972 | rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count; |
| 5973 | rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5974 | } |
| 5975 | adapter->rsc_total_count = rsc_count; |
| 5976 | adapter->rsc_total_flush = rsc_flush; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 5977 | } |
| 5978 | |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5979 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 5980 | struct ixgbe_ring *rx_ring = adapter->rx_ring[i]; |
| 5981 | non_eop_descs += rx_ring->rx_stats.non_eop_descs; |
| 5982 | alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed; |
| 5983 | alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 5984 | hw_csum_rx_error += rx_ring->rx_stats.csum_err; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5985 | bytes += rx_ring->stats.bytes; |
| 5986 | packets += rx_ring->stats.packets; |
| 5987 | } |
Mallikarjuna R Chilakala | eb985f0 | 2009-12-15 11:56:59 +0000 | [diff] [blame] | 5988 | adapter->non_eop_descs = non_eop_descs; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5989 | adapter->alloc_rx_page_failed = alloc_rx_page_failed; |
| 5990 | adapter->alloc_rx_buff_failed = alloc_rx_buff_failed; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 5991 | adapter->hw_csum_rx_error = hw_csum_rx_error; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5992 | netdev->stats.rx_bytes = bytes; |
| 5993 | netdev->stats.rx_packets = packets; |
| 5994 | |
| 5995 | bytes = 0; |
| 5996 | packets = 0; |
| 5997 | /* gather some stats to the adapter struct that are per queue */ |
| 5998 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 5999 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 6000 | restart_queue += tx_ring->tx_stats.restart_queue; |
| 6001 | tx_busy += tx_ring->tx_stats.tx_busy; |
| 6002 | bytes += tx_ring->stats.bytes; |
| 6003 | packets += tx_ring->stats.packets; |
| 6004 | } |
| 6005 | adapter->restart_queue = restart_queue; |
| 6006 | adapter->tx_busy = tx_busy; |
| 6007 | netdev->stats.tx_bytes = bytes; |
| 6008 | netdev->stats.tx_packets = packets; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 6009 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6010 | hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS); |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6011 | |
| 6012 | /* 8 register reads */ |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6013 | for (i = 0; i < 8; i++) { |
| 6014 | /* for packet buffers not used, the register should read 0 */ |
| 6015 | mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i)); |
| 6016 | missed_rx += mpc; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6017 | hwstats->mpc[i] += mpc; |
| 6018 | total_mpc += hwstats->mpc[i]; |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6019 | hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i)); |
| 6020 | hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6021 | switch (hw->mac.type) { |
| 6022 | case ixgbe_mac_82598EB: |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6023 | hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i)); |
| 6024 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i)); |
| 6025 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i)); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6026 | hwstats->pxonrxc[i] += |
| 6027 | IXGBE_READ_REG(hw, IXGBE_PXONRXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6028 | break; |
| 6029 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 6030 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6031 | case ixgbe_mac_X550: |
| 6032 | case ixgbe_mac_X550EM_x: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6033 | hwstats->pxonrxc[i] += |
| 6034 | IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6035 | break; |
| 6036 | default: |
| 6037 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6038 | } |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6039 | } |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6040 | |
| 6041 | /*16 register reads */ |
| 6042 | for (i = 0; i < 16; i++) { |
| 6043 | hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i)); |
| 6044 | hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i)); |
| 6045 | if ((hw->mac.type == ixgbe_mac_82599EB) || |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6046 | (hw->mac.type == ixgbe_mac_X540) || |
| 6047 | (hw->mac.type == ixgbe_mac_X550) || |
| 6048 | (hw->mac.type == ixgbe_mac_X550EM_x)) { |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6049 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i)); |
| 6050 | IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */ |
| 6051 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i)); |
| 6052 | IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */ |
| 6053 | } |
| 6054 | } |
| 6055 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6056 | hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6057 | /* work around hardware counting issue */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6058 | hwstats->gprc -= missed_rx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6059 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 6060 | ixgbe_update_xoff_received(adapter); |
| 6061 | |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6062 | /* 82598 hardware only has a 32 bit counter in the high register */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6063 | switch (hw->mac.type) { |
| 6064 | case ixgbe_mac_82598EB: |
| 6065 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6066 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH); |
| 6067 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH); |
| 6068 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH); |
| 6069 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 6070 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6071 | case ixgbe_mac_X550: |
| 6072 | case ixgbe_mac_X550EM_x: |
| 6073 | /* OS2BMC stats are X540 and later */ |
Emil Tantilov | 58f6bcf | 2011-04-21 08:43:43 +0000 | [diff] [blame] | 6074 | hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC); |
| 6075 | hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC); |
| 6076 | hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC); |
| 6077 | hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC); |
| 6078 | case ixgbe_mac_82599EB: |
Alexander Duyck | a4d4f62 | 2012-03-28 08:03:32 +0000 | [diff] [blame] | 6079 | for (i = 0; i < 16; i++) |
| 6080 | adapter->hw_rx_no_dma_resources += |
| 6081 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6082 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6083 | IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6084 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6085 | IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6086 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6087 | IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6088 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6089 | hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH); |
| 6090 | hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS); |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 6091 | #ifdef IXGBE_FCOE |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6092 | hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC); |
| 6093 | hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC); |
| 6094 | hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC); |
| 6095 | hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC); |
| 6096 | hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC); |
| 6097 | hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC); |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 6098 | /* Add up per cpu counters for total ddp aloc fail */ |
Alexander Duyck | 5a1ee27 | 2012-05-05 17:14:28 +0000 | [diff] [blame] | 6099 | if (adapter->fcoe.ddp_pool) { |
| 6100 | struct ixgbe_fcoe *fcoe = &adapter->fcoe; |
| 6101 | struct ixgbe_fcoe_ddp_pool *ddp_pool; |
| 6102 | unsigned int cpu; |
| 6103 | u64 noddp = 0, noddp_ext_buff = 0; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 6104 | for_each_possible_cpu(cpu) { |
Alexander Duyck | 5a1ee27 | 2012-05-05 17:14:28 +0000 | [diff] [blame] | 6105 | ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu); |
| 6106 | noddp += ddp_pool->noddp; |
| 6107 | noddp_ext_buff += ddp_pool->noddp_ext_buff; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 6108 | } |
Alexander Duyck | 5a1ee27 | 2012-05-05 17:14:28 +0000 | [diff] [blame] | 6109 | hwstats->fcoe_noddp = noddp; |
| 6110 | hwstats->fcoe_noddp_ext_buff = noddp_ext_buff; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 6111 | } |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 6112 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6113 | break; |
| 6114 | default: |
| 6115 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6116 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6117 | bprc = IXGBE_READ_REG(hw, IXGBE_BPRC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6118 | hwstats->bprc += bprc; |
| 6119 | hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6120 | if (hw->mac.type == ixgbe_mac_82598EB) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6121 | hwstats->mprc -= bprc; |
| 6122 | hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC); |
| 6123 | hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64); |
| 6124 | hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127); |
| 6125 | hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255); |
| 6126 | hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511); |
| 6127 | hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023); |
| 6128 | hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522); |
| 6129 | hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6130 | lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6131 | hwstats->lxontxc += lxon; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6132 | lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6133 | hwstats->lxofftxc += lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6134 | hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC); |
| 6135 | hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6136 | /* |
| 6137 | * 82598 errata - tx of flow control packets is included in tx counters |
| 6138 | */ |
| 6139 | xon_off_tot = lxon + lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6140 | hwstats->gptc -= xon_off_tot; |
| 6141 | hwstats->mptc -= xon_off_tot; |
| 6142 | hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN)); |
| 6143 | hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 6144 | hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC); |
| 6145 | hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC); |
| 6146 | hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR); |
| 6147 | hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64); |
| 6148 | hwstats->ptc64 -= xon_off_tot; |
| 6149 | hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127); |
| 6150 | hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255); |
| 6151 | hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511); |
| 6152 | hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023); |
| 6153 | hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522); |
| 6154 | hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6155 | |
| 6156 | /* Fill out the OS statistics structure */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6157 | netdev->stats.multicast = hwstats->mprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6158 | |
| 6159 | /* Rx Errors */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6160 | netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 6161 | netdev->stats.rx_dropped = 0; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6162 | netdev->stats.rx_length_errors = hwstats->rlec; |
| 6163 | netdev->stats.rx_crc_errors = hwstats->crcerrs; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 6164 | netdev->stats.rx_missed_errors = total_mpc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6165 | } |
| 6166 | |
| 6167 | /** |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6168 | * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6169 | * @adapter: pointer to the device adapter structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6170 | **/ |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6171 | static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6172 | { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6173 | struct ixgbe_hw *hw = &adapter->hw; |
| 6174 | int i; |
| 6175 | |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6176 | if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 6177 | return; |
| 6178 | |
| 6179 | adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 6180 | |
| 6181 | /* if interface is down do nothing */ |
| 6182 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 6183 | return; |
| 6184 | |
| 6185 | /* do nothing if we are not using signature filters */ |
| 6186 | if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) |
| 6187 | return; |
| 6188 | |
| 6189 | adapter->fdir_overflow++; |
| 6190 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6191 | if (ixgbe_reinit_fdir_tables_82599(hw) == 0) { |
| 6192 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 6193 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 6194 | &(adapter->tx_ring[i]->state)); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6195 | /* re-enable flow director interrupts */ |
| 6196 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6197 | } else { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 6198 | e_err(probe, "failed to finish FDIR re-initialization, " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 6199 | "ignored adding FDIR ATR filters\n"); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6200 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6201 | } |
| 6202 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6203 | /** |
| 6204 | * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6205 | * @adapter: pointer to the device adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6206 | * |
| 6207 | * This function serves two purposes. First it strobes the interrupt lines |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 6208 | * in order to make certain interrupts are occurring. Secondly it sets the |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6209 | * 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] | 6210 | * determine if a hang has occurred. |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6211 | */ |
| 6212 | static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter) |
| 6213 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6214 | struct ixgbe_hw *hw = &adapter->hw; |
| 6215 | u64 eics = 0; |
| 6216 | int i; |
| 6217 | |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 6218 | /* If we're down, removing or resetting, just bail */ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6219 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 6220 | test_bit(__IXGBE_REMOVING, &adapter->state) || |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6221 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 6222 | return; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6223 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6224 | /* Force detection of hung controller */ |
| 6225 | if (netif_carrier_ok(adapter->netdev)) { |
| 6226 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 6227 | set_check_for_tx_hang(adapter->tx_ring[i]); |
| 6228 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6229 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 6230 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6231 | /* |
| 6232 | * for legacy and MSI interrupts don't set any bits |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 6233 | * that are enabled for EIAM, because this operation |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6234 | * would set *both* EIMS and EICS for any bit in EIAM |
| 6235 | */ |
| 6236 | IXGBE_WRITE_REG(hw, IXGBE_EICS, |
| 6237 | (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER)); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6238 | } else { |
| 6239 | /* get one bit for every active tx/rx interrupt vector */ |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 6240 | for (i = 0; i < adapter->num_q_vectors; i++) { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6241 | struct ixgbe_q_vector *qv = adapter->q_vector[i]; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 6242 | if (qv->rx.ring || qv->tx.ring) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6243 | eics |= ((u64)1 << i); |
| 6244 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6245 | } |
| 6246 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6247 | /* Cause software interrupt to ensure rings are cleaned */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6248 | ixgbe_irq_rearm_queues(adapter, eics); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6249 | } |
| 6250 | |
| 6251 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6252 | * ixgbe_watchdog_update_link - update the link status |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6253 | * @adapter: pointer to the device adapter structure |
| 6254 | * @link_speed: pointer to a u32 to store the link_speed |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6255 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6256 | static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter) |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6257 | { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6258 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6259 | u32 link_speed = adapter->link_speed; |
| 6260 | bool link_up = adapter->link_up; |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 6261 | bool pfc_en = adapter->dcb_cfg.pfc_mode_enable; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6262 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6263 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) |
| 6264 | return; |
| 6265 | |
| 6266 | if (hw->mac.ops.check_link) { |
| 6267 | 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] | 6268 | } else { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6269 | /* always assume link is up, if no check link function */ |
| 6270 | link_speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 6271 | link_up = true; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6272 | } |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 6273 | |
| 6274 | if (adapter->ixgbe_ieee_pfc) |
| 6275 | pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en); |
| 6276 | |
Alexander Duyck | 3ebe8fd | 2012-04-25 04:36:38 +0000 | [diff] [blame] | 6277 | if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) { |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 6278 | hw->mac.ops.fc_enable(hw); |
Alexander Duyck | 3ebe8fd | 2012-04-25 04:36:38 +0000 | [diff] [blame] | 6279 | ixgbe_set_rx_drop_en(adapter); |
| 6280 | } |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6281 | |
| 6282 | if (link_up || |
| 6283 | time_after(jiffies, (adapter->link_check_timeout + |
| 6284 | IXGBE_TRY_LINK_TIMEOUT))) { |
| 6285 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 6286 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC); |
| 6287 | IXGBE_WRITE_FLUSH(hw); |
| 6288 | } |
| 6289 | |
| 6290 | adapter->link_up = link_up; |
| 6291 | adapter->link_speed = link_speed; |
| 6292 | } |
| 6293 | |
Alexander Duyck | 107d301 | 2012-10-02 00:17:03 +0000 | [diff] [blame] | 6294 | static void ixgbe_update_default_up(struct ixgbe_adapter *adapter) |
| 6295 | { |
| 6296 | #ifdef CONFIG_IXGBE_DCB |
| 6297 | struct net_device *netdev = adapter->netdev; |
| 6298 | struct dcb_app app = { |
| 6299 | .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE, |
| 6300 | .protocol = 0, |
| 6301 | }; |
| 6302 | u8 up = 0; |
| 6303 | |
| 6304 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE) |
| 6305 | up = dcb_ieee_getapp_mask(netdev, &app); |
| 6306 | |
| 6307 | adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0; |
| 6308 | #endif |
| 6309 | } |
| 6310 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6311 | /** |
| 6312 | * ixgbe_watchdog_link_is_up - update netif_carrier status and |
| 6313 | * print link up message |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6314 | * @adapter: pointer to the device adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6315 | **/ |
| 6316 | static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter) |
| 6317 | { |
| 6318 | struct net_device *netdev = adapter->netdev; |
| 6319 | struct ixgbe_hw *hw = &adapter->hw; |
Emil Tantilov | cdc04dc | 2014-03-20 03:47:53 +0000 | [diff] [blame] | 6320 | struct net_device *upper; |
| 6321 | struct list_head *iter; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6322 | u32 link_speed = adapter->link_speed; |
| 6323 | bool flow_rx, flow_tx; |
| 6324 | |
| 6325 | /* only continue if link was previously down */ |
| 6326 | if (netif_carrier_ok(netdev)) |
| 6327 | return; |
| 6328 | |
| 6329 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 6330 | |
| 6331 | switch (hw->mac.type) { |
| 6332 | case ixgbe_mac_82598EB: { |
| 6333 | u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 6334 | u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS); |
| 6335 | flow_rx = !!(frctl & IXGBE_FCTRL_RFCE); |
| 6336 | flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X); |
| 6337 | } |
| 6338 | break; |
| 6339 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6340 | case ixgbe_mac_X550: |
| 6341 | case ixgbe_mac_X550EM_x: |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6342 | case ixgbe_mac_82599EB: { |
| 6343 | u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN); |
| 6344 | u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG); |
| 6345 | flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE); |
| 6346 | flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X); |
| 6347 | } |
| 6348 | break; |
| 6349 | default: |
| 6350 | flow_tx = false; |
| 6351 | flow_rx = false; |
| 6352 | break; |
| 6353 | } |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 6354 | |
Jacob Keller | 6cb562d | 2012-12-05 07:24:41 +0000 | [diff] [blame] | 6355 | adapter->last_rx_ptp_check = jiffies; |
| 6356 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 6357 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6358 | ixgbe_ptp_start_cyclecounter(adapter); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 6359 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6360 | e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", |
| 6361 | (link_speed == IXGBE_LINK_SPEED_10GB_FULL ? |
| 6362 | "10 Gbps" : |
| 6363 | (link_speed == IXGBE_LINK_SPEED_1GB_FULL ? |
| 6364 | "1 Gbps" : |
| 6365 | (link_speed == IXGBE_LINK_SPEED_100_FULL ? |
| 6366 | "100 Mbps" : |
| 6367 | "unknown speed"))), |
| 6368 | ((flow_rx && flow_tx) ? "RX/TX" : |
| 6369 | (flow_rx ? "RX" : |
| 6370 | (flow_tx ? "TX" : "None")))); |
| 6371 | |
| 6372 | netif_carrier_on(netdev); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6373 | ixgbe_check_vf_rate_limit(adapter); |
Alexander Duyck | befa2af | 2012-05-05 05:30:38 +0000 | [diff] [blame] | 6374 | |
Emil Tantilov | cdc04dc | 2014-03-20 03:47:53 +0000 | [diff] [blame] | 6375 | /* enable transmits */ |
| 6376 | netif_tx_wake_all_queues(adapter->netdev); |
| 6377 | |
| 6378 | /* enable any upper devices */ |
| 6379 | rtnl_lock(); |
| 6380 | netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) { |
| 6381 | if (netif_is_macvlan(upper)) { |
| 6382 | struct macvlan_dev *vlan = netdev_priv(upper); |
| 6383 | |
| 6384 | if (vlan->fwd_priv) |
| 6385 | netif_tx_wake_all_queues(upper); |
| 6386 | } |
| 6387 | } |
| 6388 | rtnl_unlock(); |
| 6389 | |
Alexander Duyck | 107d301 | 2012-10-02 00:17:03 +0000 | [diff] [blame] | 6390 | /* update the default user priority for VFs */ |
| 6391 | ixgbe_update_default_up(adapter); |
| 6392 | |
Alexander Duyck | befa2af | 2012-05-05 05:30:38 +0000 | [diff] [blame] | 6393 | /* ping all the active vfs to let them know link has changed */ |
| 6394 | ixgbe_ping_all_vfs(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6395 | } |
| 6396 | |
| 6397 | /** |
| 6398 | * ixgbe_watchdog_link_is_down - update netif_carrier status and |
| 6399 | * print link down message |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6400 | * @adapter: pointer to the adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6401 | **/ |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 6402 | static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6403 | { |
| 6404 | struct net_device *netdev = adapter->netdev; |
| 6405 | struct ixgbe_hw *hw = &adapter->hw; |
| 6406 | |
| 6407 | adapter->link_up = false; |
| 6408 | adapter->link_speed = 0; |
| 6409 | |
| 6410 | /* only continue if link was up previously */ |
| 6411 | if (!netif_carrier_ok(netdev)) |
| 6412 | return; |
| 6413 | |
| 6414 | /* poll for SFP+ cable when link is down */ |
| 6415 | if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB) |
| 6416 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 6417 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 6418 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6419 | ixgbe_ptp_start_cyclecounter(adapter); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 6420 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6421 | e_info(drv, "NIC Link is Down\n"); |
| 6422 | netif_carrier_off(netdev); |
Alexander Duyck | befa2af | 2012-05-05 05:30:38 +0000 | [diff] [blame] | 6423 | |
| 6424 | /* ping all the active vfs to let them know link has changed */ |
| 6425 | ixgbe_ping_all_vfs(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6426 | } |
| 6427 | |
Emil Tantilov | 07923c1 | 2014-08-12 07:12:08 +0000 | [diff] [blame] | 6428 | static bool ixgbe_ring_tx_pending(struct ixgbe_adapter *adapter) |
| 6429 | { |
| 6430 | int i; |
| 6431 | |
| 6432 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 6433 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 6434 | |
| 6435 | if (tx_ring->next_to_use != tx_ring->next_to_clean) |
| 6436 | return true; |
| 6437 | } |
| 6438 | |
| 6439 | return false; |
| 6440 | } |
| 6441 | |
| 6442 | static bool ixgbe_vf_tx_pending(struct ixgbe_adapter *adapter) |
| 6443 | { |
| 6444 | struct ixgbe_hw *hw = &adapter->hw; |
| 6445 | struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ]; |
| 6446 | u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask); |
| 6447 | |
| 6448 | int i, j; |
| 6449 | |
| 6450 | if (!adapter->num_vfs) |
| 6451 | return false; |
| 6452 | |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6453 | /* resetting the PF is only needed for MAC before X550 */ |
| 6454 | if (hw->mac.type >= ixgbe_mac_X550) |
| 6455 | return false; |
| 6456 | |
Emil Tantilov | 07923c1 | 2014-08-12 07:12:08 +0000 | [diff] [blame] | 6457 | for (i = 0; i < adapter->num_vfs; i++) { |
| 6458 | for (j = 0; j < q_per_pool; j++) { |
| 6459 | u32 h, t; |
| 6460 | |
| 6461 | h = IXGBE_READ_REG(hw, IXGBE_PVFTDHN(q_per_pool, i, j)); |
| 6462 | t = IXGBE_READ_REG(hw, IXGBE_PVFTDTN(q_per_pool, i, j)); |
| 6463 | |
| 6464 | if (h != t) |
| 6465 | return true; |
| 6466 | } |
| 6467 | } |
| 6468 | |
| 6469 | return false; |
| 6470 | } |
| 6471 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6472 | /** |
| 6473 | * ixgbe_watchdog_flush_tx - flush queues on link down |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6474 | * @adapter: pointer to the device adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6475 | **/ |
| 6476 | static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter) |
| 6477 | { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6478 | if (!netif_carrier_ok(adapter->netdev)) { |
Emil Tantilov | 07923c1 | 2014-08-12 07:12:08 +0000 | [diff] [blame] | 6479 | if (ixgbe_ring_tx_pending(adapter) || |
| 6480 | ixgbe_vf_tx_pending(adapter)) { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6481 | /* We've lost link, so the controller stops DMA, |
| 6482 | * but we've got queued Tx work that's never going |
| 6483 | * to get done, so reset controller to flush Tx. |
| 6484 | * (Do the reset outside of interrupt context). |
| 6485 | */ |
Jacob Keller | 12ff3f3 | 2012-12-01 07:57:17 +0000 | [diff] [blame] | 6486 | 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] | 6487 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6488 | } |
| 6489 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6490 | } |
| 6491 | |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 6492 | #ifdef CONFIG_PCI_IOV |
| 6493 | static inline void ixgbe_issue_vf_flr(struct ixgbe_adapter *adapter, |
| 6494 | struct pci_dev *vfdev) |
| 6495 | { |
| 6496 | if (!pci_wait_for_pending_transaction(vfdev)) |
| 6497 | e_dev_warn("Issuing VFLR with pending transactions\n"); |
| 6498 | |
| 6499 | e_dev_err("Issuing VFLR for VF %s\n", pci_name(vfdev)); |
| 6500 | pcie_capability_set_word(vfdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_BCR_FLR); |
| 6501 | |
| 6502 | msleep(100); |
| 6503 | } |
| 6504 | |
| 6505 | static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter) |
| 6506 | { |
| 6507 | struct ixgbe_hw *hw = &adapter->hw; |
| 6508 | struct pci_dev *pdev = adapter->pdev; |
| 6509 | struct pci_dev *vfdev; |
| 6510 | u32 gpc; |
| 6511 | int pos; |
| 6512 | unsigned short vf_id; |
| 6513 | |
| 6514 | if (!(netif_carrier_ok(adapter->netdev))) |
| 6515 | return; |
| 6516 | |
| 6517 | gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC); |
| 6518 | if (gpc) /* If incrementing then no need for the check below */ |
| 6519 | return; |
| 6520 | /* Check to see if a bad DMA write target from an errant or |
| 6521 | * malicious VF has caused a PCIe error. If so then we can |
| 6522 | * issue a VFLR to the offending VF(s) and then resume without |
| 6523 | * requesting a full slot reset. |
| 6524 | */ |
| 6525 | |
| 6526 | if (!pdev) |
| 6527 | return; |
| 6528 | |
| 6529 | pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV); |
| 6530 | if (!pos) |
| 6531 | return; |
| 6532 | |
| 6533 | /* get the device ID for the VF */ |
| 6534 | pci_read_config_word(pdev, pos + PCI_SRIOV_VF_DID, &vf_id); |
| 6535 | |
| 6536 | /* check status reg for all VFs owned by this PF */ |
| 6537 | vfdev = pci_get_device(pdev->vendor, vf_id, NULL); |
| 6538 | while (vfdev) { |
| 6539 | if (vfdev->is_virtfn && (vfdev->physfn == pdev)) { |
| 6540 | u16 status_reg; |
| 6541 | |
| 6542 | pci_read_config_word(vfdev, PCI_STATUS, &status_reg); |
| 6543 | if (status_reg & PCI_STATUS_REC_MASTER_ABORT) |
| 6544 | /* issue VFLR */ |
| 6545 | ixgbe_issue_vf_flr(adapter, vfdev); |
| 6546 | } |
| 6547 | |
| 6548 | vfdev = pci_get_device(pdev->vendor, vf_id, vfdev); |
| 6549 | } |
| 6550 | } |
| 6551 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6552 | static void ixgbe_spoof_check(struct ixgbe_adapter *adapter) |
| 6553 | { |
| 6554 | u32 ssvpc; |
| 6555 | |
Greg Rose | 0584d99 | 2012-08-08 00:00:58 +0000 | [diff] [blame] | 6556 | /* Do not perform spoof check for 82598 or if not in IOV mode */ |
| 6557 | if (adapter->hw.mac.type == ixgbe_mac_82598EB || |
| 6558 | adapter->num_vfs == 0) |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6559 | return; |
| 6560 | |
| 6561 | ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC); |
| 6562 | |
| 6563 | /* |
| 6564 | * ssvpc register is cleared on read, if zero then no |
| 6565 | * spoofed packets in the last interval. |
| 6566 | */ |
| 6567 | if (!ssvpc) |
| 6568 | return; |
| 6569 | |
Emil Tantilov | d6ea075 | 2012-08-08 06:28:37 +0000 | [diff] [blame] | 6570 | e_warn(drv, "%u Spoofed packets detected\n", ssvpc); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6571 | } |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 6572 | #else |
| 6573 | static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused *adapter) |
| 6574 | { |
| 6575 | } |
| 6576 | |
| 6577 | static void |
| 6578 | ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused *adapter) |
| 6579 | { |
| 6580 | } |
| 6581 | #endif /* CONFIG_PCI_IOV */ |
| 6582 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6583 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6584 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6585 | * ixgbe_watchdog_subtask - check and bring link up |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6586 | * @adapter: pointer to the device adapter structure |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6587 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6588 | static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6589 | { |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 6590 | /* if interface is down, removing or resetting, do nothing */ |
Emil Tantilov | 7edebf9 | 2011-08-27 07:18:37 +0000 | [diff] [blame] | 6591 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 6592 | test_bit(__IXGBE_REMOVING, &adapter->state) || |
Emil Tantilov | 7edebf9 | 2011-08-27 07:18:37 +0000 | [diff] [blame] | 6593 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6594 | return; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6595 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6596 | ixgbe_watchdog_update_link(adapter); |
John Fastabend | 10eec95 | 2010-02-03 14:23:32 +0000 | [diff] [blame] | 6597 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6598 | if (adapter->link_up) |
| 6599 | ixgbe_watchdog_link_is_up(adapter); |
| 6600 | else |
| 6601 | ixgbe_watchdog_link_is_down(adapter); |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 6602 | |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 6603 | ixgbe_check_for_bad_vf(adapter); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6604 | ixgbe_spoof_check(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6605 | ixgbe_update_stats(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6606 | |
| 6607 | ixgbe_watchdog_flush_tx(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6608 | } |
| 6609 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6610 | /** |
| 6611 | * ixgbe_sfp_detection_subtask - poll for SFP+ cable |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6612 | * @adapter: the ixgbe adapter structure |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6613 | **/ |
| 6614 | static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter) |
| 6615 | { |
| 6616 | struct ixgbe_hw *hw = &adapter->hw; |
| 6617 | s32 err; |
| 6618 | |
| 6619 | /* not searching for SFP so there is nothing to do here */ |
| 6620 | if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) && |
| 6621 | !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 6622 | return; |
| 6623 | |
| 6624 | /* someone else is in init, wait until next service event */ |
| 6625 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 6626 | return; |
| 6627 | |
| 6628 | err = hw->phy.ops.identify_sfp(hw); |
| 6629 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 6630 | goto sfp_out; |
| 6631 | |
| 6632 | if (err == IXGBE_ERR_SFP_NOT_PRESENT) { |
| 6633 | /* If no cable is present, then we need to reset |
| 6634 | * the next time we find a good cable. */ |
| 6635 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 6636 | } |
| 6637 | |
| 6638 | /* exit on error */ |
| 6639 | if (err) |
| 6640 | goto sfp_out; |
| 6641 | |
| 6642 | /* exit if reset not needed */ |
| 6643 | if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 6644 | goto sfp_out; |
| 6645 | |
| 6646 | adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 6647 | |
| 6648 | /* |
| 6649 | * A module may be identified correctly, but the EEPROM may not have |
| 6650 | * support for that module. setup_sfp() will fail in that case, so |
| 6651 | * we should not allow that module to load. |
| 6652 | */ |
| 6653 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 6654 | err = hw->phy.ops.reset(hw); |
| 6655 | else |
| 6656 | err = hw->mac.ops.setup_sfp(hw); |
| 6657 | |
| 6658 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 6659 | goto sfp_out; |
| 6660 | |
| 6661 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 6662 | e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type); |
| 6663 | |
| 6664 | sfp_out: |
| 6665 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 6666 | |
| 6667 | if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) && |
| 6668 | (adapter->netdev->reg_state == NETREG_REGISTERED)) { |
| 6669 | e_dev_err("failed to initialize because an unsupported " |
| 6670 | "SFP+ module type was detected.\n"); |
| 6671 | e_dev_err("Reload the driver after installing a " |
| 6672 | "supported module.\n"); |
| 6673 | unregister_netdev(adapter->netdev); |
| 6674 | } |
| 6675 | } |
| 6676 | |
| 6677 | /** |
| 6678 | * ixgbe_sfp_link_config_subtask - set up link SFP after module install |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6679 | * @adapter: the ixgbe adapter structure |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6680 | **/ |
| 6681 | static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter) |
| 6682 | { |
| 6683 | struct ixgbe_hw *hw = &adapter->hw; |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 6684 | u32 speed; |
| 6685 | bool autoneg = false; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6686 | |
| 6687 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG)) |
| 6688 | return; |
| 6689 | |
| 6690 | /* someone else is in init, wait until next service event */ |
| 6691 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 6692 | return; |
| 6693 | |
| 6694 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 6695 | |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 6696 | speed = hw->phy.autoneg_advertised; |
Emil Tantilov | ed33ff6 | 2013-08-30 07:55:24 +0000 | [diff] [blame] | 6697 | if ((!speed) && (hw->mac.ops.get_link_capabilities)) { |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 6698 | hw->mac.ops.get_link_capabilities(hw, &speed, &autoneg); |
Emil Tantilov | ed33ff6 | 2013-08-30 07:55:24 +0000 | [diff] [blame] | 6699 | |
| 6700 | /* setup the highest link when no autoneg */ |
| 6701 | if (!autoneg) { |
| 6702 | if (speed & IXGBE_LINK_SPEED_10GB_FULL) |
| 6703 | speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 6704 | } |
| 6705 | } |
| 6706 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6707 | if (hw->mac.ops.setup_link) |
Josh Hay | fd0326f | 2012-12-15 03:28:30 +0000 | [diff] [blame] | 6708 | hw->mac.ops.setup_link(hw, speed, true); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6709 | |
| 6710 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 6711 | adapter->link_check_timeout = jiffies; |
| 6712 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 6713 | } |
| 6714 | |
| 6715 | /** |
| 6716 | * ixgbe_service_timer - Timer Call-back |
| 6717 | * @data: pointer to adapter cast into an unsigned long |
| 6718 | **/ |
| 6719 | static void ixgbe_service_timer(unsigned long data) |
| 6720 | { |
| 6721 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
| 6722 | unsigned long next_event_offset; |
| 6723 | |
| 6724 | /* poll faster when waiting for link */ |
| 6725 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 6726 | next_event_offset = HZ / 10; |
| 6727 | else |
| 6728 | next_event_offset = HZ * 2; |
| 6729 | |
| 6730 | /* Reset the timer */ |
| 6731 | mod_timer(&adapter->service_timer, next_event_offset + jiffies); |
| 6732 | |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 6733 | ixgbe_service_event_schedule(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6734 | } |
| 6735 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6736 | static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter) |
| 6737 | { |
| 6738 | if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED)) |
| 6739 | return; |
| 6740 | |
| 6741 | adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED; |
| 6742 | |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 6743 | /* If we're already down, removing or resetting, just bail */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6744 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 6745 | test_bit(__IXGBE_REMOVING, &adapter->state) || |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6746 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 6747 | return; |
| 6748 | |
| 6749 | ixgbe_dump(adapter); |
| 6750 | netdev_err(adapter->netdev, "Reset adapter\n"); |
| 6751 | adapter->tx_timeout_count++; |
| 6752 | |
John Fastabend | 8f4c5c9 | 2014-01-16 02:30:05 -0800 | [diff] [blame] | 6753 | rtnl_lock(); |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6754 | ixgbe_reinit_locked(adapter); |
John Fastabend | 8f4c5c9 | 2014-01-16 02:30:05 -0800 | [diff] [blame] | 6755 | rtnl_unlock(); |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6756 | } |
| 6757 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6758 | /** |
| 6759 | * ixgbe_service_task - manages and runs subtasks |
| 6760 | * @work: pointer to work_struct containing our data |
| 6761 | **/ |
| 6762 | static void ixgbe_service_task(struct work_struct *work) |
| 6763 | { |
| 6764 | struct ixgbe_adapter *adapter = container_of(work, |
| 6765 | struct ixgbe_adapter, |
| 6766 | service_task); |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 6767 | if (ixgbe_removed(adapter->hw.hw_addr)) { |
| 6768 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 6769 | rtnl_lock(); |
| 6770 | ixgbe_down(adapter); |
| 6771 | rtnl_unlock(); |
| 6772 | } |
| 6773 | ixgbe_service_event_complete(adapter); |
| 6774 | return; |
| 6775 | } |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6776 | ixgbe_reset_subtask(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6777 | ixgbe_sfp_detection_subtask(adapter); |
| 6778 | ixgbe_sfp_link_config_subtask(adapter); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 6779 | ixgbe_check_overtemp_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6780 | ixgbe_watchdog_subtask(adapter); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6781 | ixgbe_fdir_reinit_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6782 | ixgbe_check_hang_subtask(adapter); |
Jacob Keller | 891dc08 | 2012-12-05 07:24:46 +0000 | [diff] [blame] | 6783 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 6784 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) { |
Jacob Keller | 891dc08 | 2012-12-05 07:24:46 +0000 | [diff] [blame] | 6785 | ixgbe_ptp_overflow_check(adapter); |
| 6786 | ixgbe_ptp_rx_hang(adapter); |
| 6787 | } |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6788 | |
| 6789 | ixgbe_service_event_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6790 | } |
| 6791 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6792 | static int ixgbe_tso(struct ixgbe_ring *tx_ring, |
| 6793 | struct ixgbe_tx_buffer *first, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6794 | u8 *hdr_len) |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6795 | { |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6796 | struct sk_buff *skb = first->skb; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6797 | u32 vlan_macip_lens, type_tucmd; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6798 | u32 mss_l4len_idx, l4len; |
Francois Romieu | 2049e1f | 2014-03-30 03:14:27 +0000 | [diff] [blame] | 6799 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6800 | |
Alexander Duyck | 8f4fbb9 | 2012-10-30 06:01:40 +0000 | [diff] [blame] | 6801 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 6802 | return 0; |
| 6803 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6804 | if (!skb_is_gso(skb)) |
| 6805 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6806 | |
Francois Romieu | 2049e1f | 2014-03-30 03:14:27 +0000 | [diff] [blame] | 6807 | err = skb_cow_head(skb, 0); |
| 6808 | if (err < 0) |
| 6809 | return err; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6810 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6811 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
| 6812 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 6813 | |
Joe Perches | a1108ff | 2014-03-13 05:19:25 +0000 | [diff] [blame] | 6814 | if (first->protocol == htons(ETH_P_IP)) { |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6815 | struct iphdr *iph = ip_hdr(skb); |
| 6816 | iph->tot_len = 0; |
| 6817 | iph->check = 0; |
| 6818 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 6819 | iph->daddr, 0, |
| 6820 | IPPROTO_TCP, |
| 6821 | 0); |
| 6822 | type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6823 | first->tx_flags |= IXGBE_TX_FLAGS_TSO | |
| 6824 | IXGBE_TX_FLAGS_CSUM | |
| 6825 | IXGBE_TX_FLAGS_IPV4; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6826 | } else if (skb_is_gso_v6(skb)) { |
| 6827 | ipv6_hdr(skb)->payload_len = 0; |
| 6828 | tcp_hdr(skb)->check = |
| 6829 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 6830 | &ipv6_hdr(skb)->daddr, |
| 6831 | 0, IPPROTO_TCP, 0); |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6832 | first->tx_flags |= IXGBE_TX_FLAGS_TSO | |
| 6833 | IXGBE_TX_FLAGS_CSUM; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6834 | } |
| 6835 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 6836 | /* compute header lengths */ |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6837 | l4len = tcp_hdrlen(skb); |
| 6838 | *hdr_len = skb_transport_offset(skb) + l4len; |
| 6839 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 6840 | /* update gso size and bytecount with header size */ |
| 6841 | first->gso_segs = skb_shinfo(skb)->gso_segs; |
| 6842 | first->bytecount += (first->gso_segs - 1) * *hdr_len; |
| 6843 | |
Alexander Duyck | c44f5f5 | 2012-10-30 06:01:45 +0000 | [diff] [blame] | 6844 | /* mss_l4len_id: use 0 as index for TSO */ |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6845 | mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6846 | mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6847 | |
| 6848 | /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */ |
| 6849 | vlan_macip_lens = skb_network_header_len(skb); |
| 6850 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6851 | vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6852 | |
| 6853 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6854 | mss_l4len_idx); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6855 | |
| 6856 | return 1; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6857 | } |
| 6858 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6859 | static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring, |
| 6860 | struct ixgbe_tx_buffer *first) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6861 | { |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6862 | struct sk_buff *skb = first->skb; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6863 | u32 vlan_macip_lens = 0; |
| 6864 | u32 mss_l4len_idx = 0; |
| 6865 | u32 type_tucmd = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6866 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6867 | if (skb->ip_summed != CHECKSUM_PARTIAL) { |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 6868 | if (!(first->tx_flags & IXGBE_TX_FLAGS_HW_VLAN) && |
| 6869 | !(first->tx_flags & IXGBE_TX_FLAGS_CC)) |
| 6870 | return; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6871 | } else { |
| 6872 | u8 l4_hdr = 0; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6873 | switch (first->protocol) { |
Joe Perches | a1108ff | 2014-03-13 05:19:25 +0000 | [diff] [blame] | 6874 | case htons(ETH_P_IP): |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6875 | vlan_macip_lens |= skb_network_header_len(skb); |
| 6876 | type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 6877 | l4_hdr = ip_hdr(skb)->protocol; |
| 6878 | break; |
Joe Perches | a1108ff | 2014-03-13 05:19:25 +0000 | [diff] [blame] | 6879 | case htons(ETH_P_IPV6): |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6880 | vlan_macip_lens |= skb_network_header_len(skb); |
| 6881 | l4_hdr = ipv6_hdr(skb)->nexthdr; |
| 6882 | break; |
| 6883 | default: |
| 6884 | if (unlikely(net_ratelimit())) { |
| 6885 | dev_warn(tx_ring->dev, |
| 6886 | "partial checksum but proto=%x!\n", |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6887 | first->protocol); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6888 | } |
| 6889 | break; |
| 6890 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6891 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6892 | switch (l4_hdr) { |
| 6893 | case IPPROTO_TCP: |
| 6894 | type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 6895 | mss_l4len_idx = tcp_hdrlen(skb) << |
| 6896 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6897 | break; |
| 6898 | case IPPROTO_SCTP: |
| 6899 | type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
| 6900 | mss_l4len_idx = sizeof(struct sctphdr) << |
| 6901 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6902 | break; |
| 6903 | case IPPROTO_UDP: |
| 6904 | mss_l4len_idx = sizeof(struct udphdr) << |
| 6905 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6906 | break; |
| 6907 | default: |
| 6908 | if (unlikely(net_ratelimit())) { |
| 6909 | dev_warn(tx_ring->dev, |
| 6910 | "partial checksum but l4 proto=%x!\n", |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6911 | l4_hdr); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6912 | } |
| 6913 | break; |
| 6914 | } |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6915 | |
| 6916 | /* update TX checksum flag */ |
| 6917 | first->tx_flags |= IXGBE_TX_FLAGS_CSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6918 | } |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6919 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6920 | /* vlan_macip_lens: MACLEN, VLAN tag */ |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6921 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6922 | vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6923 | |
| 6924 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, |
| 6925 | type_tucmd, mss_l4len_idx); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6926 | } |
| 6927 | |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 6928 | #define IXGBE_SET_FLAG(_input, _flag, _result) \ |
| 6929 | ((_flag <= _result) ? \ |
| 6930 | ((u32)(_input & _flag) * (_result / _flag)) : \ |
| 6931 | ((u32)(_input & _flag) / (_flag / _result))) |
| 6932 | |
| 6933 | 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] | 6934 | { |
| 6935 | /* set type for advanced descriptor with frame checksum insertion */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 6936 | u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA | |
| 6937 | IXGBE_ADVTXD_DCMD_DEXT | |
| 6938 | IXGBE_ADVTXD_DCMD_IFCS; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6939 | |
| 6940 | /* set HW vlan bit if vlan is present */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 6941 | cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN, |
| 6942 | IXGBE_ADVTXD_DCMD_VLE); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 6943 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6944 | /* set segmentation enable bits for TSO/FSO */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 6945 | cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO, |
| 6946 | IXGBE_ADVTXD_DCMD_TSE); |
| 6947 | |
| 6948 | /* set timestamp bit if present */ |
| 6949 | cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP, |
| 6950 | IXGBE_ADVTXD_MAC_TSTAMP); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6951 | |
Alexander Duyck | 62748b7 | 2012-07-20 08:09:01 +0000 | [diff] [blame] | 6952 | /* insert frame checksum */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 6953 | 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] | 6954 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6955 | return cmd_type; |
| 6956 | } |
| 6957 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6958 | static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc, |
| 6959 | u32 tx_flags, unsigned int paylen) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6960 | { |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 6961 | u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6962 | |
| 6963 | /* enable L4 checksum for TSO and TX checksum offload */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 6964 | olinfo_status |= IXGBE_SET_FLAG(tx_flags, |
| 6965 | IXGBE_TX_FLAGS_CSUM, |
| 6966 | IXGBE_ADVTXD_POPTS_TXSM); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6967 | |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 6968 | /* enble IPv4 checksum for TSO */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 6969 | olinfo_status |= IXGBE_SET_FLAG(tx_flags, |
| 6970 | IXGBE_TX_FLAGS_IPV4, |
| 6971 | IXGBE_ADVTXD_POPTS_IXSM); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6972 | |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 6973 | /* |
| 6974 | * Check Context must be set if Tx switch is enabled, which it |
| 6975 | * always is for case where virtual functions are running |
| 6976 | */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 6977 | olinfo_status |= IXGBE_SET_FLAG(tx_flags, |
| 6978 | IXGBE_TX_FLAGS_CC, |
| 6979 | IXGBE_ADVTXD_CC); |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 6980 | |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 6981 | tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6982 | } |
| 6983 | |
Daniel Borkmann | 2367a17 | 2014-08-26 19:34:18 +0200 | [diff] [blame] | 6984 | static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size) |
| 6985 | { |
| 6986 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 6987 | |
| 6988 | /* Herbert's original patch had: |
| 6989 | * smp_mb__after_netif_stop_queue(); |
| 6990 | * but since that doesn't exist yet, just open code it. |
| 6991 | */ |
| 6992 | smp_mb(); |
| 6993 | |
| 6994 | /* We need to check again in a case another CPU has just |
| 6995 | * made room available. |
| 6996 | */ |
| 6997 | if (likely(ixgbe_desc_unused(tx_ring) < size)) |
| 6998 | return -EBUSY; |
| 6999 | |
| 7000 | /* A reprieve! - use start_queue because it doesn't call schedule */ |
| 7001 | netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 7002 | ++tx_ring->tx_stats.restart_queue; |
| 7003 | return 0; |
| 7004 | } |
| 7005 | |
| 7006 | static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size) |
| 7007 | { |
| 7008 | if (likely(ixgbe_desc_unused(tx_ring) >= size)) |
| 7009 | return 0; |
| 7010 | |
| 7011 | return __ixgbe_maybe_stop_tx(tx_ring, size); |
| 7012 | } |
| 7013 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7014 | #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \ |
| 7015 | IXGBE_TXD_CMD_RS) |
| 7016 | |
| 7017 | static void ixgbe_tx_map(struct ixgbe_ring *tx_ring, |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7018 | struct ixgbe_tx_buffer *first, |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7019 | const u8 hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7020 | { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7021 | struct sk_buff *skb = first->skb; |
| 7022 | struct ixgbe_tx_buffer *tx_buffer; |
| 7023 | union ixgbe_adv_tx_desc *tx_desc; |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7024 | struct skb_frag_struct *frag; |
| 7025 | dma_addr_t dma; |
| 7026 | unsigned int data_len, size; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7027 | u32 tx_flags = first->tx_flags; |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7028 | u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7029 | u16 i = tx_ring->next_to_use; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7030 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7031 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
| 7032 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7033 | ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len); |
| 7034 | |
| 7035 | size = skb_headlen(skb); |
| 7036 | data_len = skb->data_len; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7037 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7038 | #ifdef IXGBE_FCOE |
| 7039 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7040 | if (data_len < sizeof(struct fcoe_crc_eof)) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7041 | size -= sizeof(struct fcoe_crc_eof) - data_len; |
| 7042 | data_len = 0; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7043 | } else { |
| 7044 | data_len -= sizeof(struct fcoe_crc_eof); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 7045 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7046 | } |
| 7047 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7048 | #endif |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7049 | 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] | 7050 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7051 | tx_buffer = first; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7052 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7053 | for (frag = &skb_shinfo(skb)->frags[0];; frag++) { |
| 7054 | if (dma_mapping_error(tx_ring->dev, dma)) |
| 7055 | goto dma_error; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7056 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7057 | /* record length, and DMA address */ |
| 7058 | dma_unmap_len_set(tx_buffer, len, size); |
| 7059 | dma_unmap_addr_set(tx_buffer, dma, dma); |
| 7060 | |
| 7061 | tx_desc->read.buffer_addr = cpu_to_le64(dma); |
| 7062 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7063 | while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7064 | tx_desc->read.cmd_type_len = |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7065 | cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7066 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7067 | i++; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7068 | tx_desc++; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7069 | if (i == tx_ring->count) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 7070 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7071 | i = 0; |
| 7072 | } |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7073 | tx_desc->read.olinfo_status = 0; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7074 | |
| 7075 | dma += IXGBE_MAX_DATA_PER_TXD; |
| 7076 | size -= IXGBE_MAX_DATA_PER_TXD; |
| 7077 | |
| 7078 | tx_desc->read.buffer_addr = cpu_to_le64(dma); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7079 | } |
| 7080 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7081 | if (likely(!data_len)) |
| 7082 | break; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7083 | |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7084 | tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7085 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7086 | i++; |
| 7087 | tx_desc++; |
| 7088 | if (i == tx_ring->count) { |
| 7089 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
| 7090 | i = 0; |
| 7091 | } |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7092 | tx_desc->read.olinfo_status = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7093 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7094 | #ifdef IXGBE_FCOE |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 7095 | size = min_t(unsigned int, data_len, skb_frag_size(frag)); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7096 | #else |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 7097 | size = skb_frag_size(frag); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7098 | #endif |
| 7099 | data_len -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7100 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7101 | dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size, |
| 7102 | DMA_TO_DEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7103 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7104 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7105 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 7106 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7107 | /* write last descriptor with RS and EOP bits */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7108 | cmd_type |= size | IXGBE_TXD_CMD; |
| 7109 | tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7110 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 7111 | netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount); |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 7112 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7113 | /* set the timestamp */ |
| 7114 | first->time_stamp = jiffies; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7115 | |
| 7116 | /* |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7117 | * Force memory writes to complete before letting h/w know there |
| 7118 | * are new descriptors to fetch. (Only applicable for weak-ordered |
| 7119 | * memory model archs, such as IA-64). |
| 7120 | * |
| 7121 | * We also need this memory barrier to make certain all of the |
| 7122 | * status bits have been updated before next_to_watch is written. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7123 | */ |
| 7124 | wmb(); |
| 7125 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7126 | /* set next_to_watch value indicating a packet is present */ |
| 7127 | first->next_to_watch = tx_desc; |
| 7128 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7129 | i++; |
| 7130 | if (i == tx_ring->count) |
| 7131 | i = 0; |
| 7132 | |
| 7133 | tx_ring->next_to_use = i; |
| 7134 | |
Daniel Borkmann | 2367a17 | 2014-08-26 19:34:18 +0200 | [diff] [blame] | 7135 | ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED); |
| 7136 | |
| 7137 | if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) { |
Alexander Duyck | ad435ec | 2014-11-14 00:56:35 +0000 | [diff] [blame] | 7138 | writel(i, tx_ring->tail); |
| 7139 | |
| 7140 | /* we need this if more than one processor can write to our tail |
| 7141 | * at a time, it synchronizes IO on IA64/Altix systems |
| 7142 | */ |
| 7143 | mmiowb(); |
Daniel Borkmann | 9c938cd | 2014-08-24 15:42:16 +0200 | [diff] [blame] | 7144 | } |
Daniel Borkmann | 2367a17 | 2014-08-26 19:34:18 +0200 | [diff] [blame] | 7145 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7146 | return; |
| 7147 | dma_error: |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7148 | dev_err(tx_ring->dev, "TX DMA map failed\n"); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7149 | |
| 7150 | /* clear dma mappings for failed tx_buffer_info map */ |
| 7151 | for (;;) { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7152 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
| 7153 | ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer); |
| 7154 | if (tx_buffer == first) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7155 | break; |
| 7156 | if (i == 0) |
| 7157 | i = tx_ring->count; |
| 7158 | i--; |
| 7159 | } |
| 7160 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7161 | tx_ring->next_to_use = i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7162 | } |
| 7163 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7164 | static void ixgbe_atr(struct ixgbe_ring *ring, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7165 | struct ixgbe_tx_buffer *first) |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7166 | { |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7167 | struct ixgbe_q_vector *q_vector = ring->q_vector; |
| 7168 | union ixgbe_atr_hash_dword input = { .dword = 0 }; |
| 7169 | union ixgbe_atr_hash_dword common = { .dword = 0 }; |
| 7170 | union { |
| 7171 | unsigned char *network; |
| 7172 | struct iphdr *ipv4; |
| 7173 | struct ipv6hdr *ipv6; |
| 7174 | } hdr; |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 7175 | struct tcphdr *th; |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 7176 | __be16 vlan_id; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7177 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7178 | /* if ring doesn't have a interrupt vector, cannot perform ATR */ |
| 7179 | if (!q_vector) |
Guillaume Gaudonville | d3ead24 | 2010-06-29 18:29:00 +0000 | [diff] [blame] | 7180 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7181 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7182 | /* do nothing if sampling is disabled */ |
| 7183 | if (!ring->atr_sample_rate) |
| 7184 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7185 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7186 | ring->atr_count++; |
| 7187 | |
| 7188 | /* snag network header to get L4 type and address */ |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7189 | hdr.network = skb_network_header(first->skb); |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7190 | |
| 7191 | /* Currently only IPv4/IPv6 with TCP is supported */ |
Joe Perches | a1108ff | 2014-03-13 05:19:25 +0000 | [diff] [blame] | 7192 | if ((first->protocol != htons(ETH_P_IPV6) || |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7193 | hdr.ipv6->nexthdr != IPPROTO_TCP) && |
Joe Perches | a1108ff | 2014-03-13 05:19:25 +0000 | [diff] [blame] | 7194 | (first->protocol != htons(ETH_P_IP) || |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7195 | hdr.ipv4->protocol != IPPROTO_TCP)) |
| 7196 | return; |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 7197 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7198 | th = tcp_hdr(first->skb); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7199 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7200 | /* skip this packet since it is invalid or the socket is closing */ |
| 7201 | if (!th || th->fin) |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7202 | return; |
| 7203 | |
| 7204 | /* sample on all syn packets or once every atr sample count */ |
| 7205 | if (!th->syn && (ring->atr_count < ring->atr_sample_rate)) |
| 7206 | return; |
| 7207 | |
| 7208 | /* reset sample count */ |
| 7209 | ring->atr_count = 0; |
| 7210 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7211 | vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT); |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7212 | |
| 7213 | /* |
| 7214 | * src and dst are inverted, think how the receiver sees them |
| 7215 | * |
| 7216 | * The input is broken into two sections, a non-compressed section |
| 7217 | * containing vm_pool, vlan_id, and flow_type. The rest of the data |
| 7218 | * is XORed together and stored in the compressed dword. |
| 7219 | */ |
| 7220 | input.formatted.vlan_id = vlan_id; |
| 7221 | |
| 7222 | /* |
| 7223 | * since src port and flex bytes occupy the same word XOR them together |
| 7224 | * and write the value to source port portion of compressed dword |
| 7225 | */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7226 | 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] | 7227 | common.port.src ^= th->dest ^ htons(ETH_P_8021Q); |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7228 | else |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7229 | common.port.src ^= th->dest ^ first->protocol; |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7230 | common.port.dst ^= th->source; |
| 7231 | |
Joe Perches | a1108ff | 2014-03-13 05:19:25 +0000 | [diff] [blame] | 7232 | if (first->protocol == htons(ETH_P_IP)) { |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7233 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4; |
| 7234 | common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr; |
| 7235 | } else { |
| 7236 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6; |
| 7237 | common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^ |
| 7238 | hdr.ipv6->saddr.s6_addr32[1] ^ |
| 7239 | hdr.ipv6->saddr.s6_addr32[2] ^ |
| 7240 | hdr.ipv6->saddr.s6_addr32[3] ^ |
| 7241 | hdr.ipv6->daddr.s6_addr32[0] ^ |
| 7242 | hdr.ipv6->daddr.s6_addr32[1] ^ |
| 7243 | hdr.ipv6->daddr.s6_addr32[2] ^ |
| 7244 | hdr.ipv6->daddr.s6_addr32[3]; |
| 7245 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7246 | |
| 7247 | /* 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] | 7248 | ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw, |
| 7249 | input, common, ring->queue_index); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7250 | } |
| 7251 | |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 7252 | 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] | 7253 | void *accel_priv, select_queue_fallback_t fallback) |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 7254 | { |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 7255 | struct ixgbe_fwd_adapter *fwd_adapter = accel_priv; |
| 7256 | #ifdef IXGBE_FCOE |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 7257 | struct ixgbe_adapter *adapter; |
| 7258 | struct ixgbe_ring_feature *f; |
| 7259 | int txq; |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 7260 | #endif |
| 7261 | |
| 7262 | if (fwd_adapter) |
| 7263 | return skb->queue_mapping + fwd_adapter->tx_base_queue; |
| 7264 | |
| 7265 | #ifdef IXGBE_FCOE |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 7266 | |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 7267 | /* |
| 7268 | * only execute the code below if protocol is FCoE |
| 7269 | * or FIP and we have FCoE enabled on the adapter |
| 7270 | */ |
| 7271 | switch (vlan_get_protocol(skb)) { |
Joe Perches | a1108ff | 2014-03-13 05:19:25 +0000 | [diff] [blame] | 7272 | case htons(ETH_P_FCOE): |
| 7273 | case htons(ETH_P_FIP): |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 7274 | adapter = netdev_priv(dev); |
Alexander Duyck | c087663 | 2012-05-10 00:01:46 +0000 | [diff] [blame] | 7275 | |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 7276 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 7277 | break; |
| 7278 | default: |
Daniel Borkmann | 99932d4 | 2014-02-16 15:55:20 +0100 | [diff] [blame] | 7279 | return fallback(dev, skb); |
Krishna Kumar | fdd3d63 | 2010-02-03 13:13:10 +0000 | [diff] [blame] | 7280 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7281 | |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 7282 | f = &adapter->ring_feature[RING_F_FCOE]; |
| 7283 | |
| 7284 | txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) : |
| 7285 | smp_processor_id(); |
| 7286 | |
| 7287 | while (txq >= f->indices) |
| 7288 | txq -= f->indices; |
| 7289 | |
| 7290 | return txq + f->offset; |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 7291 | #else |
Daniel Borkmann | 99932d4 | 2014-02-16 15:55:20 +0100 | [diff] [blame] | 7292 | return fallback(dev, skb); |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 7293 | #endif |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 7294 | } |
| 7295 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 7296 | netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb, |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 7297 | struct ixgbe_adapter *adapter, |
| 7298 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7299 | { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7300 | struct ixgbe_tx_buffer *first; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 7301 | int tso; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7302 | u32 tx_flags = 0; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7303 | unsigned short f; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7304 | u16 count = TXD_USE_COUNT(skb_headlen(skb)); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7305 | __be16 protocol = skb->protocol; |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 7306 | u8 hdr_len = 0; |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 7307 | |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7308 | /* |
| 7309 | * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD, |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 7310 | * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD, |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7311 | * + 2 desc gap to keep tail from touching head, |
| 7312 | * + 1 desc for context descriptor, |
| 7313 | * otherwise try next time |
| 7314 | */ |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7315 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) |
| 7316 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size); |
Alexander Duyck | 7f66162 | 2013-02-09 01:19:55 +0000 | [diff] [blame] | 7317 | |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7318 | if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) { |
| 7319 | tx_ring->tx_stats.tx_busy++; |
| 7320 | return NETDEV_TX_BUSY; |
| 7321 | } |
| 7322 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7323 | /* record the location of the first descriptor for this packet */ |
| 7324 | first = &tx_ring->tx_buffer_info[tx_ring->next_to_use]; |
| 7325 | first->skb = skb; |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 7326 | first->bytecount = skb->len; |
| 7327 | first->gso_segs = 1; |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7328 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7329 | /* 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] | 7330 | if (skb_vlan_tag_present(skb)) { |
| 7331 | tx_flags |= skb_vlan_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7332 | tx_flags |= IXGBE_TX_FLAGS_HW_VLAN; |
| 7333 | /* 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] | 7334 | } else if (protocol == htons(ETH_P_8021Q)) { |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7335 | struct vlan_hdr *vhdr, _vhdr; |
| 7336 | vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr); |
| 7337 | if (!vhdr) |
| 7338 | goto out_drop; |
| 7339 | |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 7340 | tx_flags |= ntohs(vhdr->h_vlan_TCI) << |
| 7341 | IXGBE_TX_FLAGS_VLAN_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7342 | tx_flags |= IXGBE_TX_FLAGS_SW_VLAN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7343 | } |
Toshiaki Makita | 0213668 | 2015-01-29 20:37:09 +0900 | [diff] [blame] | 7344 | protocol = vlan_get_protocol(skb); |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7345 | |
Mark Rustad | d523493 | 2014-08-09 07:02:09 +0000 | [diff] [blame] | 7346 | if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && |
| 7347 | adapter->ptp_clock && |
| 7348 | !test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS, |
| 7349 | &adapter->state)) { |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7350 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; |
| 7351 | tx_flags |= IXGBE_TX_FLAGS_TSTAMP; |
Jacob Keller | 891dc08 | 2012-12-05 07:24:46 +0000 | [diff] [blame] | 7352 | |
| 7353 | /* schedule check for Tx timestamp */ |
| 7354 | adapter->ptp_tx_skb = skb_get(skb); |
| 7355 | adapter->ptp_tx_start = jiffies; |
| 7356 | schedule_work(&adapter->ptp_tx_work); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7357 | } |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7358 | |
Jakub Kicinski | ff29a86 | 2014-03-15 14:55:16 +0000 | [diff] [blame] | 7359 | skb_tx_timestamp(skb); |
| 7360 | |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 7361 | #ifdef CONFIG_PCI_IOV |
| 7362 | /* |
| 7363 | * Use the l2switch_enable flag - would be false if the DMA |
| 7364 | * Tx switch had been disabled. |
| 7365 | */ |
| 7366 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7367 | tx_flags |= IXGBE_TX_FLAGS_CC; |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 7368 | |
| 7369 | #endif |
John Fastabend | 32701dc | 2011-09-27 03:51:56 +0000 | [diff] [blame] | 7370 | /* 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] | 7371 | if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && |
Alexander Duyck | 09dca47 | 2011-07-20 00:09:10 +0000 | [diff] [blame] | 7372 | ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) || |
| 7373 | (skb->priority != TC_PRIO_CONTROL))) { |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7374 | tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK; |
John Fastabend | 32701dc | 2011-09-27 03:51:56 +0000 | [diff] [blame] | 7375 | tx_flags |= (skb->priority & 0x7) << |
| 7376 | IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7377 | if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) { |
| 7378 | struct vlan_ethhdr *vhdr; |
Francois Romieu | 2049e1f | 2014-03-30 03:14:27 +0000 | [diff] [blame] | 7379 | |
| 7380 | if (skb_cow_head(skb, 0)) |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7381 | goto out_drop; |
| 7382 | vhdr = (struct vlan_ethhdr *)skb->data; |
| 7383 | vhdr->h_vlan_TCI = htons(tx_flags >> |
| 7384 | IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 7385 | } else { |
| 7386 | tx_flags |= IXGBE_TX_FLAGS_HW_VLAN; |
| 7387 | } |
| 7388 | } |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7389 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7390 | /* record initial flags and protocol */ |
| 7391 | first->tx_flags = tx_flags; |
| 7392 | first->protocol = protocol; |
| 7393 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7394 | #ifdef IXGBE_FCOE |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7395 | /* setup tx offload for FCoE */ |
Joe Perches | a1108ff | 2014-03-13 05:19:25 +0000 | [diff] [blame] | 7396 | if ((protocol == htons(ETH_P_FCOE)) && |
Alexander Duyck | a58915c | 2012-05-25 06:38:18 +0000 | [diff] [blame] | 7397 | (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) { |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7398 | tso = ixgbe_fso(tx_ring, first, &hdr_len); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7399 | if (tso < 0) |
| 7400 | goto out_drop; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7401 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7402 | goto xmit_fcoe; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 7403 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7404 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7405 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7406 | tso = ixgbe_tso(tx_ring, first, &hdr_len); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7407 | if (tso < 0) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7408 | goto out_drop; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7409 | else if (!tso) |
| 7410 | ixgbe_tx_csum(tx_ring, first); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7411 | |
| 7412 | /* add the ATR filter if ATR is on */ |
| 7413 | if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state)) |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7414 | ixgbe_atr(tx_ring, first); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7415 | |
| 7416 | #ifdef IXGBE_FCOE |
| 7417 | xmit_fcoe: |
| 7418 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7419 | ixgbe_tx_map(tx_ring, first, hdr_len); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7420 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7421 | return NETDEV_TX_OK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7422 | |
| 7423 | out_drop: |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7424 | dev_kfree_skb_any(first->skb); |
| 7425 | first->skb = NULL; |
| 7426 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7427 | return NETDEV_TX_OK; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7428 | } |
| 7429 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 7430 | static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb, |
| 7431 | struct net_device *netdev, |
| 7432 | struct ixgbe_ring *ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7433 | { |
| 7434 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7435 | struct ixgbe_ring *tx_ring; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7436 | |
Alexander Duyck | a50c29d | 2012-02-08 07:50:40 +0000 | [diff] [blame] | 7437 | /* |
| 7438 | * The minimum packet size for olinfo paylen is 17 so pad the skb |
| 7439 | * in order to meet this minimum size requirement. |
| 7440 | */ |
Alexander Duyck | a94d9e2 | 2014-12-03 08:17:39 -0800 | [diff] [blame] | 7441 | if (skb_put_padto(skb, 17)) |
| 7442 | return NETDEV_TX_OK; |
Alexander Duyck | a50c29d | 2012-02-08 07:50:40 +0000 | [diff] [blame] | 7443 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 7444 | tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping]; |
| 7445 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7446 | return ixgbe_xmit_frame_ring(skb, adapter, tx_ring); |
| 7447 | } |
| 7448 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 7449 | static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, |
| 7450 | struct net_device *netdev) |
| 7451 | { |
| 7452 | return __ixgbe_xmit_frame(skb, netdev, NULL); |
| 7453 | } |
| 7454 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7455 | /** |
| 7456 | * ixgbe_set_mac - Change the Ethernet Address of the NIC |
| 7457 | * @netdev: network interface device structure |
| 7458 | * @p: pointer to an address structure |
| 7459 | * |
| 7460 | * Returns 0 on success, negative on failure |
| 7461 | **/ |
| 7462 | static int ixgbe_set_mac(struct net_device *netdev, void *p) |
| 7463 | { |
| 7464 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7465 | struct ixgbe_hw *hw = &adapter->hw; |
| 7466 | struct sockaddr *addr = p; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 7467 | int ret; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7468 | |
| 7469 | if (!is_valid_ether_addr(addr->sa_data)) |
| 7470 | return -EADDRNOTAVAIL; |
| 7471 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 7472 | ixgbe_del_mac_filter(adapter, hw->mac.addr, VMDQ_P(0)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7473 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7474 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7475 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 7476 | ret = ixgbe_add_mac_filter(adapter, hw->mac.addr, VMDQ_P(0)); |
| 7477 | return ret > 0 ? 0 : ret; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7478 | } |
| 7479 | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7480 | static int |
| 7481 | ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr) |
| 7482 | { |
| 7483 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7484 | struct ixgbe_hw *hw = &adapter->hw; |
| 7485 | u16 value; |
| 7486 | int rc; |
| 7487 | |
| 7488 | if (prtad != hw->phy.mdio.prtad) |
| 7489 | return -EINVAL; |
| 7490 | rc = hw->phy.ops.read_reg(hw, addr, devad, &value); |
| 7491 | if (!rc) |
| 7492 | rc = value; |
| 7493 | return rc; |
| 7494 | } |
| 7495 | |
| 7496 | static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad, |
| 7497 | u16 addr, u16 value) |
| 7498 | { |
| 7499 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7500 | struct ixgbe_hw *hw = &adapter->hw; |
| 7501 | |
| 7502 | if (prtad != hw->phy.mdio.prtad) |
| 7503 | return -EINVAL; |
| 7504 | return hw->phy.ops.write_reg(hw, addr, devad, value); |
| 7505 | } |
| 7506 | |
| 7507 | static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd) |
| 7508 | { |
| 7509 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7510 | |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7511 | switch (cmd) { |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7512 | case SIOCSHWTSTAMP: |
Jacob Keller | 93501d4 | 2014-02-28 15:48:58 -0800 | [diff] [blame] | 7513 | return ixgbe_ptp_set_ts_config(adapter, req); |
| 7514 | case SIOCGHWTSTAMP: |
| 7515 | return ixgbe_ptp_get_ts_config(adapter, req); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7516 | default: |
| 7517 | return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd); |
| 7518 | } |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7519 | } |
| 7520 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7521 | /** |
| 7522 | * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 7523 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7524 | * @netdev: network interface device structure |
| 7525 | * |
| 7526 | * Returns non-zero on failure |
| 7527 | **/ |
| 7528 | static int ixgbe_add_sanmac_netdev(struct net_device *dev) |
| 7529 | { |
| 7530 | int err = 0; |
| 7531 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 7532 | struct ixgbe_hw *hw = &adapter->hw; |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7533 | |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 7534 | if (is_valid_ether_addr(hw->mac.san_addr)) { |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7535 | rtnl_lock(); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 7536 | 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] | 7537 | rtnl_unlock(); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 7538 | |
| 7539 | /* update SAN MAC vmdq pool selection */ |
| 7540 | hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0)); |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7541 | } |
| 7542 | return err; |
| 7543 | } |
| 7544 | |
| 7545 | /** |
| 7546 | * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 7547 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7548 | * @netdev: network interface device structure |
| 7549 | * |
| 7550 | * Returns non-zero on failure |
| 7551 | **/ |
| 7552 | static int ixgbe_del_sanmac_netdev(struct net_device *dev) |
| 7553 | { |
| 7554 | int err = 0; |
| 7555 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 7556 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 7557 | |
| 7558 | if (is_valid_ether_addr(mac->san_addr)) { |
| 7559 | rtnl_lock(); |
| 7560 | err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 7561 | rtnl_unlock(); |
| 7562 | } |
| 7563 | return err; |
| 7564 | } |
| 7565 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7566 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7567 | /* |
| 7568 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 7569 | * without having to re-enable interrupts. It's not called while |
| 7570 | * the interrupt routine is executing. |
| 7571 | */ |
| 7572 | static void ixgbe_netpoll(struct net_device *netdev) |
| 7573 | { |
| 7574 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 7575 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7576 | |
Alexander Duyck | 1a647bd | 2010-01-13 01:49:13 +0000 | [diff] [blame] | 7577 | /* if interface is down do nothing */ |
| 7578 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 7579 | return; |
| 7580 | |
Alexander Duyck | 856f606 | 2015-02-25 17:45:54 +0000 | [diff] [blame] | 7581 | /* loop through and schedule all active queues */ |
| 7582 | for (i = 0; i < adapter->num_q_vectors; i++) |
| 7583 | ixgbe_msix_clean_rings(0, adapter->q_vector[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7584 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7585 | |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 7586 | #endif |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7587 | static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev, |
| 7588 | struct rtnl_link_stats64 *stats) |
| 7589 | { |
| 7590 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7591 | int i; |
| 7592 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7593 | rcu_read_lock(); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7594 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7595 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7596 | u64 bytes, packets; |
| 7597 | unsigned int start; |
| 7598 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7599 | if (ring) { |
| 7600 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7601 | start = u64_stats_fetch_begin_irq(&ring->syncp); |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7602 | packets = ring->stats.packets; |
| 7603 | bytes = ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7604 | } while (u64_stats_fetch_retry_irq(&ring->syncp, start)); |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7605 | stats->rx_packets += packets; |
| 7606 | stats->rx_bytes += bytes; |
| 7607 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7608 | } |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 7609 | |
| 7610 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 7611 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]); |
| 7612 | u64 bytes, packets; |
| 7613 | unsigned int start; |
| 7614 | |
| 7615 | if (ring) { |
| 7616 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7617 | start = u64_stats_fetch_begin_irq(&ring->syncp); |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 7618 | packets = ring->stats.packets; |
| 7619 | bytes = ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7620 | } while (u64_stats_fetch_retry_irq(&ring->syncp, start)); |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 7621 | stats->tx_packets += packets; |
| 7622 | stats->tx_bytes += bytes; |
| 7623 | } |
| 7624 | } |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7625 | rcu_read_unlock(); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7626 | /* following stats updated by ixgbe_watchdog_task() */ |
| 7627 | stats->multicast = netdev->stats.multicast; |
| 7628 | stats->rx_errors = netdev->stats.rx_errors; |
| 7629 | stats->rx_length_errors = netdev->stats.rx_length_errors; |
| 7630 | stats->rx_crc_errors = netdev->stats.rx_crc_errors; |
| 7631 | stats->rx_missed_errors = netdev->stats.rx_missed_errors; |
| 7632 | return stats; |
| 7633 | } |
| 7634 | |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 7635 | #ifdef CONFIG_IXGBE_DCB |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7636 | /** |
| 7637 | * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid. |
| 7638 | * @adapter: pointer to ixgbe_adapter |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7639 | * @tc: number of traffic classes currently enabled |
| 7640 | * |
| 7641 | * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm |
| 7642 | * 802.1Q priority maps to a packet buffer that exists. |
| 7643 | */ |
| 7644 | static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc) |
| 7645 | { |
| 7646 | struct ixgbe_hw *hw = &adapter->hw; |
| 7647 | u32 reg, rsave; |
| 7648 | int i; |
| 7649 | |
| 7650 | /* 82598 have a static priority to TC mapping that can not |
| 7651 | * be changed so no validation is needed. |
| 7652 | */ |
| 7653 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 7654 | return; |
| 7655 | |
| 7656 | reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC); |
| 7657 | rsave = reg; |
| 7658 | |
| 7659 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 7660 | u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT); |
| 7661 | |
| 7662 | /* If up2tc is out of bounds default to zero */ |
| 7663 | if (up2tc > tc) |
| 7664 | reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT); |
| 7665 | } |
| 7666 | |
| 7667 | if (reg != rsave) |
| 7668 | IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg); |
| 7669 | |
| 7670 | return; |
| 7671 | } |
| 7672 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7673 | /** |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 7674 | * ixgbe_set_prio_tc_map - Configure netdev prio tc map |
| 7675 | * @adapter: Pointer to adapter struct |
| 7676 | * |
| 7677 | * Populate the netdev user priority to tc map |
| 7678 | */ |
| 7679 | static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter) |
| 7680 | { |
| 7681 | struct net_device *dev = adapter->netdev; |
| 7682 | struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg; |
| 7683 | struct ieee_ets *ets = adapter->ixgbe_ieee_ets; |
| 7684 | u8 prio; |
| 7685 | |
| 7686 | for (prio = 0; prio < MAX_USER_PRIORITY; prio++) { |
| 7687 | u8 tc = 0; |
| 7688 | |
| 7689 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) |
| 7690 | tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio); |
| 7691 | else if (ets) |
| 7692 | tc = ets->prio_tc[prio]; |
| 7693 | |
| 7694 | netdev_set_prio_tc_map(dev, prio, tc); |
| 7695 | } |
| 7696 | } |
| 7697 | |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 7698 | #endif /* CONFIG_IXGBE_DCB */ |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 7699 | /** |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7700 | * ixgbe_setup_tc - configure net_device for multiple traffic classes |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7701 | * |
| 7702 | * @netdev: net device to configure |
| 7703 | * @tc: number of traffic classes to enable |
| 7704 | */ |
| 7705 | int ixgbe_setup_tc(struct net_device *dev, u8 tc) |
| 7706 | { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7707 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 7708 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 7709 | bool pools; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7710 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7711 | /* Hardware supports up to 8 traffic classes */ |
John Fastabend | 4de2a02 | 2011-09-27 03:52:01 +0000 | [diff] [blame] | 7712 | if (tc > adapter->dcb_cfg.num_tcs.pg_tcs || |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 7713 | (hw->mac.type == ixgbe_mac_82598EB && |
| 7714 | tc < MAX_TRAFFIC_CLASS)) |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7715 | return -EINVAL; |
| 7716 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 7717 | pools = (find_first_zero_bit(&adapter->fwd_bitmask, 32) > 1); |
| 7718 | if (tc && pools && adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS) |
| 7719 | return -EBUSY; |
| 7720 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7721 | /* Hardware has to reinitialize queues and interrupts to |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 7722 | * match packet buffer alignment. Unfortunately, the |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7723 | * hardware is not flexible enough to do this dynamically. |
| 7724 | */ |
| 7725 | if (netif_running(dev)) |
| 7726 | ixgbe_close(dev); |
| 7727 | ixgbe_clear_interrupt_scheme(adapter); |
| 7728 | |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 7729 | #ifdef CONFIG_IXGBE_DCB |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 7730 | if (tc) { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7731 | netdev_set_num_tc(dev, tc); |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 7732 | ixgbe_set_prio_tc_map(adapter); |
| 7733 | |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 7734 | adapter->flags |= IXGBE_FLAG_DCB_ENABLED; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 7735 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 7736 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 7737 | adapter->last_lfc_mode = adapter->hw.fc.requested_mode; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 7738 | adapter->hw.fc.requested_mode = ixgbe_fc_none; |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 7739 | } |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 7740 | } else { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7741 | netdev_reset_tc(dev); |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 7742 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 7743 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 7744 | adapter->hw.fc.requested_mode = adapter->last_lfc_mode; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 7745 | |
| 7746 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 7747 | |
| 7748 | adapter->temp_dcb_cfg.pfc_mode_enable = false; |
| 7749 | adapter->dcb_cfg.pfc_mode_enable = false; |
| 7750 | } |
| 7751 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7752 | ixgbe_validate_rtr(adapter, tc); |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 7753 | |
| 7754 | #endif /* CONFIG_IXGBE_DCB */ |
| 7755 | ixgbe_init_interrupt_scheme(adapter); |
| 7756 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7757 | if (netif_running(dev)) |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 7758 | return ixgbe_open(dev); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7759 | |
| 7760 | return 0; |
| 7761 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7762 | |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 7763 | #ifdef CONFIG_PCI_IOV |
| 7764 | void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter) |
| 7765 | { |
| 7766 | struct net_device *netdev = adapter->netdev; |
| 7767 | |
| 7768 | rtnl_lock(); |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 7769 | ixgbe_setup_tc(netdev, netdev_get_num_tc(netdev)); |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 7770 | rtnl_unlock(); |
| 7771 | } |
| 7772 | |
| 7773 | #endif |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7774 | void ixgbe_do_reset(struct net_device *netdev) |
| 7775 | { |
| 7776 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7777 | |
| 7778 | if (netif_running(netdev)) |
| 7779 | ixgbe_reinit_locked(adapter); |
| 7780 | else |
| 7781 | ixgbe_reset(adapter); |
| 7782 | } |
| 7783 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7784 | static netdev_features_t ixgbe_fix_features(struct net_device *netdev, |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 7785 | netdev_features_t features) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7786 | { |
| 7787 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7788 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7789 | /* If Rx checksum is disabled, then RSC/LRO should also be disabled */ |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 7790 | if (!(features & NETIF_F_RXCSUM)) |
| 7791 | features &= ~NETIF_F_LRO; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7792 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 7793 | /* Turn off LRO if not RSC capable */ |
| 7794 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) |
| 7795 | features &= ~NETIF_F_LRO; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 7796 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 7797 | return features; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7798 | } |
| 7799 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7800 | static int ixgbe_set_features(struct net_device *netdev, |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 7801 | netdev_features_t features) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7802 | { |
| 7803 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 7804 | netdev_features_t changed = netdev->features ^ features; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7805 | bool need_reset = false; |
| 7806 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7807 | /* Make sure RSC matches LRO, reset if change */ |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 7808 | if (!(features & NETIF_F_LRO)) { |
| 7809 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7810 | need_reset = true; |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 7811 | adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED; |
| 7812 | } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) && |
| 7813 | !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) { |
| 7814 | if (adapter->rx_itr_setting == 1 || |
| 7815 | adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) { |
| 7816 | adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED; |
| 7817 | need_reset = true; |
| 7818 | } else if ((changed ^ features) & NETIF_F_LRO) { |
| 7819 | e_info(probe, "rx-usecs set too low, " |
| 7820 | "disabling RSC\n"); |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7821 | } |
| 7822 | } |
| 7823 | |
| 7824 | /* |
| 7825 | * Check if Flow Director n-tuple support was enabled or disabled. If |
| 7826 | * the state changed, we need to reset. |
| 7827 | */ |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 7828 | switch (features & NETIF_F_NTUPLE) { |
| 7829 | case NETIF_F_NTUPLE: |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 7830 | /* turn off ATR, enable perfect filters and reset */ |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 7831 | if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) |
| 7832 | need_reset = true; |
| 7833 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 7834 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 7835 | adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 7836 | break; |
| 7837 | default: |
| 7838 | /* turn off perfect filters, enable ATR and reset */ |
| 7839 | if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 7840 | need_reset = true; |
| 7841 | |
| 7842 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 7843 | |
| 7844 | /* We cannot enable ATR if SR-IOV is enabled */ |
| 7845 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 7846 | break; |
| 7847 | |
| 7848 | /* We cannot enable ATR if we have 2 or more traffic classes */ |
| 7849 | if (netdev_get_num_tc(netdev) > 1) |
| 7850 | break; |
| 7851 | |
| 7852 | /* We cannot enable ATR if RSS is disabled */ |
| 7853 | if (adapter->ring_feature[RING_F_RSS].limit <= 1) |
| 7854 | break; |
| 7855 | |
| 7856 | /* A sample rate of 0 indicates ATR disabled */ |
| 7857 | if (!adapter->atr_sample_rate) |
| 7858 | break; |
| 7859 | |
| 7860 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 7861 | break; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7862 | } |
| 7863 | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 7864 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
John Fastabend | 146d4cc | 2012-05-15 05:59:26 +0000 | [diff] [blame] | 7865 | ixgbe_vlan_strip_enable(adapter); |
| 7866 | else |
| 7867 | ixgbe_vlan_strip_disable(adapter); |
| 7868 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 7869 | if (changed & NETIF_F_RXALL) |
| 7870 | need_reset = true; |
| 7871 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 7872 | netdev->features = features; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7873 | if (need_reset) |
| 7874 | ixgbe_do_reset(netdev); |
| 7875 | |
| 7876 | return 0; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7877 | } |
| 7878 | |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 7879 | /** |
| 7880 | * ixgbe_add_vxlan_port - Get notifications about VXLAN ports that come up |
| 7881 | * @dev: The port's netdev |
| 7882 | * @sa_family: Socket Family that VXLAN is notifiying us about |
| 7883 | * @port: New UDP port number that VXLAN started listening to |
| 7884 | **/ |
| 7885 | static void ixgbe_add_vxlan_port(struct net_device *dev, sa_family_t sa_family, |
| 7886 | __be16 port) |
| 7887 | { |
| 7888 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 7889 | struct ixgbe_hw *hw = &adapter->hw; |
| 7890 | u16 new_port = ntohs(port); |
| 7891 | |
| 7892 | if (sa_family == AF_INET6) |
| 7893 | return; |
| 7894 | |
| 7895 | if (adapter->vxlan_port == new_port) { |
| 7896 | netdev_info(dev, "Port %d already offloaded\n", new_port); |
| 7897 | return; |
| 7898 | } |
| 7899 | |
| 7900 | if (adapter->vxlan_port) { |
| 7901 | netdev_info(dev, |
| 7902 | "Hit Max num of UDP ports, not adding port %d\n", |
| 7903 | new_port); |
| 7904 | return; |
| 7905 | } |
| 7906 | |
| 7907 | adapter->vxlan_port = new_port; |
| 7908 | IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, new_port); |
| 7909 | } |
| 7910 | |
| 7911 | /** |
| 7912 | * ixgbe_del_vxlan_port - Get notifications about VXLAN ports that go away |
| 7913 | * @dev: The port's netdev |
| 7914 | * @sa_family: Socket Family that VXLAN is notifying us about |
| 7915 | * @port: UDP port number that VXLAN stopped listening to |
| 7916 | **/ |
| 7917 | static void ixgbe_del_vxlan_port(struct net_device *dev, sa_family_t sa_family, |
| 7918 | __be16 port) |
| 7919 | { |
| 7920 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 7921 | struct ixgbe_hw *hw = &adapter->hw; |
| 7922 | u16 new_port = ntohs(port); |
| 7923 | |
| 7924 | if (sa_family == AF_INET6) |
| 7925 | return; |
| 7926 | |
| 7927 | if (adapter->vxlan_port != new_port) { |
| 7928 | netdev_info(dev, "Port %d was not found, not deleting\n", |
| 7929 | new_port); |
| 7930 | return; |
| 7931 | } |
| 7932 | |
| 7933 | adapter->vxlan_port = 0; |
| 7934 | IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, 0); |
| 7935 | } |
| 7936 | |
stephen hemminger | edc7d57 | 2012-10-01 12:32:33 +0000 | [diff] [blame] | 7937 | static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 7938 | struct net_device *dev, |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 7939 | const unsigned char *addr, u16 vid, |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 7940 | u16 flags) |
| 7941 | { |
Alexander Duyck | bcfd343 | 2014-07-17 02:11:22 +0000 | [diff] [blame] | 7942 | /* guarantee we can provide a unique filter for the unicast address */ |
Ben Hutchings | 46acc46 | 2012-11-01 09:11:11 +0000 | [diff] [blame] | 7943 | if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) { |
Alexander Duyck | bcfd343 | 2014-07-17 02:11:22 +0000 | [diff] [blame] | 7944 | if (IXGBE_MAX_PF_MACVLANS <= netdev_uc_count(dev)) |
| 7945 | return -ENOMEM; |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 7946 | } |
| 7947 | |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 7948 | return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags); |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 7949 | } |
| 7950 | |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 7951 | /** |
| 7952 | * ixgbe_configure_bridge_mode - set various bridge modes |
| 7953 | * @adapter - the private structure |
| 7954 | * @mode - requested bridge mode |
| 7955 | * |
| 7956 | * Configure some settings require for various bridge modes. |
| 7957 | **/ |
| 7958 | static int ixgbe_configure_bridge_mode(struct ixgbe_adapter *adapter, |
| 7959 | __u16 mode) |
| 7960 | { |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 7961 | struct ixgbe_hw *hw = &adapter->hw; |
| 7962 | unsigned int p, num_pools; |
| 7963 | u32 vmdctl; |
| 7964 | |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 7965 | switch (mode) { |
| 7966 | case BRIDGE_MODE_VEPA: |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 7967 | /* disable Tx loopback, rely on switch hairpin mode */ |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 7968 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, 0); |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 7969 | |
| 7970 | /* must enable Rx switching replication to allow multicast |
| 7971 | * packet reception on all VFs, and to enable source address |
| 7972 | * pruning. |
| 7973 | */ |
| 7974 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL); |
| 7975 | vmdctl |= IXGBE_VT_CTL_REPLEN; |
| 7976 | IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl); |
| 7977 | |
| 7978 | /* enable Rx source address pruning. Note, this requires |
| 7979 | * replication to be enabled or else it does nothing. |
| 7980 | */ |
| 7981 | num_pools = adapter->num_vfs + adapter->num_rx_pools; |
| 7982 | for (p = 0; p < num_pools; p++) { |
| 7983 | if (hw->mac.ops.set_source_address_pruning) |
| 7984 | hw->mac.ops.set_source_address_pruning(hw, |
| 7985 | true, |
| 7986 | p); |
| 7987 | } |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 7988 | break; |
| 7989 | case BRIDGE_MODE_VEB: |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 7990 | /* enable Tx loopback for internal VF/PF communication */ |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 7991 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, |
| 7992 | IXGBE_PFDTXGSWC_VT_LBEN); |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 7993 | |
| 7994 | /* disable Rx switching replication unless we have SR-IOV |
| 7995 | * virtual functions |
| 7996 | */ |
| 7997 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL); |
| 7998 | if (!adapter->num_vfs) |
| 7999 | vmdctl &= ~IXGBE_VT_CTL_REPLEN; |
| 8000 | IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl); |
| 8001 | |
| 8002 | /* disable Rx source address pruning, since we don't expect to |
| 8003 | * be receiving external loopback of our transmitted frames. |
| 8004 | */ |
| 8005 | num_pools = adapter->num_vfs + adapter->num_rx_pools; |
| 8006 | for (p = 0; p < num_pools; p++) { |
| 8007 | if (hw->mac.ops.set_source_address_pruning) |
| 8008 | hw->mac.ops.set_source_address_pruning(hw, |
| 8009 | false, |
| 8010 | p); |
| 8011 | } |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 8012 | break; |
| 8013 | default: |
| 8014 | return -EINVAL; |
| 8015 | } |
| 8016 | |
| 8017 | adapter->bridge_mode = mode; |
| 8018 | |
| 8019 | e_info(drv, "enabling bridge mode: %s\n", |
| 8020 | mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
| 8021 | |
| 8022 | return 0; |
| 8023 | } |
| 8024 | |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8025 | static int ixgbe_ndo_bridge_setlink(struct net_device *dev, |
Roopa Prabhu | add511b | 2015-01-29 22:40:12 -0800 | [diff] [blame] | 8026 | struct nlmsghdr *nlh, u16 flags) |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8027 | { |
| 8028 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 8029 | struct nlattr *attr, *br_spec; |
| 8030 | int rem; |
| 8031 | |
| 8032 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 8033 | return -EOPNOTSUPP; |
| 8034 | |
| 8035 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
Thomas Graf | 4ea85e8 | 2014-11-26 13:42:18 +0100 | [diff] [blame] | 8036 | if (!br_spec) |
| 8037 | return -EINVAL; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8038 | |
| 8039 | nla_for_each_nested(attr, br_spec, rem) { |
Mark Rustad | a1e869d | 2015-04-10 10:36:36 -0700 | [diff] [blame] | 8040 | int status; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8041 | __u16 mode; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8042 | |
| 8043 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 8044 | continue; |
| 8045 | |
Thomas Graf | b7c1a31 | 2014-11-26 13:42:17 +0100 | [diff] [blame] | 8046 | if (nla_len(attr) < sizeof(mode)) |
| 8047 | return -EINVAL; |
| 8048 | |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8049 | mode = nla_get_u16(attr); |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 8050 | status = ixgbe_configure_bridge_mode(adapter, mode); |
| 8051 | if (status) |
| 8052 | return status; |
Don Skidmore | aa2bacb | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 8053 | |
| 8054 | break; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8055 | } |
| 8056 | |
| 8057 | return 0; |
| 8058 | } |
| 8059 | |
| 8060 | 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] | 8061 | struct net_device *dev, |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 8062 | u32 filter_mask, int nlflags) |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8063 | { |
| 8064 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8065 | |
| 8066 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 8067 | return 0; |
| 8068 | |
Don Skidmore | aa2bacb | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 8069 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 8070 | adapter->bridge_mode, 0, 0, nlflags); |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8071 | } |
| 8072 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8073 | static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev) |
| 8074 | { |
| 8075 | struct ixgbe_fwd_adapter *fwd_adapter = NULL; |
| 8076 | struct ixgbe_adapter *adapter = netdev_priv(pdev); |
Jacob Keller | aac2f1b | 2014-08-21 06:17:59 +0000 | [diff] [blame] | 8077 | int used_pools = adapter->num_vfs + adapter->num_rx_pools; |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 8078 | unsigned int limit; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8079 | int pool, err; |
| 8080 | |
Jacob Keller | aac2f1b | 2014-08-21 06:17:59 +0000 | [diff] [blame] | 8081 | /* Hardware has a limited number of available pools. Each VF, and the |
| 8082 | * PF require a pool. Check to ensure we don't attempt to use more |
| 8083 | * then the available number of pools. |
| 8084 | */ |
| 8085 | if (used_pools >= IXGBE_MAX_VF_FUNCTIONS) |
| 8086 | return ERR_PTR(-EINVAL); |
| 8087 | |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 8088 | #ifdef CONFIG_RPS |
| 8089 | if (vdev->num_rx_queues != vdev->num_tx_queues) { |
| 8090 | netdev_info(pdev, "%s: Only supports a single queue count for TX and RX\n", |
| 8091 | vdev->name); |
| 8092 | return ERR_PTR(-EINVAL); |
| 8093 | } |
| 8094 | #endif |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8095 | /* Check for hardware restriction on number of rx/tx queues */ |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 8096 | if (vdev->num_tx_queues > IXGBE_MAX_L2A_QUEUES || |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8097 | vdev->num_tx_queues == IXGBE_BAD_L2A_QUEUE) { |
| 8098 | netdev_info(pdev, |
| 8099 | "%s: Supports RX/TX Queue counts 1,2, and 4\n", |
| 8100 | pdev->name); |
| 8101 | return ERR_PTR(-EINVAL); |
| 8102 | } |
| 8103 | |
| 8104 | if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && |
| 8105 | adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS - 1) || |
| 8106 | (adapter->num_rx_pools > IXGBE_MAX_MACVLANS)) |
| 8107 | return ERR_PTR(-EBUSY); |
| 8108 | |
| 8109 | fwd_adapter = kcalloc(1, sizeof(struct ixgbe_fwd_adapter), GFP_KERNEL); |
| 8110 | if (!fwd_adapter) |
| 8111 | return ERR_PTR(-ENOMEM); |
| 8112 | |
| 8113 | pool = find_first_zero_bit(&adapter->fwd_bitmask, 32); |
| 8114 | adapter->num_rx_pools++; |
| 8115 | set_bit(pool, &adapter->fwd_bitmask); |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 8116 | limit = find_last_bit(&adapter->fwd_bitmask, 32); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8117 | |
| 8118 | /* Enable VMDq flag so device will be set in VM mode */ |
| 8119 | adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED | IXGBE_FLAG_SRIOV_ENABLED; |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 8120 | adapter->ring_feature[RING_F_VMDQ].limit = limit + 1; |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 8121 | adapter->ring_feature[RING_F_RSS].limit = vdev->num_tx_queues; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8122 | |
| 8123 | /* Force reinit of ring allocation with VMDQ enabled */ |
| 8124 | err = ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev)); |
| 8125 | if (err) |
| 8126 | goto fwd_add_err; |
| 8127 | fwd_adapter->pool = pool; |
| 8128 | fwd_adapter->real_adapter = adapter; |
| 8129 | err = ixgbe_fwd_ring_up(vdev, fwd_adapter); |
| 8130 | if (err) |
| 8131 | goto fwd_add_err; |
| 8132 | netif_tx_start_all_queues(vdev); |
| 8133 | return fwd_adapter; |
| 8134 | fwd_add_err: |
| 8135 | /* unwind counter and free adapter struct */ |
| 8136 | netdev_info(pdev, |
| 8137 | "%s: dfwd hardware acceleration failed\n", vdev->name); |
| 8138 | clear_bit(pool, &adapter->fwd_bitmask); |
| 8139 | adapter->num_rx_pools--; |
| 8140 | kfree(fwd_adapter); |
| 8141 | return ERR_PTR(err); |
| 8142 | } |
| 8143 | |
| 8144 | static void ixgbe_fwd_del(struct net_device *pdev, void *priv) |
| 8145 | { |
| 8146 | struct ixgbe_fwd_adapter *fwd_adapter = priv; |
| 8147 | struct ixgbe_adapter *adapter = fwd_adapter->real_adapter; |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 8148 | unsigned int limit; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8149 | |
| 8150 | clear_bit(fwd_adapter->pool, &adapter->fwd_bitmask); |
| 8151 | adapter->num_rx_pools--; |
| 8152 | |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 8153 | limit = find_last_bit(&adapter->fwd_bitmask, 32); |
| 8154 | adapter->ring_feature[RING_F_VMDQ].limit = limit + 1; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8155 | ixgbe_fwd_ring_down(fwd_adapter->netdev, fwd_adapter); |
| 8156 | ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev)); |
| 8157 | netdev_dbg(pdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n", |
| 8158 | fwd_adapter->pool, adapter->num_rx_pools, |
| 8159 | fwd_adapter->rx_base_queue, |
| 8160 | fwd_adapter->rx_base_queue + adapter->num_rx_queues_per_pool, |
| 8161 | adapter->fwd_bitmask); |
| 8162 | kfree(fwd_adapter); |
| 8163 | } |
| 8164 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 8165 | static const struct net_device_ops ixgbe_netdev_ops = { |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 8166 | .ndo_open = ixgbe_open, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 8167 | .ndo_stop = ixgbe_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 8168 | .ndo_start_xmit = ixgbe_xmit_frame, |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 8169 | .ndo_select_queue = ixgbe_select_queue, |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 8170 | .ndo_set_rx_mode = ixgbe_set_rx_mode, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 8171 | .ndo_validate_addr = eth_validate_addr, |
| 8172 | .ndo_set_mac_address = ixgbe_set_mac, |
| 8173 | .ndo_change_mtu = ixgbe_change_mtu, |
| 8174 | .ndo_tx_timeout = ixgbe_tx_timeout, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 8175 | .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid, |
| 8176 | .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid, |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 8177 | .ndo_do_ioctl = ixgbe_ioctl, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 8178 | .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac, |
| 8179 | .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan, |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 8180 | .ndo_set_vf_rate = ixgbe_ndo_set_vf_bw, |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 8181 | .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk, |
Vlad Zolotarov | e65ce0d | 2015-03-30 21:35:24 +0300 | [diff] [blame] | 8182 | .ndo_set_vf_rss_query_en = ixgbe_ndo_set_vf_rss_query_en, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 8183 | .ndo_get_vf_config = ixgbe_ndo_get_vf_config, |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8184 | .ndo_get_stats64 = ixgbe_get_stats64, |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 8185 | #ifdef CONFIG_IXGBE_DCB |
John Fastabend | 24095aa | 2011-02-23 05:58:03 +0000 | [diff] [blame] | 8186 | .ndo_setup_tc = ixgbe_setup_tc, |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 8187 | #endif |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 8188 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 8189 | .ndo_poll_controller = ixgbe_netpoll, |
| 8190 | #endif |
Cong Wang | e0d1095 | 2013-08-01 11:10:25 +0800 | [diff] [blame] | 8191 | #ifdef CONFIG_NET_RX_BUSY_POLL |
Eliezer Tamir | 8b80cda | 2013-07-10 17:13:26 +0300 | [diff] [blame] | 8192 | .ndo_busy_poll = ixgbe_low_latency_recv, |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 8193 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 8194 | #ifdef IXGBE_FCOE |
| 8195 | .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get, |
Yi Zou | 68a683c | 2011-02-01 07:22:16 +0000 | [diff] [blame] | 8196 | .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 8197 | .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put, |
Yi Zou | 8450ff8 | 2009-08-31 12:32:14 +0000 | [diff] [blame] | 8198 | .ndo_fcoe_enable = ixgbe_fcoe_enable, |
| 8199 | .ndo_fcoe_disable = ixgbe_fcoe_disable, |
Yi Zou | 61a1fa1 | 2009-10-28 18:24:56 +0000 | [diff] [blame] | 8200 | .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn, |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 8201 | .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 8202 | #endif /* IXGBE_FCOE */ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8203 | .ndo_set_features = ixgbe_set_features, |
| 8204 | .ndo_fix_features = ixgbe_fix_features, |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 8205 | .ndo_fdb_add = ixgbe_ndo_fdb_add, |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8206 | .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink, |
| 8207 | .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink, |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8208 | .ndo_dfwd_add_station = ixgbe_fwd_add, |
| 8209 | .ndo_dfwd_del_station = ixgbe_fwd_del, |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8210 | .ndo_add_vxlan_port = ixgbe_add_vxlan_port, |
| 8211 | .ndo_del_vxlan_port = ixgbe_del_vxlan_port, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 8212 | }; |
| 8213 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 8214 | /** |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 8215 | * ixgbe_enumerate_functions - Get the number of ports this device has |
| 8216 | * @adapter: adapter structure |
| 8217 | * |
| 8218 | * This function enumerates the phsyical functions co-located on a single slot, |
| 8219 | * in order to determine how many ports a device has. This is most useful in |
| 8220 | * determining the required GT/s of PCIe bandwidth necessary for optimal |
| 8221 | * performance. |
| 8222 | **/ |
| 8223 | static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter) |
| 8224 | { |
Jacob Keller | caafb95 | 2014-07-19 07:17:17 +0000 | [diff] [blame] | 8225 | struct pci_dev *entry, *pdev = adapter->pdev; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 8226 | int physfns = 0; |
| 8227 | |
Jacob Keller | f1f9657 | 2013-08-31 02:45:38 +0000 | [diff] [blame] | 8228 | /* Some cards can not use the generic count PCIe functions method, |
| 8229 | * because they are behind a parent switch, so we hardcode these with |
| 8230 | * the correct number of functions. |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 8231 | */ |
Jacob Keller | 8818970 | 2014-07-19 07:17:16 +0000 | [diff] [blame] | 8232 | if (ixgbe_pcie_from_parent(&adapter->hw)) |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 8233 | physfns = 4; |
Jacob Keller | 8818970 | 2014-07-19 07:17:16 +0000 | [diff] [blame] | 8234 | |
| 8235 | list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) { |
| 8236 | /* don't count virtual functions */ |
Jacob Keller | caafb95 | 2014-07-19 07:17:17 +0000 | [diff] [blame] | 8237 | if (entry->is_virtfn) |
| 8238 | continue; |
| 8239 | |
| 8240 | /* When the devices on the bus don't all match our device ID, |
| 8241 | * we can't reliably determine the correct number of |
| 8242 | * functions. This can occur if a function has been direct |
| 8243 | * attached to a virtual machine using VT-d, for example. In |
| 8244 | * this case, simply return -1 to indicate this. |
| 8245 | */ |
| 8246 | if ((entry->vendor != pdev->vendor) || |
| 8247 | (entry->device != pdev->device)) |
| 8248 | return -1; |
| 8249 | |
| 8250 | physfns++; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 8251 | } |
| 8252 | |
| 8253 | return physfns; |
| 8254 | } |
| 8255 | |
| 8256 | /** |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 8257 | * ixgbe_wol_supported - Check whether device supports WoL |
| 8258 | * @hw: hw specific details |
| 8259 | * @device_id: the device ID |
| 8260 | * @subdev_id: the subsystem device ID |
| 8261 | * |
| 8262 | * This function is used by probe and ethtool to determine |
| 8263 | * which devices have WoL support |
| 8264 | * |
| 8265 | **/ |
| 8266 | int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id, |
| 8267 | u16 subdevice_id) |
| 8268 | { |
| 8269 | struct ixgbe_hw *hw = &adapter->hw; |
| 8270 | u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK; |
| 8271 | int is_wol_supported = 0; |
| 8272 | |
| 8273 | switch (device_id) { |
| 8274 | case IXGBE_DEV_ID_82599_SFP: |
| 8275 | /* Only these subdevices could supports WOL */ |
| 8276 | switch (subdevice_id) { |
Mark Rustad | 8755744 | 2014-02-25 17:58:55 -0800 | [diff] [blame] | 8277 | case IXGBE_SUBDEV_ID_82599_SFP_WOL0: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 8278 | case IXGBE_SUBDEV_ID_82599_560FLR: |
| 8279 | /* only support first port */ |
| 8280 | if (hw->bus.func != 0) |
| 8281 | break; |
Emil Tantilov | 5700ff2 | 2013-04-18 08:18:55 +0000 | [diff] [blame] | 8282 | case IXGBE_SUBDEV_ID_82599_SP_560FLR: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 8283 | case IXGBE_SUBDEV_ID_82599_SFP: |
Don Skidmore | b6dfd93 | 2012-07-11 07:17:42 +0000 | [diff] [blame] | 8284 | case IXGBE_SUBDEV_ID_82599_RNDC: |
Emil Tantilov | f8a06c2 | 2012-08-16 08:13:07 +0000 | [diff] [blame] | 8285 | case IXGBE_SUBDEV_ID_82599_ECNA_DP: |
Jacob Keller | 979fe5f | 2013-04-03 04:41:37 +0000 | [diff] [blame] | 8286 | case IXGBE_SUBDEV_ID_82599_LOM_SFP: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 8287 | is_wol_supported = 1; |
| 8288 | break; |
| 8289 | } |
| 8290 | break; |
Don Skidmore | 5daebbb | 2013-04-05 05:49:34 +0000 | [diff] [blame] | 8291 | case IXGBE_DEV_ID_82599EN_SFP: |
| 8292 | /* Only this subdevice supports WOL */ |
| 8293 | switch (subdevice_id) { |
| 8294 | case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1: |
| 8295 | is_wol_supported = 1; |
| 8296 | break; |
| 8297 | } |
| 8298 | break; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 8299 | case IXGBE_DEV_ID_82599_COMBO_BACKPLANE: |
| 8300 | /* All except this subdevice support WOL */ |
| 8301 | if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ) |
| 8302 | is_wol_supported = 1; |
| 8303 | break; |
| 8304 | case IXGBE_DEV_ID_82599_KX4: |
| 8305 | is_wol_supported = 1; |
| 8306 | break; |
| 8307 | case IXGBE_DEV_ID_X540T: |
joshua.a.hay@intel.com | df376f0 | 2012-09-21 00:08:21 +0000 | [diff] [blame] | 8308 | case IXGBE_DEV_ID_X540T1: |
Don Skidmore | df8c26f | 2015-06-09 16:00:17 -0700 | [diff] [blame] | 8309 | case IXGBE_DEV_ID_X550T: |
| 8310 | case IXGBE_DEV_ID_X550EM_X_KX4: |
| 8311 | case IXGBE_DEV_ID_X550EM_X_KR: |
| 8312 | case IXGBE_DEV_ID_X550EM_X_10G_T: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 8313 | /* check eeprom to see if enabled wol */ |
| 8314 | if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) || |
| 8315 | ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) && |
| 8316 | (hw->bus.func == 0))) { |
| 8317 | is_wol_supported = 1; |
| 8318 | } |
| 8319 | break; |
| 8320 | } |
| 8321 | |
| 8322 | return is_wol_supported; |
| 8323 | } |
| 8324 | |
| 8325 | /** |
Martin K Petersen | c762dff | 2014-11-15 14:24:51 +0000 | [diff] [blame] | 8326 | * ixgbe_get_platform_mac_addr - Look up MAC address in Open Firmware / IDPROM |
| 8327 | * @adapter: Pointer to adapter struct |
| 8328 | */ |
| 8329 | static void ixgbe_get_platform_mac_addr(struct ixgbe_adapter *adapter) |
| 8330 | { |
| 8331 | #ifdef CONFIG_OF |
| 8332 | struct device_node *dp = pci_device_to_OF_node(adapter->pdev); |
| 8333 | struct ixgbe_hw *hw = &adapter->hw; |
| 8334 | const unsigned char *addr; |
| 8335 | |
| 8336 | addr = of_get_mac_address(dp); |
| 8337 | if (addr) { |
| 8338 | ether_addr_copy(hw->mac.perm_addr, addr); |
| 8339 | return; |
| 8340 | } |
| 8341 | #endif /* CONFIG_OF */ |
| 8342 | |
| 8343 | #ifdef CONFIG_SPARC |
| 8344 | ether_addr_copy(hw->mac.perm_addr, idprom->id_ethaddr); |
| 8345 | #endif /* CONFIG_SPARC */ |
| 8346 | } |
| 8347 | |
| 8348 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8349 | * ixgbe_probe - Device Initialization Routine |
| 8350 | * @pdev: PCI device information struct |
| 8351 | * @ent: entry in ixgbe_pci_tbl |
| 8352 | * |
| 8353 | * Returns 0 on success, negative on failure |
| 8354 | * |
| 8355 | * ixgbe_probe initializes an adapter identified by a pci_dev structure. |
| 8356 | * The OS initialization, configuring of the adapter private structure, |
| 8357 | * and a hardware reset occur. |
| 8358 | **/ |
Greg Kroah-Hartman | 1dd06ae | 2012-12-06 14:30:56 +0000 | [diff] [blame] | 8359 | 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] | 8360 | { |
| 8361 | struct net_device *netdev; |
| 8362 | struct ixgbe_adapter *adapter = NULL; |
| 8363 | struct ixgbe_hw *hw; |
| 8364 | const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data]; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 8365 | int i, err, pci_using_dac, expected_gts; |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 8366 | unsigned int indices = MAX_TX_QUEUES; |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 8367 | u8 part_str[IXGBE_PBANUM_LENGTH]; |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 8368 | bool disable_dev = false; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 8369 | #ifdef IXGBE_FCOE |
| 8370 | u16 device_caps; |
| 8371 | #endif |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 8372 | u32 eec; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8373 | |
Andy Gospodarek | bded64a | 2010-07-21 06:40:31 +0000 | [diff] [blame] | 8374 | /* Catch broken hardware that put the wrong VF device ID in |
| 8375 | * the PCIe SR-IOV capability. |
| 8376 | */ |
| 8377 | if (pdev->is_virtfn) { |
| 8378 | WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n", |
| 8379 | pci_name(pdev), pdev->vendor, pdev->device); |
| 8380 | return -EINVAL; |
| 8381 | } |
| 8382 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 8383 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8384 | if (err) |
| 8385 | return err; |
| 8386 | |
Russell King | f5f2eda | 2013-06-10 12:47:42 +0100 | [diff] [blame] | 8387 | if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8388 | pci_using_dac = 1; |
| 8389 | } else { |
Russell King | f5f2eda | 2013-06-10 12:47:42 +0100 | [diff] [blame] | 8390 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8391 | if (err) { |
Russell King | f5f2eda | 2013-06-10 12:47:42 +0100 | [diff] [blame] | 8392 | dev_err(&pdev->dev, |
| 8393 | "No usable DMA configuration, aborting\n"); |
| 8394 | goto err_dma; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8395 | } |
| 8396 | pci_using_dac = 0; |
| 8397 | } |
| 8398 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 8399 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 8400 | IORESOURCE_MEM), ixgbe_driver_name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8401 | if (err) { |
Dan Carpenter | b8bc042 | 2010-07-27 00:05:56 +0000 | [diff] [blame] | 8402 | dev_err(&pdev->dev, |
| 8403 | "pci_request_selected_regions failed 0x%x\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8404 | goto err_pci_reg; |
| 8405 | } |
| 8406 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 8407 | pci_enable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8408 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8409 | pci_set_master(pdev); |
Wendy Xiong | fb3b27b | 2008-04-23 11:09:24 -0700 | [diff] [blame] | 8410 | pci_save_state(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8411 | |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 8412 | if (ii->mac == ixgbe_mac_82598EB) { |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 8413 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 8414 | /* 8 TC w/ 4 queues per TC */ |
| 8415 | indices = 4 * MAX_TRAFFIC_CLASS; |
| 8416 | #else |
| 8417 | indices = IXGBE_MAX_RSS_INDICES; |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 8418 | #endif |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 8419 | } |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 8420 | |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 8421 | netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8422 | if (!netdev) { |
| 8423 | err = -ENOMEM; |
| 8424 | goto err_alloc_etherdev; |
| 8425 | } |
| 8426 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8427 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 8428 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8429 | adapter = netdev_priv(netdev); |
| 8430 | |
| 8431 | adapter->netdev = netdev; |
| 8432 | adapter->pdev = pdev; |
| 8433 | hw = &adapter->hw; |
| 8434 | hw->back = adapter; |
stephen hemminger | b3f4d59 | 2012-03-13 06:04:20 +0000 | [diff] [blame] | 8435 | adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8436 | |
Jeff Kirsher | 0585798 | 2008-09-11 19:57:00 -0700 | [diff] [blame] | 8437 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 8438 | pci_resource_len(pdev, 0)); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 8439 | adapter->io_addr = hw->hw_addr; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8440 | if (!hw->hw_addr) { |
| 8441 | err = -EIO; |
| 8442 | goto err_ioremap; |
| 8443 | } |
| 8444 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 8445 | netdev->netdev_ops = &ixgbe_netdev_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8446 | ixgbe_set_ethtool_ops(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8447 | netdev->watchdog_timeo = 5 * HZ; |
Mark Rustad | 339de30 | 2014-06-06 01:57:06 +0000 | [diff] [blame] | 8448 | strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8449 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8450 | /* Setup hw api */ |
| 8451 | memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops)); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 8452 | hw->mac.type = ii->mac; |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 8453 | hw->mvals = ii->mvals; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8454 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 8455 | /* EEPROM */ |
| 8456 | memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops)); |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 8457 | eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw)); |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 8458 | if (ixgbe_removed(hw->hw_addr)) { |
| 8459 | err = -EIO; |
| 8460 | goto err_ioremap; |
| 8461 | } |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 8462 | /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */ |
| 8463 | if (!(eec & (1 << 8))) |
| 8464 | hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic; |
| 8465 | |
| 8466 | /* PHY */ |
| 8467 | memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops)); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 8468 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 8469 | /* ixgbe_identify_phy_generic will set prtad and mmds properly */ |
| 8470 | hw->phy.mdio.prtad = MDIO_PRTAD_NONE; |
| 8471 | hw->phy.mdio.mmds = 0; |
| 8472 | hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 8473 | hw->phy.mdio.dev = netdev; |
| 8474 | hw->phy.mdio.mdio_read = ixgbe_mdio_read; |
| 8475 | hw->phy.mdio.mdio_write = ixgbe_mdio_write; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 8476 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 8477 | ii->get_invariants(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8478 | |
| 8479 | /* setup the private structure */ |
| 8480 | err = ixgbe_sw_init(adapter); |
| 8481 | if (err) |
| 8482 | goto err_sw_init; |
| 8483 | |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 8484 | /* Make it possible the adapter to be woken up via WOL */ |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 8485 | switch (adapter->hw.mac.type) { |
| 8486 | case ixgbe_mac_82599EB: |
| 8487 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 8488 | case ixgbe_mac_X550: |
| 8489 | case ixgbe_mac_X550EM_x: |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 8490 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 8491 | break; |
| 8492 | default: |
| 8493 | break; |
| 8494 | } |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 8495 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 8496 | /* |
| 8497 | * If there is a fan on this device and it has failed log the |
| 8498 | * failure. |
| 8499 | */ |
| 8500 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 8501 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 8502 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 8503 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 8504 | } |
| 8505 | |
Peter P Waskiewicz Jr | 8ef78ad | 2012-02-01 09:19:21 +0000 | [diff] [blame] | 8506 | if (allow_unsupported_sfp) |
| 8507 | hw->allow_unsupported_sfp = allow_unsupported_sfp; |
| 8508 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 8509 | /* reset_hw fills in the perm_addr as well */ |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 8510 | hw->phy.reset_if_overtemp = true; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 8511 | err = hw->mac.ops.reset_hw(hw); |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 8512 | hw->phy.reset_if_overtemp = false; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 8513 | if (err == IXGBE_ERR_SFP_NOT_PRESENT && |
| 8514 | hw->mac.type == ixgbe_mac_82598EB) { |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 8515 | err = 0; |
| 8516 | } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 1b1bf31 | 2013-07-31 05:27:04 +0000 | [diff] [blame] | 8517 | e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n"); |
| 8518 | e_dev_err("Reload the driver after installing a supported module.\n"); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 8519 | goto err_sw_init; |
| 8520 | } else if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 8521 | e_dev_err("HW Init failed: %d\n", err); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 8522 | goto err_sw_init; |
| 8523 | } |
| 8524 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 8525 | #ifdef CONFIG_PCI_IOV |
Greg Rose | 60a1a68 | 2012-12-11 08:26:33 +0000 | [diff] [blame] | 8526 | /* SR-IOV not supported on the 82598 */ |
| 8527 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 8528 | goto skip_sriov; |
| 8529 | /* Mailbox */ |
| 8530 | ixgbe_init_mbx_params_pf(hw); |
| 8531 | memcpy(&hw->mbx.ops, ii->mbx_ops, sizeof(hw->mbx.ops)); |
ethan.zhao | dcc23e3 | 2014-01-16 19:41:04 -0800 | [diff] [blame] | 8532 | pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT); |
ethan.zhao | 31ac910 | 2014-01-16 19:41:05 -0800 | [diff] [blame] | 8533 | ixgbe_enable_sriov(adapter); |
Greg Rose | 60a1a68 | 2012-12-11 08:26:33 +0000 | [diff] [blame] | 8534 | skip_sriov: |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 8535 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 8536 | #endif |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 8537 | netdev->features = NETIF_F_SG | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 8538 | NETIF_F_IP_CSUM | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8539 | NETIF_F_IPV6_CSUM | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 8540 | NETIF_F_HW_VLAN_CTAG_TX | |
| 8541 | NETIF_F_HW_VLAN_CTAG_RX | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8542 | NETIF_F_TSO | |
| 8543 | NETIF_F_TSO6 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8544 | NETIF_F_RXHASH | |
John Fastabend | 8bf1264 | 2013-11-12 12:13:29 +0000 | [diff] [blame] | 8545 | NETIF_F_RXCSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8546 | |
John Fastabend | 8bf1264 | 2013-11-12 12:13:29 +0000 | [diff] [blame] | 8547 | netdev->hw_features = netdev->features | NETIF_F_HW_L2FW_DOFFLOAD; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 8548 | |
Don Skidmore | 58be766 | 2011-04-12 09:42:11 +0000 | [diff] [blame] | 8549 | switch (adapter->hw.mac.type) { |
| 8550 | case ixgbe_mac_82599EB: |
| 8551 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 8552 | case ixgbe_mac_X550: |
| 8553 | case ixgbe_mac_X550EM_x: |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 8554 | netdev->features |= NETIF_F_SCTP_CSUM; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8555 | netdev->hw_features |= NETIF_F_SCTP_CSUM | |
| 8556 | NETIF_F_NTUPLE; |
Don Skidmore | 58be766 | 2011-04-12 09:42:11 +0000 | [diff] [blame] | 8557 | break; |
| 8558 | default: |
| 8559 | break; |
| 8560 | } |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 8561 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 8562 | netdev->hw_features |= NETIF_F_RXALL; |
Alexander Duyck | 87031c0 | 2015-04-09 22:03:24 -0700 | [diff] [blame] | 8563 | netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 8564 | |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 8565 | netdev->vlan_features |= NETIF_F_TSO; |
| 8566 | netdev->vlan_features |= NETIF_F_TSO6; |
Jesse Brandeburg | 22f32b7a5 | 2008-08-26 04:27:18 -0700 | [diff] [blame] | 8567 | netdev->vlan_features |= NETIF_F_IP_CSUM; |
Alexander Duyck | cd1da50 | 2009-08-25 04:47:50 +0000 | [diff] [blame] | 8568 | netdev->vlan_features |= NETIF_F_IPV6_CSUM; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 8569 | netdev->vlan_features |= NETIF_F_SG; |
| 8570 | |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 8571 | netdev->priv_flags |= IFF_UNICAST_FLT; |
Ben Greear | f43f313 | 2012-03-06 09:42:04 +0000 | [diff] [blame] | 8572 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 8573 | |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8574 | switch (adapter->hw.mac.type) { |
| 8575 | case ixgbe_mac_X550: |
| 8576 | case ixgbe_mac_X550EM_x: |
| 8577 | netdev->hw_enc_features |= NETIF_F_RXCSUM; |
| 8578 | break; |
| 8579 | default: |
| 8580 | break; |
| 8581 | } |
| 8582 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 8583 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 8584 | netdev->dcbnl_ops = &dcbnl_ops; |
| 8585 | #endif |
| 8586 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 8587 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 8588 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 8589 | unsigned int fcoe_l; |
| 8590 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 8591 | if (hw->mac.ops.get_device_caps) { |
| 8592 | hw->mac.ops.get_device_caps(hw, &device_caps); |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 8593 | if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS) |
| 8594 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 8595 | } |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 8596 | |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 8597 | |
| 8598 | fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus()); |
| 8599 | adapter->ring_feature[RING_F_FCOE].limit = fcoe_l; |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 8600 | |
Alexander Duyck | a58915c | 2012-05-25 06:38:18 +0000 | [diff] [blame] | 8601 | netdev->features |= NETIF_F_FSO | |
| 8602 | NETIF_F_FCOE_CRC; |
| 8603 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 8604 | netdev->vlan_features |= NETIF_F_FSO | |
| 8605 | NETIF_F_FCOE_CRC | |
| 8606 | NETIF_F_FCOE_MTU; |
Yi Zou | 5e09d7f | 2010-07-19 13:59:52 +0000 | [diff] [blame] | 8607 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 8608 | #endif /* IXGBE_FCOE */ |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 8609 | if (pci_using_dac) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8610 | netdev->features |= NETIF_F_HIGHDMA; |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 8611 | netdev->vlan_features |= NETIF_F_HIGHDMA; |
| 8612 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8613 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8614 | if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) |
| 8615 | netdev->hw_features |= NETIF_F_LRO; |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 8616 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 8617 | netdev->features |= NETIF_F_LRO; |
| 8618 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8619 | /* make sure the EEPROM is good */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 8620 | if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 8621 | e_dev_err("The EEPROM Checksum Is Not Valid\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8622 | err = -EIO; |
Alexander Duyck | 35937c0 | 2012-02-08 07:51:37 +0000 | [diff] [blame] | 8623 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8624 | } |
| 8625 | |
Martin K Petersen | c762dff | 2014-11-15 14:24:51 +0000 | [diff] [blame] | 8626 | ixgbe_get_platform_mac_addr(adapter); |
| 8627 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8628 | memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8629 | |
Jiri Pirko | aaeb6cd | 2013-01-08 01:38:26 +0000 | [diff] [blame] | 8630 | if (!is_valid_ether_addr(netdev->dev_addr)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 8631 | e_dev_err("invalid MAC address\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8632 | err = -EIO; |
Alexander Duyck | 35937c0 | 2012-02-08 07:51:37 +0000 | [diff] [blame] | 8633 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8634 | } |
| 8635 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 8636 | ixgbe_mac_set_default_filter(adapter, hw->mac.perm_addr); |
| 8637 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 8638 | setup_timer(&adapter->service_timer, &ixgbe_service_timer, |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 8639 | (unsigned long) adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8640 | |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 8641 | if (ixgbe_removed(hw->hw_addr)) { |
| 8642 | err = -EIO; |
| 8643 | goto err_sw_init; |
| 8644 | } |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 8645 | INIT_WORK(&adapter->service_task, ixgbe_service_task); |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 8646 | set_bit(__IXGBE_SERVICE_INITED, &adapter->state); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 8647 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8648 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 8649 | err = ixgbe_init_interrupt_scheme(adapter); |
| 8650 | if (err) |
| 8651 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8652 | |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 8653 | /* WOL not supported for all devices */ |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 8654 | adapter->wol = 0; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 8655 | hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap); |
Jacob Keller | 6b92b0b | 2013-04-13 05:40:37 +0000 | [diff] [blame] | 8656 | hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device, |
Don Skidmore | b8f8363 | 2013-02-28 08:08:44 +0000 | [diff] [blame] | 8657 | pdev->subsystem_device); |
Jacob Keller | 6b92b0b | 2013-04-13 05:40:37 +0000 | [diff] [blame] | 8658 | if (hw->wol_enabled) |
Andy Gospodarek | 9417c46 | 2011-07-16 07:31:33 +0000 | [diff] [blame] | 8659 | adapter->wol = IXGBE_WUFC_MAG; |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 8660 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 8661 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 8662 | |
Emil Tantilov | 15e5209 | 2011-09-29 05:01:29 +0000 | [diff] [blame] | 8663 | /* save off EEPROM version number */ |
| 8664 | hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh); |
| 8665 | hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl); |
| 8666 | |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 8667 | /* pick up the PCI bus settings for reporting later */ |
| 8668 | hw->mac.ops.get_bus_info(hw); |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 8669 | if (ixgbe_pcie_from_parent(hw)) |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 8670 | ixgbe_get_parent_bus_info(adapter); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 8671 | |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 8672 | /* calculate the expected PCIe bandwidth required for optimal |
| 8673 | * performance. Note that some older parts will never have enough |
| 8674 | * bandwidth due to being older generation PCIe parts. We clamp these |
| 8675 | * parts to ensure no warning is displayed if it can't be fixed. |
| 8676 | */ |
| 8677 | switch (hw->mac.type) { |
| 8678 | case ixgbe_mac_82598EB: |
| 8679 | expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16); |
| 8680 | break; |
| 8681 | default: |
| 8682 | expected_gts = ixgbe_enumerate_functions(adapter) * 10; |
| 8683 | break; |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 8684 | } |
Jacob Keller | caafb95 | 2014-07-19 07:17:17 +0000 | [diff] [blame] | 8685 | |
| 8686 | /* don't check link if we failed to enumerate functions */ |
| 8687 | if (expected_gts > 0) |
| 8688 | ixgbe_check_minimum_link(adapter, expected_gts); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 8689 | |
Mark Rustad | 339de30 | 2014-06-06 01:57:06 +0000 | [diff] [blame] | 8690 | err = ixgbe_read_pba_string_generic(hw, part_str, sizeof(part_str)); |
Jacob Keller | 6a2aae5 | 2013-10-18 05:09:24 +0000 | [diff] [blame] | 8691 | if (err) |
Mark Rustad | 339de30 | 2014-06-06 01:57:06 +0000 | [diff] [blame] | 8692 | strlcpy(part_str, "Unknown", sizeof(part_str)); |
Jacob Keller | 6a2aae5 | 2013-10-18 05:09:24 +0000 | [diff] [blame] | 8693 | if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present) |
| 8694 | e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n", |
| 8695 | hw->mac.type, hw->phy.type, hw->phy.sfp_type, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 8696 | part_str); |
Jacob Keller | 6a2aae5 | 2013-10-18 05:09:24 +0000 | [diff] [blame] | 8697 | else |
| 8698 | e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n", |
| 8699 | hw->mac.type, hw->phy.type, part_str); |
| 8700 | |
| 8701 | e_dev_info("%pM\n", netdev->dev_addr); |
| 8702 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8703 | /* reset the hardware with the new settings */ |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 8704 | err = hw->mac.ops.start_hw(hw); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 8705 | if (err == IXGBE_ERR_EEPROM_VERSION) { |
| 8706 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 8707 | e_dev_warn("This device is a pre-production adapter/LOM. " |
| 8708 | "Please be aware there may be issues associated " |
| 8709 | "with your hardware. If you are experiencing " |
| 8710 | "problems please contact your Intel or hardware " |
| 8711 | "representative who provided you with this " |
| 8712 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 8713 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8714 | strcpy(netdev->name, "eth%d"); |
| 8715 | err = register_netdev(netdev); |
| 8716 | if (err) |
| 8717 | goto err_register; |
| 8718 | |
Emil Tantilov | 0fb6a55 | 2014-12-04 03:03:38 +0000 | [diff] [blame] | 8719 | pci_set_drvdata(pdev, adapter); |
| 8720 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 8721 | /* power down the optics for 82599 SFP+ fiber */ |
| 8722 | if (hw->mac.ops.disable_tx_laser) |
Emil Tantilov | 93d3ce8 | 2011-10-19 07:59:55 +0000 | [diff] [blame] | 8723 | hw->mac.ops.disable_tx_laser(hw); |
| 8724 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 8725 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 8726 | netif_carrier_off(netdev); |
| 8727 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 8728 | #ifdef CONFIG_IXGBE_DCA |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 8729 | if (dca_add_requester(&pdev->dev) == 0) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8730 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8731 | ixgbe_setup_dca(adapter); |
| 8732 | } |
| 8733 | #endif |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 8734 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 8735 | 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] | 8736 | for (i = 0; i < adapter->num_vfs; i++) |
| 8737 | ixgbe_vf_configuration(pdev, (i | 0x10000000)); |
| 8738 | } |
| 8739 | |
Jacob Keller | 2466dd9 | 2011-09-08 03:50:54 +0000 | [diff] [blame] | 8740 | /* firmware requires driver version to be 0xFFFFFFFF |
| 8741 | * since os does not support feature |
| 8742 | */ |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 8743 | if (hw->mac.ops.set_fw_drv_ver) |
Jacob Keller | 2466dd9 | 2011-09-08 03:50:54 +0000 | [diff] [blame] | 8744 | hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, |
| 8745 | 0xFF); |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 8746 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8747 | /* add san mac addr to netdev */ |
| 8748 | ixgbe_add_sanmac_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8749 | |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 8750 | e_dev_info("%s\n", ixgbe_default_device_descr); |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 8751 | |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 8752 | #ifdef CONFIG_IXGBE_HWMON |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 8753 | if (ixgbe_sysfs_init(adapter)) |
| 8754 | e_err(probe, "failed to allocate sysfs resources\n"); |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 8755 | #endif /* CONFIG_IXGBE_HWMON */ |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 8756 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 8757 | ixgbe_dbg_adapter_init(adapter); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 8758 | |
Emil Tantilov | d1a35ee | 2014-05-13 08:24:00 +0000 | [diff] [blame] | 8759 | /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */ |
| 8760 | 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] | 8761 | hw->mac.ops.setup_link(hw, |
| 8762 | IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL, |
| 8763 | true); |
| 8764 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8765 | return 0; |
| 8766 | |
| 8767 | err_register: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 8768 | ixgbe_release_hw_control(adapter); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 8769 | ixgbe_clear_interrupt_scheme(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8770 | err_sw_init: |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 8771 | ixgbe_disable_sriov(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 8772 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 8773 | iounmap(adapter->io_addr); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 8774 | kfree(adapter->mac_table); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8775 | err_ioremap: |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 8776 | disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8777 | free_netdev(netdev); |
| 8778 | err_alloc_etherdev: |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 8779 | pci_release_selected_regions(pdev, |
| 8780 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8781 | err_pci_reg: |
| 8782 | err_dma: |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 8783 | if (!adapter || disable_dev) |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 8784 | pci_disable_device(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8785 | return err; |
| 8786 | } |
| 8787 | |
| 8788 | /** |
| 8789 | * ixgbe_remove - Device Removal Routine |
| 8790 | * @pdev: PCI device information struct |
| 8791 | * |
| 8792 | * ixgbe_remove is called by the PCI subsystem to alert the driver |
| 8793 | * that it should release a PCI device. The could be caused by a |
| 8794 | * Hot-Plug event, or because the driver is going to be removed from |
| 8795 | * memory. |
| 8796 | **/ |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 8797 | static void ixgbe_remove(struct pci_dev *pdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8798 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 8799 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
Emil Tantilov | 0fb6a55 | 2014-12-04 03:03:38 +0000 | [diff] [blame] | 8800 | struct net_device *netdev; |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 8801 | bool disable_dev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8802 | |
Emil Tantilov | 0fb6a55 | 2014-12-04 03:03:38 +0000 | [diff] [blame] | 8803 | /* if !adapter then we already cleaned up in probe */ |
| 8804 | if (!adapter) |
| 8805 | return; |
| 8806 | |
| 8807 | netdev = adapter->netdev; |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 8808 | ixgbe_dbg_adapter_exit(adapter); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 8809 | |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 8810 | set_bit(__IXGBE_REMOVING, &adapter->state); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 8811 | cancel_work_sync(&adapter->service_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8812 | |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 8813 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 8814 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8815 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 8816 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 8817 | dca_remove_requester(&pdev->dev); |
| 8818 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 8819 | } |
| 8820 | |
| 8821 | #endif |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 8822 | #ifdef CONFIG_IXGBE_HWMON |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 8823 | ixgbe_sysfs_exit(adapter); |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 8824 | #endif /* CONFIG_IXGBE_HWMON */ |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 8825 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8826 | /* remove the added san mac */ |
| 8827 | ixgbe_del_sanmac_netdev(netdev); |
| 8828 | |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 8829 | if (netdev->reg_state == NETREG_REGISTERED) |
| 8830 | unregister_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8831 | |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 8832 | #ifdef CONFIG_PCI_IOV |
| 8833 | /* |
| 8834 | * Only disable SR-IOV on unload if the user specified the now |
| 8835 | * deprecated max_vfs module parameter. |
| 8836 | */ |
| 8837 | if (max_vfs) |
| 8838 | ixgbe_disable_sriov(adapter); |
| 8839 | #endif |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 8840 | ixgbe_clear_interrupt_scheme(adapter); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 8841 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 8842 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8843 | |
Alexander Duyck | 2b1588c | 2012-03-17 02:39:16 +0000 | [diff] [blame] | 8844 | #ifdef CONFIG_DCB |
| 8845 | kfree(adapter->ixgbe_ieee_pfc); |
| 8846 | kfree(adapter->ixgbe_ieee_ets); |
| 8847 | |
| 8848 | #endif |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 8849 | iounmap(adapter->io_addr); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 8850 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 8851 | IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8852 | |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 8853 | e_dev_info("complete\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 8854 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 8855 | kfree(adapter->mac_table); |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 8856 | disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8857 | free_netdev(netdev); |
| 8858 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 8859 | pci_disable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8860 | |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 8861 | if (disable_dev) |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 8862 | pci_disable_device(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8863 | } |
| 8864 | |
| 8865 | /** |
| 8866 | * ixgbe_io_error_detected - called when PCI error is detected |
| 8867 | * @pdev: Pointer to PCI device |
| 8868 | * @state: The current pci connection state |
| 8869 | * |
| 8870 | * This function is called after a PCI bus error affecting |
| 8871 | * this device has been detected. |
| 8872 | */ |
| 8873 | 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] | 8874 | pci_channel_state_t state) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8875 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 8876 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 8877 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8878 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 8879 | #ifdef CONFIG_PCI_IOV |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 8880 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 8881 | struct pci_dev *bdev, *vfdev; |
| 8882 | u32 dw0, dw1, dw2, dw3; |
| 8883 | int vf, pos; |
| 8884 | u16 req_id, pf_func; |
| 8885 | |
| 8886 | if (adapter->hw.mac.type == ixgbe_mac_82598EB || |
| 8887 | adapter->num_vfs == 0) |
| 8888 | goto skip_bad_vf_detection; |
| 8889 | |
| 8890 | bdev = pdev->bus->self; |
Yijing Wang | 62f87c0 | 2012-07-24 17:20:03 +0800 | [diff] [blame] | 8891 | while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT)) |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 8892 | bdev = bdev->bus->self; |
| 8893 | |
| 8894 | if (!bdev) |
| 8895 | goto skip_bad_vf_detection; |
| 8896 | |
| 8897 | pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR); |
| 8898 | if (!pos) |
| 8899 | goto skip_bad_vf_detection; |
| 8900 | |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 8901 | dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG); |
| 8902 | dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4); |
| 8903 | dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8); |
| 8904 | dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12); |
| 8905 | if (ixgbe_removed(hw->hw_addr)) |
| 8906 | goto skip_bad_vf_detection; |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 8907 | |
| 8908 | req_id = dw1 >> 16; |
| 8909 | /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */ |
| 8910 | if (!(req_id & 0x0080)) |
| 8911 | goto skip_bad_vf_detection; |
| 8912 | |
| 8913 | pf_func = req_id & 0x01; |
| 8914 | if ((pf_func & 1) == (pdev->devfn & 1)) { |
| 8915 | unsigned int device_id; |
| 8916 | |
| 8917 | vf = (req_id & 0x7F) >> 1; |
| 8918 | e_dev_err("VF %d has caused a PCIe error\n", vf); |
| 8919 | e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: " |
| 8920 | "%8.8x\tdw3: %8.8x\n", |
| 8921 | dw0, dw1, dw2, dw3); |
| 8922 | switch (adapter->hw.mac.type) { |
| 8923 | case ixgbe_mac_82599EB: |
| 8924 | device_id = IXGBE_82599_VF_DEVICE_ID; |
| 8925 | break; |
| 8926 | case ixgbe_mac_X540: |
| 8927 | device_id = IXGBE_X540_VF_DEVICE_ID; |
| 8928 | break; |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 8929 | case ixgbe_mac_X550: |
| 8930 | device_id = IXGBE_DEV_ID_X550_VF; |
| 8931 | break; |
| 8932 | case ixgbe_mac_X550EM_x: |
| 8933 | device_id = IXGBE_DEV_ID_X550EM_X_VF; |
| 8934 | break; |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 8935 | default: |
| 8936 | device_id = 0; |
| 8937 | break; |
| 8938 | } |
| 8939 | |
| 8940 | /* Find the pci device of the offending VF */ |
Jon Mason | 36e9031 | 2012-07-19 21:02:09 +0000 | [diff] [blame] | 8941 | vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL); |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 8942 | while (vfdev) { |
| 8943 | if (vfdev->devfn == (req_id & 0xFF)) |
| 8944 | break; |
Jon Mason | 36e9031 | 2012-07-19 21:02:09 +0000 | [diff] [blame] | 8945 | vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 8946 | device_id, vfdev); |
| 8947 | } |
| 8948 | /* |
| 8949 | * There's a slim chance the VF could have been hot plugged, |
| 8950 | * so if it is no longer present we don't need to issue the |
| 8951 | * VFLR. Just clean up the AER in that case. |
| 8952 | */ |
| 8953 | if (vfdev) { |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 8954 | ixgbe_issue_vf_flr(adapter, vfdev); |
Greg Rose | b4fafbe | 2012-12-13 01:14:06 +0000 | [diff] [blame] | 8955 | /* Free device reference count */ |
| 8956 | pci_dev_put(vfdev); |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 8957 | } |
| 8958 | |
| 8959 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 8960 | } |
| 8961 | |
| 8962 | /* |
| 8963 | * Even though the error may have occurred on the other port |
| 8964 | * we still need to increment the vf error reference count for |
| 8965 | * both ports because the I/O resume function will be called |
| 8966 | * for both of them. |
| 8967 | */ |
| 8968 | adapter->vferr_refcount++; |
| 8969 | |
| 8970 | return PCI_ERS_RESULT_RECOVERED; |
| 8971 | |
| 8972 | skip_bad_vf_detection: |
| 8973 | #endif /* CONFIG_PCI_IOV */ |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 8974 | if (!test_bit(__IXGBE_SERVICE_INITED, &adapter->state)) |
| 8975 | return PCI_ERS_RESULT_DISCONNECT; |
| 8976 | |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 8977 | rtnl_lock(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8978 | netif_device_detach(netdev); |
| 8979 | |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 8980 | if (state == pci_channel_io_perm_failure) { |
| 8981 | rtnl_unlock(); |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 8982 | return PCI_ERS_RESULT_DISCONNECT; |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 8983 | } |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 8984 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8985 | if (netif_running(netdev)) |
| 8986 | ixgbe_down(adapter); |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 8987 | |
| 8988 | if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state)) |
| 8989 | pci_disable_device(pdev); |
| 8990 | rtnl_unlock(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8991 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 8992 | /* Request a slot reset. */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8993 | return PCI_ERS_RESULT_NEED_RESET; |
| 8994 | } |
| 8995 | |
| 8996 | /** |
| 8997 | * ixgbe_io_slot_reset - called after the pci bus has been reset. |
| 8998 | * @pdev: Pointer to PCI device |
| 8999 | * |
| 9000 | * Restart the card from scratch, as if from a cold-boot. |
| 9001 | */ |
| 9002 | static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev) |
| 9003 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 9004 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9005 | pci_ers_result_t result; |
| 9006 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9007 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 9008 | if (pci_enable_device_mem(pdev)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 9009 | 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] | 9010 | result = PCI_ERS_RESULT_DISCONNECT; |
| 9011 | } else { |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 9012 | smp_mb__before_atomic(); |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 9013 | clear_bit(__IXGBE_DISABLED, &adapter->state); |
Mark Rustad | 0391bbe | 2014-02-28 15:48:55 -0800 | [diff] [blame] | 9014 | adapter->hw.hw_addr = adapter->io_addr; |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9015 | pci_set_master(pdev); |
| 9016 | pci_restore_state(pdev); |
Breno Leitao | c0e1f68 | 2009-11-10 08:37:47 +0000 | [diff] [blame] | 9017 | pci_save_state(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9018 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 9019 | pci_wake_from_d3(pdev, false); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9020 | |
| 9021 | ixgbe_reset(adapter); |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 9022 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9023 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9024 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9025 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9026 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 9027 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 9028 | e_dev_err("pci_cleanup_aer_uncorrect_error_status " |
| 9029 | "failed 0x%0x\n", err); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9030 | /* non-fatal, continue */ |
| 9031 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9032 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9033 | return result; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9034 | } |
| 9035 | |
| 9036 | /** |
| 9037 | * ixgbe_io_resume - called when traffic can start flowing again. |
| 9038 | * @pdev: Pointer to PCI device |
| 9039 | * |
| 9040 | * This callback is called when the error recovery driver tells us that |
| 9041 | * its OK to resume normal operation. |
| 9042 | */ |
| 9043 | static void ixgbe_io_resume(struct pci_dev *pdev) |
| 9044 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 9045 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 9046 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9047 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 9048 | #ifdef CONFIG_PCI_IOV |
| 9049 | if (adapter->vferr_refcount) { |
| 9050 | e_info(drv, "Resuming after VF err\n"); |
| 9051 | adapter->vferr_refcount--; |
| 9052 | return; |
| 9053 | } |
| 9054 | |
| 9055 | #endif |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 9056 | if (netif_running(netdev)) |
| 9057 | ixgbe_up(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9058 | |
| 9059 | netif_device_attach(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9060 | } |
| 9061 | |
Stephen Hemminger | 3646f0e | 2012-09-07 09:33:15 -0700 | [diff] [blame] | 9062 | static const struct pci_error_handlers ixgbe_err_handler = { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9063 | .error_detected = ixgbe_io_error_detected, |
| 9064 | .slot_reset = ixgbe_io_slot_reset, |
| 9065 | .resume = ixgbe_io_resume, |
| 9066 | }; |
| 9067 | |
| 9068 | static struct pci_driver ixgbe_driver = { |
| 9069 | .name = ixgbe_driver_name, |
| 9070 | .id_table = ixgbe_pci_tbl, |
| 9071 | .probe = ixgbe_probe, |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 9072 | .remove = ixgbe_remove, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9073 | #ifdef CONFIG_PM |
| 9074 | .suspend = ixgbe_suspend, |
| 9075 | .resume = ixgbe_resume, |
| 9076 | #endif |
| 9077 | .shutdown = ixgbe_shutdown, |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 9078 | .sriov_configure = ixgbe_pci_sriov_configure, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9079 | .err_handler = &ixgbe_err_handler |
| 9080 | }; |
| 9081 | |
| 9082 | /** |
| 9083 | * ixgbe_init_module - Driver Registration Routine |
| 9084 | * |
| 9085 | * ixgbe_init_module is the first routine called when the driver is |
| 9086 | * loaded. All it does is register with the PCI subsystem. |
| 9087 | **/ |
| 9088 | static int __init ixgbe_init_module(void) |
| 9089 | { |
| 9090 | int ret; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 9091 | pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version); |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 9092 | pr_info("%s\n", ixgbe_copyright); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9093 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 9094 | ixgbe_dbg_init(); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 9095 | |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 9096 | ret = pci_register_driver(&ixgbe_driver); |
| 9097 | if (ret) { |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 9098 | ixgbe_dbg_exit(); |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 9099 | return ret; |
| 9100 | } |
| 9101 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 9102 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9103 | dca_register_notify(&dca_notifier); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9104 | #endif |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 9105 | |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 9106 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9107 | } |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 9108 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9109 | module_init(ixgbe_init_module); |
| 9110 | |
| 9111 | /** |
| 9112 | * ixgbe_exit_module - Driver Exit Cleanup Routine |
| 9113 | * |
| 9114 | * ixgbe_exit_module is called just before the driver is removed |
| 9115 | * from memory. |
| 9116 | **/ |
| 9117 | static void __exit ixgbe_exit_module(void) |
| 9118 | { |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 9119 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9120 | dca_unregister_notify(&dca_notifier); |
| 9121 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9122 | pci_unregister_driver(&ixgbe_driver); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 9123 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 9124 | ixgbe_dbg_exit(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9125 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9126 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 9127 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9128 | static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 9129 | void *p) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9130 | { |
| 9131 | int ret_val; |
| 9132 | |
| 9133 | ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 9134 | __ixgbe_notify_dca); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9135 | |
| 9136 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; |
| 9137 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9138 | |
Alexander Duyck | b453368 | 2009-03-31 21:32:42 +0000 | [diff] [blame] | 9139 | #endif /* CONFIG_IXGBE_DCA */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 9140 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9141 | module_exit(ixgbe_exit_module); |
| 9142 | |
| 9143 | /* ixgbe_main.c */ |