Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel 10 Gigabit PCI Express Linux driver |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 4 | Copyright(c) 1999 - 2016 Intel Corporation. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms and conditions of the GNU General Public License, |
| 8 | version 2, as published by the Free Software Foundation. |
| 9 | |
| 10 | This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License along with |
| 16 | this program; if not, write to the Free Software Foundation, Inc., |
| 17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | |
| 19 | The full GNU General Public License is included in this distribution in |
| 20 | the file called "COPYING". |
| 21 | |
| 22 | Contact Information: |
Jacob Keller | b89aae7 | 2014-02-22 01:23:50 +0000 | [diff] [blame] | 23 | Linux NICS <linux.nics@intel.com> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 24 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 26 | |
| 27 | *******************************************************************************/ |
| 28 | |
| 29 | #include <linux/types.h> |
| 30 | #include <linux/module.h> |
| 31 | #include <linux/pci.h> |
| 32 | #include <linux/netdevice.h> |
| 33 | #include <linux/vmalloc.h> |
| 34 | #include <linux/string.h> |
| 35 | #include <linux/in.h> |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 36 | #include <linux/interrupt.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 37 | #include <linux/ip.h> |
| 38 | #include <linux/tcp.h> |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 39 | #include <linux/sctp.h> |
Lucy Liu | 6012786 | 2009-07-22 14:07:33 +0000 | [diff] [blame] | 40 | #include <linux/pkt_sched.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 41 | #include <linux/ipv6.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 42 | #include <linux/slab.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 43 | #include <net/checksum.h> |
| 44 | #include <net/ip6_checksum.h> |
Martin K Petersen | c762dff | 2014-11-15 14:24:51 +0000 | [diff] [blame] | 45 | #include <linux/etherdevice.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 46 | #include <linux/ethtool.h> |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 47 | #include <linux/if.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 48 | #include <linux/if_vlan.h> |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 49 | #include <linux/if_macvlan.h> |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 50 | #include <linux/if_bridge.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 51 | #include <linux/prefetch.h> |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 52 | #include <scsi/fc/fc_fcoe.h> |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 53 | #include <net/udp_tunnel.h> |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 54 | #include <net/pkt_cls.h> |
| 55 | #include <net/tc_act/tc_gact.h> |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 56 | #include <net/tc_act/tc_mirred.h> |
Sowmini Varadhan | 9f3c750 | 2016-10-24 15:36:39 -0700 | [diff] [blame^] | 57 | #include <net/vxlan.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 58 | |
| 59 | #include "ixgbe.h" |
| 60 | #include "ixgbe_common.h" |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 61 | #include "ixgbe_dcb_82599.h" |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 62 | #include "ixgbe_sriov.h" |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 63 | #include "ixgbe_model.h" |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 64 | |
| 65 | char ixgbe_driver_name[] = "ixgbe"; |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 66 | static const char ixgbe_driver_string[] = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 67 | "Intel(R) 10 Gigabit PCI Express Network Driver"; |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 68 | #ifdef IXGBE_FCOE |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 69 | char ixgbe_default_device_descr[] = |
| 70 | "Intel(R) 10 Gigabit Network Connection"; |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 71 | #else |
| 72 | static char ixgbe_default_device_descr[] = |
| 73 | "Intel(R) 10 Gigabit Network Connection"; |
| 74 | #endif |
Mark Rustad | 10ef00f | 2016-04-01 12:18:51 -0700 | [diff] [blame] | 75 | #define DRV_VERSION "4.4.0-k" |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 76 | const char ixgbe_driver_version[] = DRV_VERSION; |
Don Skidmore | a52055e | 2011-02-23 09:58:39 +0000 | [diff] [blame] | 77 | static const char ixgbe_copyright[] = |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 78 | "Copyright (c) 1999-2016 Intel Corporation."; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 79 | |
Don Skidmore | f44e751 | 2015-06-09 16:36:23 -0700 | [diff] [blame] | 80 | static const char ixgbe_overheat_msg[] = "Network adapter has been stopped because it has over heated. Restart the computer. If the problem persists, power off the system and replace the adapter"; |
| 81 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 82 | static const struct ixgbe_info *ixgbe_info_tbl[] = { |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 83 | [board_82598] = &ixgbe_82598_info, |
| 84 | [board_82599] = &ixgbe_82599_info, |
| 85 | [board_X540] = &ixgbe_X540_info, |
| 86 | [board_X550] = &ixgbe_X550_info, |
| 87 | [board_X550EM_x] = &ixgbe_X550EM_x_info, |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 88 | [board_x550em_a] = &ixgbe_x550em_a_info, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | /* ixgbe_pci_tbl - PCI Device ID Table |
| 92 | * |
| 93 | * Wildcard entries (PCI_ANY_ID) should come last |
| 94 | * Last entry must be all 0s |
| 95 | * |
| 96 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 97 | * Class, Class Mask, private data (not used) } |
| 98 | */ |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 99 | static const struct pci_device_id ixgbe_pci_tbl[] = { |
Alexander Duyck | 54239c6 | 2011-07-15 03:06:06 +0000 | [diff] [blame] | 100 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 }, |
| 101 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 }, |
| 102 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 }, |
| 103 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 }, |
| 104 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 }, |
| 105 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 }, |
| 106 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 }, |
| 107 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 }, |
| 108 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 }, |
| 109 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 }, |
| 110 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 }, |
| 111 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 }, |
| 112 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 }, |
| 113 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 }, |
| 114 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 }, |
| 115 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 }, |
| 116 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 }, |
| 117 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 }, |
| 118 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 }, |
| 119 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 }, |
| 120 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 }, |
| 121 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 }, |
| 122 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 }, |
| 123 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 }, |
| 124 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 }, |
| 125 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 }, |
Don Skidmore | 8f58332 | 2013-07-27 06:25:38 +0000 | [diff] [blame] | 126 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_QSFP_SF_QP), board_82599 }, |
Emil Tantilov | 7d14528 | 2011-09-08 08:30:14 +0000 | [diff] [blame] | 127 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 }, |
Emil Tantilov | 9e791e4 | 2011-11-04 06:43:29 +0000 | [diff] [blame] | 128 | {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] | 129 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 }, |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 130 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T), board_X550}, |
Mark Rustad | a711ad8 | 2016-03-21 11:21:31 -0700 | [diff] [blame] | 131 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T1), board_X550}, |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 132 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KX4), board_X550EM_x}, |
| 133 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KR), board_X550EM_x}, |
Don Skidmore | deda562 | 2015-06-09 17:39:46 -0700 | [diff] [blame] | 134 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_10G_T), board_X550EM_x}, |
Mark Rustad | 018d714 | 2015-08-08 16:19:19 -0700 | [diff] [blame] | 135 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_SFP), board_X550EM_x}, |
Mark Rustad | f572b2c | 2016-04-01 12:18:46 -0700 | [diff] [blame] | 136 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR), board_x550em_a }, |
| 137 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR_L), board_x550em_a }, |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 138 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP_N), board_x550em_a }, |
Mark Rustad | 200157c | 2016-04-01 12:18:40 -0700 | [diff] [blame] | 139 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII), board_x550em_a }, |
| 140 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII_L), board_x550em_a }, |
Don Skidmore | 92ed843 | 2016-08-17 20:34:40 -0400 | [diff] [blame] | 141 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_10G_T), board_x550em_a}, |
Mark Rustad | 2d40cd1 | 2016-04-01 12:18:35 -0700 | [diff] [blame] | 142 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP), board_x550em_a }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 143 | /* required last entry */ |
| 144 | {0, } |
| 145 | }; |
| 146 | MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl); |
| 147 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 148 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 149 | static int ixgbe_notify_dca(struct notifier_block *, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 150 | void *p); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 151 | static struct notifier_block dca_notifier = { |
| 152 | .notifier_call = ixgbe_notify_dca, |
| 153 | .next = NULL, |
| 154 | .priority = 0 |
| 155 | }; |
| 156 | #endif |
| 157 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 158 | #ifdef CONFIG_PCI_IOV |
| 159 | static unsigned int max_vfs; |
| 160 | module_param(max_vfs, uint, 0); |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 161 | MODULE_PARM_DESC(max_vfs, |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 162 | "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] | 163 | #endif /* CONFIG_PCI_IOV */ |
| 164 | |
Peter P Waskiewicz Jr | 8ef78ad | 2012-02-01 09:19:21 +0000 | [diff] [blame] | 165 | static unsigned int allow_unsupported_sfp; |
| 166 | module_param(allow_unsupported_sfp, uint, 0); |
| 167 | MODULE_PARM_DESC(allow_unsupported_sfp, |
| 168 | "Allow unsupported and untested SFP+ modules on 82599-based adapters"); |
| 169 | |
stephen hemminger | b3f4d59 | 2012-03-13 06:04:20 +0000 | [diff] [blame] | 170 | #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK) |
| 171 | static int debug = -1; |
| 172 | module_param(debug, int, 0); |
| 173 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 174 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 175 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 176 | MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver"); |
| 177 | MODULE_LICENSE("GPL"); |
| 178 | MODULE_VERSION(DRV_VERSION); |
| 179 | |
Mark Rustad | 780484d | 2015-10-21 17:21:10 -0700 | [diff] [blame] | 180 | static struct workqueue_struct *ixgbe_wq; |
| 181 | |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 182 | static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev); |
| 183 | |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 184 | static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter *adapter, |
| 185 | u32 reg, u16 *value) |
| 186 | { |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 187 | struct pci_dev *parent_dev; |
| 188 | struct pci_bus *parent_bus; |
| 189 | |
| 190 | parent_bus = adapter->pdev->bus->parent; |
| 191 | if (!parent_bus) |
| 192 | return -1; |
| 193 | |
| 194 | parent_dev = parent_bus->self; |
| 195 | if (!parent_dev) |
| 196 | return -1; |
| 197 | |
Yijing Wang | c0798ed | 2013-09-04 17:30:08 +0000 | [diff] [blame] | 198 | if (!pci_is_pcie(parent_dev)) |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 199 | return -1; |
| 200 | |
Yijing Wang | c0798ed | 2013-09-04 17:30:08 +0000 | [diff] [blame] | 201 | pcie_capability_read_word(parent_dev, reg, value); |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 202 | if (*value == IXGBE_FAILED_READ_CFG_WORD && |
| 203 | ixgbe_check_cfg_remove(&adapter->hw, parent_dev)) |
| 204 | return -1; |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | static s32 ixgbe_get_parent_bus_info(struct ixgbe_adapter *adapter) |
| 209 | { |
| 210 | struct ixgbe_hw *hw = &adapter->hw; |
| 211 | u16 link_status = 0; |
| 212 | int err; |
| 213 | |
| 214 | hw->bus.type = ixgbe_bus_type_pci_express; |
| 215 | |
| 216 | /* Get the negotiated link width and speed from PCI config space of the |
| 217 | * parent, as this device is behind a switch |
| 218 | */ |
| 219 | err = ixgbe_read_pci_cfg_word_parent(adapter, 18, &link_status); |
| 220 | |
| 221 | /* assume caller will handle error case */ |
| 222 | if (err) |
| 223 | return err; |
| 224 | |
| 225 | hw->bus.width = ixgbe_convert_bus_width(link_status); |
| 226 | hw->bus.speed = ixgbe_convert_bus_speed(link_status); |
| 227 | |
| 228 | return 0; |
| 229 | } |
| 230 | |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 231 | /** |
| 232 | * ixgbe_check_from_parent - Determine whether PCIe info should come from parent |
| 233 | * @hw: hw specific details |
| 234 | * |
| 235 | * This function is used by probe to determine whether a device's PCI-Express |
| 236 | * bandwidth details should be gathered from the parent bus instead of from the |
| 237 | * device. Used to ensure that various locations all have the correct device ID |
| 238 | * checks. |
| 239 | */ |
| 240 | static inline bool ixgbe_pcie_from_parent(struct ixgbe_hw *hw) |
| 241 | { |
| 242 | switch (hw->device_id) { |
| 243 | case IXGBE_DEV_ID_82599_SFP_SF_QP: |
Don Skidmore | 8f58332 | 2013-07-27 06:25:38 +0000 | [diff] [blame] | 244 | case IXGBE_DEV_ID_82599_QSFP_SF_QP: |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 245 | return true; |
| 246 | default: |
| 247 | return false; |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | static void ixgbe_check_minimum_link(struct ixgbe_adapter *adapter, |
| 252 | int expected_gts) |
| 253 | { |
Don Skidmore | f9328bc | 2015-06-18 13:24:06 -0400 | [diff] [blame] | 254 | struct ixgbe_hw *hw = &adapter->hw; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 255 | int max_gts = 0; |
| 256 | enum pci_bus_speed speed = PCI_SPEED_UNKNOWN; |
| 257 | enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN; |
| 258 | struct pci_dev *pdev; |
| 259 | |
Don Skidmore | f9328bc | 2015-06-18 13:24:06 -0400 | [diff] [blame] | 260 | /* Some devices are not connected over PCIe and thus do not negotiate |
| 261 | * speed. These devices do not have valid bus info, and thus any report |
| 262 | * we generate may not be correct. |
| 263 | */ |
| 264 | if (hw->bus.type == ixgbe_bus_type_internal) |
| 265 | return; |
| 266 | |
Jacob Keller | 56d1392 | 2015-06-10 11:44:45 -0700 | [diff] [blame] | 267 | /* determine whether to use the parent device */ |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 268 | if (ixgbe_pcie_from_parent(&adapter->hw)) |
| 269 | pdev = adapter->pdev->bus->parent->self; |
| 270 | else |
| 271 | pdev = adapter->pdev; |
| 272 | |
| 273 | if (pcie_get_minimum_link(pdev, &speed, &width) || |
| 274 | speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) { |
| 275 | e_dev_warn("Unable to determine PCI Express bandwidth.\n"); |
| 276 | return; |
| 277 | } |
| 278 | |
| 279 | switch (speed) { |
| 280 | case PCIE_SPEED_2_5GT: |
| 281 | /* 8b/10b encoding reduces max throughput by 20% */ |
| 282 | max_gts = 2 * width; |
| 283 | break; |
| 284 | case PCIE_SPEED_5_0GT: |
| 285 | /* 8b/10b encoding reduces max throughput by 20% */ |
| 286 | max_gts = 4 * width; |
| 287 | break; |
| 288 | case PCIE_SPEED_8_0GT: |
Jacob Keller | 9f0a433 | 2013-10-18 05:09:19 +0000 | [diff] [blame] | 289 | /* 128b/130b encoding reduces throughput by less than 2% */ |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 290 | max_gts = 8 * width; |
| 291 | break; |
| 292 | default: |
| 293 | e_dev_warn("Unable to determine PCI Express bandwidth.\n"); |
| 294 | return; |
| 295 | } |
| 296 | |
| 297 | e_dev_info("PCI Express bandwidth of %dGT/s available\n", |
| 298 | max_gts); |
| 299 | e_dev_info("(Speed:%s, Width: x%d, Encoding Loss:%s)\n", |
| 300 | (speed == PCIE_SPEED_8_0GT ? "8.0GT/s" : |
| 301 | speed == PCIE_SPEED_5_0GT ? "5.0GT/s" : |
| 302 | speed == PCIE_SPEED_2_5GT ? "2.5GT/s" : |
| 303 | "Unknown"), |
| 304 | width, |
| 305 | (speed == PCIE_SPEED_2_5GT ? "20%" : |
| 306 | speed == PCIE_SPEED_5_0GT ? "20%" : |
Jacob Keller | 9f0a433 | 2013-10-18 05:09:19 +0000 | [diff] [blame] | 307 | speed == PCIE_SPEED_8_0GT ? "<2%" : |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 308 | "Unknown")); |
| 309 | |
| 310 | if (max_gts < expected_gts) { |
| 311 | e_dev_warn("This is not sufficient for optimal performance of this card.\n"); |
| 312 | e_dev_warn("For optimal performance, at least %dGT/s of bandwidth is required.\n", |
| 313 | expected_gts); |
| 314 | e_dev_warn("A slot with more lanes and/or higher speed is suggested.\n"); |
| 315 | } |
| 316 | } |
| 317 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 318 | static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter) |
| 319 | { |
| 320 | if (!test_bit(__IXGBE_DOWN, &adapter->state) && |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 321 | !test_bit(__IXGBE_REMOVING, &adapter->state) && |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 322 | !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state)) |
Mark Rustad | 780484d | 2015-10-21 17:21:10 -0700 | [diff] [blame] | 323 | queue_work(ixgbe_wq, &adapter->service_task); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 324 | } |
| 325 | |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 326 | static void ixgbe_remove_adapter(struct ixgbe_hw *hw) |
| 327 | { |
| 328 | struct ixgbe_adapter *adapter = hw->back; |
| 329 | |
| 330 | if (!hw->hw_addr) |
| 331 | return; |
| 332 | hw->hw_addr = NULL; |
| 333 | e_dev_err("Adapter removed\n"); |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 334 | if (test_bit(__IXGBE_SERVICE_INITED, &adapter->state)) |
| 335 | ixgbe_service_event_schedule(adapter); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 336 | } |
| 337 | |
Mark Rustad | f8e2472 | 2014-03-18 07:03:40 +0000 | [diff] [blame] | 338 | static void ixgbe_check_remove(struct ixgbe_hw *hw, u32 reg) |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 339 | { |
| 340 | u32 value; |
| 341 | |
| 342 | /* The following check not only optimizes a bit by not |
| 343 | * performing a read on the status register when the |
| 344 | * register just read was a status register read that |
| 345 | * returned IXGBE_FAILED_READ_REG. It also blocks any |
| 346 | * potential recursion. |
| 347 | */ |
| 348 | if (reg == IXGBE_STATUS) { |
| 349 | ixgbe_remove_adapter(hw); |
| 350 | return; |
| 351 | } |
| 352 | value = ixgbe_read_reg(hw, IXGBE_STATUS); |
| 353 | if (value == IXGBE_FAILED_READ_REG) |
| 354 | ixgbe_remove_adapter(hw); |
| 355 | } |
| 356 | |
Mark Rustad | f8e2472 | 2014-03-18 07:03:40 +0000 | [diff] [blame] | 357 | /** |
| 358 | * ixgbe_read_reg - Read from device register |
| 359 | * @hw: hw specific details |
| 360 | * @reg: offset of register to read |
| 361 | * |
| 362 | * Returns : value read or IXGBE_FAILED_READ_REG if removed |
| 363 | * |
| 364 | * This function is used to read device registers. It checks for device |
| 365 | * removal by confirming any read that returns all ones by checking the |
| 366 | * status register value for all ones. This function avoids reading from |
| 367 | * the hardware if a removal was previously detected in which case it |
| 368 | * returns IXGBE_FAILED_READ_REG (all ones). |
| 369 | */ |
| 370 | u32 ixgbe_read_reg(struct ixgbe_hw *hw, u32 reg) |
| 371 | { |
| 372 | u8 __iomem *reg_addr = ACCESS_ONCE(hw->hw_addr); |
| 373 | u32 value; |
| 374 | |
| 375 | if (ixgbe_removed(reg_addr)) |
| 376 | return IXGBE_FAILED_READ_REG; |
Mark Rustad | 2f2219b | 2016-04-07 10:43:50 -0700 | [diff] [blame] | 377 | if (unlikely(hw->phy.nw_mng_if_sel & |
| 378 | IXGBE_NW_MNG_IF_SEL_ENABLE_10_100M)) { |
| 379 | struct ixgbe_adapter *adapter; |
| 380 | int i; |
| 381 | |
| 382 | for (i = 0; i < 200; ++i) { |
| 383 | value = readl(reg_addr + IXGBE_MAC_SGMII_BUSY); |
| 384 | if (likely(!value)) |
| 385 | goto writes_completed; |
| 386 | if (value == IXGBE_FAILED_READ_REG) { |
| 387 | ixgbe_remove_adapter(hw); |
| 388 | return IXGBE_FAILED_READ_REG; |
| 389 | } |
| 390 | udelay(5); |
| 391 | } |
| 392 | |
| 393 | adapter = hw->back; |
| 394 | e_warn(hw, "register writes incomplete %08x\n", value); |
| 395 | } |
| 396 | |
| 397 | writes_completed: |
Mark Rustad | f8e2472 | 2014-03-18 07:03:40 +0000 | [diff] [blame] | 398 | value = readl(reg_addr + reg); |
| 399 | if (unlikely(value == IXGBE_FAILED_READ_REG)) |
| 400 | ixgbe_check_remove(hw, reg); |
| 401 | return value; |
| 402 | } |
| 403 | |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 404 | static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev) |
| 405 | { |
| 406 | u16 value; |
| 407 | |
| 408 | pci_read_config_word(pdev, PCI_VENDOR_ID, &value); |
| 409 | if (value == IXGBE_FAILED_READ_CFG_WORD) { |
| 410 | ixgbe_remove_adapter(hw); |
| 411 | return true; |
| 412 | } |
| 413 | return false; |
| 414 | } |
| 415 | |
| 416 | u16 ixgbe_read_pci_cfg_word(struct ixgbe_hw *hw, u32 reg) |
| 417 | { |
| 418 | struct ixgbe_adapter *adapter = hw->back; |
| 419 | u16 value; |
| 420 | |
| 421 | if (ixgbe_removed(hw->hw_addr)) |
| 422 | return IXGBE_FAILED_READ_CFG_WORD; |
| 423 | pci_read_config_word(adapter->pdev, reg, &value); |
| 424 | if (value == IXGBE_FAILED_READ_CFG_WORD && |
| 425 | ixgbe_check_cfg_remove(hw, adapter->pdev)) |
| 426 | return IXGBE_FAILED_READ_CFG_WORD; |
| 427 | return value; |
| 428 | } |
| 429 | |
| 430 | #ifdef CONFIG_PCI_IOV |
| 431 | static u32 ixgbe_read_pci_cfg_dword(struct ixgbe_hw *hw, u32 reg) |
| 432 | { |
| 433 | struct ixgbe_adapter *adapter = hw->back; |
| 434 | u32 value; |
| 435 | |
| 436 | if (ixgbe_removed(hw->hw_addr)) |
| 437 | return IXGBE_FAILED_READ_CFG_DWORD; |
| 438 | pci_read_config_dword(adapter->pdev, reg, &value); |
| 439 | if (value == IXGBE_FAILED_READ_CFG_DWORD && |
| 440 | ixgbe_check_cfg_remove(hw, adapter->pdev)) |
| 441 | return IXGBE_FAILED_READ_CFG_DWORD; |
| 442 | return value; |
| 443 | } |
| 444 | #endif /* CONFIG_PCI_IOV */ |
| 445 | |
Jacob Keller | ed19231 | 2014-02-22 01:23:53 +0000 | [diff] [blame] | 446 | void ixgbe_write_pci_cfg_word(struct ixgbe_hw *hw, u32 reg, u16 value) |
| 447 | { |
| 448 | struct ixgbe_adapter *adapter = hw->back; |
| 449 | |
| 450 | if (ixgbe_removed(hw->hw_addr)) |
| 451 | return; |
| 452 | pci_write_config_word(adapter->pdev, reg, value); |
| 453 | } |
| 454 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 455 | static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter) |
| 456 | { |
| 457 | BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state)); |
| 458 | |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 459 | /* flush memory to make sure state is correct before next watchdog */ |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 460 | smp_mb__before_atomic(); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 461 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
| 462 | } |
| 463 | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 464 | struct ixgbe_reg_info { |
| 465 | u32 ofs; |
| 466 | char *name; |
| 467 | }; |
| 468 | |
| 469 | static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = { |
| 470 | |
| 471 | /* General Registers */ |
| 472 | {IXGBE_CTRL, "CTRL"}, |
| 473 | {IXGBE_STATUS, "STATUS"}, |
| 474 | {IXGBE_CTRL_EXT, "CTRL_EXT"}, |
| 475 | |
| 476 | /* Interrupt Registers */ |
| 477 | {IXGBE_EICR, "EICR"}, |
| 478 | |
| 479 | /* RX Registers */ |
| 480 | {IXGBE_SRRCTL(0), "SRRCTL"}, |
| 481 | {IXGBE_DCA_RXCTRL(0), "DRXCTL"}, |
| 482 | {IXGBE_RDLEN(0), "RDLEN"}, |
| 483 | {IXGBE_RDH(0), "RDH"}, |
| 484 | {IXGBE_RDT(0), "RDT"}, |
| 485 | {IXGBE_RXDCTL(0), "RXDCTL"}, |
| 486 | {IXGBE_RDBAL(0), "RDBAL"}, |
| 487 | {IXGBE_RDBAH(0), "RDBAH"}, |
| 488 | |
| 489 | /* TX Registers */ |
| 490 | {IXGBE_TDBAL(0), "TDBAL"}, |
| 491 | {IXGBE_TDBAH(0), "TDBAH"}, |
| 492 | {IXGBE_TDLEN(0), "TDLEN"}, |
| 493 | {IXGBE_TDH(0), "TDH"}, |
| 494 | {IXGBE_TDT(0), "TDT"}, |
| 495 | {IXGBE_TXDCTL(0), "TXDCTL"}, |
| 496 | |
| 497 | /* List Terminator */ |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 498 | { .name = NULL } |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 499 | }; |
| 500 | |
| 501 | |
| 502 | /* |
| 503 | * ixgbe_regdump - register printout routine |
| 504 | */ |
| 505 | static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo) |
| 506 | { |
| 507 | int i = 0, j = 0; |
| 508 | char rname[16]; |
| 509 | u32 regs[64]; |
| 510 | |
| 511 | switch (reginfo->ofs) { |
| 512 | case IXGBE_SRRCTL(0): |
| 513 | for (i = 0; i < 64; i++) |
| 514 | regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i)); |
| 515 | break; |
| 516 | case IXGBE_DCA_RXCTRL(0): |
| 517 | for (i = 0; i < 64; i++) |
| 518 | regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i)); |
| 519 | break; |
| 520 | case IXGBE_RDLEN(0): |
| 521 | for (i = 0; i < 64; i++) |
| 522 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i)); |
| 523 | break; |
| 524 | case IXGBE_RDH(0): |
| 525 | for (i = 0; i < 64; i++) |
| 526 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i)); |
| 527 | break; |
| 528 | case IXGBE_RDT(0): |
| 529 | for (i = 0; i < 64; i++) |
| 530 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i)); |
| 531 | break; |
| 532 | case IXGBE_RXDCTL(0): |
| 533 | for (i = 0; i < 64; i++) |
| 534 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i)); |
| 535 | break; |
| 536 | case IXGBE_RDBAL(0): |
| 537 | for (i = 0; i < 64; i++) |
| 538 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i)); |
| 539 | break; |
| 540 | case IXGBE_RDBAH(0): |
| 541 | for (i = 0; i < 64; i++) |
| 542 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i)); |
| 543 | break; |
| 544 | case IXGBE_TDBAL(0): |
| 545 | for (i = 0; i < 64; i++) |
| 546 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i)); |
| 547 | break; |
| 548 | case IXGBE_TDBAH(0): |
| 549 | for (i = 0; i < 64; i++) |
| 550 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i)); |
| 551 | break; |
| 552 | case IXGBE_TDLEN(0): |
| 553 | for (i = 0; i < 64; i++) |
| 554 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i)); |
| 555 | break; |
| 556 | case IXGBE_TDH(0): |
| 557 | for (i = 0; i < 64; i++) |
| 558 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i)); |
| 559 | break; |
| 560 | case IXGBE_TDT(0): |
| 561 | for (i = 0; i < 64; i++) |
| 562 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i)); |
| 563 | break; |
| 564 | case IXGBE_TXDCTL(0): |
| 565 | for (i = 0; i < 64; i++) |
| 566 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i)); |
| 567 | break; |
| 568 | default: |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 569 | pr_info("%-15s %08x\n", reginfo->name, |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 570 | IXGBE_READ_REG(hw, reginfo->ofs)); |
| 571 | return; |
| 572 | } |
| 573 | |
| 574 | for (i = 0; i < 8; i++) { |
| 575 | 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] | 576 | pr_err("%-15s", rname); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 577 | for (j = 0; j < 8; j++) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 578 | pr_cont(" %08x", regs[i*8+j]); |
| 579 | pr_cont("\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | } |
| 583 | |
| 584 | /* |
| 585 | * ixgbe_dump - Print registers, tx-rings and rx-rings |
| 586 | */ |
| 587 | static void ixgbe_dump(struct ixgbe_adapter *adapter) |
| 588 | { |
| 589 | struct net_device *netdev = adapter->netdev; |
| 590 | struct ixgbe_hw *hw = &adapter->hw; |
| 591 | struct ixgbe_reg_info *reginfo; |
| 592 | int n = 0; |
| 593 | struct ixgbe_ring *tx_ring; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 594 | struct ixgbe_tx_buffer *tx_buffer; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 595 | union ixgbe_adv_tx_desc *tx_desc; |
| 596 | struct my_u0 { u64 a; u64 b; } *u0; |
| 597 | struct ixgbe_ring *rx_ring; |
| 598 | union ixgbe_adv_rx_desc *rx_desc; |
| 599 | struct ixgbe_rx_buffer *rx_buffer_info; |
| 600 | u32 staterr; |
| 601 | int i = 0; |
| 602 | |
| 603 | if (!netif_msg_hw(adapter)) |
| 604 | return; |
| 605 | |
| 606 | /* Print netdevice Info */ |
| 607 | if (netdev) { |
| 608 | dev_info(&adapter->pdev->dev, "Net device Info\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 609 | pr_info("Device Name state " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 610 | "trans_start last_rx\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 611 | pr_info("%-15s %016lX %016lX %016lX\n", |
| 612 | netdev->name, |
| 613 | netdev->state, |
Florian Westphal | 4d0e965 | 2016-05-03 16:30:59 +0200 | [diff] [blame] | 614 | dev_trans_start(netdev), |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 615 | netdev->last_rx); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | /* Print Registers */ |
| 619 | dev_info(&adapter->pdev->dev, "Register Dump\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 620 | pr_info(" Register Name Value\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 621 | for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl; |
| 622 | reginfo->name; reginfo++) { |
| 623 | ixgbe_regdump(hw, reginfo); |
| 624 | } |
| 625 | |
| 626 | /* Print TX Ring Summary */ |
| 627 | if (!netdev || !netif_running(netdev)) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 628 | return; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 629 | |
| 630 | dev_info(&adapter->pdev->dev, "TX Rings Summary\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 631 | pr_info(" %s %s %s %s\n", |
| 632 | "Queue [NTU] [NTC] [bi(ntc)->dma ]", |
| 633 | "leng", "ntw", "timestamp"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 634 | for (n = 0; n < adapter->num_tx_queues; n++) { |
| 635 | tx_ring = adapter->tx_ring[n]; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 636 | tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean]; |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 637 | pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n", |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 638 | n, tx_ring->next_to_use, tx_ring->next_to_clean, |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 639 | (u64)dma_unmap_addr(tx_buffer, dma), |
| 640 | dma_unmap_len(tx_buffer, len), |
| 641 | tx_buffer->next_to_watch, |
| 642 | (u64)tx_buffer->time_stamp); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | /* Print TX Rings */ |
| 646 | if (!netif_msg_tx_done(adapter)) |
| 647 | goto rx_ring_summary; |
| 648 | |
| 649 | dev_info(&adapter->pdev->dev, "TX Rings Dump\n"); |
| 650 | |
| 651 | /* Transmit Descriptor Formats |
| 652 | * |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 653 | * 82598 Advanced Transmit Descriptor |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 654 | * +--------------------------------------------------------------+ |
| 655 | * 0 | Buffer Address [63:0] | |
| 656 | * +--------------------------------------------------------------+ |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 657 | * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 658 | * +--------------------------------------------------------------+ |
| 659 | * 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] | 660 | * |
| 661 | * 82598 Advanced Transmit Descriptor (Write-Back Format) |
| 662 | * +--------------------------------------------------------------+ |
| 663 | * 0 | RSV [63:0] | |
| 664 | * +--------------------------------------------------------------+ |
| 665 | * 8 | RSV | STA | NXTSEQ | |
| 666 | * +--------------------------------------------------------------+ |
| 667 | * 63 36 35 32 31 0 |
| 668 | * |
| 669 | * 82599+ Advanced Transmit Descriptor |
| 670 | * +--------------------------------------------------------------+ |
| 671 | * 0 | Buffer Address [63:0] | |
| 672 | * +--------------------------------------------------------------+ |
| 673 | * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN | |
| 674 | * +--------------------------------------------------------------+ |
| 675 | * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0 |
| 676 | * |
| 677 | * 82599+ Advanced Transmit Descriptor (Write-Back Format) |
| 678 | * +--------------------------------------------------------------+ |
| 679 | * 0 | RSV [63:0] | |
| 680 | * +--------------------------------------------------------------+ |
| 681 | * 8 | RSV | STA | RSV | |
| 682 | * +--------------------------------------------------------------+ |
| 683 | * 63 36 35 32 31 0 |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 684 | */ |
| 685 | |
| 686 | for (n = 0; n < adapter->num_tx_queues; n++) { |
| 687 | tx_ring = adapter->tx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 688 | pr_info("------------------------------------\n"); |
| 689 | pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index); |
| 690 | pr_info("------------------------------------\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 691 | pr_info("%s%s %s %s %s %s\n", |
| 692 | "T [desc] [address 63:0 ] ", |
| 693 | "[PlPOIdStDDt Ln] [bi->dma ] ", |
| 694 | "leng", "ntw", "timestamp", "bi->skb"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 695 | |
| 696 | for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 697 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 698 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 699 | u0 = (struct my_u0 *)tx_desc; |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 700 | if (dma_unmap_len(tx_buffer, len) > 0) { |
| 701 | pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p", |
| 702 | i, |
| 703 | le64_to_cpu(u0->a), |
| 704 | le64_to_cpu(u0->b), |
| 705 | (u64)dma_unmap_addr(tx_buffer, dma), |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 706 | dma_unmap_len(tx_buffer, len), |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 707 | tx_buffer->next_to_watch, |
| 708 | (u64)tx_buffer->time_stamp, |
| 709 | tx_buffer->skb); |
| 710 | if (i == tx_ring->next_to_use && |
| 711 | i == tx_ring->next_to_clean) |
| 712 | pr_cont(" NTC/U\n"); |
| 713 | else if (i == tx_ring->next_to_use) |
| 714 | pr_cont(" NTU\n"); |
| 715 | else if (i == tx_ring->next_to_clean) |
| 716 | pr_cont(" NTC\n"); |
| 717 | else |
| 718 | pr_cont("\n"); |
| 719 | |
| 720 | if (netif_msg_pktdata(adapter) && |
| 721 | tx_buffer->skb) |
| 722 | print_hex_dump(KERN_INFO, "", |
| 723 | DUMP_PREFIX_ADDRESS, 16, 1, |
| 724 | tx_buffer->skb->data, |
| 725 | dma_unmap_len(tx_buffer, len), |
| 726 | true); |
| 727 | } |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 728 | } |
| 729 | } |
| 730 | |
| 731 | /* Print RX Rings Summary */ |
| 732 | rx_ring_summary: |
| 733 | dev_info(&adapter->pdev->dev, "RX Rings Summary\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 734 | pr_info("Queue [NTU] [NTC]\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 735 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 736 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 737 | pr_info("%5d %5X %5X\n", |
| 738 | n, rx_ring->next_to_use, rx_ring->next_to_clean); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | /* Print RX Rings */ |
| 742 | if (!netif_msg_rx_status(adapter)) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 743 | return; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 744 | |
| 745 | dev_info(&adapter->pdev->dev, "RX Rings Dump\n"); |
| 746 | |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 747 | /* Receive Descriptor Formats |
| 748 | * |
| 749 | * 82598 Advanced Receive Descriptor (Read) Format |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 750 | * 63 1 0 |
| 751 | * +-----------------------------------------------------+ |
| 752 | * 0 | Packet Buffer Address [63:1] |A0/NSE| |
| 753 | * +----------------------------------------------+------+ |
| 754 | * 8 | Header Buffer Address [63:1] | DD | |
| 755 | * +-----------------------------------------------------+ |
| 756 | * |
| 757 | * |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 758 | * 82598 Advanced Receive Descriptor (Write-Back) Format |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 759 | * |
| 760 | * 63 48 47 32 31 30 21 20 16 15 4 3 0 |
| 761 | * +------------------------------------------------------+ |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 762 | * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS | |
| 763 | * | Packet | IP | | | | Type | Type | |
| 764 | * | Checksum | Ident | | | | | | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 765 | * +------------------------------------------------------+ |
| 766 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | |
| 767 | * +------------------------------------------------------+ |
| 768 | * 63 48 47 32 31 20 19 0 |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 769 | * |
| 770 | * 82599+ Advanced Receive Descriptor (Read) Format |
| 771 | * 63 1 0 |
| 772 | * +-----------------------------------------------------+ |
| 773 | * 0 | Packet Buffer Address [63:1] |A0/NSE| |
| 774 | * +----------------------------------------------+------+ |
| 775 | * 8 | Header Buffer Address [63:1] | DD | |
| 776 | * +-----------------------------------------------------+ |
| 777 | * |
| 778 | * |
| 779 | * 82599+ Advanced Receive Descriptor (Write-Back) Format |
| 780 | * |
| 781 | * 63 48 47 32 31 30 21 20 17 16 4 3 0 |
| 782 | * +------------------------------------------------------+ |
| 783 | * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS | |
| 784 | * |/ RTT / PCoE_PARAM | | | CNT | Type | Type | |
| 785 | * |/ Flow Dir Flt ID | | | | | | |
| 786 | * +------------------------------------------------------+ |
| 787 | * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP | |
| 788 | * +------------------------------------------------------+ |
| 789 | * 63 48 47 32 31 20 19 0 |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 790 | */ |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 791 | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 792 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 793 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 794 | pr_info("------------------------------------\n"); |
| 795 | pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index); |
| 796 | pr_info("------------------------------------\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 797 | pr_info("%s%s%s", |
| 798 | "R [desc] [ PktBuf A0] ", |
| 799 | "[ HeadBuf DD] [bi->dma ] [bi->skb ] ", |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 800 | "<-- Adv Rx Read format\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 801 | pr_info("%s%s%s", |
| 802 | "RWB[desc] [PcsmIpSHl PtRs] ", |
| 803 | "[vl er S cks ln] ---------------- [bi->skb ] ", |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 804 | "<-- Adv Rx Write-Back format\n"); |
| 805 | |
| 806 | for (i = 0; i < rx_ring->count; i++) { |
| 807 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 808 | rx_desc = IXGBE_RX_DESC(rx_ring, i); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 809 | u0 = (struct my_u0 *)rx_desc; |
| 810 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 811 | if (staterr & IXGBE_RXD_STAT_DD) { |
| 812 | /* Descriptor Done */ |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 813 | pr_info("RWB[0x%03X] %016llX " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 814 | "%016llX ---------------- %p", i, |
| 815 | le64_to_cpu(u0->a), |
| 816 | le64_to_cpu(u0->b), |
| 817 | rx_buffer_info->skb); |
| 818 | } else { |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 819 | pr_info("R [0x%03X] %016llX " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 820 | "%016llX %016llX %p", i, |
| 821 | le64_to_cpu(u0->a), |
| 822 | le64_to_cpu(u0->b), |
| 823 | (u64)rx_buffer_info->dma, |
| 824 | rx_buffer_info->skb); |
| 825 | |
Emil Tantilov | 9c50c03 | 2012-07-26 01:21:24 +0000 | [diff] [blame] | 826 | if (netif_msg_pktdata(adapter) && |
| 827 | rx_buffer_info->dma) { |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 828 | print_hex_dump(KERN_INFO, "", |
| 829 | DUMP_PREFIX_ADDRESS, 16, 1, |
Emil Tantilov | 9c50c03 | 2012-07-26 01:21:24 +0000 | [diff] [blame] | 830 | page_address(rx_buffer_info->page) + |
| 831 | rx_buffer_info->page_offset, |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 832 | ixgbe_rx_bufsz(rx_ring), true); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 833 | } |
| 834 | } |
| 835 | |
| 836 | if (i == rx_ring->next_to_use) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 837 | pr_cont(" NTU\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 838 | else if (i == rx_ring->next_to_clean) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 839 | pr_cont(" NTC\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 840 | else |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 841 | pr_cont("\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 842 | |
| 843 | } |
| 844 | } |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 845 | } |
| 846 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 847 | static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter) |
| 848 | { |
| 849 | u32 ctrl_ext; |
| 850 | |
| 851 | /* Let firmware take over control of h/w */ |
| 852 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 853 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 854 | ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter) |
| 858 | { |
| 859 | u32 ctrl_ext; |
| 860 | |
| 861 | /* Let firmware know the driver has taken over */ |
| 862 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 863 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 864 | ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 865 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 866 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 867 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 868 | * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors |
| 869 | * @adapter: pointer to adapter struct |
| 870 | * @direction: 0 for Rx, 1 for Tx, -1 for other causes |
| 871 | * @queue: queue to map the corresponding interrupt to |
| 872 | * @msix_vector: the vector to map to the corresponding queue |
| 873 | * |
| 874 | */ |
| 875 | static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 876 | u8 queue, u8 msix_vector) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 877 | { |
| 878 | u32 ivar, index; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 879 | struct ixgbe_hw *hw = &adapter->hw; |
| 880 | switch (hw->mac.type) { |
| 881 | case ixgbe_mac_82598EB: |
| 882 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 883 | if (direction == -1) |
| 884 | direction = 0; |
| 885 | index = (((direction * 64) + queue) >> 2) & 0x1F; |
| 886 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index)); |
| 887 | ivar &= ~(0xFF << (8 * (queue & 0x3))); |
| 888 | ivar |= (msix_vector << (8 * (queue & 0x3))); |
| 889 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar); |
| 890 | break; |
| 891 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 892 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 893 | case ixgbe_mac_X550: |
| 894 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 895 | case ixgbe_mac_x550em_a: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 896 | if (direction == -1) { |
| 897 | /* other causes */ |
| 898 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 899 | index = ((queue & 1) * 8); |
| 900 | ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC); |
| 901 | ivar &= ~(0xFF << index); |
| 902 | ivar |= (msix_vector << index); |
| 903 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar); |
| 904 | break; |
| 905 | } else { |
| 906 | /* tx or rx causes */ |
| 907 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 908 | index = ((16 * (queue & 1)) + (8 * direction)); |
| 909 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1)); |
| 910 | ivar &= ~(0xFF << index); |
| 911 | ivar |= (msix_vector << index); |
| 912 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar); |
| 913 | break; |
| 914 | } |
| 915 | default: |
| 916 | break; |
| 917 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 918 | } |
| 919 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 920 | static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 921 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 922 | { |
| 923 | u32 mask; |
| 924 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 925 | switch (adapter->hw.mac.type) { |
| 926 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 927 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 928 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 929 | break; |
| 930 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 931 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 932 | case ixgbe_mac_X550: |
| 933 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 934 | case ixgbe_mac_x550em_a: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 935 | mask = (qmask & 0xFFFFFFFF); |
| 936 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask); |
| 937 | mask = (qmask >> 32); |
| 938 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 939 | break; |
| 940 | default: |
| 941 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 942 | } |
| 943 | } |
| 944 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 945 | void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *ring, |
| 946 | struct ixgbe_tx_buffer *tx_buffer) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 947 | { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 948 | if (tx_buffer->skb) { |
| 949 | dev_kfree_skb_any(tx_buffer->skb); |
| 950 | if (dma_unmap_len(tx_buffer, len)) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 951 | dma_unmap_single(ring->dev, |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 952 | dma_unmap_addr(tx_buffer, dma), |
| 953 | dma_unmap_len(tx_buffer, len), |
| 954 | DMA_TO_DEVICE); |
| 955 | } else if (dma_unmap_len(tx_buffer, len)) { |
| 956 | dma_unmap_page(ring->dev, |
| 957 | dma_unmap_addr(tx_buffer, dma), |
| 958 | dma_unmap_len(tx_buffer, len), |
| 959 | DMA_TO_DEVICE); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 960 | } |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 961 | tx_buffer->next_to_watch = NULL; |
| 962 | tx_buffer->skb = NULL; |
| 963 | dma_unmap_len_set(tx_buffer, len, 0); |
| 964 | /* tx_buffer must be completely set up in the transmit path */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 965 | } |
| 966 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 967 | static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter) |
| 968 | { |
| 969 | struct ixgbe_hw *hw = &adapter->hw; |
| 970 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
| 971 | int i; |
| 972 | u32 data; |
| 973 | |
| 974 | if ((hw->fc.current_mode != ixgbe_fc_full) && |
| 975 | (hw->fc.current_mode != ixgbe_fc_rx_pause)) |
| 976 | return; |
| 977 | |
| 978 | switch (hw->mac.type) { |
| 979 | case ixgbe_mac_82598EB: |
| 980 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); |
| 981 | break; |
| 982 | default: |
| 983 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); |
| 984 | } |
| 985 | hwstats->lxoffrxc += data; |
| 986 | |
| 987 | /* refill credits (no tx hang) if we received xoff */ |
| 988 | if (!data) |
| 989 | return; |
| 990 | |
| 991 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 992 | clear_bit(__IXGBE_HANG_CHECK_ARMED, |
| 993 | &adapter->tx_ring[i]->state); |
| 994 | } |
| 995 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 996 | static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 997 | { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 998 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 999 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1000 | u32 xoff[8] = {0}; |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 1001 | u8 tc; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1002 | int i; |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 1003 | bool pfc_en = adapter->dcb_cfg.pfc_mode_enable; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1004 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 1005 | if (adapter->ixgbe_ieee_pfc) |
| 1006 | pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1007 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 1008 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) { |
| 1009 | ixgbe_update_xoff_rx_lfc(adapter); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1010 | return; |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 1011 | } |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1012 | |
| 1013 | /* update stats for each tc, only valid with PFC enabled */ |
| 1014 | for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) { |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 1015 | u32 pxoffrxc; |
| 1016 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1017 | switch (hw->mac.type) { |
| 1018 | case ixgbe_mac_82598EB: |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 1019 | pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i)); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1020 | break; |
| 1021 | default: |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 1022 | pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i)); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1023 | } |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 1024 | hwstats->pxoffrxc[i] += pxoffrxc; |
| 1025 | /* Get the TC for given UP */ |
| 1026 | tc = netdev_get_prio_tc_map(adapter->netdev, i); |
| 1027 | xoff[tc] += pxoffrxc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1028 | } |
| 1029 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1030 | /* disarm tx queues that have received xoff frames */ |
| 1031 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 1032 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1033 | |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 1034 | tc = tx_ring->dcb_tc; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1035 | if (xoff[tc]) |
| 1036 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring) |
| 1041 | { |
Alexander Duyck | 7d7ce68 | 2012-02-08 07:50:51 +0000 | [diff] [blame] | 1042 | return ring->stats.packets; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1043 | } |
| 1044 | |
| 1045 | static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring) |
| 1046 | { |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 1047 | struct ixgbe_adapter *adapter; |
| 1048 | struct ixgbe_hw *hw; |
| 1049 | u32 head, tail; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1050 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 1051 | if (ring->l2_accel_priv) |
| 1052 | adapter = ring->l2_accel_priv->real_adapter; |
| 1053 | else |
| 1054 | adapter = netdev_priv(ring->netdev); |
| 1055 | |
| 1056 | hw = &adapter->hw; |
| 1057 | head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx)); |
| 1058 | tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx)); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1059 | |
| 1060 | if (head != tail) |
| 1061 | return (head < tail) ? |
| 1062 | tail - head : (tail + ring->count - head); |
| 1063 | |
| 1064 | return 0; |
| 1065 | } |
| 1066 | |
| 1067 | static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring) |
| 1068 | { |
| 1069 | u32 tx_done = ixgbe_get_tx_completed(tx_ring); |
| 1070 | u32 tx_done_old = tx_ring->tx_stats.tx_done_old; |
| 1071 | u32 tx_pending = ixgbe_get_tx_pending(tx_ring); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1072 | |
| 1073 | clear_check_for_tx_hang(tx_ring); |
| 1074 | |
| 1075 | /* |
| 1076 | * Check for a hung queue, but be thorough. This verifies |
| 1077 | * that a transmit has been completed since the previous |
| 1078 | * check AND there is at least one packet pending. The |
| 1079 | * ARMED bit is set to indicate a potential hang. The |
| 1080 | * bit is cleared if a pause frame is received to remove |
| 1081 | * false hang detection due to PFC or 802.3x frames. By |
| 1082 | * requiring this to fail twice we avoid races with |
| 1083 | * pfc clearing the ARMED bit and conditions where we |
| 1084 | * run the check_tx_hang logic with a transmit completion |
| 1085 | * pending but without time to complete it yet. |
| 1086 | */ |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 1087 | if (tx_done_old == tx_done && tx_pending) |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1088 | /* make sure it is true for two checks in a row */ |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 1089 | return test_and_set_bit(__IXGBE_HANG_CHECK_ARMED, |
| 1090 | &tx_ring->state); |
| 1091 | /* update completed stats and continue */ |
| 1092 | tx_ring->tx_stats.tx_done_old = tx_done; |
| 1093 | /* reset the countdown */ |
| 1094 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1095 | |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 1096 | return false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1097 | } |
| 1098 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 1099 | /** |
| 1100 | * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout |
| 1101 | * @adapter: driver private struct |
| 1102 | **/ |
| 1103 | static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter) |
| 1104 | { |
| 1105 | |
| 1106 | /* Do the reset outside of interrupt context */ |
| 1107 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
Emil Tantilov | 57ca2a4 | 2016-07-29 14:46:31 -0700 | [diff] [blame] | 1108 | set_bit(__IXGBE_RESET_REQUESTED, &adapter->state); |
Jacob Keller | 12ff3f3 | 2012-12-01 07:57:17 +0000 | [diff] [blame] | 1109 | e_warn(drv, "initiating reset due to tx timeout\n"); |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 1110 | ixgbe_service_event_schedule(adapter); |
| 1111 | } |
| 1112 | } |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1113 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1114 | /** |
Rostislav Pehlivanov | c04f90e | 2016-01-27 18:33:30 +0000 | [diff] [blame] | 1115 | * ixgbe_tx_maxrate - callback to set the maximum per-queue bitrate |
| 1116 | **/ |
| 1117 | static int ixgbe_tx_maxrate(struct net_device *netdev, |
| 1118 | int queue_index, u32 maxrate) |
| 1119 | { |
| 1120 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1121 | struct ixgbe_hw *hw = &adapter->hw; |
| 1122 | u32 bcnrc_val = ixgbe_link_mbps(adapter); |
| 1123 | |
| 1124 | if (!maxrate) |
| 1125 | return 0; |
| 1126 | |
| 1127 | /* Calculate the rate factor values to set */ |
| 1128 | bcnrc_val <<= IXGBE_RTTBCNRC_RF_INT_SHIFT; |
| 1129 | bcnrc_val /= maxrate; |
| 1130 | |
| 1131 | /* clear everything but the rate factor */ |
| 1132 | bcnrc_val &= IXGBE_RTTBCNRC_RF_INT_MASK | |
| 1133 | IXGBE_RTTBCNRC_RF_DEC_MASK; |
| 1134 | |
| 1135 | /* enable the rate scheduler */ |
| 1136 | bcnrc_val |= IXGBE_RTTBCNRC_RS_ENA; |
| 1137 | |
| 1138 | IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, queue_index); |
| 1139 | IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val); |
| 1140 | |
| 1141 | return 0; |
| 1142 | } |
| 1143 | |
| 1144 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1145 | * ixgbe_clean_tx_irq - Reclaim resources after transmit completes |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1146 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1147 | * @tx_ring: tx ring to clean |
Alexander Duyck | 8220bbc | 2016-03-07 09:30:09 -0800 | [diff] [blame] | 1148 | * @napi_budget: Used to determine if we are in netpoll |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1149 | **/ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1150 | static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector, |
Jesper Dangaard Brouer | a3a8749 | 2016-02-08 13:15:09 +0100 | [diff] [blame] | 1151 | struct ixgbe_ring *tx_ring, int napi_budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1152 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1153 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1154 | struct ixgbe_tx_buffer *tx_buffer; |
| 1155 | union ixgbe_adv_tx_desc *tx_desc; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1156 | unsigned int total_bytes = 0, total_packets = 0; |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 1157 | unsigned int budget = q_vector->tx.work_limit; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1158 | unsigned int i = tx_ring->next_to_clean; |
| 1159 | |
| 1160 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1161 | return true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1162 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1163 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1164 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1165 | i -= tx_ring->count; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 1166 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1167 | do { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1168 | union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1169 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1170 | /* if next_to_watch is not set then there is no work pending */ |
| 1171 | if (!eop_desc) |
| 1172 | break; |
| 1173 | |
Alexander Duyck | 7f83a9e | 2012-02-08 07:49:23 +0000 | [diff] [blame] | 1174 | /* prevent any other reads prior to eop_desc */ |
Alexander Duyck | 7e63bf4 | 2013-01-08 07:00:58 +0000 | [diff] [blame] | 1175 | read_barrier_depends(); |
Alexander Duyck | 7f83a9e | 2012-02-08 07:49:23 +0000 | [diff] [blame] | 1176 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1177 | /* if DD is not set pending work has not been completed */ |
| 1178 | if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD))) |
| 1179 | break; |
| 1180 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1181 | /* clear next_to_watch to prevent false hangs */ |
| 1182 | tx_buffer->next_to_watch = NULL; |
| 1183 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 1184 | /* update the statistics for this packet */ |
| 1185 | total_bytes += tx_buffer->bytecount; |
| 1186 | total_packets += tx_buffer->gso_segs; |
| 1187 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1188 | /* free the skb */ |
Jesper Dangaard Brouer | a3a8749 | 2016-02-08 13:15:09 +0100 | [diff] [blame] | 1189 | napi_consume_skb(tx_buffer->skb, napi_budget); |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1190 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1191 | /* unmap skb header data */ |
| 1192 | dma_unmap_single(tx_ring->dev, |
| 1193 | dma_unmap_addr(tx_buffer, dma), |
| 1194 | dma_unmap_len(tx_buffer, len), |
| 1195 | DMA_TO_DEVICE); |
| 1196 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1197 | /* clear tx_buffer data */ |
| 1198 | tx_buffer->skb = NULL; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1199 | dma_unmap_len_set(tx_buffer, len, 0); |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1200 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1201 | /* unmap remaining buffers */ |
| 1202 | while (tx_desc != eop_desc) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1203 | tx_buffer++; |
| 1204 | tx_desc++; |
| 1205 | i++; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1206 | if (unlikely(!i)) { |
| 1207 | i -= tx_ring->count; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1208 | tx_buffer = tx_ring->tx_buffer_info; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1209 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1210 | } |
| 1211 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1212 | /* unmap any remaining paged data */ |
| 1213 | if (dma_unmap_len(tx_buffer, len)) { |
| 1214 | dma_unmap_page(tx_ring->dev, |
| 1215 | dma_unmap_addr(tx_buffer, dma), |
| 1216 | dma_unmap_len(tx_buffer, len), |
| 1217 | DMA_TO_DEVICE); |
| 1218 | dma_unmap_len_set(tx_buffer, len, 0); |
| 1219 | } |
| 1220 | } |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 1221 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1222 | /* move us one more past the eop_desc for start of next pkt */ |
| 1223 | tx_buffer++; |
| 1224 | tx_desc++; |
| 1225 | i++; |
| 1226 | if (unlikely(!i)) { |
| 1227 | i -= tx_ring->count; |
| 1228 | tx_buffer = tx_ring->tx_buffer_info; |
| 1229 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
| 1230 | } |
| 1231 | |
| 1232 | /* issue prefetch for next Tx descriptor */ |
| 1233 | prefetch(tx_desc); |
| 1234 | |
| 1235 | /* update budget accounting */ |
| 1236 | budget--; |
| 1237 | } while (likely(budget)); |
| 1238 | |
| 1239 | i += tx_ring->count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1240 | tx_ring->next_to_clean = i; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1241 | u64_stats_update_begin(&tx_ring->syncp); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1242 | tx_ring->stats.bytes += total_bytes; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1243 | tx_ring->stats.packets += total_packets; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1244 | u64_stats_update_end(&tx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1245 | q_vector->tx.total_bytes += total_bytes; |
| 1246 | q_vector->tx.total_packets += total_packets; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1247 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1248 | 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] | 1249 | /* schedule immediate reset if we believe we hung */ |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1250 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1251 | e_err(drv, "Detected Tx Unit Hang\n" |
| 1252 | " Tx Queue <%d>\n" |
| 1253 | " TDH, TDT <%x>, <%x>\n" |
| 1254 | " next_to_use <%x>\n" |
| 1255 | " next_to_clean <%x>\n" |
| 1256 | "tx_buffer_info[next_to_clean]\n" |
| 1257 | " time_stamp <%lx>\n" |
| 1258 | " jiffies <%lx>\n", |
| 1259 | tx_ring->queue_index, |
| 1260 | IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)), |
| 1261 | IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)), |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1262 | tx_ring->next_to_use, i, |
| 1263 | tx_ring->tx_buffer_info[i].time_stamp, jiffies); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1264 | |
| 1265 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 1266 | |
| 1267 | e_info(probe, |
| 1268 | "tx hang %d detected on queue %d, resetting adapter\n", |
| 1269 | adapter->tx_timeout_count + 1, tx_ring->queue_index); |
| 1270 | |
| 1271 | /* schedule immediate reset if we believe we hung */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 1272 | ixgbe_tx_timeout_reset(adapter); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1273 | |
| 1274 | /* the adapter is about to reset, no point in enabling stuff */ |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 1275 | return true; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1276 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1277 | |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 1278 | netdev_tx_completed_queue(txring_txq(tx_ring), |
| 1279 | total_packets, total_bytes); |
| 1280 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 1281 | #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) |
Alexander Duyck | 30065e6 | 2011-07-15 03:05:14 +0000 | [diff] [blame] | 1282 | if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) && |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 1283 | (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 1284 | /* Make sure that anybody stopping the queue after this |
| 1285 | * sees the new next_to_clean. |
| 1286 | */ |
| 1287 | smp_mb(); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1288 | if (__netif_subqueue_stopped(tx_ring->netdev, |
| 1289 | tx_ring->queue_index) |
| 1290 | && !test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1291 | netif_wake_subqueue(tx_ring->netdev, |
| 1292 | tx_ring->queue_index); |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 1293 | ++tx_ring->tx_stats.restart_queue; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 1294 | } |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 1295 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1296 | |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 1297 | return !!budget; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1298 | } |
| 1299 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1300 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1301 | static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter, |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1302 | struct ixgbe_ring *tx_ring, |
| 1303 | int cpu) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1304 | { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 1305 | struct ixgbe_hw *hw = &adapter->hw; |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1306 | u32 txctrl = 0; |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1307 | u16 reg_offset; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1308 | |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1309 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1310 | txctrl = dca3_get_tag(tx_ring->dev, cpu); |
| 1311 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1312 | switch (hw->mac.type) { |
| 1313 | case ixgbe_mac_82598EB: |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1314 | reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1315 | break; |
| 1316 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1317 | case ixgbe_mac_X540: |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1318 | reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx); |
| 1319 | txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599; |
| 1320 | break; |
| 1321 | default: |
| 1322 | /* for unknown hardware do not write register */ |
| 1323 | return; |
| 1324 | } |
| 1325 | |
| 1326 | /* |
| 1327 | * We can enable relaxed ordering for reads, but not writes when |
| 1328 | * DCA is enabled. This is due to a known issue in some chipsets |
| 1329 | * which will cause the DCA tag to be cleared. |
| 1330 | */ |
| 1331 | txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN | |
| 1332 | IXGBE_DCA_TXCTRL_DATA_RRO_EN | |
| 1333 | IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
| 1334 | |
| 1335 | IXGBE_WRITE_REG(hw, reg_offset, txctrl); |
| 1336 | } |
| 1337 | |
| 1338 | static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter, |
| 1339 | struct ixgbe_ring *rx_ring, |
| 1340 | int cpu) |
| 1341 | { |
| 1342 | struct ixgbe_hw *hw = &adapter->hw; |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1343 | u32 rxctrl = 0; |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1344 | u8 reg_idx = rx_ring->reg_idx; |
| 1345 | |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1346 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1347 | rxctrl = dca3_get_tag(rx_ring->dev, cpu); |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1348 | |
| 1349 | switch (hw->mac.type) { |
| 1350 | case ixgbe_mac_82599EB: |
| 1351 | case ixgbe_mac_X540: |
| 1352 | rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1353 | break; |
| 1354 | default: |
| 1355 | break; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1356 | } |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1357 | |
| 1358 | /* |
| 1359 | * We can enable relaxed ordering for reads, but not writes when |
| 1360 | * DCA is enabled. This is due to a known issue in some chipsets |
| 1361 | * which will cause the DCA tag to be cleared. |
| 1362 | */ |
| 1363 | rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN | |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1364 | IXGBE_DCA_RXCTRL_DATA_DCA_EN | |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1365 | IXGBE_DCA_RXCTRL_DESC_DCA_EN; |
| 1366 | |
| 1367 | IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1368 | } |
| 1369 | |
| 1370 | static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector) |
| 1371 | { |
| 1372 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1373 | struct ixgbe_ring *ring; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1374 | int cpu = get_cpu(); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1375 | |
| 1376 | if (q_vector->cpu == cpu) |
| 1377 | goto out_no_update; |
| 1378 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 1379 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1380 | ixgbe_update_tx_dca(adapter, ring, cpu); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1381 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 1382 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1383 | ixgbe_update_rx_dca(adapter, ring, cpu); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1384 | |
| 1385 | q_vector->cpu = cpu; |
| 1386 | out_no_update: |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1387 | put_cpu(); |
| 1388 | } |
| 1389 | |
| 1390 | static void ixgbe_setup_dca(struct ixgbe_adapter *adapter) |
| 1391 | { |
| 1392 | int i; |
| 1393 | |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 1394 | /* always use CB2 mode, difference is masked in the CB driver */ |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1395 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1396 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 1397 | IXGBE_DCA_CTRL_DCA_MODE_CB2); |
| 1398 | else |
| 1399 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 1400 | IXGBE_DCA_CTRL_DCA_DISABLE); |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 1401 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 1402 | for (i = 0; i < adapter->num_q_vectors; i++) { |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1403 | adapter->q_vector[i]->cpu = -1; |
| 1404 | ixgbe_update_dca(adapter->q_vector[i]); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1405 | } |
| 1406 | } |
| 1407 | |
| 1408 | static int __ixgbe_notify_dca(struct device *dev, void *data) |
| 1409 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 1410 | struct ixgbe_adapter *adapter = dev_get_drvdata(dev); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1411 | unsigned long event = *(unsigned long *)data; |
| 1412 | |
Don Skidmore | 2a72c31 | 2011-07-20 02:27:05 +0000 | [diff] [blame] | 1413 | if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE)) |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1414 | return 0; |
| 1415 | |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1416 | switch (event) { |
| 1417 | case DCA_PROVIDER_ADD: |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 1418 | /* if we're already enabled, don't do it again */ |
| 1419 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1420 | break; |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 1421 | if (dca_add_requester(dev) == 0) { |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 1422 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1423 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 1424 | IXGBE_DCA_CTRL_DCA_MODE_CB2); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1425 | break; |
| 1426 | } |
| 1427 | /* Fall Through since DCA is disabled. */ |
| 1428 | case DCA_PROVIDER_REMOVE: |
| 1429 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 1430 | dca_remove_requester(dev); |
| 1431 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1432 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 1433 | IXGBE_DCA_CTRL_DCA_DISABLE); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1434 | } |
| 1435 | break; |
| 1436 | } |
| 1437 | |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 1438 | return 0; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1439 | } |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1440 | |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1441 | #endif /* CONFIG_IXGBE_DCA */ |
Fan Du | 7edda4b | 2015-04-29 10:57:39 +0800 | [diff] [blame] | 1442 | |
| 1443 | #define IXGBE_RSS_L4_TYPES_MASK \ |
| 1444 | ((1ul << IXGBE_RXDADV_RSSTYPE_IPV4_TCP) | \ |
| 1445 | (1ul << IXGBE_RXDADV_RSSTYPE_IPV4_UDP) | \ |
| 1446 | (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_TCP) | \ |
| 1447 | (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_UDP)) |
| 1448 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1449 | static inline void ixgbe_rx_hash(struct ixgbe_ring *ring, |
| 1450 | union ixgbe_adv_rx_desc *rx_desc, |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1451 | struct sk_buff *skb) |
| 1452 | { |
Fan Du | 7edda4b | 2015-04-29 10:57:39 +0800 | [diff] [blame] | 1453 | u16 rss_type; |
| 1454 | |
| 1455 | if (!(ring->netdev->features & NETIF_F_RXHASH)) |
| 1456 | return; |
| 1457 | |
| 1458 | rss_type = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) & |
| 1459 | IXGBE_RXDADV_RSSTYPE_MASK; |
| 1460 | |
| 1461 | if (!rss_type) |
| 1462 | return; |
| 1463 | |
| 1464 | skb_set_hash(skb, le32_to_cpu(rx_desc->wb.lower.hi_dword.rss), |
| 1465 | (IXGBE_RSS_L4_TYPES_MASK & (1ul << rss_type)) ? |
| 1466 | PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3); |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1467 | } |
| 1468 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1469 | #ifdef IXGBE_FCOE |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1470 | /** |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1471 | * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1472 | * @ring: structure containing ring specific data |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1473 | * @rx_desc: advanced rx descriptor |
| 1474 | * |
| 1475 | * Returns : true if it is FCoE pkt |
| 1476 | */ |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1477 | static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring, |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1478 | union ixgbe_adv_rx_desc *rx_desc) |
| 1479 | { |
| 1480 | __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 1481 | |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1482 | return test_bit(__IXGBE_RX_FCOE, &ring->state) && |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1483 | ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) == |
| 1484 | (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE << |
| 1485 | IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT))); |
| 1486 | } |
| 1487 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1488 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1489 | /** |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1490 | * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1491 | * @ring: structure containing ring specific data |
| 1492 | * @rx_desc: current Rx descriptor being processed |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1493 | * @skb: skb currently being received and modified |
| 1494 | **/ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1495 | static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring, |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1496 | union ixgbe_adv_rx_desc *rx_desc, |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1497 | struct sk_buff *skb) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1498 | { |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1499 | __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1500 | bool encap_pkt = false; |
| 1501 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1502 | skb_checksum_none_assert(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1503 | |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 1504 | /* Rx csum disabled */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1505 | if (!(ring->netdev->features & NETIF_F_RXCSUM)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1506 | return; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1507 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 1508 | /* check for VXLAN and Geneve packets */ |
| 1509 | if (pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_VXLAN)) { |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1510 | encap_pkt = true; |
| 1511 | skb->encapsulation = 1; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1512 | } |
| 1513 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1514 | /* if IP and error */ |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1515 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) && |
| 1516 | ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1517 | ring->rx_stats.csum_err++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1518 | return; |
| 1519 | } |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1520 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1521 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS)) |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1522 | return; |
| 1523 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1524 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) { |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1525 | /* |
| 1526 | * 82599 errata, UDP frames with a 0 checksum can be marked as |
| 1527 | * checksum errors. |
| 1528 | */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1529 | if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) && |
| 1530 | test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state)) |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1531 | return; |
| 1532 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1533 | ring->rx_stats.csum_err++; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1534 | return; |
| 1535 | } |
| 1536 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1537 | /* It must be a TCP or UDP packet with a valid checksum */ |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1538 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1539 | if (encap_pkt) { |
| 1540 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_OUTERIPCS)) |
| 1541 | return; |
| 1542 | |
| 1543 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_OUTERIPER)) { |
Mark Rustad | d469251 | 2015-12-04 11:26:43 -0800 | [diff] [blame] | 1544 | skb->ip_summed = CHECKSUM_NONE; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1545 | return; |
| 1546 | } |
| 1547 | /* If we checked the outer header let the stack know */ |
| 1548 | skb->csum_level = 1; |
| 1549 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1550 | } |
| 1551 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1552 | static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring, |
| 1553 | struct ixgbe_rx_buffer *bi) |
| 1554 | { |
| 1555 | struct page *page = bi->page; |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1556 | dma_addr_t dma; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1557 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1558 | /* since we are recycling buffers we should seldom need to alloc */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1559 | if (likely(page)) |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1560 | return true; |
| 1561 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1562 | /* alloc new page for storage */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1563 | page = dev_alloc_pages(ixgbe_rx_pg_order(rx_ring)); |
| 1564 | if (unlikely(!page)) { |
| 1565 | rx_ring->rx_stats.alloc_rx_page_failed++; |
| 1566 | return false; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1567 | } |
| 1568 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1569 | /* map page for use */ |
| 1570 | dma = dma_map_page(rx_ring->dev, page, 0, |
| 1571 | ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1572 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1573 | /* |
| 1574 | * if mapping failed free memory back to system since |
| 1575 | * there isn't much point in holding memory we can't use |
| 1576 | */ |
| 1577 | if (dma_mapping_error(rx_ring->dev, dma)) { |
Alexander Duyck | dd411ec | 2012-04-06 04:24:50 +0000 | [diff] [blame] | 1578 | __free_pages(page, ixgbe_rx_pg_order(rx_ring)); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1579 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1580 | rx_ring->rx_stats.alloc_rx_page_failed++; |
| 1581 | return false; |
| 1582 | } |
| 1583 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1584 | bi->dma = dma; |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1585 | bi->page = page; |
Alexander Duyck | afaa945 | 2012-07-20 08:08:12 +0000 | [diff] [blame] | 1586 | bi->page_offset = 0; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1587 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1588 | return true; |
| 1589 | } |
| 1590 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1591 | /** |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1592 | * ixgbe_alloc_rx_buffers - Replace used receive buffers |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1593 | * @rx_ring: ring to place buffers on |
| 1594 | * @cleaned_count: number of buffers to replace |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1595 | **/ |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1596 | 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] | 1597 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1598 | union ixgbe_adv_rx_desc *rx_desc; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1599 | struct ixgbe_rx_buffer *bi; |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1600 | u16 i = rx_ring->next_to_use; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1601 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1602 | /* nothing to do */ |
| 1603 | if (!cleaned_count) |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1604 | return; |
| 1605 | |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1606 | rx_desc = IXGBE_RX_DESC(rx_ring, i); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1607 | bi = &rx_ring->rx_buffer_info[i]; |
| 1608 | i -= rx_ring->count; |
| 1609 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1610 | do { |
| 1611 | if (!ixgbe_alloc_mapped_page(rx_ring, bi)) |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1612 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1613 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1614 | /* |
| 1615 | * Refresh the desc even if buffer_addrs didn't change |
| 1616 | * because each write-back erases this info. |
| 1617 | */ |
| 1618 | 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] | 1619 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1620 | rx_desc++; |
| 1621 | bi++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1622 | i++; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1623 | if (unlikely(!i)) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1624 | rx_desc = IXGBE_RX_DESC(rx_ring, 0); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1625 | bi = rx_ring->rx_buffer_info; |
| 1626 | i -= rx_ring->count; |
| 1627 | } |
| 1628 | |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1629 | /* clear the status bits for the next_to_use descriptor */ |
| 1630 | rx_desc->wb.upper.status_error = 0; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1631 | |
| 1632 | cleaned_count--; |
| 1633 | } while (cleaned_count); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1634 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1635 | i += rx_ring->count; |
| 1636 | |
Alexander Duyck | ad435ec | 2014-11-14 00:56:35 +0000 | [diff] [blame] | 1637 | if (rx_ring->next_to_use != i) { |
| 1638 | rx_ring->next_to_use = i; |
| 1639 | |
| 1640 | /* update next to alloc since we have filled the ring */ |
| 1641 | rx_ring->next_to_alloc = i; |
| 1642 | |
| 1643 | /* Force memory writes to complete before letting h/w |
| 1644 | * know there are new descriptors to fetch. (Only |
| 1645 | * applicable for weak-ordered memory model archs, |
| 1646 | * such as IA-64). |
| 1647 | */ |
| 1648 | wmb(); |
| 1649 | writel(i, rx_ring->tail); |
| 1650 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1651 | } |
| 1652 | |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1653 | static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring, |
| 1654 | struct sk_buff *skb) |
| 1655 | { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1656 | u16 hdr_len = skb_headlen(skb); |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1657 | |
| 1658 | /* set gso_size to avoid messing up TCP MSS */ |
| 1659 | skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len), |
| 1660 | IXGBE_CB(skb)->append_cnt); |
Alexander Duyck | 96be80a | 2013-02-12 09:45:44 +0000 | [diff] [blame] | 1661 | skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4; |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1662 | } |
| 1663 | |
| 1664 | static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring, |
| 1665 | struct sk_buff *skb) |
| 1666 | { |
| 1667 | /* if append_cnt is 0 then frame is not RSC */ |
| 1668 | if (!IXGBE_CB(skb)->append_cnt) |
| 1669 | return; |
| 1670 | |
| 1671 | rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt; |
| 1672 | rx_ring->rx_stats.rsc_flush++; |
| 1673 | |
| 1674 | ixgbe_set_rsc_gso_size(rx_ring, skb); |
| 1675 | |
| 1676 | /* gso_size is computed using append_cnt so always clear it last */ |
| 1677 | IXGBE_CB(skb)->append_cnt = 0; |
| 1678 | } |
| 1679 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1680 | /** |
| 1681 | * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor |
| 1682 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1683 | * @rx_desc: pointer to the EOP Rx descriptor |
| 1684 | * @skb: pointer to current skb being populated |
| 1685 | * |
| 1686 | * This function checks the ring, descriptor, and packet information in |
| 1687 | * order to populate the hash, checksum, VLAN, timestamp, protocol, and |
| 1688 | * other fields within the skb. |
| 1689 | **/ |
| 1690 | static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring, |
| 1691 | union ixgbe_adv_rx_desc *rx_desc, |
| 1692 | struct sk_buff *skb) |
| 1693 | { |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1694 | struct net_device *dev = rx_ring->netdev; |
Mark Rustad | a9763f3 | 2015-10-27 09:58:07 -0700 | [diff] [blame] | 1695 | u32 flags = rx_ring->q_vector->adapter->flags; |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1696 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1697 | ixgbe_update_rsc_stats(rx_ring, skb); |
| 1698 | |
| 1699 | ixgbe_rx_hash(rx_ring, rx_desc, skb); |
| 1700 | |
| 1701 | ixgbe_rx_checksum(rx_ring, rx_desc, skb); |
| 1702 | |
Mark Rustad | a9763f3 | 2015-10-27 09:58:07 -0700 | [diff] [blame] | 1703 | if (unlikely(flags & IXGBE_FLAG_RX_HWTSTAMP_ENABLED)) |
| 1704 | ixgbe_ptp_rx_hwtstamp(rx_ring, rx_desc, skb); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 1705 | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 1706 | if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) && |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1707 | ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1708 | u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan); |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 1709 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid); |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1710 | } |
| 1711 | |
| 1712 | skb_record_rx_queue(skb, rx_ring->queue_index); |
| 1713 | |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1714 | skb->protocol = eth_type_trans(skb, dev); |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector, |
| 1718 | struct sk_buff *skb) |
| 1719 | { |
Eric Dumazet | 93f93a4 | 2015-11-18 06:30:59 -0800 | [diff] [blame] | 1720 | skb_mark_napi_id(skb, &q_vector->napi); |
Jacob Keller | b464003 | 2013-10-01 04:33:54 -0700 | [diff] [blame] | 1721 | if (ixgbe_qv_busy_polling(q_vector)) |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 1722 | netif_receive_skb(skb); |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1723 | else |
Alexander Duyck | 856f606 | 2015-02-25 17:45:54 +0000 | [diff] [blame] | 1724 | napi_gro_receive(&q_vector->napi, skb); |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1725 | } |
Mallikarjuna R Chilakala | 43634e8 | 2010-02-25 23:14:37 +0000 | [diff] [blame] | 1726 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1727 | /** |
| 1728 | * ixgbe_is_non_eop - process handling of non-EOP buffers |
| 1729 | * @rx_ring: Rx ring being processed |
| 1730 | * @rx_desc: Rx descriptor for current buffer |
| 1731 | * @skb: Current socket buffer containing buffer in progress |
| 1732 | * |
| 1733 | * This function updates next to clean. If the buffer is an EOP buffer |
| 1734 | * this function exits returning false, otherwise it will place the |
| 1735 | * sk_buff in the next buffer to be chained and return true indicating |
| 1736 | * that this is in fact a non-EOP buffer. |
| 1737 | **/ |
| 1738 | static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring, |
| 1739 | union ixgbe_adv_rx_desc *rx_desc, |
| 1740 | struct sk_buff *skb) |
| 1741 | { |
| 1742 | u32 ntc = rx_ring->next_to_clean + 1; |
| 1743 | |
| 1744 | /* fetch, update, and store next to clean */ |
| 1745 | ntc = (ntc < rx_ring->count) ? ntc : 0; |
| 1746 | rx_ring->next_to_clean = ntc; |
| 1747 | |
| 1748 | prefetch(IXGBE_RX_DESC(rx_ring, ntc)); |
| 1749 | |
Alexander Duyck | 5a02cbd | 2012-07-20 08:08:51 +0000 | [diff] [blame] | 1750 | /* update RSC append count if present */ |
| 1751 | if (ring_is_rsc_enabled(rx_ring)) { |
| 1752 | __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data & |
| 1753 | cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK); |
| 1754 | |
| 1755 | if (unlikely(rsc_enabled)) { |
| 1756 | u32 rsc_cnt = le32_to_cpu(rsc_enabled); |
| 1757 | |
| 1758 | rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT; |
| 1759 | IXGBE_CB(skb)->append_cnt += rsc_cnt - 1; |
| 1760 | |
| 1761 | /* update ntc based on RSC value */ |
| 1762 | ntc = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 1763 | ntc &= IXGBE_RXDADV_NEXTP_MASK; |
| 1764 | ntc >>= IXGBE_RXDADV_NEXTP_SHIFT; |
| 1765 | } |
| 1766 | } |
| 1767 | |
| 1768 | /* 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] | 1769 | if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))) |
| 1770 | return false; |
| 1771 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1772 | /* place skb in next buffer to be received */ |
| 1773 | rx_ring->rx_buffer_info[ntc].skb = skb; |
| 1774 | rx_ring->rx_stats.non_eop_descs++; |
| 1775 | |
| 1776 | return true; |
| 1777 | } |
| 1778 | |
| 1779 | /** |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1780 | * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail |
| 1781 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1782 | * @skb: pointer to current skb being adjusted |
| 1783 | * |
| 1784 | * This function is an ixgbe specific version of __pskb_pull_tail. The |
| 1785 | * main difference between this version and the original function is that |
| 1786 | * this function can make several assumptions about the state of things |
| 1787 | * that allow for significant optimizations versus the standard function. |
| 1788 | * As a result we can do things like drop a frag and maintain an accurate |
| 1789 | * truesize for the skb. |
| 1790 | */ |
| 1791 | static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring, |
| 1792 | struct sk_buff *skb) |
| 1793 | { |
| 1794 | struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0]; |
| 1795 | unsigned char *va; |
| 1796 | unsigned int pull_len; |
| 1797 | |
| 1798 | /* |
| 1799 | * it is valid to use page_address instead of kmap since we are |
| 1800 | * working with pages allocated out of the lomem pool per |
| 1801 | * alloc_page(GFP_ATOMIC) |
| 1802 | */ |
| 1803 | va = skb_frag_address(frag); |
| 1804 | |
| 1805 | /* |
| 1806 | * we need the header to contain the greater of either ETH_HLEN or |
| 1807 | * 60 bytes if the skb->len is less than 60 for skb_pad. |
| 1808 | */ |
Alexander Duyck | 8496e33 | 2014-09-05 19:22:18 -0400 | [diff] [blame] | 1809 | pull_len = eth_get_headlen(va, IXGBE_RX_HDR_SIZE); |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1810 | |
| 1811 | /* align pull length to size of long to optimize memcpy performance */ |
| 1812 | skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long))); |
| 1813 | |
| 1814 | /* update all of the pointers */ |
| 1815 | skb_frag_size_sub(frag, pull_len); |
| 1816 | frag->page_offset += pull_len; |
| 1817 | skb->data_len -= pull_len; |
| 1818 | skb->tail += pull_len; |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1819 | } |
| 1820 | |
| 1821 | /** |
Alexander Duyck | 42073d9 | 2012-07-20 08:08:28 +0000 | [diff] [blame] | 1822 | * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB |
| 1823 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1824 | * @skb: pointer to current skb being updated |
| 1825 | * |
| 1826 | * This function provides a basic DMA sync up for the first fragment of an |
| 1827 | * skb. The reason for doing this is that the first fragment cannot be |
| 1828 | * unmapped until we have reached the end of packet descriptor for a buffer |
| 1829 | * chain. |
| 1830 | */ |
| 1831 | static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring, |
| 1832 | struct sk_buff *skb) |
| 1833 | { |
| 1834 | /* if the page was released unmap it, else just sync our portion */ |
| 1835 | if (unlikely(IXGBE_CB(skb)->page_released)) { |
| 1836 | dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma, |
| 1837 | ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE); |
| 1838 | IXGBE_CB(skb)->page_released = false; |
| 1839 | } else { |
| 1840 | struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0]; |
| 1841 | |
| 1842 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 1843 | IXGBE_CB(skb)->dma, |
| 1844 | frag->page_offset, |
| 1845 | ixgbe_rx_bufsz(rx_ring), |
| 1846 | DMA_FROM_DEVICE); |
| 1847 | } |
| 1848 | IXGBE_CB(skb)->dma = 0; |
| 1849 | } |
| 1850 | |
| 1851 | /** |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1852 | * ixgbe_cleanup_headers - Correct corrupted or empty headers |
| 1853 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1854 | * @rx_desc: pointer to the EOP Rx descriptor |
| 1855 | * @skb: pointer to current skb being fixed |
| 1856 | * |
| 1857 | * Check for corrupted packet headers caused by senders on the local L2 |
| 1858 | * embedded NIC switch not setting up their Tx Descriptors right. These |
| 1859 | * should be very rare. |
| 1860 | * |
| 1861 | * Also address the case where we are pulling data in on pages only |
| 1862 | * and as such no data is present in the skb header. |
| 1863 | * |
| 1864 | * In addition if skb is not at least 60 bytes we need to pad it so that |
| 1865 | * it is large enough to qualify as a valid Ethernet frame. |
| 1866 | * |
| 1867 | * Returns true if an error was encountered and skb was freed. |
| 1868 | **/ |
| 1869 | static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring, |
| 1870 | union ixgbe_adv_rx_desc *rx_desc, |
| 1871 | struct sk_buff *skb) |
| 1872 | { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1873 | struct net_device *netdev = rx_ring->netdev; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1874 | |
| 1875 | /* verify that the packet does not have any known errors */ |
| 1876 | if (unlikely(ixgbe_test_staterr(rx_desc, |
| 1877 | IXGBE_RXDADV_ERR_FRAME_ERR_MASK) && |
| 1878 | !(netdev->features & NETIF_F_RXALL))) { |
| 1879 | dev_kfree_skb_any(skb); |
| 1880 | return true; |
| 1881 | } |
| 1882 | |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1883 | /* place header in linear portion of buffer */ |
Alexander Duyck | cf3fe7a | 2012-07-20 08:08:39 +0000 | [diff] [blame] | 1884 | if (skb_is_nonlinear(skb)) |
| 1885 | ixgbe_pull_tail(rx_ring, skb); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1886 | |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1887 | #ifdef IXGBE_FCOE |
| 1888 | /* do not attempt to pad FCoE Frames as this will disrupt DDP */ |
| 1889 | if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) |
| 1890 | return false; |
| 1891 | |
| 1892 | #endif |
Alexander Duyck | a94d9e2 | 2014-12-03 08:17:39 -0800 | [diff] [blame] | 1893 | /* if eth_skb_pad returns an error the skb was freed */ |
| 1894 | if (eth_skb_pad(skb)) |
| 1895 | return true; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1896 | |
| 1897 | return false; |
| 1898 | } |
| 1899 | |
| 1900 | /** |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1901 | * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring |
| 1902 | * @rx_ring: rx descriptor ring to store buffers on |
| 1903 | * @old_buff: donor buffer to have page reused |
| 1904 | * |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1905 | * Synchronizes page for reuse by the adapter |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1906 | **/ |
| 1907 | static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring, |
| 1908 | struct ixgbe_rx_buffer *old_buff) |
| 1909 | { |
| 1910 | struct ixgbe_rx_buffer *new_buff; |
| 1911 | u16 nta = rx_ring->next_to_alloc; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1912 | |
| 1913 | new_buff = &rx_ring->rx_buffer_info[nta]; |
| 1914 | |
| 1915 | /* update, and store next to alloc */ |
| 1916 | nta++; |
| 1917 | rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0; |
| 1918 | |
| 1919 | /* transfer page from old buffer to new buffer */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1920 | *new_buff = *old_buff; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1921 | |
| 1922 | /* sync the buffer for use by the device */ |
| 1923 | dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma, |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1924 | new_buff->page_offset, |
| 1925 | ixgbe_rx_bufsz(rx_ring), |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1926 | DMA_FROM_DEVICE); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1927 | } |
| 1928 | |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1929 | static inline bool ixgbe_page_is_reserved(struct page *page) |
| 1930 | { |
Michal Hocko | 2f064f3 | 2015-08-21 14:11:51 -0700 | [diff] [blame] | 1931 | return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page); |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1932 | } |
| 1933 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1934 | /** |
| 1935 | * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff |
| 1936 | * @rx_ring: rx descriptor ring to transact packets on |
| 1937 | * @rx_buffer: buffer containing page to add |
| 1938 | * @rx_desc: descriptor containing length of buffer written by hardware |
| 1939 | * @skb: sk_buff to place the data into |
| 1940 | * |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1941 | * This function will add the data contained in rx_buffer->page to the skb. |
| 1942 | * This is done either through a direct copy if the data in the buffer is |
| 1943 | * less than the skb header size, otherwise it will just attach the page as |
| 1944 | * a frag to the skb. |
| 1945 | * |
| 1946 | * The function will then update the page offset if necessary and return |
| 1947 | * true if the buffer can be reused by the adapter. |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1948 | **/ |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1949 | static bool ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring, |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1950 | struct ixgbe_rx_buffer *rx_buffer, |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1951 | union ixgbe_adv_rx_desc *rx_desc, |
| 1952 | struct sk_buff *skb) |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1953 | { |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1954 | struct page *page = rx_buffer->page; |
| 1955 | unsigned int size = le16_to_cpu(rx_desc->wb.upper.length); |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1956 | #if (PAGE_SIZE < 8192) |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1957 | unsigned int truesize = ixgbe_rx_bufsz(rx_ring); |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1958 | #else |
| 1959 | unsigned int truesize = ALIGN(size, L1_CACHE_BYTES); |
| 1960 | unsigned int last_offset = ixgbe_rx_pg_size(rx_ring) - |
| 1961 | ixgbe_rx_bufsz(rx_ring); |
| 1962 | #endif |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1963 | |
Alexander Duyck | cf3fe7a | 2012-07-20 08:08:39 +0000 | [diff] [blame] | 1964 | if ((size <= IXGBE_RX_HDR_SIZE) && !skb_is_nonlinear(skb)) { |
| 1965 | unsigned char *va = page_address(page) + rx_buffer->page_offset; |
| 1966 | |
| 1967 | memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long))); |
| 1968 | |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1969 | /* page is not reserved, we can reuse buffer as-is */ |
| 1970 | if (likely(!ixgbe_page_is_reserved(page))) |
Alexander Duyck | cf3fe7a | 2012-07-20 08:08:39 +0000 | [diff] [blame] | 1971 | return true; |
| 1972 | |
| 1973 | /* this page cannot be reused so discard it */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1974 | __free_pages(page, ixgbe_rx_pg_order(rx_ring)); |
Alexander Duyck | cf3fe7a | 2012-07-20 08:08:39 +0000 | [diff] [blame] | 1975 | return false; |
| 1976 | } |
| 1977 | |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1978 | skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page, |
| 1979 | rx_buffer->page_offset, size, truesize); |
| 1980 | |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1981 | /* avoid re-using remote pages */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1982 | if (unlikely(ixgbe_page_is_reserved(page))) |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1983 | return false; |
| 1984 | |
| 1985 | #if (PAGE_SIZE < 8192) |
| 1986 | /* if we are only owner of page we can reuse it */ |
| 1987 | if (unlikely(page_count(page) != 1)) |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1988 | return false; |
| 1989 | |
| 1990 | /* flip page offset to other buffer */ |
| 1991 | rx_buffer->page_offset ^= truesize; |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1992 | #else |
| 1993 | /* move offset up to the next cache line */ |
| 1994 | rx_buffer->page_offset += truesize; |
| 1995 | |
| 1996 | if (rx_buffer->page_offset > last_offset) |
| 1997 | return false; |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1998 | #endif |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1999 | |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 2000 | /* Even if we own the page, we are not allowed to use atomic_set() |
| 2001 | * This would break get_page_unless_zero() users. |
| 2002 | */ |
Joonsoo Kim | fe896d1 | 2016-03-17 14:19:26 -0700 | [diff] [blame] | 2003 | page_ref_inc(page); |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 2004 | |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 2005 | return true; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2006 | } |
| 2007 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2008 | static struct sk_buff *ixgbe_fetch_rx_buffer(struct ixgbe_ring *rx_ring, |
| 2009 | union ixgbe_adv_rx_desc *rx_desc) |
| 2010 | { |
| 2011 | struct ixgbe_rx_buffer *rx_buffer; |
| 2012 | struct sk_buff *skb; |
| 2013 | struct page *page; |
| 2014 | |
| 2015 | rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean]; |
| 2016 | page = rx_buffer->page; |
| 2017 | prefetchw(page); |
| 2018 | |
| 2019 | skb = rx_buffer->skb; |
| 2020 | |
| 2021 | if (likely(!skb)) { |
| 2022 | void *page_addr = page_address(page) + |
| 2023 | rx_buffer->page_offset; |
| 2024 | |
| 2025 | /* prefetch first cache line of first page */ |
| 2026 | prefetch(page_addr); |
| 2027 | #if L1_CACHE_BYTES < 128 |
| 2028 | prefetch(page_addr + L1_CACHE_BYTES); |
| 2029 | #endif |
| 2030 | |
| 2031 | /* allocate a skb to store the frags */ |
Alexander Duyck | 67fd893 | 2014-12-09 19:40:56 -0800 | [diff] [blame] | 2032 | skb = napi_alloc_skb(&rx_ring->q_vector->napi, |
| 2033 | IXGBE_RX_HDR_SIZE); |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2034 | if (unlikely(!skb)) { |
| 2035 | rx_ring->rx_stats.alloc_rx_buff_failed++; |
| 2036 | return NULL; |
| 2037 | } |
| 2038 | |
| 2039 | /* |
| 2040 | * we will be copying header into skb->data in |
| 2041 | * pskb_may_pull so it is in our interest to prefetch |
| 2042 | * it now to avoid a possible cache miss |
| 2043 | */ |
| 2044 | prefetchw(skb->data); |
| 2045 | |
| 2046 | /* |
| 2047 | * Delay unmapping of the first packet. It carries the |
| 2048 | * header information, HW may still access the header |
| 2049 | * after the writeback. Only unmap it when EOP is |
| 2050 | * reached |
| 2051 | */ |
| 2052 | if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))) |
| 2053 | goto dma_sync; |
| 2054 | |
| 2055 | IXGBE_CB(skb)->dma = rx_buffer->dma; |
| 2056 | } else { |
| 2057 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)) |
| 2058 | ixgbe_dma_sync_frag(rx_ring, skb); |
| 2059 | |
| 2060 | dma_sync: |
| 2061 | /* we are reusing so sync this buffer for CPU use */ |
| 2062 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 2063 | rx_buffer->dma, |
| 2064 | rx_buffer->page_offset, |
| 2065 | ixgbe_rx_bufsz(rx_ring), |
| 2066 | DMA_FROM_DEVICE); |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 2067 | |
| 2068 | rx_buffer->skb = NULL; |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2069 | } |
| 2070 | |
| 2071 | /* pull page into skb */ |
| 2072 | if (ixgbe_add_rx_frag(rx_ring, rx_buffer, rx_desc, skb)) { |
| 2073 | /* hand second half of page back to the ring */ |
| 2074 | ixgbe_reuse_rx_page(rx_ring, rx_buffer); |
| 2075 | } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) { |
| 2076 | /* the page has been released from the ring */ |
| 2077 | IXGBE_CB(skb)->page_released = true; |
| 2078 | } else { |
| 2079 | /* we are not reusing the buffer so unmap it */ |
| 2080 | dma_unmap_page(rx_ring->dev, rx_buffer->dma, |
| 2081 | ixgbe_rx_pg_size(rx_ring), |
| 2082 | DMA_FROM_DEVICE); |
| 2083 | } |
| 2084 | |
| 2085 | /* clear contents of buffer_info */ |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2086 | rx_buffer->page = NULL; |
| 2087 | |
| 2088 | return skb; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2089 | } |
| 2090 | |
| 2091 | /** |
| 2092 | * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf |
| 2093 | * @q_vector: structure containing interrupt and ring information |
| 2094 | * @rx_ring: rx descriptor ring to transact packets on |
| 2095 | * @budget: Total limit on number of packets to process |
| 2096 | * |
| 2097 | * This function provides a "bounce buffer" approach to Rx interrupt |
| 2098 | * processing. The advantage to this is that on systems that have |
| 2099 | * expensive overhead for IOMMU access this provides a means of avoiding |
| 2100 | * it by maintaining the mapping of the page to the syste. |
| 2101 | * |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2102 | * Returns amount of work completed |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2103 | **/ |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2104 | static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2105 | struct ixgbe_ring *rx_ring, |
Alexander Duyck | f4de00e | 2012-09-25 00:29:37 +0000 | [diff] [blame] | 2106 | const int budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2107 | { |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 2108 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 2109 | #ifdef IXGBE_FCOE |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2110 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Mark Rustad | 4ffdf91 | 2012-07-18 06:05:50 +0000 | [diff] [blame] | 2111 | int ddp_bytes; |
| 2112 | unsigned int mss = 0; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 2113 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2114 | u16 cleaned_count = ixgbe_desc_unused(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2115 | |
Eric W. Biederman | fdabfc8a | 2014-03-14 18:00:41 -0700 | [diff] [blame] | 2116 | while (likely(total_rx_packets < budget)) { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2117 | union ixgbe_adv_rx_desc *rx_desc; |
| 2118 | struct sk_buff *skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2119 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2120 | /* return some buffers to hardware, one at a time is too slow */ |
| 2121 | if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) { |
| 2122 | ixgbe_alloc_rx_buffers(rx_ring, cleaned_count); |
| 2123 | cleaned_count = 0; |
| 2124 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2125 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2126 | rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2127 | |
Alexander Duyck | 124b74c | 2014-12-11 15:02:28 -0800 | [diff] [blame] | 2128 | if (!rx_desc->wb.upper.status_error) |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2129 | break; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 2130 | |
Alexander Duyck | 124b74c | 2014-12-11 15:02:28 -0800 | [diff] [blame] | 2131 | /* This memory barrier is needed to keep us from reading |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2132 | * any other fields out of the rx_desc until we know the |
Alexander Duyck | 124b74c | 2014-12-11 15:02:28 -0800 | [diff] [blame] | 2133 | * descriptor has been written back |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2134 | */ |
Alexander Duyck | 124b74c | 2014-12-11 15:02:28 -0800 | [diff] [blame] | 2135 | dma_rmb(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2136 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2137 | /* retrieve a buffer from the ring */ |
| 2138 | skb = ixgbe_fetch_rx_buffer(rx_ring, rx_desc); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2139 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2140 | /* exit if we failed to retrieve a buffer */ |
| 2141 | if (!skb) |
| 2142 | break; |
Alexander Duyck | 4c1975d | 2012-01-31 02:59:23 +0000 | [diff] [blame] | 2143 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2144 | cleaned_count++; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2145 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2146 | /* place incomplete frames back on ring for completion */ |
| 2147 | if (ixgbe_is_non_eop(rx_ring, rx_desc, skb)) |
| 2148 | continue; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2149 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2150 | /* verify the packet layout is correct */ |
| 2151 | if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb)) |
| 2152 | continue; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 2153 | |
| 2154 | /* probably a little skewed due to removing CRC */ |
| 2155 | total_rx_bytes += skb->len; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 2156 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 2157 | /* populate checksum, timestamp, VLAN, and protocol */ |
| 2158 | ixgbe_process_skb_fields(rx_ring, rx_desc, skb); |
| 2159 | |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 2160 | #ifdef IXGBE_FCOE |
| 2161 | /* if ddp, not passing to ULD unless for FCP_RSP or error */ |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 2162 | if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) { |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 2163 | ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb); |
Mark Rustad | 4ffdf91 | 2012-07-18 06:05:50 +0000 | [diff] [blame] | 2164 | /* include DDPed FCoE data */ |
| 2165 | if (ddp_bytes > 0) { |
| 2166 | if (!mss) { |
| 2167 | mss = rx_ring->netdev->mtu - |
| 2168 | sizeof(struct fcoe_hdr) - |
| 2169 | sizeof(struct fc_frame_header) - |
| 2170 | sizeof(struct fcoe_crc_eof); |
| 2171 | if (mss > 512) |
| 2172 | mss &= ~511; |
| 2173 | } |
| 2174 | total_rx_bytes += ddp_bytes; |
| 2175 | total_rx_packets += DIV_ROUND_UP(ddp_bytes, |
| 2176 | mss); |
| 2177 | } |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 2178 | if (!ddp_bytes) { |
| 2179 | dev_kfree_skb_any(skb); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2180 | continue; |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 2181 | } |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 2182 | } |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2183 | |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 2184 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 2185 | ixgbe_rx_skb(q_vector, skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2186 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2187 | /* update budget accounting */ |
Alexander Duyck | f4de00e | 2012-09-25 00:29:37 +0000 | [diff] [blame] | 2188 | total_rx_packets++; |
Eric W. Biederman | fdabfc8a | 2014-03-14 18:00:41 -0700 | [diff] [blame] | 2189 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2190 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 2191 | u64_stats_update_begin(&rx_ring->syncp); |
| 2192 | rx_ring->stats.packets += total_rx_packets; |
| 2193 | rx_ring->stats.bytes += total_rx_bytes; |
| 2194 | u64_stats_update_end(&rx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2195 | q_vector->rx.total_packets += total_rx_packets; |
| 2196 | q_vector->rx.total_bytes += total_rx_bytes; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2197 | |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2198 | return total_rx_packets; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2199 | } |
| 2200 | |
Cong Wang | e0d1095 | 2013-08-01 11:10:25 +0800 | [diff] [blame] | 2201 | #ifdef CONFIG_NET_RX_BUSY_POLL |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2202 | /* must be called with local_bh_disable()d */ |
| 2203 | static int ixgbe_low_latency_recv(struct napi_struct *napi) |
| 2204 | { |
| 2205 | struct ixgbe_q_vector *q_vector = |
| 2206 | container_of(napi, struct ixgbe_q_vector, napi); |
| 2207 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 2208 | struct ixgbe_ring *ring; |
| 2209 | int found = 0; |
| 2210 | |
| 2211 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2212 | return LL_FLUSH_FAILED; |
| 2213 | |
| 2214 | if (!ixgbe_qv_lock_poll(q_vector)) |
| 2215 | return LL_FLUSH_BUSY; |
| 2216 | |
| 2217 | ixgbe_for_each_ring(ring, q_vector->rx) { |
| 2218 | found = ixgbe_clean_rx_irq(q_vector, ring, 4); |
Jacob Keller | b464003 | 2013-10-01 04:33:54 -0700 | [diff] [blame] | 2219 | #ifdef BP_EXTENDED_STATS |
Eliezer Tamir | 7e15b90 | 2013-06-10 11:40:31 +0300 | [diff] [blame] | 2220 | if (found) |
| 2221 | ring->stats.cleaned += found; |
| 2222 | else |
| 2223 | ring->stats.misses++; |
| 2224 | #endif |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2225 | if (found) |
| 2226 | break; |
| 2227 | } |
| 2228 | |
| 2229 | ixgbe_qv_unlock_poll(q_vector); |
| 2230 | |
| 2231 | return found; |
| 2232 | } |
Cong Wang | e0d1095 | 2013-08-01 11:10:25 +0800 | [diff] [blame] | 2233 | #endif /* CONFIG_NET_RX_BUSY_POLL */ |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2234 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2235 | /** |
| 2236 | * ixgbe_configure_msix - Configure MSI-X hardware |
| 2237 | * @adapter: board private structure |
| 2238 | * |
| 2239 | * ixgbe_configure_msix sets up the hardware to properly generate MSI-X |
| 2240 | * interrupts. |
| 2241 | **/ |
| 2242 | static void ixgbe_configure_msix(struct ixgbe_adapter *adapter) |
| 2243 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2244 | struct ixgbe_q_vector *q_vector; |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2245 | int v_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2246 | u32 mask; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2247 | |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 2248 | /* Populate MSIX to EITR Select */ |
| 2249 | if (adapter->num_vfs > 32) { |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 2250 | u32 eitrsel = BIT(adapter->num_vfs - 32) - 1; |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 2251 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel); |
| 2252 | } |
| 2253 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 2254 | /* |
| 2255 | * Populate the IVAR table and set the ITR values to the |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2256 | * corresponding register. |
| 2257 | */ |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2258 | for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) { |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2259 | struct ixgbe_ring *ring; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2260 | q_vector = adapter->q_vector[v_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2261 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 2262 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2263 | ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2264 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 2265 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2266 | ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2267 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2268 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2269 | } |
| 2270 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2271 | switch (adapter->hw.mac.type) { |
| 2272 | case ixgbe_mac_82598EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2273 | ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2274 | v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2275 | break; |
| 2276 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2277 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2278 | case ixgbe_mac_X550: |
| 2279 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2280 | case ixgbe_mac_x550em_a: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2281 | ixgbe_set_ivar(adapter, -1, 1, v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2282 | break; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2283 | default: |
| 2284 | break; |
| 2285 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2286 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2287 | |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 2288 | /* set up to autoclear timer, and the vectors */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2289 | mask = IXGBE_EIMS_ENABLE_MASK; |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2290 | mask &= ~(IXGBE_EIMS_OTHER | |
| 2291 | IXGBE_EIMS_MAILBOX | |
| 2292 | IXGBE_EIMS_LSC); |
| 2293 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2294 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2295 | } |
| 2296 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2297 | enum latency_range { |
| 2298 | lowest_latency = 0, |
| 2299 | low_latency = 1, |
| 2300 | bulk_latency = 2, |
| 2301 | latency_invalid = 255 |
| 2302 | }; |
| 2303 | |
| 2304 | /** |
| 2305 | * ixgbe_update_itr - update the dynamic ITR value based on statistics |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2306 | * @q_vector: structure containing interrupt and ring information |
| 2307 | * @ring_container: structure containing ring performance data |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2308 | * |
| 2309 | * Stores a new ITR value based on packets and byte |
| 2310 | * counts during the last interrupt. The advantage of per interrupt |
| 2311 | * computation is faster updates and more accurate ITR for the current |
| 2312 | * traffic pattern. Constants in this function were computed |
| 2313 | * based on theoretical maximum wire speed and thresholds were set based |
| 2314 | * on testing data as well as attempting to minimize response time |
| 2315 | * while increasing bulk throughput. |
| 2316 | * this functionality is controlled by the InterruptThrottleRate module |
| 2317 | * parameter (see ixgbe_param.c) |
| 2318 | **/ |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2319 | static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector, |
| 2320 | struct ixgbe_ring_container *ring_container) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2321 | { |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2322 | int bytes = ring_container->total_bytes; |
| 2323 | int packets = ring_container->total_packets; |
| 2324 | u32 timepassed_us; |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2325 | u64 bytes_perint; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2326 | u8 itr_setting = ring_container->itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2327 | |
| 2328 | if (packets == 0) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2329 | return; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2330 | |
| 2331 | /* simple throttlerate management |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2332 | * 0-10MB/s lowest (100000 ints/s) |
| 2333 | * 10-20MB/s low (20000 ints/s) |
Alexander Duyck | 8ac34f1 | 2015-07-30 15:19:28 -0700 | [diff] [blame] | 2334 | * 20-1249MB/s bulk (12000 ints/s) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2335 | */ |
| 2336 | /* what was last interrupt timeslice? */ |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2337 | timepassed_us = q_vector->itr >> 2; |
Don Skidmore | bdbeefe | 2013-03-02 07:17:37 +0000 | [diff] [blame] | 2338 | if (timepassed_us == 0) |
| 2339 | return; |
| 2340 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2341 | bytes_perint = bytes / timepassed_us; /* bytes/usec */ |
| 2342 | |
| 2343 | switch (itr_setting) { |
| 2344 | case lowest_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2345 | if (bytes_perint > 10) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2346 | itr_setting = low_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2347 | break; |
| 2348 | case low_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2349 | if (bytes_perint > 20) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2350 | itr_setting = bulk_latency; |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2351 | else if (bytes_perint <= 10) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2352 | itr_setting = lowest_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2353 | break; |
| 2354 | case bulk_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2355 | if (bytes_perint <= 20) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2356 | itr_setting = low_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2357 | break; |
| 2358 | } |
| 2359 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2360 | /* clear work counters since we have the values we need */ |
| 2361 | ring_container->total_bytes = 0; |
| 2362 | ring_container->total_packets = 0; |
| 2363 | |
| 2364 | /* write updated itr to ring container */ |
| 2365 | ring_container->itr = itr_setting; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2366 | } |
| 2367 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2368 | /** |
| 2369 | * ixgbe_write_eitr - write EITR register in hardware specific way |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2370 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2371 | * |
| 2372 | * This function is made to be called by ethtool and by the driver |
| 2373 | * when it needs to update EITR registers at runtime. Hardware |
| 2374 | * specific quirks/differences are taken care of here. |
| 2375 | */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2376 | void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector) |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2377 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2378 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2379 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2380 | int v_idx = q_vector->v_idx; |
Alexander Duyck | 5d967eb | 2012-02-08 07:49:43 +0000 | [diff] [blame] | 2381 | u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2382 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2383 | switch (adapter->hw.mac.type) { |
| 2384 | case ixgbe_mac_82598EB: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2385 | /* must write high and low 16 bits to reset counter */ |
| 2386 | itr_reg |= (itr_reg << 16); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2387 | break; |
| 2388 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2389 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2390 | case ixgbe_mac_X550: |
| 2391 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2392 | case ixgbe_mac_x550em_a: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2393 | /* |
| 2394 | * set the WDIS bit to not clear the timer bits and cause an |
| 2395 | * immediate assertion of the interrupt |
| 2396 | */ |
| 2397 | itr_reg |= IXGBE_EITR_CNT_WDIS; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2398 | break; |
| 2399 | default: |
| 2400 | break; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2401 | } |
| 2402 | IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg); |
| 2403 | } |
| 2404 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2405 | static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2406 | { |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2407 | u32 new_itr = q_vector->itr; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2408 | u8 current_itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2409 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2410 | ixgbe_update_itr(q_vector, &q_vector->tx); |
| 2411 | ixgbe_update_itr(q_vector, &q_vector->rx); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2412 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2413 | current_itr = max(q_vector->rx.itr, q_vector->tx.itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2414 | |
| 2415 | switch (current_itr) { |
| 2416 | /* counts and packets in update_itr are dependent on these numbers */ |
| 2417 | case lowest_latency: |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2418 | new_itr = IXGBE_100K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2419 | break; |
| 2420 | case low_latency: |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2421 | new_itr = IXGBE_20K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2422 | break; |
| 2423 | case bulk_latency: |
Alexander Duyck | 8ac34f1 | 2015-07-30 15:19:28 -0700 | [diff] [blame] | 2424 | new_itr = IXGBE_12K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2425 | break; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2426 | default: |
| 2427 | break; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2428 | } |
| 2429 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2430 | if (new_itr != q_vector->itr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2431 | /* do an exponential smoothing */ |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2432 | new_itr = (10 * new_itr * q_vector->itr) / |
| 2433 | ((9 * new_itr) + q_vector->itr); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2434 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2435 | /* save the algorithm value here */ |
Alexander Duyck | 5d967eb | 2012-02-08 07:49:43 +0000 | [diff] [blame] | 2436 | q_vector->itr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2437 | |
| 2438 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2439 | } |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2440 | } |
| 2441 | |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2442 | /** |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2443 | * ixgbe_check_overtemp_subtask - check for over temperature |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2444 | * @adapter: pointer to adapter |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2445 | **/ |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2446 | static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter) |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2447 | { |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2448 | struct ixgbe_hw *hw = &adapter->hw; |
| 2449 | u32 eicr = adapter->interrupt_event; |
| 2450 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2451 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2452 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2453 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2454 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) && |
| 2455 | !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT)) |
| 2456 | return; |
| 2457 | |
| 2458 | adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2459 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2460 | switch (hw->device_id) { |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2461 | case IXGBE_DEV_ID_82599_T3_LOM: |
| 2462 | /* |
| 2463 | * Since the warning interrupt is for both ports |
| 2464 | * we don't have to check if: |
| 2465 | * - This interrupt wasn't for our port. |
| 2466 | * - We may have missed the interrupt so always have to |
| 2467 | * check if we got a LSC |
| 2468 | */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2469 | if (!(eicr & IXGBE_EICR_GPI_SDP0_8259X) && |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2470 | !(eicr & IXGBE_EICR_LSC)) |
| 2471 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2472 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2473 | if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) { |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 2474 | u32 speed; |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2475 | bool link_up = false; |
| 2476 | |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 2477 | hw->mac.ops.check_link(hw, &speed, &link_up, false); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2478 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2479 | if (link_up) |
| 2480 | return; |
| 2481 | } |
| 2482 | |
| 2483 | /* Check if this is not due to overtemp */ |
| 2484 | if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP) |
| 2485 | return; |
| 2486 | |
| 2487 | break; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2488 | default: |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 2489 | if (adapter->hw.mac.type >= ixgbe_mac_X540) |
| 2490 | return; |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2491 | if (!(eicr & IXGBE_EICR_GPI_SDP0(hw))) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2492 | return; |
| 2493 | break; |
| 2494 | } |
Don Skidmore | f44e751 | 2015-06-09 16:36:23 -0700 | [diff] [blame] | 2495 | e_crit(drv, "%s\n", ixgbe_overheat_msg); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2496 | |
| 2497 | adapter->interrupt_event = 0; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2498 | } |
| 2499 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2500 | static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr) |
| 2501 | { |
| 2502 | struct ixgbe_hw *hw = &adapter->hw; |
| 2503 | |
| 2504 | if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) && |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2505 | (eicr & IXGBE_EICR_GPI_SDP1(hw))) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2506 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2507 | /* write to clear the interrupt */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2508 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw)); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2509 | } |
| 2510 | } |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2511 | |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2512 | static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 2513 | { |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2514 | struct ixgbe_hw *hw = &adapter->hw; |
| 2515 | |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2516 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)) |
| 2517 | return; |
| 2518 | |
| 2519 | switch (adapter->hw.mac.type) { |
| 2520 | case ixgbe_mac_82599EB: |
| 2521 | /* |
| 2522 | * Need to check link state so complete overtemp check |
| 2523 | * on service task |
| 2524 | */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2525 | if (((eicr & IXGBE_EICR_GPI_SDP0(hw)) || |
| 2526 | (eicr & IXGBE_EICR_LSC)) && |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2527 | (!test_bit(__IXGBE_DOWN, &adapter->state))) { |
| 2528 | adapter->interrupt_event = eicr; |
| 2529 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2530 | ixgbe_service_event_schedule(adapter); |
| 2531 | return; |
| 2532 | } |
| 2533 | return; |
| 2534 | case ixgbe_mac_X540: |
| 2535 | if (!(eicr & IXGBE_EICR_TS)) |
| 2536 | return; |
| 2537 | break; |
| 2538 | default: |
| 2539 | return; |
| 2540 | } |
| 2541 | |
Don Skidmore | f44e751 | 2015-06-09 16:36:23 -0700 | [diff] [blame] | 2542 | e_crit(drv, "%s\n", ixgbe_overheat_msg); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2543 | } |
| 2544 | |
Don Skidmore | 45788d2 | 2015-06-09 16:59:04 -0700 | [diff] [blame] | 2545 | static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw) |
| 2546 | { |
| 2547 | switch (hw->mac.type) { |
| 2548 | case ixgbe_mac_82598EB: |
| 2549 | if (hw->phy.type == ixgbe_phy_nl) |
| 2550 | return true; |
| 2551 | return false; |
| 2552 | case ixgbe_mac_82599EB: |
| 2553 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2554 | case ixgbe_mac_x550em_a: |
Don Skidmore | 45788d2 | 2015-06-09 16:59:04 -0700 | [diff] [blame] | 2555 | switch (hw->mac.ops.get_media_type(hw)) { |
| 2556 | case ixgbe_media_type_fiber: |
| 2557 | case ixgbe_media_type_fiber_qsfp: |
| 2558 | return true; |
| 2559 | default: |
| 2560 | return false; |
| 2561 | } |
| 2562 | default: |
| 2563 | return false; |
| 2564 | } |
| 2565 | } |
| 2566 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2567 | static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 2568 | { |
| 2569 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 4ccc650 | 2015-09-02 13:47:54 -0700 | [diff] [blame] | 2570 | u32 eicr_mask = IXGBE_EICR_GPI_SDP2(hw); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2571 | |
Don Skidmore | 4ccc650 | 2015-09-02 13:47:54 -0700 | [diff] [blame] | 2572 | if (!ixgbe_is_sfp(hw)) |
| 2573 | return; |
| 2574 | |
| 2575 | /* Later MAC's use different SDP */ |
| 2576 | if (hw->mac.type >= ixgbe_mac_X540) |
| 2577 | eicr_mask = IXGBE_EICR_GPI_SDP0_X540; |
| 2578 | |
| 2579 | if (eicr & eicr_mask) { |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2580 | /* Clear the interrupt */ |
Don Skidmore | 4ccc650 | 2015-09-02 13:47:54 -0700 | [diff] [blame] | 2581 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr_mask); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2582 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2583 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
Mark Rustad | 58e7cd2 | 2015-08-08 16:18:48 -0700 | [diff] [blame] | 2584 | adapter->sfp_poll_time = 0; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2585 | ixgbe_service_event_schedule(adapter); |
| 2586 | } |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2587 | } |
| 2588 | |
Don Skidmore | 4ccc650 | 2015-09-02 13:47:54 -0700 | [diff] [blame] | 2589 | if (adapter->hw.mac.type == ixgbe_mac_82599EB && |
| 2590 | (eicr & IXGBE_EICR_GPI_SDP1(hw))) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2591 | /* Clear the interrupt */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2592 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw)); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2593 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2594 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 2595 | ixgbe_service_event_schedule(adapter); |
| 2596 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2597 | } |
| 2598 | } |
| 2599 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2600 | static void ixgbe_check_lsc(struct ixgbe_adapter *adapter) |
| 2601 | { |
| 2602 | struct ixgbe_hw *hw = &adapter->hw; |
| 2603 | |
| 2604 | adapter->lsc_int++; |
| 2605 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 2606 | adapter->link_check_timeout = jiffies; |
| 2607 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2608 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC); |
Nelson, Shannon | 8a0717f | 2009-11-12 18:47:11 +0000 | [diff] [blame] | 2609 | IXGBE_WRITE_FLUSH(hw); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 2610 | ixgbe_service_event_schedule(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2611 | } |
| 2612 | } |
| 2613 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2614 | static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter, |
| 2615 | u64 qmask) |
| 2616 | { |
| 2617 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2618 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2619 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2620 | switch (hw->mac.type) { |
| 2621 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2622 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2623 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask); |
| 2624 | break; |
| 2625 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 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: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2629 | case ixgbe_mac_x550em_a: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2630 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2631 | if (mask) |
| 2632 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2633 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2634 | if (mask) |
| 2635 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask); |
| 2636 | break; |
| 2637 | default: |
| 2638 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2639 | } |
| 2640 | /* skip the flush */ |
| 2641 | } |
| 2642 | |
| 2643 | static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2644 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2645 | { |
| 2646 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2647 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2648 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2649 | switch (hw->mac.type) { |
| 2650 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2651 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2652 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask); |
| 2653 | break; |
| 2654 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2655 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2656 | case ixgbe_mac_X550: |
| 2657 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2658 | case ixgbe_mac_x550em_a: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2659 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2660 | if (mask) |
| 2661 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2662 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2663 | if (mask) |
| 2664 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask); |
| 2665 | break; |
| 2666 | default: |
| 2667 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2668 | } |
| 2669 | /* skip the flush */ |
| 2670 | } |
| 2671 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2672 | /** |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2673 | * ixgbe_irq_enable - Enable default interrupt generation settings |
| 2674 | * @adapter: board private structure |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2675 | **/ |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2676 | static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues, |
| 2677 | bool flush) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2678 | { |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2679 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2680 | u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE); |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 2681 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2682 | /* don't reenable LSC while waiting for link */ |
| 2683 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 2684 | mask &= ~IXGBE_EIMS_LSC; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2685 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2686 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2687 | switch (adapter->hw.mac.type) { |
| 2688 | case ixgbe_mac_82599EB: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2689 | mask |= IXGBE_EIMS_GPI_SDP0(hw); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2690 | break; |
| 2691 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2692 | case ixgbe_mac_X550: |
| 2693 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2694 | case ixgbe_mac_x550em_a: |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2695 | mask |= IXGBE_EIMS_TS; |
| 2696 | break; |
| 2697 | default: |
| 2698 | break; |
| 2699 | } |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2700 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2701 | mask |= IXGBE_EIMS_GPI_SDP1(hw); |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2702 | switch (adapter->hw.mac.type) { |
| 2703 | case ixgbe_mac_82599EB: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2704 | mask |= IXGBE_EIMS_GPI_SDP1(hw); |
| 2705 | mask |= IXGBE_EIMS_GPI_SDP2(hw); |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2706 | /* fall through */ |
Don Skidmore | 858bc08 | 2011-08-04 09:28:30 +0000 | [diff] [blame] | 2707 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2708 | case ixgbe_mac_X550: |
| 2709 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2710 | case ixgbe_mac_x550em_a: |
| 2711 | if (adapter->hw.device_id == IXGBE_DEV_ID_X550EM_X_SFP || |
Mark Rustad | 2d40cd1 | 2016-04-01 12:18:35 -0700 | [diff] [blame] | 2712 | adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP || |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2713 | adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP_N) |
Mark Rustad | cbd45ec | 2015-08-08 16:17:51 -0700 | [diff] [blame] | 2714 | mask |= IXGBE_EIMS_GPI_SDP0(&adapter->hw); |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 2715 | if (adapter->hw.phy.type == ixgbe_phy_x550em_ext_t) |
| 2716 | mask |= IXGBE_EICR_GPI_SDP0_X540; |
Don Skidmore | 858bc08 | 2011-08-04 09:28:30 +0000 | [diff] [blame] | 2717 | mask |= IXGBE_EIMS_ECC; |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2718 | mask |= IXGBE_EIMS_MAILBOX; |
| 2719 | break; |
| 2720 | default: |
| 2721 | break; |
| 2722 | } |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2723 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2724 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) && |
| 2725 | !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 2726 | mask |= IXGBE_EIMS_FLOW_DIR; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2727 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2728 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
| 2729 | if (queues) |
| 2730 | ixgbe_irq_enable_queues(adapter, ~0); |
| 2731 | if (flush) |
| 2732 | IXGBE_WRITE_FLUSH(&adapter->hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2733 | } |
| 2734 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2735 | static irqreturn_t ixgbe_msix_other(int irq, void *data) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2736 | { |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2737 | struct ixgbe_adapter *adapter = data; |
| 2738 | struct ixgbe_hw *hw = &adapter->hw; |
| 2739 | u32 eicr; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2740 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2741 | /* |
| 2742 | * Workaround for Silicon errata. Use clear-by-write instead |
| 2743 | * of clear-by-read. Reading with EICS will return the |
| 2744 | * interrupt causes without clearing, which later be done |
| 2745 | * with the write to EICR. |
| 2746 | */ |
| 2747 | eicr = IXGBE_READ_REG(hw, IXGBE_EICS); |
Jacob Keller | d87d830 | 2013-03-02 07:51:42 +0000 | [diff] [blame] | 2748 | |
| 2749 | /* The lower 16bits of the EICR register are for the queue interrupts |
Joe Perches | dbedd44 | 2015-03-06 20:49:12 -0800 | [diff] [blame] | 2750 | * 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] | 2751 | * the bits are high when ixgbe_msix_other is called. There is a race |
| 2752 | * condition otherwise which results in possible performance loss |
| 2753 | * especially if the ixgbe_msix_other interrupt is triggering |
| 2754 | * consistently (as it would when PPS is turned on for the X540 device) |
| 2755 | */ |
| 2756 | eicr &= 0xFFFF0000; |
| 2757 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2758 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2759 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2760 | if (eicr & IXGBE_EICR_LSC) |
| 2761 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2762 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2763 | if (eicr & IXGBE_EICR_MAILBOX) |
| 2764 | ixgbe_msg_task(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2765 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2766 | switch (hw->mac.type) { |
| 2767 | case ixgbe_mac_82599EB: |
| 2768 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2769 | case ixgbe_mac_X550: |
| 2770 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2771 | case ixgbe_mac_x550em_a: |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 2772 | if (hw->phy.type == ixgbe_phy_x550em_ext_t && |
| 2773 | (eicr & IXGBE_EICR_GPI_SDP0_X540)) { |
| 2774 | adapter->flags2 |= IXGBE_FLAG2_PHY_INTERRUPT; |
| 2775 | ixgbe_service_event_schedule(adapter); |
| 2776 | IXGBE_WRITE_REG(hw, IXGBE_EICR, |
| 2777 | IXGBE_EICR_GPI_SDP0_X540); |
| 2778 | } |
Don Skidmore | d773ce2 | 2014-02-25 17:58:53 -0800 | [diff] [blame] | 2779 | if (eicr & IXGBE_EICR_ECC) { |
| 2780 | e_info(link, "Received ECC Err, initiating reset\n"); |
Emil Tantilov | 57ca2a4 | 2016-07-29 14:46:31 -0700 | [diff] [blame] | 2781 | set_bit(__IXGBE_RESET_REQUESTED, &adapter->state); |
Don Skidmore | d773ce2 | 2014-02-25 17:58:53 -0800 | [diff] [blame] | 2782 | ixgbe_service_event_schedule(adapter); |
| 2783 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC); |
| 2784 | } |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2785 | /* Handle Flow Director Full threshold interrupt */ |
| 2786 | if (eicr & IXGBE_EICR_FLOW_DIR) { |
| 2787 | int reinit_count = 0; |
| 2788 | int i; |
| 2789 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2790 | struct ixgbe_ring *ring = adapter->tx_ring[i]; |
| 2791 | if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE, |
| 2792 | &ring->state)) |
| 2793 | reinit_count++; |
| 2794 | } |
| 2795 | if (reinit_count) { |
| 2796 | /* no more flow director interrupts until after init */ |
| 2797 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR); |
| 2798 | adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 2799 | ixgbe_service_event_schedule(adapter); |
| 2800 | } |
| 2801 | } |
| 2802 | ixgbe_check_sfp_event(adapter, eicr); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2803 | ixgbe_check_overtemp_event(adapter, eicr); |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2804 | break; |
| 2805 | default: |
| 2806 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2807 | } |
| 2808 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2809 | ixgbe_check_fan_failure(adapter, eicr); |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2810 | |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2811 | if (unlikely(eicr & IXGBE_EICR_TIMESYNC)) |
Mark Rustad | a9763f3 | 2015-10-27 09:58:07 -0700 | [diff] [blame] | 2812 | ixgbe_ptp_check_pps_event(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2813 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2814 | /* re-enable the original interrupt state, no lsc, no queues */ |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2815 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2816 | ixgbe_irq_enable(adapter, false, false); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2817 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2818 | return IRQ_HANDLED; |
| 2819 | } |
| 2820 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2821 | static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2822 | { |
| 2823 | struct ixgbe_q_vector *q_vector = data; |
| 2824 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2825 | /* EIAM disabled interrupts (on this vector) for us */ |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2826 | |
| 2827 | if (q_vector->rx.ring || q_vector->tx.ring) |
Alexander Duyck | ef2662b | 2015-09-29 15:19:43 -0700 | [diff] [blame] | 2828 | napi_schedule_irqoff(&q_vector->napi); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2829 | |
| 2830 | return IRQ_HANDLED; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2831 | } |
| 2832 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2833 | /** |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2834 | * ixgbe_poll - NAPI Rx polling callback |
| 2835 | * @napi: structure for representing this polling device |
| 2836 | * @budget: how many packets driver is allowed to clean |
| 2837 | * |
| 2838 | * This function is used for legacy and MSI, NAPI mode |
| 2839 | **/ |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 2840 | int ixgbe_poll(struct napi_struct *napi, int budget) |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2841 | { |
| 2842 | struct ixgbe_q_vector *q_vector = |
| 2843 | container_of(napi, struct ixgbe_q_vector, napi); |
| 2844 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 2845 | struct ixgbe_ring *ring; |
Jesse Brandeburg | 32b3e08 | 2015-09-24 16:35:47 -0700 | [diff] [blame] | 2846 | int per_ring_budget, work_done = 0; |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2847 | bool clean_complete = true; |
| 2848 | |
| 2849 | #ifdef CONFIG_IXGBE_DCA |
| 2850 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 2851 | ixgbe_update_dca(q_vector); |
| 2852 | #endif |
| 2853 | |
Alexander Duyck | 8220bbc | 2016-03-07 09:30:09 -0800 | [diff] [blame] | 2854 | ixgbe_for_each_ring(ring, q_vector->tx) { |
| 2855 | if (!ixgbe_clean_tx_irq(q_vector, ring, budget)) |
| 2856 | clean_complete = false; |
| 2857 | } |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2858 | |
Alexander Duyck | 5d6002b | 2015-09-22 14:35:41 -0700 | [diff] [blame] | 2859 | /* Exit if we are called by netpoll or busy polling is active */ |
| 2860 | if ((budget <= 0) || !ixgbe_qv_lock_napi(q_vector)) |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2861 | return budget; |
| 2862 | |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2863 | /* attempt to distribute budget to each queue fairly, but don't allow |
| 2864 | * the budget to go below 1 because we'll exit polling */ |
| 2865 | if (q_vector->rx.count > 1) |
| 2866 | per_ring_budget = max(budget/q_vector->rx.count, 1); |
| 2867 | else |
| 2868 | per_ring_budget = budget; |
| 2869 | |
Jesse Brandeburg | 32b3e08 | 2015-09-24 16:35:47 -0700 | [diff] [blame] | 2870 | ixgbe_for_each_ring(ring, q_vector->rx) { |
| 2871 | int cleaned = ixgbe_clean_rx_irq(q_vector, ring, |
| 2872 | per_ring_budget); |
| 2873 | |
| 2874 | work_done += cleaned; |
Alexander Duyck | 8220bbc | 2016-03-07 09:30:09 -0800 | [diff] [blame] | 2875 | if (cleaned >= per_ring_budget) |
| 2876 | clean_complete = false; |
Jesse Brandeburg | 32b3e08 | 2015-09-24 16:35:47 -0700 | [diff] [blame] | 2877 | } |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2878 | |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2879 | ixgbe_qv_unlock_napi(q_vector); |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2880 | /* If all work not completed, return budget and keep polling */ |
| 2881 | if (!clean_complete) |
| 2882 | return budget; |
| 2883 | |
| 2884 | /* all work done, exit the polling mode */ |
Jesse Brandeburg | 32b3e08 | 2015-09-24 16:35:47 -0700 | [diff] [blame] | 2885 | napi_complete_done(napi, work_done); |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2886 | if (adapter->rx_itr_setting & 1) |
| 2887 | ixgbe_set_itr(q_vector); |
| 2888 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 2889 | ixgbe_irq_enable_queues(adapter, BIT_ULL(q_vector->v_idx)); |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2890 | |
Paolo Abeni | 4b732cd | 2016-06-15 15:37:59 +0200 | [diff] [blame] | 2891 | return min(work_done, budget - 1); |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2892 | } |
| 2893 | |
| 2894 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2895 | * ixgbe_request_msix_irqs - Initialize MSI-X interrupts |
| 2896 | * @adapter: board private structure |
| 2897 | * |
| 2898 | * ixgbe_request_msix_irqs allocates MSI-X vectors and requests |
| 2899 | * interrupts from the kernel. |
| 2900 | **/ |
| 2901 | static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter) |
| 2902 | { |
| 2903 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2904 | int vector, err; |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2905 | int ri = 0, ti = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2906 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2907 | for (vector = 0; vector < adapter->num_q_vectors; vector++) { |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2908 | struct ixgbe_q_vector *q_vector = adapter->q_vector[vector]; |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2909 | struct msix_entry *entry = &adapter->msix_entries[vector]; |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 2910 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2911 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 2912 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2913 | "%s-%s-%d", netdev->name, "TxRx", ri++); |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2914 | ti++; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2915 | } else if (q_vector->rx.ring) { |
| 2916 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2917 | "%s-%s-%d", netdev->name, "rx", ri++); |
| 2918 | } else if (q_vector->tx.ring) { |
| 2919 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2920 | "%s-%s-%d", netdev->name, "tx", ti++); |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2921 | } else { |
| 2922 | /* skip this unused q_vector */ |
| 2923 | continue; |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2924 | } |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2925 | err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0, |
| 2926 | q_vector->name, q_vector); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2927 | if (err) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2928 | e_err(probe, "request_irq failed for MSIX interrupt " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 2929 | "Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2930 | goto free_queue_irqs; |
| 2931 | } |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2932 | /* If Flow Director is enabled, set interrupt affinity */ |
| 2933 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 2934 | /* assign the mask for this irq */ |
| 2935 | irq_set_affinity_hint(entry->vector, |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2936 | &q_vector->affinity_mask); |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2937 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2938 | } |
| 2939 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2940 | err = request_irq(adapter->msix_entries[vector].vector, |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2941 | ixgbe_msix_other, 0, netdev->name, adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2942 | if (err) { |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2943 | e_err(probe, "request_irq for msix_other failed: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2944 | goto free_queue_irqs; |
| 2945 | } |
| 2946 | |
| 2947 | return 0; |
| 2948 | |
| 2949 | free_queue_irqs: |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2950 | while (vector) { |
| 2951 | vector--; |
| 2952 | irq_set_affinity_hint(adapter->msix_entries[vector].vector, |
| 2953 | NULL); |
| 2954 | free_irq(adapter->msix_entries[vector].vector, |
| 2955 | adapter->q_vector[vector]); |
| 2956 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2957 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 2958 | pci_disable_msix(adapter->pdev); |
| 2959 | kfree(adapter->msix_entries); |
| 2960 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2961 | return err; |
| 2962 | } |
| 2963 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 2964 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2965 | * ixgbe_intr - legacy mode Interrupt Handler |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2966 | * @irq: interrupt number |
| 2967 | * @data: pointer to a network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2968 | **/ |
| 2969 | static irqreturn_t ixgbe_intr(int irq, void *data) |
| 2970 | { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2971 | struct ixgbe_adapter *adapter = data; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2972 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2973 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2974 | u32 eicr; |
| 2975 | |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 2976 | /* |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 2977 | * Workaround for silicon errata #26 on 82598. Mask the interrupt |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 2978 | * before the read of EICR. |
| 2979 | */ |
| 2980 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); |
| 2981 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2982 | /* 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] | 2983 | * therefore no explicit interrupt disable is necessary */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2984 | eicr = IXGBE_READ_REG(hw, IXGBE_EICR); |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2985 | if (!eicr) { |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2986 | /* |
| 2987 | * shared interrupt alert! |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2988 | * make sure interrupts are enabled because the read will |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2989 | * have disabled interrupts due to EIAM |
| 2990 | * finish the workaround of silicon errata on 82598. Unmask |
| 2991 | * the interrupt that we masked before the EICR read. |
| 2992 | */ |
| 2993 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2994 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2995 | return IRQ_NONE; /* Not our interrupt */ |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2996 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2997 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2998 | if (eicr & IXGBE_EICR_LSC) |
| 2999 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3000 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3001 | switch (hw->mac.type) { |
| 3002 | case ixgbe_mac_82599EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3003 | ixgbe_check_sfp_event(adapter, eicr); |
Don Skidmore | 0ccb974 | 2011-08-04 02:07:48 +0000 | [diff] [blame] | 3004 | /* Fall through */ |
| 3005 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 3006 | case ixgbe_mac_X550: |
| 3007 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 3008 | case ixgbe_mac_x550em_a: |
Don Skidmore | d773ce2 | 2014-02-25 17:58:53 -0800 | [diff] [blame] | 3009 | if (eicr & IXGBE_EICR_ECC) { |
| 3010 | e_info(link, "Received ECC Err, initiating reset\n"); |
Emil Tantilov | 57ca2a4 | 2016-07-29 14:46:31 -0700 | [diff] [blame] | 3011 | set_bit(__IXGBE_RESET_REQUESTED, &adapter->state); |
Don Skidmore | d773ce2 | 2014-02-25 17:58:53 -0800 | [diff] [blame] | 3012 | ixgbe_service_event_schedule(adapter); |
| 3013 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC); |
| 3014 | } |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 3015 | ixgbe_check_overtemp_event(adapter, eicr); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3016 | break; |
| 3017 | default: |
| 3018 | break; |
| 3019 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3020 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 3021 | ixgbe_check_fan_failure(adapter, eicr); |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 3022 | if (unlikely(eicr & IXGBE_EICR_TIMESYNC)) |
Mark Rustad | a9763f3 | 2015-10-27 09:58:07 -0700 | [diff] [blame] | 3023 | ixgbe_ptp_check_pps_event(adapter); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 3024 | |
Alexander Duyck | b9f6ed2 | 2012-02-08 07:49:54 +0000 | [diff] [blame] | 3025 | /* would disable interrupts here but EIAM disabled it */ |
Alexander Duyck | ef2662b | 2015-09-29 15:19:43 -0700 | [diff] [blame] | 3026 | napi_schedule_irqoff(&q_vector->napi); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3027 | |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 3028 | /* |
| 3029 | * re-enable link(maybe) and non-queue interrupts, no flush. |
| 3030 | * ixgbe_poll will re-enable the queue interrupts |
| 3031 | */ |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 3032 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 3033 | ixgbe_irq_enable(adapter, false, false); |
| 3034 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3035 | return IRQ_HANDLED; |
| 3036 | } |
| 3037 | |
| 3038 | /** |
| 3039 | * ixgbe_request_irq - initialize interrupts |
| 3040 | * @adapter: board private structure |
| 3041 | * |
| 3042 | * Attempts to configure interrupts using the best available |
| 3043 | * capabilities of the hardware and kernel. |
| 3044 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3045 | static int ixgbe_request_irq(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3046 | { |
| 3047 | struct net_device *netdev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3048 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3049 | |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 3050 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3051 | err = ixgbe_request_msix_irqs(adapter); |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 3052 | else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 3053 | err = request_irq(adapter->pdev->irq, ixgbe_intr, 0, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 3054 | netdev->name, adapter); |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 3055 | else |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 3056 | err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 3057 | netdev->name, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3058 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 3059 | if (err) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 3060 | e_err(probe, "request_irq failed, Error %d\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3061 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3062 | return err; |
| 3063 | } |
| 3064 | |
| 3065 | static void ixgbe_free_irq(struct ixgbe_adapter *adapter) |
| 3066 | { |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3067 | int vector; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3068 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3069 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 3070 | free_irq(adapter->pdev->irq, adapter); |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3071 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3072 | } |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3073 | |
Mark Rustad | 1fa7125 | 2016-09-28 15:36:38 -0700 | [diff] [blame] | 3074 | if (!adapter->msix_entries) |
| 3075 | return; |
| 3076 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3077 | for (vector = 0; vector < adapter->num_q_vectors; vector++) { |
| 3078 | struct ixgbe_q_vector *q_vector = adapter->q_vector[vector]; |
| 3079 | struct msix_entry *entry = &adapter->msix_entries[vector]; |
| 3080 | |
| 3081 | /* free only the irqs that were actually requested */ |
| 3082 | if (!q_vector->rx.ring && !q_vector->tx.ring) |
| 3083 | continue; |
| 3084 | |
| 3085 | /* clear the affinity_mask in the IRQ descriptor */ |
| 3086 | irq_set_affinity_hint(entry->vector, NULL); |
| 3087 | |
| 3088 | free_irq(entry->vector, q_vector); |
| 3089 | } |
| 3090 | |
Babu Moger | 90c6f87 | 2016-06-18 17:40:47 -0700 | [diff] [blame] | 3091 | free_irq(adapter->msix_entries[vector].vector, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3092 | } |
| 3093 | |
| 3094 | /** |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3095 | * ixgbe_irq_disable - Mask off interrupt generation on the NIC |
| 3096 | * @adapter: board private structure |
| 3097 | **/ |
| 3098 | static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter) |
| 3099 | { |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3100 | switch (adapter->hw.mac.type) { |
| 3101 | case ixgbe_mac_82598EB: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 3102 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3103 | break; |
| 3104 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3105 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 3106 | case ixgbe_mac_X550: |
| 3107 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 3108 | case ixgbe_mac_x550em_a: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 3109 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000); |
| 3110 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3111 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3112 | break; |
| 3113 | default: |
| 3114 | break; |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3115 | } |
| 3116 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 3117 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3118 | int vector; |
| 3119 | |
| 3120 | for (vector = 0; vector < adapter->num_q_vectors; vector++) |
| 3121 | synchronize_irq(adapter->msix_entries[vector].vector); |
| 3122 | |
| 3123 | synchronize_irq(adapter->msix_entries[vector++].vector); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3124 | } else { |
| 3125 | synchronize_irq(adapter->pdev->irq); |
| 3126 | } |
| 3127 | } |
| 3128 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3129 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3130 | * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts |
| 3131 | * |
| 3132 | **/ |
| 3133 | static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter) |
| 3134 | { |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 3135 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3136 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 3137 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3138 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3139 | ixgbe_set_ivar(adapter, 0, 0, 0); |
| 3140 | ixgbe_set_ivar(adapter, 1, 0, 0); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3141 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 3142 | e_info(hw, "Legacy interrupt IVAR setup done\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3143 | } |
| 3144 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3145 | /** |
| 3146 | * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset |
| 3147 | * @adapter: board private structure |
| 3148 | * @ring: structure containing ring specific data |
| 3149 | * |
| 3150 | * Configure the Tx descriptor ring after a reset. |
| 3151 | **/ |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 3152 | void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter, |
| 3153 | struct ixgbe_ring *ring) |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3154 | { |
| 3155 | struct ixgbe_hw *hw = &adapter->hw; |
| 3156 | u64 tdba = ring->dma; |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3157 | int wait_loop = 10; |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3158 | u32 txdctl = IXGBE_TXDCTL_ENABLE; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3159 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3160 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3161 | /* disable queue to avoid issues while updating state */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3162 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3163 | IXGBE_WRITE_FLUSH(hw); |
| 3164 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3165 | IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3166 | (tdba & DMA_BIT_MASK(32))); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3167 | IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32)); |
| 3168 | IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx), |
| 3169 | ring->count * sizeof(union ixgbe_adv_tx_desc)); |
| 3170 | IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0); |
| 3171 | IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 3172 | ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3173 | |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3174 | /* |
| 3175 | * set WTHRESH to encourage burst writeback, it should not be set |
Emil Tantilov | 67da097 | 2013-01-25 06:19:20 +0000 | [diff] [blame] | 3176 | * higher than 1 when: |
| 3177 | * - ITR is 0 as it could cause false TX hangs |
| 3178 | * - ITR is set to > 100k int/sec and BQL is enabled |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3179 | * |
| 3180 | * In order to avoid issues WTHRESH + PTHRESH should always be equal |
| 3181 | * to or less than the number of on chip descriptors, which is |
| 3182 | * currently 40. |
| 3183 | */ |
Emil Tantilov | 67da097 | 2013-01-25 06:19:20 +0000 | [diff] [blame] | 3184 | if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR)) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 3185 | txdctl |= 1u << 16; /* WTHRESH = 1 */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3186 | else |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 3187 | txdctl |= 8u << 16; /* WTHRESH = 8 */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3188 | |
Alexander Duyck | e954b37 | 2012-02-08 07:49:38 +0000 | [diff] [blame] | 3189 | /* |
| 3190 | * Setting PTHRESH to 32 both improves performance |
| 3191 | * and avoids a TX hang with DFP enabled |
| 3192 | */ |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 3193 | txdctl |= (1u << 8) | /* HTHRESH = 1 */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3194 | 32; /* PTHRESH = 32 */ |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3195 | |
| 3196 | /* reinitialize flowdirector state */ |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 3197 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 3198 | ring->atr_sample_rate = adapter->atr_sample_rate; |
| 3199 | ring->atr_count = 0; |
| 3200 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state); |
| 3201 | } else { |
| 3202 | ring->atr_sample_rate = 0; |
| 3203 | } |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3204 | |
Alexander Duyck | fd786b7 | 2013-01-12 06:33:31 +0000 | [diff] [blame] | 3205 | /* initialize XPS */ |
| 3206 | if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) { |
| 3207 | struct ixgbe_q_vector *q_vector = ring->q_vector; |
| 3208 | |
| 3209 | if (q_vector) |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 3210 | netif_set_xps_queue(ring->netdev, |
Alexander Duyck | fd786b7 | 2013-01-12 06:33:31 +0000 | [diff] [blame] | 3211 | &q_vector->affinity_mask, |
| 3212 | ring->queue_index); |
| 3213 | } |
| 3214 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 3215 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state); |
| 3216 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3217 | /* enable queue */ |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3218 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl); |
| 3219 | |
| 3220 | /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 3221 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 3222 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 3223 | return; |
| 3224 | |
| 3225 | /* poll to verify queue is enabled */ |
| 3226 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 3227 | usleep_range(1000, 2000); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3228 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx)); |
| 3229 | } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE)); |
| 3230 | if (!wait_loop) |
Emil Tantilov | a55defd | 2016-07-29 10:30:06 -0700 | [diff] [blame] | 3231 | hw_dbg(hw, "Could not enable Tx Queue %d\n", reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3232 | } |
| 3233 | |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 3234 | static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter) |
| 3235 | { |
| 3236 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3237 | u32 rttdcs, mtqc; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3238 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 3239 | |
| 3240 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3241 | return; |
| 3242 | |
| 3243 | /* disable the arbiter while setting MTQC */ |
| 3244 | rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS); |
| 3245 | rttdcs |= IXGBE_RTTDCS_ARBDIS; |
| 3246 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 3247 | |
| 3248 | /* set transmit pool layout */ |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3249 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 3250 | mtqc = IXGBE_MTQC_VT_ENA; |
| 3251 | if (tcs > 4) |
| 3252 | mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ; |
| 3253 | else if (tcs > 1) |
| 3254 | mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ; |
Alexander Duyck | e24fcf2 | 2016-09-07 20:28:24 -0700 | [diff] [blame] | 3255 | else if (adapter->ring_feature[RING_F_VMDQ].mask == |
| 3256 | IXGBE_82599_VMDQ_4Q_MASK) |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3257 | mtqc |= IXGBE_MTQC_32VF; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3258 | else |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3259 | mtqc |= IXGBE_MTQC_64VF; |
| 3260 | } else { |
| 3261 | if (tcs > 4) |
| 3262 | mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ; |
| 3263 | else if (tcs > 1) |
| 3264 | mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ; |
| 3265 | else |
| 3266 | mtqc = IXGBE_MTQC_64Q_1PB; |
| 3267 | } |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3268 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3269 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3270 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3271 | /* Enable Security TX Buffer IFG for multiple pb */ |
| 3272 | if (tcs) { |
| 3273 | u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG); |
| 3274 | sectx |= IXGBE_SECTX_DCB; |
| 3275 | IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx); |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 3276 | } |
| 3277 | |
| 3278 | /* re-enable the arbiter */ |
| 3279 | rttdcs &= ~IXGBE_RTTDCS_ARBDIS; |
| 3280 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 3281 | } |
| 3282 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3283 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3284 | * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3285 | * @adapter: board private structure |
| 3286 | * |
| 3287 | * Configure the Tx unit of the MAC after a reset. |
| 3288 | **/ |
| 3289 | static void ixgbe_configure_tx(struct ixgbe_adapter *adapter) |
| 3290 | { |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3291 | struct ixgbe_hw *hw = &adapter->hw; |
| 3292 | u32 dmatxctl; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3293 | u32 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3294 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3295 | ixgbe_setup_mtqc(adapter); |
| 3296 | |
| 3297 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 3298 | /* DMATXCTL.EN must be before Tx queues are enabled */ |
| 3299 | dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); |
| 3300 | dmatxctl |= IXGBE_DMATXCTL_TE; |
| 3301 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl); |
| 3302 | } |
| 3303 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3304 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3305 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 3306 | ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3307 | } |
| 3308 | |
Alexander Duyck | 3ebe8fd | 2012-04-25 04:36:38 +0000 | [diff] [blame] | 3309 | static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter, |
| 3310 | struct ixgbe_ring *ring) |
| 3311 | { |
| 3312 | struct ixgbe_hw *hw = &adapter->hw; |
| 3313 | u8 reg_idx = ring->reg_idx; |
| 3314 | u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx)); |
| 3315 | |
| 3316 | srrctl |= IXGBE_SRRCTL_DROP_EN; |
| 3317 | |
| 3318 | IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl); |
| 3319 | } |
| 3320 | |
| 3321 | static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter, |
| 3322 | struct ixgbe_ring *ring) |
| 3323 | { |
| 3324 | struct ixgbe_hw *hw = &adapter->hw; |
| 3325 | u8 reg_idx = ring->reg_idx; |
| 3326 | u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx)); |
| 3327 | |
| 3328 | srrctl &= ~IXGBE_SRRCTL_DROP_EN; |
| 3329 | |
| 3330 | IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl); |
| 3331 | } |
| 3332 | |
| 3333 | #ifdef CONFIG_IXGBE_DCB |
| 3334 | void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter) |
| 3335 | #else |
| 3336 | static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter) |
| 3337 | #endif |
| 3338 | { |
| 3339 | int i; |
| 3340 | bool pfc_en = adapter->dcb_cfg.pfc_mode_enable; |
| 3341 | |
| 3342 | if (adapter->ixgbe_ieee_pfc) |
| 3343 | pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en); |
| 3344 | |
| 3345 | /* |
| 3346 | * We should set the drop enable bit if: |
| 3347 | * SR-IOV is enabled |
| 3348 | * or |
| 3349 | * Number of Rx queues > 1 and flow control is disabled |
| 3350 | * |
| 3351 | * This allows us to avoid head of line blocking for security |
| 3352 | * and performance reasons. |
| 3353 | */ |
| 3354 | if (adapter->num_vfs || (adapter->num_rx_queues > 1 && |
| 3355 | !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) { |
| 3356 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3357 | ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]); |
| 3358 | } else { |
| 3359 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3360 | ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]); |
| 3361 | } |
| 3362 | } |
| 3363 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3364 | #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3365 | |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 3366 | static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3367 | struct ixgbe_ring *rx_ring) |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3368 | { |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3369 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3370 | u32 srrctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3371 | u8 reg_idx = rx_ring->reg_idx; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3372 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3373 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 3374 | u16 mask = adapter->ring_feature[RING_F_RSS].mask; |
| 3375 | |
| 3376 | /* |
| 3377 | * if VMDq is not active we must program one srrctl register |
| 3378 | * per RSS queue since we have enabled RDRXCTL.MVMEN |
| 3379 | */ |
| 3380 | reg_idx &= mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3381 | } |
| 3382 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3383 | /* configure header buffer length, needed for RSC */ |
| 3384 | srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3385 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3386 | /* configure the packet buffer length */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 3387 | srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3388 | |
| 3389 | /* configure descriptor type */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 3390 | srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3391 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3392 | IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3393 | } |
| 3394 | |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3395 | /** |
Jean Sacren | a897a2a | 2015-09-19 05:08:44 -0600 | [diff] [blame] | 3396 | * ixgbe_rss_indir_tbl_entries - Return RSS indirection table entries |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3397 | * @adapter: device handle |
| 3398 | * |
| 3399 | * - 82598/82599/X540: 128 |
| 3400 | * - X550(non-SRIOV mode): 512 |
| 3401 | * - X550(SRIOV mode): 64 |
| 3402 | */ |
Vlad Zolotarov | 7f276ef | 2015-03-30 21:18:58 +0300 | [diff] [blame] | 3403 | u32 ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3404 | { |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3405 | if (adapter->hw.mac.type < ixgbe_mac_X550) |
| 3406 | return 128; |
| 3407 | else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 3408 | return 64; |
| 3409 | else |
| 3410 | return 512; |
| 3411 | } |
| 3412 | |
| 3413 | /** |
Jean Sacren | a897a2a | 2015-09-19 05:08:44 -0600 | [diff] [blame] | 3414 | * ixgbe_store_reta - Write the RETA table to HW |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3415 | * @adapter: device handle |
| 3416 | * |
| 3417 | * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW. |
| 3418 | */ |
Tom Barbette | 1c7cf07 | 2015-06-26 15:40:18 +0200 | [diff] [blame] | 3419 | void ixgbe_store_reta(struct ixgbe_adapter *adapter) |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3420 | { |
| 3421 | u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter); |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3422 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3423 | u32 reta = 0; |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3424 | u32 indices_multi; |
| 3425 | u8 *indir_tbl = adapter->rss_indir_tbl; |
John Fastabend | 86b4db3 | 2011-04-26 07:26:19 +0000 | [diff] [blame] | 3426 | |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3427 | /* Fill out the redirection table as follows: |
| 3428 | * - 82598: 8 bit wide entries containing pair of 4 bit RSS |
| 3429 | * indices. |
| 3430 | * - 82599/X540: 8 bit wide entries containing 4 bit RSS index |
| 3431 | * - X550: 8 bit wide entries containing 6 bit RSS index |
| 3432 | */ |
| 3433 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 3434 | indices_multi = 0x11; |
| 3435 | else |
| 3436 | indices_multi = 0x1; |
| 3437 | |
| 3438 | /* Write redirection table to HW */ |
| 3439 | for (i = 0; i < reta_entries; i++) { |
| 3440 | reta |= indices_multi * indir_tbl[i] << (i & 0x3) * 8; |
| 3441 | if ((i & 3) == 3) { |
| 3442 | if (i < 128) |
| 3443 | IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); |
| 3444 | else |
| 3445 | IXGBE_WRITE_REG(hw, IXGBE_ERETA((i >> 2) - 32), |
| 3446 | reta); |
| 3447 | reta = 0; |
| 3448 | } |
| 3449 | } |
| 3450 | } |
| 3451 | |
| 3452 | /** |
Jean Sacren | a897a2a | 2015-09-19 05:08:44 -0600 | [diff] [blame] | 3453 | * ixgbe_store_vfreta - Write the RETA table to HW (x550 devices in SRIOV mode) |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3454 | * @adapter: device handle |
| 3455 | * |
| 3456 | * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW. |
| 3457 | */ |
| 3458 | static void ixgbe_store_vfreta(struct ixgbe_adapter *adapter) |
| 3459 | { |
| 3460 | u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter); |
| 3461 | struct ixgbe_hw *hw = &adapter->hw; |
| 3462 | u32 vfreta = 0; |
| 3463 | unsigned int pf_pool = adapter->num_vfs; |
| 3464 | |
| 3465 | /* Write redirection table to HW */ |
| 3466 | for (i = 0; i < reta_entries; i++) { |
| 3467 | vfreta |= (u32)adapter->rss_indir_tbl[i] << (i & 0x3) * 8; |
| 3468 | if ((i & 3) == 3) { |
| 3469 | IXGBE_WRITE_REG(hw, IXGBE_PFVFRETA(i >> 2, pf_pool), |
| 3470 | vfreta); |
| 3471 | vfreta = 0; |
| 3472 | } |
| 3473 | } |
| 3474 | } |
| 3475 | |
| 3476 | static void ixgbe_setup_reta(struct ixgbe_adapter *adapter) |
| 3477 | { |
| 3478 | struct ixgbe_hw *hw = &adapter->hw; |
| 3479 | u32 i, j; |
| 3480 | u32 reta_entries = ixgbe_rss_indir_tbl_entries(adapter); |
| 3481 | u16 rss_i = adapter->ring_feature[RING_F_RSS].indices; |
| 3482 | |
Alexander Duyck | e24fcf2 | 2016-09-07 20:28:24 -0700 | [diff] [blame] | 3483 | /* Program table for at least 4 queues w/ SR-IOV so that VFs can |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3484 | * make full use of any rings they may have. We will use the |
| 3485 | * PSRTYPE register to control how many rings we use within the PF. |
| 3486 | */ |
Alexander Duyck | e24fcf2 | 2016-09-07 20:28:24 -0700 | [diff] [blame] | 3487 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 4)) |
| 3488 | rss_i = 4; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3489 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3490 | /* Fill out hash function seeds */ |
| 3491 | for (i = 0; i < 10; i++) |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3492 | IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), adapter->rss_key[i]); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3493 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3494 | /* Fill out redirection table */ |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3495 | memset(adapter->rss_indir_tbl, 0, sizeof(adapter->rss_indir_tbl)); |
| 3496 | |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3497 | for (i = 0, j = 0; i < reta_entries; i++, j++) { |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3498 | if (j == rss_i) |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3499 | j = 0; |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3500 | |
| 3501 | adapter->rss_indir_tbl[i] = j; |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3502 | } |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3503 | |
| 3504 | ixgbe_store_reta(adapter); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3505 | } |
| 3506 | |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3507 | static void ixgbe_setup_vfreta(struct ixgbe_adapter *adapter) |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3508 | { |
| 3509 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3510 | u16 rss_i = adapter->ring_feature[RING_F_RSS].indices; |
| 3511 | unsigned int pf_pool = adapter->num_vfs; |
| 3512 | int i, j; |
| 3513 | |
| 3514 | /* Fill out hash function seeds */ |
| 3515 | for (i = 0; i < 10; i++) |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3516 | IXGBE_WRITE_REG(hw, IXGBE_PFVFRSSRK(i, pf_pool), |
| 3517 | adapter->rss_key[i]); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3518 | |
| 3519 | /* Fill out the redirection table */ |
| 3520 | for (i = 0, j = 0; i < 64; i++, j++) { |
| 3521 | if (j == rss_i) |
| 3522 | j = 0; |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3523 | |
| 3524 | adapter->rss_indir_tbl[i] = j; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3525 | } |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3526 | |
| 3527 | ixgbe_store_vfreta(adapter); |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3528 | } |
| 3529 | |
| 3530 | static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter) |
| 3531 | { |
| 3532 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3533 | u32 mrqc = 0, rss_field = 0, vfmrqc = 0; |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3534 | u32 rxcsum; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3535 | |
| 3536 | /* Disable indicating checksum in descriptor, enables RSS hash */ |
| 3537 | rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); |
| 3538 | rxcsum |= IXGBE_RXCSUM_PCSD; |
| 3539 | IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); |
| 3540 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3541 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 3542 | if (adapter->ring_feature[RING_F_RSS].mask) |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3543 | mrqc = IXGBE_MRQC_RSSEN; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3544 | } else { |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3545 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3546 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3547 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 3548 | if (tcs > 4) |
| 3549 | mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */ |
| 3550 | else if (tcs > 1) |
| 3551 | mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */ |
Alexander Duyck | e24fcf2 | 2016-09-07 20:28:24 -0700 | [diff] [blame] | 3552 | else if (adapter->ring_feature[RING_F_VMDQ].mask == |
| 3553 | IXGBE_82599_VMDQ_4Q_MASK) |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3554 | mrqc = IXGBE_MRQC_VMDQRSS32EN; |
| 3555 | else |
| 3556 | mrqc = IXGBE_MRQC_VMDQRSS64EN; |
| 3557 | } else { |
| 3558 | if (tcs > 4) |
| 3559 | mrqc = IXGBE_MRQC_RTRSS8TCEN; |
| 3560 | else if (tcs > 1) |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3561 | mrqc = IXGBE_MRQC_RTRSS4TCEN; |
| 3562 | else |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3563 | mrqc = IXGBE_MRQC_RSSEN; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3564 | } |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3565 | } |
| 3566 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3567 | /* Perform hash on these packet types */ |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3568 | rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4 | |
| 3569 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP | |
| 3570 | IXGBE_MRQC_RSS_FIELD_IPV6 | |
| 3571 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3572 | |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 3573 | if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP) |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3574 | rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP; |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 3575 | if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP) |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3576 | rss_field |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP; |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 3577 | |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3578 | netdev_rss_key_fill(adapter->rss_key, sizeof(adapter->rss_key)); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3579 | if ((hw->mac.type >= ixgbe_mac_X550) && |
| 3580 | (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) { |
| 3581 | unsigned int pf_pool = adapter->num_vfs; |
| 3582 | |
| 3583 | /* Enable VF RSS mode */ |
| 3584 | mrqc |= IXGBE_MRQC_MULTIPLE_RSS; |
| 3585 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
| 3586 | |
| 3587 | /* Setup RSS through the VF registers */ |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3588 | ixgbe_setup_vfreta(adapter); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3589 | vfmrqc = IXGBE_MRQC_RSSEN; |
| 3590 | vfmrqc |= rss_field; |
| 3591 | IXGBE_WRITE_REG(hw, IXGBE_PFVFMRQC(pf_pool), vfmrqc); |
| 3592 | } else { |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3593 | ixgbe_setup_reta(adapter); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3594 | mrqc |= rss_field; |
| 3595 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
| 3596 | } |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3597 | } |
| 3598 | |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3599 | /** |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3600 | * ixgbe_configure_rscctl - enable RSC for the indicated ring |
| 3601 | * @adapter: address of board private structure |
| 3602 | * @index: index of ring to set |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3603 | **/ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 3604 | static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3605 | struct ixgbe_ring *ring) |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3606 | { |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3607 | struct ixgbe_hw *hw = &adapter->hw; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3608 | u32 rscctrl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3609 | u8 reg_idx = ring->reg_idx; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3610 | |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3611 | if (!ring_is_rsc_enabled(ring)) |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3612 | return; |
| 3613 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3614 | rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx)); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3615 | rscctrl |= IXGBE_RSCCTL_RSCEN; |
| 3616 | /* |
| 3617 | * we must limit the number of descriptors so that the |
| 3618 | * total size of max desc * buf_len is not greater |
Alexander Duyck | 642c680 | 2011-11-10 09:09:17 +0000 | [diff] [blame] | 3619 | * than 65536 |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3620 | */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 3621 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3622 | IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3623 | } |
| 3624 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3625 | #define IXGBE_MAX_RX_DESC_POLL 10 |
| 3626 | static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter, |
| 3627 | struct ixgbe_ring *ring) |
| 3628 | { |
| 3629 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3630 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 3631 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3632 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3633 | |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 3634 | if (ixgbe_removed(hw->hw_addr)) |
| 3635 | return; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3636 | /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 3637 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 3638 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 3639 | return; |
| 3640 | |
| 3641 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 3642 | usleep_range(1000, 2000); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3643 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 3644 | } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 3645 | |
| 3646 | if (!wait_loop) { |
| 3647 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within " |
| 3648 | "the polling period\n", reg_idx); |
| 3649 | } |
| 3650 | } |
| 3651 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 3652 | void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter, |
| 3653 | struct ixgbe_ring *ring) |
| 3654 | { |
| 3655 | struct ixgbe_hw *hw = &adapter->hw; |
| 3656 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 3657 | u32 rxdctl; |
| 3658 | u8 reg_idx = ring->reg_idx; |
| 3659 | |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 3660 | if (ixgbe_removed(hw->hw_addr)) |
| 3661 | return; |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 3662 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 3663 | rxdctl &= ~IXGBE_RXDCTL_ENABLE; |
| 3664 | |
| 3665 | /* write value back with RXDCTL.ENABLE bit cleared */ |
| 3666 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 3667 | |
| 3668 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 3669 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 3670 | return; |
| 3671 | |
| 3672 | /* the hardware may take up to 100us to really disable the rx queue */ |
| 3673 | do { |
| 3674 | udelay(10); |
| 3675 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 3676 | } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 3677 | |
| 3678 | if (!wait_loop) { |
| 3679 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within " |
| 3680 | "the polling period\n", reg_idx); |
| 3681 | } |
| 3682 | } |
| 3683 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 3684 | void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter, |
| 3685 | struct ixgbe_ring *ring) |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3686 | { |
| 3687 | struct ixgbe_hw *hw = &adapter->hw; |
| 3688 | u64 rdba = ring->dma; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3689 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3690 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3691 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3692 | /* disable queue to avoid issues while updating state */ |
| 3693 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 3694 | ixgbe_disable_rx_queue(adapter, ring); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3695 | |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3696 | IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32))); |
| 3697 | IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32)); |
| 3698 | IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx), |
| 3699 | ring->count * sizeof(union ixgbe_adv_rx_desc)); |
Neerav Parikh | 8b75451 | 2015-12-08 22:13:58 -0800 | [diff] [blame] | 3700 | /* Force flushing of IXGBE_RDLEN to prevent MDD */ |
| 3701 | IXGBE_WRITE_FLUSH(hw); |
| 3702 | |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3703 | IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0); |
| 3704 | IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 3705 | ring->tail = adapter->io_addr + IXGBE_RDT(reg_idx); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3706 | |
| 3707 | ixgbe_configure_srrctl(adapter, ring); |
| 3708 | ixgbe_configure_rscctl(adapter, ring); |
| 3709 | |
| 3710 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 3711 | /* |
| 3712 | * enable cache line friendly hardware writes: |
| 3713 | * PTHRESH=32 descriptors (half the internal cache), |
| 3714 | * this also removes ugly rx_no_buffer_count increment |
| 3715 | * HTHRESH=4 descriptors (to minimize latency on fetch) |
| 3716 | * WTHRESH=8 burst writeback up to two cache lines |
| 3717 | */ |
| 3718 | rxdctl &= ~0x3FFFFF; |
| 3719 | rxdctl |= 0x080420; |
| 3720 | } |
| 3721 | |
| 3722 | /* enable receive descriptor ring */ |
| 3723 | rxdctl |= IXGBE_RXDCTL_ENABLE; |
| 3724 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 3725 | |
| 3726 | ixgbe_rx_desc_queue_enable(adapter, ring); |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 3727 | ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring)); |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3728 | } |
| 3729 | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3730 | static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter) |
| 3731 | { |
| 3732 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 3733 | int rss_i = adapter->ring_feature[RING_F_RSS].indices; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 3734 | u16 pool; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3735 | |
| 3736 | /* PSRTYPE must be initialized in non 82598 adapters */ |
| 3737 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3738 | IXGBE_PSRTYPE_UDPHDR | |
| 3739 | IXGBE_PSRTYPE_IPV4HDR | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3740 | IXGBE_PSRTYPE_L2HDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3741 | IXGBE_PSRTYPE_IPV6HDR; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3742 | |
| 3743 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3744 | return; |
| 3745 | |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 3746 | if (rss_i > 3) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 3747 | psrtype |= 2u << 29; |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 3748 | else if (rss_i > 1) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 3749 | psrtype |= 1u << 29; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3750 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 3751 | for_each_set_bit(pool, &adapter->fwd_bitmask, 32) |
| 3752 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype); |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3753 | } |
| 3754 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3755 | static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter) |
| 3756 | { |
| 3757 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3758 | u32 reg_offset, vf_shift; |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3759 | u32 gcr_ext, vmdctl; |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 3760 | int i; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3761 | |
| 3762 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 3763 | return; |
| 3764 | |
| 3765 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL); |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3766 | vmdctl |= IXGBE_VMD_CTL_VMDQ_EN; |
| 3767 | vmdctl &= ~IXGBE_VT_CTL_POOL_MASK; |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3768 | vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT; |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3769 | vmdctl |= IXGBE_VT_CTL_REPLEN; |
| 3770 | IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3771 | |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3772 | vf_shift = VMDQ_P(0) % 32; |
| 3773 | reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3774 | |
| 3775 | /* Enable only the PF's pool for Tx/Rx */ |
Emil Tantilov | 11f2b49 | 2016-05-04 15:01:27 -0700 | [diff] [blame] | 3776 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), GENMASK(31, vf_shift)); |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3777 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1); |
Emil Tantilov | 11f2b49 | 2016-05-04 15:01:27 -0700 | [diff] [blame] | 3778 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), GENMASK(31, vf_shift)); |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3779 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1); |
Don Skidmore | aa2bacb | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 3780 | if (adapter->bridge_mode == BRIDGE_MODE_VEB) |
Greg Rose | 9b73598 | 2012-11-08 02:41:35 +0000 | [diff] [blame] | 3781 | IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3782 | |
| 3783 | /* 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] | 3784 | hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0)); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3785 | |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 3786 | /* clear VLAN promisc flag so VFTA will be updated if necessary */ |
| 3787 | adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC; |
| 3788 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3789 | /* |
| 3790 | * Set up VF register offsets for selected VT Mode, |
| 3791 | * i.e. 32 or 64 VFs for SR-IOV |
| 3792 | */ |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 3793 | switch (adapter->ring_feature[RING_F_VMDQ].mask) { |
| 3794 | case IXGBE_82599_VMDQ_8Q_MASK: |
| 3795 | gcr_ext = IXGBE_GCR_EXT_VT_MODE_16; |
| 3796 | break; |
| 3797 | case IXGBE_82599_VMDQ_4Q_MASK: |
| 3798 | gcr_ext = IXGBE_GCR_EXT_VT_MODE_32; |
| 3799 | break; |
| 3800 | default: |
| 3801 | gcr_ext = IXGBE_GCR_EXT_VT_MODE_64; |
| 3802 | break; |
| 3803 | } |
| 3804 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3805 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext); |
| 3806 | |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 3807 | for (i = 0; i < adapter->num_vfs; i++) { |
Emil Tantilov | 77f192a | 2016-03-18 16:11:14 -0700 | [diff] [blame] | 3808 | /* configure spoof checking */ |
| 3809 | ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, |
| 3810 | adapter->vfinfo[i].spoofchk_enabled); |
Vlad Zolotarov | e65ce0d | 2015-03-30 21:35:24 +0300 | [diff] [blame] | 3811 | |
| 3812 | /* Enable/Disable RSS query feature */ |
| 3813 | ixgbe_ndo_set_vf_rss_query_en(adapter->netdev, i, |
| 3814 | adapter->vfinfo[i].rss_query_enabled); |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 3815 | } |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3816 | } |
| 3817 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3818 | static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3819 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3820 | struct ixgbe_hw *hw = &adapter->hw; |
| 3821 | struct net_device *netdev = adapter->netdev; |
| 3822 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3823 | struct ixgbe_ring *rx_ring; |
| 3824 | int i; |
| 3825 | u32 mhadd, hlreg0; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3826 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3827 | #ifdef IXGBE_FCOE |
| 3828 | /* adjust max frame to be able to do baby jumbo for FCoE */ |
| 3829 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 3830 | (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE)) |
| 3831 | max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 3832 | |
| 3833 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 3834 | |
| 3835 | /* adjust max frame to be at least the size of a standard frame */ |
| 3836 | if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN)) |
| 3837 | max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN); |
| 3838 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3839 | mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD); |
| 3840 | if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) { |
| 3841 | mhadd &= ~IXGBE_MHADD_MFS_MASK; |
| 3842 | mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT; |
| 3843 | |
| 3844 | IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3845 | } |
| 3846 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3847 | hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3848 | /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */ |
| 3849 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3850 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0); |
| 3851 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3852 | /* |
| 3853 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3854 | * the Base and Length of the Rx Descriptor Ring |
| 3855 | */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3856 | for (i = 0; i < adapter->num_rx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3857 | rx_ring = adapter->rx_ring[i]; |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3858 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
| 3859 | set_ring_rsc_enabled(rx_ring); |
| 3860 | else |
| 3861 | clear_ring_rsc_enabled(rx_ring); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3862 | } |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3863 | } |
| 3864 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3865 | static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter) |
| 3866 | { |
| 3867 | struct ixgbe_hw *hw = &adapter->hw; |
| 3868 | u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 3869 | |
| 3870 | switch (hw->mac.type) { |
| 3871 | case ixgbe_mac_82598EB: |
| 3872 | /* |
| 3873 | * For VMDq support of different descriptor types or |
| 3874 | * buffer sizes through the use of multiple SRRCTL |
| 3875 | * registers, RDRXCTL.MVMEN must be set to 1 |
| 3876 | * |
| 3877 | * also, the manual doesn't mention it clearly but DCA hints |
| 3878 | * will only use queue 0's tags unless this bit is set. Side |
| 3879 | * effects of setting this bit are only that SRRCTL must be |
| 3880 | * fully programmed [0..15] |
| 3881 | */ |
| 3882 | rdrxctl |= IXGBE_RDRXCTL_MVMEN; |
| 3883 | break; |
Mark Rustad | 052a1a7 | 2015-08-08 16:19:04 -0700 | [diff] [blame] | 3884 | case ixgbe_mac_X550: |
| 3885 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 3886 | case ixgbe_mac_x550em_a: |
Mark Rustad | f961dda | 2015-08-08 16:19:09 -0700 | [diff] [blame] | 3887 | if (adapter->num_vfs) |
| 3888 | rdrxctl |= IXGBE_RDRXCTL_PSP; |
| 3889 | /* fall through for older HW */ |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3890 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3891 | case ixgbe_mac_X540: |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3892 | /* Disable RSC for ACK packets */ |
| 3893 | IXGBE_WRITE_REG(hw, IXGBE_RSCDBU, |
| 3894 | (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU))); |
| 3895 | rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE; |
| 3896 | /* hardware requires some bits to be set by default */ |
| 3897 | rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX); |
| 3898 | rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP; |
| 3899 | break; |
| 3900 | default: |
| 3901 | /* We should do nothing since we don't know this hardware */ |
| 3902 | return; |
| 3903 | } |
| 3904 | |
| 3905 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
| 3906 | } |
| 3907 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3908 | /** |
| 3909 | * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset |
| 3910 | * @adapter: board private structure |
| 3911 | * |
| 3912 | * Configure the Rx unit of the MAC after a reset. |
| 3913 | **/ |
| 3914 | static void ixgbe_configure_rx(struct ixgbe_adapter *adapter) |
| 3915 | { |
| 3916 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3917 | int i; |
Jacob Keller | 6dcc28b | 2013-07-17 02:53:23 +0000 | [diff] [blame] | 3918 | u32 rxctrl, rfctl; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3919 | |
| 3920 | /* disable receives while setting up the descriptors */ |
Don Skidmore | 1f9ac57 | 2015-03-13 13:54:30 -0700 | [diff] [blame] | 3921 | hw->mac.ops.disable_rx(hw); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3922 | |
| 3923 | ixgbe_setup_psrtype(adapter); |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3924 | ixgbe_setup_rdrxctl(adapter); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3925 | |
Jacob Keller | 6dcc28b | 2013-07-17 02:53:23 +0000 | [diff] [blame] | 3926 | /* RSC Setup */ |
| 3927 | rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL); |
| 3928 | rfctl &= ~IXGBE_RFCTL_RSC_DIS; |
| 3929 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) |
| 3930 | rfctl |= IXGBE_RFCTL_RSC_DIS; |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 3931 | |
| 3932 | /* disable NFS filtering */ |
| 3933 | rfctl |= (IXGBE_RFCTL_NFSW_DIS | IXGBE_RFCTL_NFSR_DIS); |
Jacob Keller | 6dcc28b | 2013-07-17 02:53:23 +0000 | [diff] [blame] | 3934 | IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl); |
| 3935 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3936 | /* Program registers for the distribution of queues */ |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3937 | ixgbe_setup_mrqc(adapter); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3938 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3939 | /* set_rx_buffer_len must be called before ring initialization */ |
| 3940 | ixgbe_set_rx_buffer_len(adapter); |
| 3941 | |
| 3942 | /* |
| 3943 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3944 | * the Base and Length of the Rx Descriptor Ring |
| 3945 | */ |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3946 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3947 | ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3948 | |
Don Skidmore | 1f9ac57 | 2015-03-13 13:54:30 -0700 | [diff] [blame] | 3949 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3950 | /* disable drop enable for 82598 parts */ |
| 3951 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3952 | rxctrl |= IXGBE_RXCTRL_DMBYPS; |
| 3953 | |
| 3954 | /* enable all receives */ |
| 3955 | rxctrl |= IXGBE_RXCTRL_RXEN; |
| 3956 | hw->mac.ops.enable_rx_dma(hw, rxctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3957 | } |
| 3958 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 3959 | static int ixgbe_vlan_rx_add_vid(struct net_device *netdev, |
| 3960 | __be16 proto, u16 vid) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3961 | { |
| 3962 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3963 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3964 | |
| 3965 | /* add VID to filter table */ |
Alexander Duyck | 18be4fc | 2016-01-06 22:48:44 -0800 | [diff] [blame] | 3966 | if (!vid || !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)) |
| 3967 | hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true, !!vid); |
| 3968 | |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3969 | set_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 3970 | |
| 3971 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3972 | } |
| 3973 | |
Alexander Duyck | e1d0a2a | 2015-11-02 17:10:19 -0800 | [diff] [blame] | 3974 | static int ixgbe_find_vlvf_entry(struct ixgbe_hw *hw, u32 vlan) |
| 3975 | { |
| 3976 | u32 vlvf; |
| 3977 | int idx; |
| 3978 | |
| 3979 | /* short cut the special case */ |
| 3980 | if (vlan == 0) |
| 3981 | return 0; |
| 3982 | |
| 3983 | /* Search for the vlan id in the VLVF entries */ |
| 3984 | for (idx = IXGBE_VLVF_ENTRIES; --idx;) { |
| 3985 | vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(idx)); |
| 3986 | if ((vlvf & VLAN_VID_MASK) == vlan) |
| 3987 | break; |
| 3988 | } |
| 3989 | |
| 3990 | return idx; |
| 3991 | } |
| 3992 | |
| 3993 | void ixgbe_update_pf_promisc_vlvf(struct ixgbe_adapter *adapter, u32 vid) |
| 3994 | { |
| 3995 | struct ixgbe_hw *hw = &adapter->hw; |
| 3996 | u32 bits, word; |
| 3997 | int idx; |
| 3998 | |
| 3999 | idx = ixgbe_find_vlvf_entry(hw, vid); |
| 4000 | if (!idx) |
| 4001 | return; |
| 4002 | |
| 4003 | /* See if any other pools are set for this VLAN filter |
| 4004 | * entry other than the PF. |
| 4005 | */ |
| 4006 | word = idx * 2 + (VMDQ_P(0) / 32); |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 4007 | bits = ~BIT(VMDQ_P(0) % 32); |
Alexander Duyck | e1d0a2a | 2015-11-02 17:10:19 -0800 | [diff] [blame] | 4008 | bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word)); |
| 4009 | |
| 4010 | /* Disable the filter so this falls into the default pool. */ |
| 4011 | if (!bits && !IXGBE_READ_REG(hw, IXGBE_VLVFB(word ^ 1))) { |
| 4012 | if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)) |
| 4013 | IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), 0); |
| 4014 | IXGBE_WRITE_REG(hw, IXGBE_VLVF(idx), 0); |
| 4015 | } |
| 4016 | } |
| 4017 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 4018 | static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev, |
| 4019 | __be16 proto, u16 vid) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4020 | { |
| 4021 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4022 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4023 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4024 | /* remove VID from filter table */ |
Alexander Duyck | 18be4fc | 2016-01-06 22:48:44 -0800 | [diff] [blame] | 4025 | if (vid && !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)) |
Alexander Duyck | e1d0a2a | 2015-11-02 17:10:19 -0800 | [diff] [blame] | 4026 | hw->mac.ops.set_vfta(hw, vid, VMDQ_P(0), false, true); |
| 4027 | |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4028 | clear_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 4029 | |
| 4030 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4031 | } |
| 4032 | |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4033 | /** |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4034 | * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping |
| 4035 | * @adapter: driver data |
| 4036 | */ |
| 4037 | static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter) |
| 4038 | { |
| 4039 | struct ixgbe_hw *hw = &adapter->hw; |
| 4040 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4041 | int i, j; |
| 4042 | |
| 4043 | switch (hw->mac.type) { |
| 4044 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4045 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 4046 | vlnctrl &= ~IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4047 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4048 | break; |
| 4049 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4050 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 4051 | case ixgbe_mac_X550: |
| 4052 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 4053 | case ixgbe_mac_x550em_a: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4054 | for (i = 0; i < adapter->num_rx_queues; i++) { |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4055 | struct ixgbe_ring *ring = adapter->rx_ring[i]; |
| 4056 | |
| 4057 | if (ring->l2_accel_priv) |
| 4058 | continue; |
| 4059 | j = ring->reg_idx; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4060 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 4061 | vlnctrl &= ~IXGBE_RXDCTL_VME; |
| 4062 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 4063 | } |
| 4064 | break; |
| 4065 | default: |
| 4066 | break; |
| 4067 | } |
| 4068 | } |
| 4069 | |
| 4070 | /** |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4071 | * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4072 | * @adapter: driver data |
| 4073 | */ |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4074 | static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4075 | { |
| 4076 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4077 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4078 | int i, j; |
| 4079 | |
| 4080 | switch (hw->mac.type) { |
| 4081 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4082 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 4083 | vlnctrl |= IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4084 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4085 | break; |
| 4086 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4087 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 4088 | case ixgbe_mac_X550: |
| 4089 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 4090 | case ixgbe_mac_x550em_a: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4091 | for (i = 0; i < adapter->num_rx_queues; i++) { |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4092 | struct ixgbe_ring *ring = adapter->rx_ring[i]; |
| 4093 | |
| 4094 | if (ring->l2_accel_priv) |
| 4095 | continue; |
| 4096 | j = ring->reg_idx; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4097 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 4098 | vlnctrl |= IXGBE_RXDCTL_VME; |
| 4099 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 4100 | } |
| 4101 | break; |
| 4102 | default: |
| 4103 | break; |
| 4104 | } |
| 4105 | } |
| 4106 | |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4107 | static void ixgbe_vlan_promisc_enable(struct ixgbe_adapter *adapter) |
| 4108 | { |
| 4109 | struct ixgbe_hw *hw = &adapter->hw; |
| 4110 | u32 vlnctrl, i; |
| 4111 | |
Alexander Duyck | f60439b | 2016-08-11 14:51:56 -0700 | [diff] [blame] | 4112 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 4113 | |
Emil Tantilov | 691e412 | 2016-08-22 16:17:46 -0700 | [diff] [blame] | 4114 | if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) { |
| 4115 | /* For VMDq and SR-IOV we must leave VLAN filtering enabled */ |
| 4116 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
| 4117 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4118 | } else { |
Alexander Duyck | f60439b | 2016-08-11 14:51:56 -0700 | [diff] [blame] | 4119 | vlnctrl &= ~IXGBE_VLNCTRL_VFE; |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4120 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4121 | return; |
| 4122 | } |
| 4123 | |
Emil Tantilov | 691e412 | 2016-08-22 16:17:46 -0700 | [diff] [blame] | 4124 | /* Nothing to do for 82598 */ |
| 4125 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4126 | return; |
| 4127 | |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4128 | /* We are already in VLAN promisc, nothing to do */ |
| 4129 | if (adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC) |
| 4130 | return; |
| 4131 | |
| 4132 | /* Set flag so we don't redo unnecessary work */ |
| 4133 | adapter->flags2 |= IXGBE_FLAG2_VLAN_PROMISC; |
| 4134 | |
| 4135 | /* Add PF to all active pools */ |
| 4136 | for (i = IXGBE_VLVF_ENTRIES; --i;) { |
| 4137 | u32 reg_offset = IXGBE_VLVFB(i * 2 + VMDQ_P(0) / 32); |
| 4138 | u32 vlvfb = IXGBE_READ_REG(hw, reg_offset); |
| 4139 | |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 4140 | vlvfb |= BIT(VMDQ_P(0) % 32); |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4141 | IXGBE_WRITE_REG(hw, reg_offset, vlvfb); |
| 4142 | } |
| 4143 | |
| 4144 | /* Set all bits in the VLAN filter table array */ |
| 4145 | for (i = hw->mac.vft_size; i--;) |
| 4146 | IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), ~0U); |
| 4147 | } |
| 4148 | |
| 4149 | #define VFTA_BLOCK_SIZE 8 |
| 4150 | static void ixgbe_scrub_vfta(struct ixgbe_adapter *adapter, u32 vfta_offset) |
| 4151 | { |
| 4152 | struct ixgbe_hw *hw = &adapter->hw; |
| 4153 | u32 vfta[VFTA_BLOCK_SIZE] = { 0 }; |
| 4154 | u32 vid_start = vfta_offset * 32; |
| 4155 | u32 vid_end = vid_start + (VFTA_BLOCK_SIZE * 32); |
| 4156 | u32 i, vid, word, bits; |
| 4157 | |
| 4158 | for (i = IXGBE_VLVF_ENTRIES; --i;) { |
| 4159 | u32 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(i)); |
| 4160 | |
| 4161 | /* pull VLAN ID from VLVF */ |
| 4162 | vid = vlvf & VLAN_VID_MASK; |
| 4163 | |
| 4164 | /* only concern outselves with a certain range */ |
| 4165 | if (vid < vid_start || vid >= vid_end) |
| 4166 | continue; |
| 4167 | |
| 4168 | if (vlvf) { |
| 4169 | /* record VLAN ID in VFTA */ |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 4170 | vfta[(vid - vid_start) / 32] |= BIT(vid % 32); |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4171 | |
| 4172 | /* if PF is part of this then continue */ |
| 4173 | if (test_bit(vid, adapter->active_vlans)) |
| 4174 | continue; |
| 4175 | } |
| 4176 | |
| 4177 | /* remove PF from the pool */ |
| 4178 | word = i * 2 + VMDQ_P(0) / 32; |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 4179 | bits = ~BIT(VMDQ_P(0) % 32); |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4180 | bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word)); |
| 4181 | IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), bits); |
| 4182 | } |
| 4183 | |
| 4184 | /* extract values from active_vlans and write back to VFTA */ |
| 4185 | for (i = VFTA_BLOCK_SIZE; i--;) { |
| 4186 | vid = (vfta_offset + i) * 32; |
| 4187 | word = vid / BITS_PER_LONG; |
| 4188 | bits = vid % BITS_PER_LONG; |
| 4189 | |
| 4190 | vfta[i] |= adapter->active_vlans[word] >> bits; |
| 4191 | |
| 4192 | IXGBE_WRITE_REG(hw, IXGBE_VFTA(vfta_offset + i), vfta[i]); |
| 4193 | } |
| 4194 | } |
| 4195 | |
| 4196 | static void ixgbe_vlan_promisc_disable(struct ixgbe_adapter *adapter) |
| 4197 | { |
| 4198 | struct ixgbe_hw *hw = &adapter->hw; |
| 4199 | u32 vlnctrl, i; |
| 4200 | |
Alexander Duyck | f60439b | 2016-08-11 14:51:56 -0700 | [diff] [blame] | 4201 | /* Set VLAN filtering to enabled */ |
| 4202 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 4203 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
| 4204 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4205 | |
Emil Tantilov | 691e412 | 2016-08-22 16:17:46 -0700 | [diff] [blame] | 4206 | if (!(adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) || |
| 4207 | hw->mac.type == ixgbe_mac_82598EB) |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4208 | return; |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4209 | |
| 4210 | /* We are not in VLAN promisc, nothing to do */ |
| 4211 | if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)) |
| 4212 | return; |
| 4213 | |
| 4214 | /* Set flag so we don't redo unnecessary work */ |
| 4215 | adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC; |
| 4216 | |
| 4217 | for (i = 0; i < hw->mac.vft_size; i += VFTA_BLOCK_SIZE) |
| 4218 | ixgbe_scrub_vfta(adapter, i); |
| 4219 | } |
| 4220 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4221 | static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter) |
| 4222 | { |
Alexander Duyck | 06bb1c3 | 2016-01-06 22:48:50 -0800 | [diff] [blame] | 4223 | u16 vid = 1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4224 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 4225 | ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4226 | |
Alexander Duyck | 06bb1c3 | 2016-01-06 22:48:50 -0800 | [diff] [blame] | 4227 | for_each_set_bit_from(vid, adapter->active_vlans, VLAN_N_VID) |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 4228 | ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4229 | } |
| 4230 | |
| 4231 | /** |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4232 | * ixgbe_write_mc_addr_list - write multicast addresses to MTA |
| 4233 | * @netdev: network interface device structure |
| 4234 | * |
| 4235 | * Writes multicast address list to the MTA hash table. |
| 4236 | * Returns: -ENOMEM on failure |
| 4237 | * 0 on no addresses written |
| 4238 | * X on writing X addresses to MTA |
| 4239 | **/ |
| 4240 | static int ixgbe_write_mc_addr_list(struct net_device *netdev) |
| 4241 | { |
| 4242 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4243 | struct ixgbe_hw *hw = &adapter->hw; |
| 4244 | |
| 4245 | if (!netif_running(netdev)) |
| 4246 | return 0; |
| 4247 | |
| 4248 | if (hw->mac.ops.update_mc_addr_list) |
| 4249 | hw->mac.ops.update_mc_addr_list(hw, netdev); |
| 4250 | else |
| 4251 | return -ENOMEM; |
| 4252 | |
| 4253 | #ifdef CONFIG_PCI_IOV |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4254 | ixgbe_restore_vf_multicasts(adapter); |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4255 | #endif |
| 4256 | |
| 4257 | return netdev_mc_count(netdev); |
| 4258 | } |
| 4259 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4260 | #ifdef CONFIG_PCI_IOV |
| 4261 | void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter) |
| 4262 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4263 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4264 | struct ixgbe_hw *hw = &adapter->hw; |
| 4265 | int i; |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4266 | |
| 4267 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4268 | mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED; |
| 4269 | |
| 4270 | if (mac_table->state & IXGBE_MAC_STATE_IN_USE) |
| 4271 | hw->mac.ops.set_rar(hw, i, |
| 4272 | mac_table->addr, |
| 4273 | mac_table->pool, |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4274 | IXGBE_RAH_AV); |
| 4275 | else |
| 4276 | hw->mac.ops.clear_rar(hw, i); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4277 | } |
| 4278 | } |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4279 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4280 | #endif |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4281 | static void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter) |
| 4282 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4283 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4284 | struct ixgbe_hw *hw = &adapter->hw; |
| 4285 | int i; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4286 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4287 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4288 | if (!(mac_table->state & IXGBE_MAC_STATE_MODIFIED)) |
| 4289 | continue; |
| 4290 | |
| 4291 | mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED; |
| 4292 | |
| 4293 | if (mac_table->state & IXGBE_MAC_STATE_IN_USE) |
| 4294 | hw->mac.ops.set_rar(hw, i, |
| 4295 | mac_table->addr, |
| 4296 | mac_table->pool, |
| 4297 | IXGBE_RAH_AV); |
| 4298 | else |
| 4299 | hw->mac.ops.clear_rar(hw, i); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4300 | } |
| 4301 | } |
| 4302 | |
| 4303 | static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter) |
| 4304 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4305 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4306 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4307 | int i; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4308 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4309 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4310 | mac_table->state |= IXGBE_MAC_STATE_MODIFIED; |
| 4311 | mac_table->state &= ~IXGBE_MAC_STATE_IN_USE; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4312 | } |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4313 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4314 | ixgbe_sync_mac_table(adapter); |
| 4315 | } |
| 4316 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4317 | static int ixgbe_available_rars(struct ixgbe_adapter *adapter, u16 pool) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4318 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4319 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4320 | struct ixgbe_hw *hw = &adapter->hw; |
| 4321 | int i, count = 0; |
| 4322 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4323 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4324 | /* do not count default RAR as available */ |
| 4325 | if (mac_table->state & IXGBE_MAC_STATE_DEFAULT) |
| 4326 | continue; |
| 4327 | |
| 4328 | /* only count unused and addresses that belong to us */ |
| 4329 | if (mac_table->state & IXGBE_MAC_STATE_IN_USE) { |
| 4330 | if (mac_table->pool != pool) |
| 4331 | continue; |
| 4332 | } |
| 4333 | |
| 4334 | count++; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4335 | } |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4336 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4337 | return count; |
| 4338 | } |
| 4339 | |
| 4340 | /* this function destroys the first RAR entry */ |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4341 | static void ixgbe_mac_set_default_filter(struct ixgbe_adapter *adapter) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4342 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4343 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4344 | struct ixgbe_hw *hw = &adapter->hw; |
| 4345 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4346 | memcpy(&mac_table->addr, hw->mac.addr, ETH_ALEN); |
| 4347 | mac_table->pool = VMDQ_P(0); |
| 4348 | |
| 4349 | mac_table->state = IXGBE_MAC_STATE_DEFAULT | IXGBE_MAC_STATE_IN_USE; |
| 4350 | |
| 4351 | hw->mac.ops.set_rar(hw, 0, mac_table->addr, mac_table->pool, |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4352 | IXGBE_RAH_AV); |
| 4353 | } |
| 4354 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4355 | int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter, |
| 4356 | const u8 *addr, u16 pool) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4357 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4358 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4359 | struct ixgbe_hw *hw = &adapter->hw; |
| 4360 | int i; |
| 4361 | |
| 4362 | if (is_zero_ether_addr(addr)) |
| 4363 | return -EINVAL; |
| 4364 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4365 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4366 | if (mac_table->state & IXGBE_MAC_STATE_IN_USE) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4367 | continue; |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4368 | |
| 4369 | ether_addr_copy(mac_table->addr, addr); |
| 4370 | mac_table->pool = pool; |
| 4371 | |
| 4372 | mac_table->state |= IXGBE_MAC_STATE_MODIFIED | |
| 4373 | IXGBE_MAC_STATE_IN_USE; |
| 4374 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4375 | ixgbe_sync_mac_table(adapter); |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4376 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4377 | return i; |
| 4378 | } |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4379 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4380 | return -ENOMEM; |
| 4381 | } |
| 4382 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4383 | int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter, |
| 4384 | const u8 *addr, u16 pool) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4385 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4386 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4387 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4388 | int i; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4389 | |
| 4390 | if (is_zero_ether_addr(addr)) |
| 4391 | return -EINVAL; |
| 4392 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4393 | /* search table for addr, if found clear IN_USE flag and sync */ |
| 4394 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4395 | /* we can only delete an entry if it is in use */ |
| 4396 | if (!(mac_table->state & IXGBE_MAC_STATE_IN_USE)) |
| 4397 | continue; |
| 4398 | /* we only care about entries that belong to the given pool */ |
| 4399 | if (mac_table->pool != pool) |
| 4400 | continue; |
| 4401 | /* we only care about a specific MAC address */ |
| 4402 | if (!ether_addr_equal(addr, mac_table->addr)) |
| 4403 | continue; |
| 4404 | |
| 4405 | mac_table->state |= IXGBE_MAC_STATE_MODIFIED; |
| 4406 | mac_table->state &= ~IXGBE_MAC_STATE_IN_USE; |
| 4407 | |
| 4408 | ixgbe_sync_mac_table(adapter); |
| 4409 | |
| 4410 | return 0; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4411 | } |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4412 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4413 | return -ENOMEM; |
| 4414 | } |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4415 | /** |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4416 | * ixgbe_write_uc_addr_list - write unicast addresses to RAR table |
| 4417 | * @netdev: network interface device structure |
| 4418 | * |
| 4419 | * Writes unicast address list to the RAR table. |
| 4420 | * Returns: -ENOMEM on failure/insufficient address space |
| 4421 | * 0 on no addresses written |
| 4422 | * X on writing X addresses to the RAR table |
| 4423 | **/ |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4424 | 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] | 4425 | { |
| 4426 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4427 | int count = 0; |
| 4428 | |
| 4429 | /* return ENOMEM indicating insufficient memory for addresses */ |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4430 | if (netdev_uc_count(netdev) > ixgbe_available_rars(adapter, vfn)) |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4431 | return -ENOMEM; |
| 4432 | |
John Fastabend | 9544746 | 2012-05-31 12:42:26 +0000 | [diff] [blame] | 4433 | if (!netdev_uc_empty(netdev)) { |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4434 | struct netdev_hw_addr *ha; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4435 | netdev_for_each_uc_addr(ha, netdev) { |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4436 | ixgbe_del_mac_filter(adapter, ha->addr, vfn); |
| 4437 | ixgbe_add_mac_filter(adapter, ha->addr, vfn); |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4438 | count++; |
| 4439 | } |
| 4440 | } |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4441 | return count; |
| 4442 | } |
| 4443 | |
Alexander Duyck | 0f079d2 | 2015-10-22 16:26:36 -0700 | [diff] [blame] | 4444 | static int ixgbe_uc_sync(struct net_device *netdev, const unsigned char *addr) |
| 4445 | { |
| 4446 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4447 | int ret; |
| 4448 | |
| 4449 | ret = ixgbe_add_mac_filter(adapter, addr, VMDQ_P(0)); |
| 4450 | |
| 4451 | return min_t(int, ret, 0); |
| 4452 | } |
| 4453 | |
| 4454 | static int ixgbe_uc_unsync(struct net_device *netdev, const unsigned char *addr) |
| 4455 | { |
| 4456 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4457 | |
| 4458 | ixgbe_del_mac_filter(adapter, addr, VMDQ_P(0)); |
| 4459 | |
| 4460 | return 0; |
| 4461 | } |
| 4462 | |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4463 | /** |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 4464 | * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4465 | * @netdev: network interface device structure |
| 4466 | * |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 4467 | * The set_rx_method entry point is called whenever the unicast/multicast |
| 4468 | * address list or the network interface flags are updated. This routine is |
| 4469 | * responsible for configuring the hardware for proper unicast, multicast and |
| 4470 | * promiscuous mode. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4471 | **/ |
Greg Rose | 7f87047 | 2010-01-09 02:25:29 +0000 | [diff] [blame] | 4472 | void ixgbe_set_rx_mode(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4473 | { |
| 4474 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4475 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4476 | u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE; |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 4477 | netdev_features_t features = netdev->features; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4478 | int count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4479 | |
| 4480 | /* Check for Promiscuous and All Multicast modes */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4481 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 4482 | |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 4483 | /* set all bits that we expect to always be set */ |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 4484 | fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */ |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 4485 | fctrl |= IXGBE_FCTRL_BAM; |
| 4486 | fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */ |
| 4487 | fctrl |= IXGBE_FCTRL_PMCF; |
| 4488 | |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4489 | /* clear the bits we are changing the status of */ |
| 4490 | fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4491 | if (netdev->flags & IFF_PROMISC) { |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 4492 | hw->addr_ctrl.user_set_promisc = true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4493 | fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4494 | vmolr |= IXGBE_VMOLR_MPE; |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 4495 | features &= ~NETIF_F_HW_VLAN_CTAG_FILTER; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4496 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 4497 | if (netdev->flags & IFF_ALLMULTI) { |
| 4498 | fctrl |= IXGBE_FCTRL_MPE; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4499 | vmolr |= IXGBE_VMOLR_MPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 4500 | } |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 4501 | hw->addr_ctrl.user_set_promisc = false; |
John Fastabend | 9dcb373 | 2012-04-15 06:44:25 +0000 | [diff] [blame] | 4502 | } |
| 4503 | |
| 4504 | /* |
| 4505 | * Write addresses to available RAR registers, if there is not |
| 4506 | * sufficient space to store all the addresses then enable |
| 4507 | * unicast promiscuous mode |
| 4508 | */ |
Alexander Duyck | 0f079d2 | 2015-10-22 16:26:36 -0700 | [diff] [blame] | 4509 | if (__dev_uc_sync(netdev, ixgbe_uc_sync, ixgbe_uc_unsync)) { |
John Fastabend | 9dcb373 | 2012-04-15 06:44:25 +0000 | [diff] [blame] | 4510 | fctrl |= IXGBE_FCTRL_UPE; |
| 4511 | vmolr |= IXGBE_VMOLR_ROPE; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4512 | } |
| 4513 | |
Emil Tantilov | cf78959 | 2013-10-26 08:13:20 +0000 | [diff] [blame] | 4514 | /* Write addresses to the MTA, if the attempt fails |
| 4515 | * then we should just turn on promiscuous mode so |
| 4516 | * that we can at least receive multicast traffic |
| 4517 | */ |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4518 | count = ixgbe_write_mc_addr_list(netdev); |
| 4519 | if (count < 0) { |
| 4520 | fctrl |= IXGBE_FCTRL_MPE; |
| 4521 | vmolr |= IXGBE_VMOLR_MPE; |
| 4522 | } else if (count) { |
| 4523 | vmolr |= IXGBE_VMOLR_ROMPE; |
| 4524 | } |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 4525 | |
| 4526 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 4527 | vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) & |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4528 | ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE | |
| 4529 | IXGBE_VMOLR_ROPE); |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 4530 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4531 | } |
| 4532 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 4533 | /* This is useful for sniffing bad packets. */ |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 4534 | if (features & NETIF_F_RXALL) { |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 4535 | /* UPE and MPE will be handled by normal PROMISC logic |
| 4536 | * in e1000e_set_rx_mode */ |
| 4537 | fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */ |
| 4538 | IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */ |
| 4539 | IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */ |
| 4540 | |
| 4541 | fctrl &= ~(IXGBE_FCTRL_DPF); |
| 4542 | /* NOTE: VLAN filtering is disabled by setting PROMISC */ |
| 4543 | } |
| 4544 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4545 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4546 | |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 4547 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4548 | ixgbe_vlan_strip_enable(adapter); |
| 4549 | else |
| 4550 | ixgbe_vlan_strip_disable(adapter); |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 4551 | |
| 4552 | if (features & NETIF_F_HW_VLAN_CTAG_FILTER) |
| 4553 | ixgbe_vlan_promisc_disable(adapter); |
| 4554 | else |
| 4555 | ixgbe_vlan_promisc_enable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4556 | } |
| 4557 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4558 | static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter) |
| 4559 | { |
| 4560 | int q_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4561 | |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 4562 | for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) { |
| 4563 | ixgbe_qv_init_lock(adapter->q_vector[q_idx]); |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 4564 | napi_enable(&adapter->q_vector[q_idx]->napi); |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 4565 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4566 | } |
| 4567 | |
| 4568 | static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter) |
| 4569 | { |
| 4570 | int q_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4571 | |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 4572 | for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) { |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 4573 | napi_disable(&adapter->q_vector[q_idx]->napi); |
Jacob Keller | 27d9ce4 | 2013-09-21 05:05:44 +0000 | [diff] [blame] | 4574 | while (!ixgbe_qv_disable(adapter->q_vector[q_idx])) { |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 4575 | pr_info("QV %d locked\n", q_idx); |
Jacob Keller | 27d9ce4 | 2013-09-21 05:05:44 +0000 | [diff] [blame] | 4576 | usleep_range(1000, 20000); |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 4577 | } |
| 4578 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4579 | } |
| 4580 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 4581 | static void ixgbe_clear_udp_tunnel_port(struct ixgbe_adapter *adapter, u32 mask) |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 4582 | { |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 4583 | struct ixgbe_hw *hw = &adapter->hw; |
| 4584 | u32 vxlanctrl; |
| 4585 | |
| 4586 | if (!(adapter->flags & (IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE | |
| 4587 | IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))) |
| 4588 | return; |
| 4589 | |
| 4590 | vxlanctrl = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) && ~mask; |
| 4591 | IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, vxlanctrl); |
| 4592 | |
| 4593 | if (mask & IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK) |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 4594 | adapter->vxlan_port = 0; |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 4595 | |
| 4596 | if (mask & IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK) |
| 4597 | adapter->geneve_port = 0; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 4598 | } |
| 4599 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 4600 | #ifdef CONFIG_IXGBE_DCB |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4601 | /** |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4602 | * ixgbe_configure_dcb - Configure DCB hardware |
| 4603 | * @adapter: ixgbe adapter struct |
| 4604 | * |
| 4605 | * This is called by the driver on open to configure the DCB hardware. |
| 4606 | * This is also called by the gennetlink interface when reconfiguring |
| 4607 | * the DCB state. |
| 4608 | */ |
| 4609 | static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter) |
| 4610 | { |
| 4611 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 9806307 | 2010-10-28 00:59:57 +0000 | [diff] [blame] | 4612 | int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4613 | |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 4614 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) { |
| 4615 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4616 | netif_set_gso_max_size(adapter->netdev, 65536); |
| 4617 | return; |
| 4618 | } |
| 4619 | |
| 4620 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4621 | netif_set_gso_max_size(adapter->netdev, 32768); |
| 4622 | |
John Fastabend | b120818 | 2011-10-15 05:00:10 +0000 | [diff] [blame] | 4623 | #ifdef IXGBE_FCOE |
| 4624 | if (adapter->netdev->features & NETIF_F_FCOE_MTU) |
| 4625 | max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE); |
| 4626 | #endif |
| 4627 | |
Alexander Duyck | 01fa7d9 | 2010-11-16 19:26:53 -0800 | [diff] [blame] | 4628 | /* reconfigure the hardware */ |
John Fastabend | 6f70f6a | 2011-04-26 07:26:25 +0000 | [diff] [blame] | 4629 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) { |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 4630 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 4631 | DCB_TX_CONFIG); |
| 4632 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 4633 | DCB_RX_CONFIG); |
| 4634 | ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg); |
John Fastabend | b120818 | 2011-10-15 05:00:10 +0000 | [diff] [blame] | 4635 | } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) { |
| 4636 | ixgbe_dcb_hw_ets(&adapter->hw, |
| 4637 | adapter->ixgbe_ieee_ets, |
| 4638 | max_frame); |
| 4639 | ixgbe_dcb_hw_pfc_config(&adapter->hw, |
| 4640 | adapter->ixgbe_ieee_pfc->pfc_en, |
| 4641 | adapter->ixgbe_ieee_ets->prio_tc); |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 4642 | } |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 4643 | |
| 4644 | /* Enable RSS Hash per TC */ |
| 4645 | if (hw->mac.type != ixgbe_mac_82598EB) { |
Alexander Duyck | 4ae6373 | 2012-06-22 06:46:33 +0000 | [diff] [blame] | 4646 | u32 msb = 0; |
| 4647 | u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1; |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 4648 | |
Alexander Duyck | d411a93 | 2012-06-30 00:14:01 +0000 | [diff] [blame] | 4649 | while (rss_i) { |
| 4650 | msb++; |
| 4651 | rss_i >>= 1; |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 4652 | } |
Alexander Duyck | d411a93 | 2012-06-30 00:14:01 +0000 | [diff] [blame] | 4653 | |
Alexander Duyck | 4ae6373 | 2012-06-22 06:46:33 +0000 | [diff] [blame] | 4654 | /* write msb to all 8 TCs in one write */ |
| 4655 | IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111); |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 4656 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4657 | } |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4658 | #endif |
| 4659 | |
| 4660 | /* Additional bittime to account for IXGBE framing */ |
| 4661 | #define IXGBE_ETH_FRAMING 20 |
| 4662 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4663 | /** |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4664 | * ixgbe_hpbthresh - calculate high water mark for flow control |
| 4665 | * |
| 4666 | * @adapter: board private structure to calculate for |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4667 | * @pb: packet buffer to calculate |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4668 | */ |
| 4669 | static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb) |
| 4670 | { |
| 4671 | struct ixgbe_hw *hw = &adapter->hw; |
| 4672 | struct net_device *dev = adapter->netdev; |
| 4673 | int link, tc, kb, marker; |
| 4674 | u32 dv_id, rx_pba; |
| 4675 | |
| 4676 | /* Calculate max LAN frame size */ |
| 4677 | tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING; |
| 4678 | |
| 4679 | #ifdef IXGBE_FCOE |
| 4680 | /* FCoE traffic class uses FCOE jumbo frames */ |
Alexander Duyck | 800bd60 | 2012-06-02 00:11:02 +0000 | [diff] [blame] | 4681 | if ((dev->features & NETIF_F_FCOE_MTU) && |
| 4682 | (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) && |
| 4683 | (pb == ixgbe_fcoe_get_tc(adapter))) |
| 4684 | tc = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4685 | #endif |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4686 | |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4687 | /* Calculate delay value for device */ |
| 4688 | switch (hw->mac.type) { |
| 4689 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 4690 | case ixgbe_mac_X550: |
| 4691 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 4692 | case ixgbe_mac_x550em_a: |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4693 | dv_id = IXGBE_DV_X540(link, tc); |
| 4694 | break; |
| 4695 | default: |
| 4696 | dv_id = IXGBE_DV(link, tc); |
| 4697 | break; |
| 4698 | } |
| 4699 | |
| 4700 | /* Loopback switch introduces additional latency */ |
| 4701 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 4702 | dv_id += IXGBE_B2BT(tc); |
| 4703 | |
| 4704 | /* Delay value is calculated in bit times convert to KB */ |
| 4705 | kb = IXGBE_BT2KB(dv_id); |
| 4706 | rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10; |
| 4707 | |
| 4708 | marker = rx_pba - kb; |
| 4709 | |
| 4710 | /* It is possible that the packet buffer is not large enough |
| 4711 | * to provide required headroom. In this case throw an error |
| 4712 | * to user and a do the best we can. |
| 4713 | */ |
| 4714 | if (marker < 0) { |
| 4715 | e_warn(drv, "Packet Buffer(%i) can not provide enough" |
| 4716 | "headroom to support flow control." |
| 4717 | "Decrease MTU or number of traffic classes\n", pb); |
| 4718 | marker = tc + 1; |
| 4719 | } |
| 4720 | |
| 4721 | return marker; |
| 4722 | } |
| 4723 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4724 | /** |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4725 | * ixgbe_lpbthresh - calculate low water mark for for flow control |
| 4726 | * |
| 4727 | * @adapter: board private structure to calculate for |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4728 | * @pb: packet buffer to calculate |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4729 | */ |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4730 | static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb) |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4731 | { |
| 4732 | struct ixgbe_hw *hw = &adapter->hw; |
| 4733 | struct net_device *dev = adapter->netdev; |
| 4734 | int tc; |
| 4735 | u32 dv_id; |
| 4736 | |
| 4737 | /* Calculate max LAN frame size */ |
| 4738 | tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN; |
| 4739 | |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4740 | #ifdef IXGBE_FCOE |
| 4741 | /* FCoE traffic class uses FCOE jumbo frames */ |
| 4742 | if ((dev->features & NETIF_F_FCOE_MTU) && |
| 4743 | (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) && |
| 4744 | (pb == netdev_get_prio_tc_map(dev, adapter->fcoe.up))) |
| 4745 | tc = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 4746 | #endif |
| 4747 | |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4748 | /* Calculate delay value for device */ |
| 4749 | switch (hw->mac.type) { |
| 4750 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 4751 | case ixgbe_mac_X550: |
| 4752 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 4753 | case ixgbe_mac_x550em_a: |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4754 | dv_id = IXGBE_LOW_DV_X540(tc); |
| 4755 | break; |
| 4756 | default: |
| 4757 | dv_id = IXGBE_LOW_DV(tc); |
| 4758 | break; |
| 4759 | } |
| 4760 | |
| 4761 | /* Delay value is calculated in bit times convert to KB */ |
| 4762 | return IXGBE_BT2KB(dv_id); |
| 4763 | } |
| 4764 | |
| 4765 | /* |
| 4766 | * ixgbe_pbthresh_setup - calculate and setup high low water marks |
| 4767 | */ |
| 4768 | static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter) |
| 4769 | { |
| 4770 | struct ixgbe_hw *hw = &adapter->hw; |
| 4771 | int num_tc = netdev_get_num_tc(adapter->netdev); |
| 4772 | int i; |
| 4773 | |
| 4774 | if (!num_tc) |
| 4775 | num_tc = 1; |
| 4776 | |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4777 | for (i = 0; i < num_tc; i++) { |
| 4778 | hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i); |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4779 | hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i); |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4780 | |
| 4781 | /* Low water marks must not be larger than high water marks */ |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4782 | if (hw->fc.low_water[i] > hw->fc.high_water[i]) |
| 4783 | hw->fc.low_water[i] = 0; |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4784 | } |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4785 | |
| 4786 | for (; i < MAX_TRAFFIC_CLASS; i++) |
| 4787 | hw->fc.high_water[i] = 0; |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4788 | } |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4789 | |
| 4790 | static void ixgbe_configure_pb(struct ixgbe_adapter *adapter) |
| 4791 | { |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4792 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 4793 | int hdrm; |
| 4794 | u8 tc = netdev_get_num_tc(adapter->netdev); |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4795 | |
| 4796 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 4797 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 4798 | hdrm = 32 << adapter->fdir_pballoc; |
| 4799 | else |
| 4800 | hdrm = 0; |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4801 | |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 4802 | hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL); |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4803 | ixgbe_pbthresh_setup(adapter); |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4804 | } |
| 4805 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4806 | static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter) |
| 4807 | { |
| 4808 | struct ixgbe_hw *hw = &adapter->hw; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 4809 | struct hlist_node *node2; |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4810 | struct ixgbe_fdir_filter *filter; |
| 4811 | |
| 4812 | spin_lock(&adapter->fdir_perfect_lock); |
| 4813 | |
| 4814 | if (!hlist_empty(&adapter->fdir_filter_list)) |
| 4815 | ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask); |
| 4816 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 4817 | hlist_for_each_entry_safe(filter, node2, |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4818 | &adapter->fdir_filter_list, fdir_node) { |
| 4819 | ixgbe_fdir_write_perfect_filter_82599(hw, |
Alexander Duyck | 1f4d518 | 2011-05-14 01:16:02 +0000 | [diff] [blame] | 4820 | &filter->filter, |
| 4821 | filter->sw_idx, |
| 4822 | (filter->action == IXGBE_FDIR_DROP_QUEUE) ? |
| 4823 | IXGBE_FDIR_DROP_QUEUE : |
| 4824 | adapter->rx_ring[filter->action]->reg_idx); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4825 | } |
| 4826 | |
| 4827 | spin_unlock(&adapter->fdir_perfect_lock); |
| 4828 | } |
| 4829 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4830 | static void ixgbe_macvlan_set_rx_mode(struct net_device *dev, unsigned int pool, |
| 4831 | struct ixgbe_adapter *adapter) |
| 4832 | { |
| 4833 | struct ixgbe_hw *hw = &adapter->hw; |
| 4834 | u32 vmolr; |
| 4835 | |
| 4836 | /* No unicast promiscuous support for VMDQ devices. */ |
| 4837 | vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(pool)); |
| 4838 | vmolr |= (IXGBE_VMOLR_ROMPE | IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE); |
| 4839 | |
| 4840 | /* clear the affected bit */ |
| 4841 | vmolr &= ~IXGBE_VMOLR_MPE; |
| 4842 | |
| 4843 | if (dev->flags & IFF_ALLMULTI) { |
| 4844 | vmolr |= IXGBE_VMOLR_MPE; |
| 4845 | } else { |
| 4846 | vmolr |= IXGBE_VMOLR_ROMPE; |
| 4847 | hw->mac.ops.update_mc_addr_list(hw, dev); |
| 4848 | } |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4849 | ixgbe_write_uc_addr_list(adapter->netdev, pool); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4850 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(pool), vmolr); |
| 4851 | } |
| 4852 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4853 | static void ixgbe_fwd_psrtype(struct ixgbe_fwd_adapter *vadapter) |
| 4854 | { |
| 4855 | struct ixgbe_adapter *adapter = vadapter->real_adapter; |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 4856 | int rss_i = adapter->num_rx_queues_per_pool; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4857 | struct ixgbe_hw *hw = &adapter->hw; |
| 4858 | u16 pool = vadapter->pool; |
| 4859 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
| 4860 | IXGBE_PSRTYPE_UDPHDR | |
| 4861 | IXGBE_PSRTYPE_IPV4HDR | |
| 4862 | IXGBE_PSRTYPE_L2HDR | |
| 4863 | IXGBE_PSRTYPE_IPV6HDR; |
| 4864 | |
| 4865 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4866 | return; |
| 4867 | |
| 4868 | if (rss_i > 3) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 4869 | psrtype |= 2u << 29; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4870 | else if (rss_i > 1) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 4871 | psrtype |= 1u << 29; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4872 | |
| 4873 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype); |
| 4874 | } |
| 4875 | |
| 4876 | /** |
| 4877 | * ixgbe_clean_rx_ring - Free Rx Buffers per Queue |
| 4878 | * @rx_ring: ring to free buffers from |
| 4879 | **/ |
| 4880 | static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring) |
| 4881 | { |
| 4882 | struct device *dev = rx_ring->dev; |
| 4883 | unsigned long size; |
| 4884 | u16 i; |
| 4885 | |
| 4886 | /* ring already cleared, nothing to do */ |
| 4887 | if (!rx_ring->rx_buffer_info) |
| 4888 | return; |
| 4889 | |
| 4890 | /* Free all the Rx ring sk_buffs */ |
| 4891 | for (i = 0; i < rx_ring->count; i++) { |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 4892 | struct ixgbe_rx_buffer *rx_buffer = &rx_ring->rx_buffer_info[i]; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4893 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4894 | if (rx_buffer->skb) { |
| 4895 | struct sk_buff *skb = rx_buffer->skb; |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 4896 | if (IXGBE_CB(skb)->page_released) |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4897 | dma_unmap_page(dev, |
| 4898 | IXGBE_CB(skb)->dma, |
| 4899 | ixgbe_rx_bufsz(rx_ring), |
| 4900 | DMA_FROM_DEVICE); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4901 | dev_kfree_skb(skb); |
Junwei Zhang | 4d2fcfb | 2014-10-22 15:29:03 +0000 | [diff] [blame] | 4902 | rx_buffer->skb = NULL; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4903 | } |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 4904 | |
| 4905 | if (!rx_buffer->page) |
| 4906 | continue; |
| 4907 | |
| 4908 | dma_unmap_page(dev, rx_buffer->dma, |
| 4909 | ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE); |
| 4910 | __free_pages(rx_buffer->page, ixgbe_rx_pg_order(rx_ring)); |
| 4911 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4912 | rx_buffer->page = NULL; |
| 4913 | } |
| 4914 | |
| 4915 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 4916 | memset(rx_ring->rx_buffer_info, 0, size); |
| 4917 | |
| 4918 | /* Zero out the descriptor ring */ |
| 4919 | memset(rx_ring->desc, 0, rx_ring->size); |
| 4920 | |
| 4921 | rx_ring->next_to_alloc = 0; |
| 4922 | rx_ring->next_to_clean = 0; |
| 4923 | rx_ring->next_to_use = 0; |
| 4924 | } |
| 4925 | |
| 4926 | static void ixgbe_disable_fwd_ring(struct ixgbe_fwd_adapter *vadapter, |
| 4927 | struct ixgbe_ring *rx_ring) |
| 4928 | { |
| 4929 | struct ixgbe_adapter *adapter = vadapter->real_adapter; |
| 4930 | int index = rx_ring->queue_index + vadapter->rx_base_queue; |
| 4931 | |
| 4932 | /* shutdown specific queue receive and wait for dma to settle */ |
| 4933 | ixgbe_disable_rx_queue(adapter, rx_ring); |
| 4934 | usleep_range(10000, 20000); |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 4935 | ixgbe_irq_disable_queues(adapter, BIT_ULL(index)); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4936 | ixgbe_clean_rx_ring(rx_ring); |
| 4937 | rx_ring->l2_accel_priv = NULL; |
| 4938 | } |
| 4939 | |
John Fastabend | ae72c8d | 2013-11-09 07:11:26 +0000 | [diff] [blame] | 4940 | static int ixgbe_fwd_ring_down(struct net_device *vdev, |
| 4941 | struct ixgbe_fwd_adapter *accel) |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4942 | { |
| 4943 | struct ixgbe_adapter *adapter = accel->real_adapter; |
| 4944 | unsigned int rxbase = accel->rx_base_queue; |
| 4945 | unsigned int txbase = accel->tx_base_queue; |
| 4946 | int i; |
| 4947 | |
| 4948 | netif_tx_stop_all_queues(vdev); |
| 4949 | |
| 4950 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 4951 | ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]); |
| 4952 | adapter->rx_ring[rxbase + i]->netdev = adapter->netdev; |
| 4953 | } |
| 4954 | |
| 4955 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 4956 | adapter->tx_ring[txbase + i]->l2_accel_priv = NULL; |
| 4957 | adapter->tx_ring[txbase + i]->netdev = adapter->netdev; |
| 4958 | } |
| 4959 | |
| 4960 | |
| 4961 | return 0; |
| 4962 | } |
| 4963 | |
| 4964 | static int ixgbe_fwd_ring_up(struct net_device *vdev, |
| 4965 | struct ixgbe_fwd_adapter *accel) |
| 4966 | { |
| 4967 | struct ixgbe_adapter *adapter = accel->real_adapter; |
| 4968 | unsigned int rxbase, txbase, queues; |
| 4969 | int i, baseq, err = 0; |
| 4970 | |
| 4971 | if (!test_bit(accel->pool, &adapter->fwd_bitmask)) |
| 4972 | return 0; |
| 4973 | |
| 4974 | baseq = accel->pool * adapter->num_rx_queues_per_pool; |
| 4975 | netdev_dbg(vdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n", |
| 4976 | accel->pool, adapter->num_rx_pools, |
| 4977 | baseq, baseq + adapter->num_rx_queues_per_pool, |
| 4978 | adapter->fwd_bitmask); |
| 4979 | |
| 4980 | accel->netdev = vdev; |
| 4981 | accel->rx_base_queue = rxbase = baseq; |
| 4982 | accel->tx_base_queue = txbase = baseq; |
| 4983 | |
| 4984 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) |
| 4985 | ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]); |
| 4986 | |
| 4987 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 4988 | adapter->rx_ring[rxbase + i]->netdev = vdev; |
| 4989 | adapter->rx_ring[rxbase + i]->l2_accel_priv = accel; |
| 4990 | ixgbe_configure_rx_ring(adapter, adapter->rx_ring[rxbase + i]); |
| 4991 | } |
| 4992 | |
| 4993 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 4994 | adapter->tx_ring[txbase + i]->netdev = vdev; |
| 4995 | adapter->tx_ring[txbase + i]->l2_accel_priv = accel; |
| 4996 | } |
| 4997 | |
| 4998 | queues = min_t(unsigned int, |
| 4999 | adapter->num_rx_queues_per_pool, vdev->num_tx_queues); |
| 5000 | err = netif_set_real_num_tx_queues(vdev, queues); |
| 5001 | if (err) |
| 5002 | goto fwd_queue_err; |
| 5003 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5004 | err = netif_set_real_num_rx_queues(vdev, queues); |
| 5005 | if (err) |
| 5006 | goto fwd_queue_err; |
| 5007 | |
| 5008 | if (is_valid_ether_addr(vdev->dev_addr)) |
| 5009 | ixgbe_add_mac_filter(adapter, vdev->dev_addr, accel->pool); |
| 5010 | |
| 5011 | ixgbe_fwd_psrtype(accel); |
| 5012 | ixgbe_macvlan_set_rx_mode(vdev, accel->pool, adapter); |
| 5013 | return err; |
| 5014 | fwd_queue_err: |
| 5015 | ixgbe_fwd_ring_down(vdev, accel); |
| 5016 | return err; |
| 5017 | } |
| 5018 | |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 5019 | static int ixgbe_upper_dev_walk(struct net_device *upper, void *data) |
| 5020 | { |
| 5021 | if (netif_is_macvlan(upper)) { |
| 5022 | struct macvlan_dev *dfwd = netdev_priv(upper); |
| 5023 | struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv; |
| 5024 | |
| 5025 | if (dfwd->fwd_priv) |
| 5026 | ixgbe_fwd_ring_up(upper, vadapter); |
| 5027 | } |
| 5028 | |
| 5029 | return 0; |
| 5030 | } |
| 5031 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5032 | static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter) |
| 5033 | { |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 5034 | netdev_walk_all_upper_dev_rcu(adapter->netdev, |
| 5035 | ixgbe_upper_dev_walk, NULL); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5036 | } |
| 5037 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5038 | static void ixgbe_configure(struct ixgbe_adapter *adapter) |
| 5039 | { |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 5040 | struct ixgbe_hw *hw = &adapter->hw; |
| 5041 | |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 5042 | ixgbe_configure_pb(adapter); |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5043 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 5044 | ixgbe_configure_dcb(adapter); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5045 | #endif |
Alexander Duyck | b35d4d4 | 2012-05-23 05:39:25 +0000 | [diff] [blame] | 5046 | /* |
| 5047 | * We must restore virtualization before VLANs or else |
| 5048 | * the VLVF registers will not be populated |
| 5049 | */ |
| 5050 | ixgbe_configure_virtualization(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5051 | |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 5052 | ixgbe_set_rx_mode(adapter->netdev); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 5053 | ixgbe_restore_vlan(adapter); |
| 5054 | |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 5055 | switch (hw->mac.type) { |
| 5056 | case ixgbe_mac_82599EB: |
| 5057 | case ixgbe_mac_X540: |
| 5058 | hw->mac.ops.disable_rx_buff(hw); |
| 5059 | break; |
| 5060 | default: |
| 5061 | break; |
| 5062 | } |
| 5063 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5064 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 5065 | ixgbe_init_fdir_signature_82599(&adapter->hw, |
| 5066 | adapter->fdir_pballoc); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5067 | } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) { |
| 5068 | ixgbe_init_fdir_perfect_82599(&adapter->hw, |
| 5069 | adapter->fdir_pballoc); |
| 5070 | ixgbe_fdir_filter_restore(adapter); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5071 | } |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 5072 | |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 5073 | switch (hw->mac.type) { |
| 5074 | case ixgbe_mac_82599EB: |
| 5075 | case ixgbe_mac_X540: |
| 5076 | hw->mac.ops.enable_rx_buff(hw); |
| 5077 | break; |
| 5078 | default: |
| 5079 | break; |
| 5080 | } |
| 5081 | |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 5082 | #ifdef CONFIG_IXGBE_DCA |
| 5083 | /* configure DCA */ |
| 5084 | if (adapter->flags & IXGBE_FLAG_DCA_CAPABLE) |
| 5085 | ixgbe_setup_dca(adapter); |
| 5086 | #endif /* CONFIG_IXGBE_DCA */ |
| 5087 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 5088 | #ifdef IXGBE_FCOE |
| 5089 | /* configure FCoE L2 filters, redirection table, and Rx control */ |
| 5090 | ixgbe_configure_fcoe(adapter); |
| 5091 | |
| 5092 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5093 | ixgbe_configure_tx(adapter); |
| 5094 | ixgbe_configure_rx(adapter); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5095 | ixgbe_configure_dfwd(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5096 | } |
| 5097 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5098 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5099 | * ixgbe_sfp_link_config - set up SFP+ link |
| 5100 | * @adapter: pointer to private adapter struct |
| 5101 | **/ |
| 5102 | static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter) |
| 5103 | { |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5104 | /* |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 5105 | * We are assuming the worst case scenario here, and that |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5106 | * is that an SFP was inserted/removed after the reset |
| 5107 | * but before SFP detection was enabled. As such the best |
| 5108 | * solution is to just start searching as soon as we start |
| 5109 | */ |
| 5110 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 5111 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5112 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5113 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
Mark Rustad | 58e7cd2 | 2015-08-08 16:18:48 -0700 | [diff] [blame] | 5114 | adapter->sfp_poll_time = 0; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5115 | } |
| 5116 | |
| 5117 | /** |
| 5118 | * ixgbe_non_sfp_link_config - set up non-SFP+ link |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5119 | * @hw: pointer to private hardware struct |
| 5120 | * |
| 5121 | * Returns 0 on success, negative on failure |
| 5122 | **/ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5123 | 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] | 5124 | { |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 5125 | u32 speed; |
| 5126 | bool autoneg, link_up = false; |
Mark Rustad | a1e869d | 2015-04-10 10:36:36 -0700 | [diff] [blame] | 5127 | int ret = IXGBE_ERR_LINK_SETUP; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5128 | |
| 5129 | if (hw->mac.ops.check_link) |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 5130 | 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] | 5131 | |
| 5132 | if (ret) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 5133 | return ret; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5134 | |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 5135 | speed = hw->phy.autoneg_advertised; |
| 5136 | if ((!speed) && (hw->mac.ops.get_link_capabilities)) |
| 5137 | ret = hw->mac.ops.get_link_capabilities(hw, &speed, |
| 5138 | &autoneg); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5139 | if (ret) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 5140 | return ret; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5141 | |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 5142 | if (hw->mac.ops.setup_link) |
Josh Hay | fd0326f | 2012-12-15 03:28:30 +0000 | [diff] [blame] | 5143 | ret = hw->mac.ops.setup_link(hw, speed, link_up); |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 5144 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5145 | return ret; |
| 5146 | } |
| 5147 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5148 | static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5149 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5150 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5151 | u32 gpie = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5152 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 5153 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5154 | gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT | |
| 5155 | IXGBE_GPIE_OCD; |
| 5156 | gpie |= IXGBE_GPIE_EIAME; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 5157 | /* |
| 5158 | * use EIAM to auto-mask when MSI-X interrupt is asserted |
| 5159 | * this saves a register write for every interrupt |
| 5160 | */ |
| 5161 | switch (hw->mac.type) { |
| 5162 | case ixgbe_mac_82598EB: |
| 5163 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
| 5164 | break; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 5165 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5166 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5167 | case ixgbe_mac_X550: |
| 5168 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 5169 | case ixgbe_mac_x550em_a: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5170 | default: |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 5171 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF); |
| 5172 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF); |
| 5173 | break; |
| 5174 | } |
| 5175 | } else { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5176 | /* legacy interrupts, use EIAM to auto-mask when reading EICR, |
| 5177 | * specifically only auto mask tx and rx interrupts */ |
| 5178 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5179 | } |
| 5180 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5181 | /* XXX: to interrupt immediately for EICS writes, enable this */ |
| 5182 | /* gpie |= IXGBE_GPIE_EIMEN; */ |
| 5183 | |
| 5184 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 5185 | gpie &= ~IXGBE_GPIE_VTMODE_MASK; |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 5186 | |
| 5187 | switch (adapter->ring_feature[RING_F_VMDQ].mask) { |
| 5188 | case IXGBE_82599_VMDQ_8Q_MASK: |
| 5189 | gpie |= IXGBE_GPIE_VTMODE_16; |
| 5190 | break; |
| 5191 | case IXGBE_82599_VMDQ_4Q_MASK: |
| 5192 | gpie |= IXGBE_GPIE_VTMODE_32; |
| 5193 | break; |
| 5194 | default: |
| 5195 | gpie |= IXGBE_GPIE_VTMODE_64; |
| 5196 | break; |
| 5197 | } |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 5198 | } |
| 5199 | |
Alexander Duyck | 5fdd31f | 2011-07-21 00:40:45 +0000 | [diff] [blame] | 5200 | /* Enable Thermal over heat sensor interrupt */ |
Don Skidmore | f3df98e | 2011-08-17 10:15:21 +0000 | [diff] [blame] | 5201 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) { |
| 5202 | switch (adapter->hw.mac.type) { |
| 5203 | case ixgbe_mac_82599EB: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 5204 | gpie |= IXGBE_SDP0_GPIEN_8259X; |
Don Skidmore | f3df98e | 2011-08-17 10:15:21 +0000 | [diff] [blame] | 5205 | break; |
Don Skidmore | f3df98e | 2011-08-17 10:15:21 +0000 | [diff] [blame] | 5206 | default: |
| 5207 | break; |
| 5208 | } |
| 5209 | } |
Alexander Duyck | 5fdd31f | 2011-07-21 00:40:45 +0000 | [diff] [blame] | 5210 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5211 | /* Enable fan failure interrupt */ |
| 5212 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 5213 | gpie |= IXGBE_SDP1_GPIEN(hw); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 5214 | |
Don Skidmore | a023bbd | 2015-06-24 16:38:53 -0400 | [diff] [blame] | 5215 | switch (hw->mac.type) { |
| 5216 | case ixgbe_mac_82599EB: |
| 5217 | gpie |= IXGBE_SDP1_GPIEN_8259X | IXGBE_SDP2_GPIEN_8259X; |
| 5218 | break; |
| 5219 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 5220 | case ixgbe_mac_x550em_a: |
Don Skidmore | a023bbd | 2015-06-24 16:38:53 -0400 | [diff] [blame] | 5221 | gpie |= IXGBE_SDP0_GPIEN_X540; |
| 5222 | break; |
| 5223 | default: |
| 5224 | break; |
Don Skidmore | 2698b20 | 2011-04-13 07:01:52 +0000 | [diff] [blame] | 5225 | } |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5226 | |
| 5227 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 5228 | } |
| 5229 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 5230 | static void ixgbe_up_complete(struct ixgbe_adapter *adapter) |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5231 | { |
| 5232 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5233 | int err; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5234 | u32 ctrl_ext; |
| 5235 | |
| 5236 | ixgbe_get_hw_control(adapter); |
| 5237 | ixgbe_setup_gpie(adapter); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5238 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5239 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 5240 | ixgbe_configure_msix(adapter); |
| 5241 | else |
| 5242 | ixgbe_configure_msi_and_legacy(adapter); |
| 5243 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 5244 | /* enable the optics for 82599 SFP+ fiber */ |
| 5245 | if (hw->mac.ops.enable_tx_laser) |
Peter Waskiewicz | 61fac74 | 2010-04-27 00:38:15 +0000 | [diff] [blame] | 5246 | hw->mac.ops.enable_tx_laser(hw); |
| 5247 | |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 5248 | if (hw->phy.ops.set_phy_power) |
| 5249 | hw->phy.ops.set_phy_power(hw, true); |
| 5250 | |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 5251 | smp_mb__before_atomic(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5252 | clear_bit(__IXGBE_DOWN, &adapter->state); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5253 | ixgbe_napi_enable_all(adapter); |
| 5254 | |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 5255 | if (ixgbe_is_sfp(hw)) { |
| 5256 | ixgbe_sfp_link_config(adapter); |
| 5257 | } else { |
| 5258 | err = ixgbe_non_sfp_link_config(hw); |
| 5259 | if (err) |
| 5260 | e_err(probe, "link_config FAILED %d\n", err); |
| 5261 | } |
| 5262 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5263 | /* clear any pending interrupts, may auto mask */ |
| 5264 | IXGBE_READ_REG(hw, IXGBE_EICR); |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 5265 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5266 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5267 | /* |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5268 | * If this adapter has a fan, check to see if we had a failure |
| 5269 | * before we enabled the interrupt. |
| 5270 | */ |
| 5271 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 5272 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 5273 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5274 | e_crit(drv, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5275 | } |
| 5276 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5277 | /* bring the link up in the watchdog, this could race with our first |
| 5278 | * link up interrupt but shouldn't be a problem */ |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5279 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 5280 | adapter->link_check_timeout = jiffies; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5281 | mod_timer(&adapter->service_timer, jiffies); |
Greg Rose | c920569 | 2010-01-22 22:46:22 +0000 | [diff] [blame] | 5282 | |
| 5283 | /* Set PF Reset Done bit so PF/VF Mail Ops can work */ |
| 5284 | ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); |
| 5285 | ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD; |
| 5286 | IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5287 | } |
| 5288 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5289 | void ixgbe_reinit_locked(struct ixgbe_adapter *adapter) |
| 5290 | { |
| 5291 | WARN_ON(in_interrupt()); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5292 | /* put off any impending NetWatchDogTimeout */ |
Florian Westphal | 860e953 | 2016-05-03 16:33:13 +0200 | [diff] [blame] | 5293 | netif_trans_update(adapter->netdev); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5294 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5295 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 5296 | usleep_range(1000, 2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5297 | ixgbe_down(adapter); |
Greg Rose | 5809a1a | 2010-03-24 09:36:08 +0000 | [diff] [blame] | 5298 | /* |
| 5299 | * If SR-IOV enabled then wait a bit before bringing the adapter |
| 5300 | * back up to give the VFs time to respond to the reset. The |
| 5301 | * two second wait is based upon the watchdog timer cycle in |
| 5302 | * the VF driver. |
| 5303 | */ |
| 5304 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 5305 | msleep(2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5306 | ixgbe_up(adapter); |
| 5307 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
| 5308 | } |
| 5309 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 5310 | void ixgbe_up(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5311 | { |
| 5312 | /* hardware has been reset, we need to reload some things */ |
| 5313 | ixgbe_configure(adapter); |
| 5314 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 5315 | ixgbe_up_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5316 | } |
| 5317 | |
| 5318 | void ixgbe_reset(struct ixgbe_adapter *adapter) |
| 5319 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5320 | struct ixgbe_hw *hw = &adapter->hw; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 5321 | struct net_device *netdev = adapter->netdev; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 5322 | int err; |
| 5323 | |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 5324 | if (ixgbe_removed(hw->hw_addr)) |
| 5325 | return; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5326 | /* lock SFP init bit to prevent race conditions with the watchdog */ |
| 5327 | while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 5328 | usleep_range(1000, 2000); |
| 5329 | |
| 5330 | /* clear all SFP and link config related flags while holding SFP_INIT */ |
| 5331 | adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP | |
| 5332 | IXGBE_FLAG2_SFP_NEEDS_RESET); |
| 5333 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 5334 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 5335 | err = hw->mac.ops.init_hw(hw); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5336 | switch (err) { |
| 5337 | case 0: |
| 5338 | case IXGBE_ERR_SFP_NOT_PRESENT: |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5339 | case IXGBE_ERR_SFP_NOT_SUPPORTED: |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5340 | break; |
| 5341 | case IXGBE_ERR_MASTER_REQUESTS_PENDING: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5342 | e_dev_err("master disable timed out\n"); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5343 | break; |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 5344 | case IXGBE_ERR_EEPROM_VERSION: |
| 5345 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5346 | e_dev_warn("This device is a pre-production adapter/LOM. " |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 5347 | "Please be aware there may be issues associated with " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5348 | "your hardware. If you are experiencing problems " |
| 5349 | "please contact your Intel or hardware " |
| 5350 | "representative who provided you with this " |
| 5351 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 5352 | break; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5353 | default: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5354 | e_dev_err("Hardware Error: %d\n", err); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5355 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5356 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5357 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
Alexander Duyck | 0f079d2 | 2015-10-22 16:26:36 -0700 | [diff] [blame] | 5358 | |
| 5359 | /* flush entries out of MAC table */ |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 5360 | ixgbe_flush_sw_mac_table(adapter); |
Alexander Duyck | 0f079d2 | 2015-10-22 16:26:36 -0700 | [diff] [blame] | 5361 | __dev_uc_unsync(netdev, NULL); |
| 5362 | |
| 5363 | /* do not flush user set addresses */ |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 5364 | ixgbe_mac_set_default_filter(adapter); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 5365 | |
| 5366 | /* update SAN MAC vmdq pool selection */ |
| 5367 | if (hw->mac.san_mac_rar_index) |
| 5368 | hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0)); |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 5369 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 5370 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 5371 | ixgbe_ptp_reset(adapter); |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 5372 | |
| 5373 | if (hw->phy.ops.set_phy_power) { |
| 5374 | if (!netif_running(adapter->netdev) && !adapter->wol) |
| 5375 | hw->phy.ops.set_phy_power(hw, false); |
| 5376 | else |
| 5377 | hw->phy.ops.set_phy_power(hw, true); |
| 5378 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5379 | } |
| 5380 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5381 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5382 | * ixgbe_clean_tx_ring - Free Tx Buffers |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5383 | * @tx_ring: ring to be cleaned |
| 5384 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5385 | static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5386 | { |
| 5387 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 5388 | unsigned long size; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5389 | u16 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5390 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 5391 | /* ring already cleared, nothing to do */ |
| 5392 | if (!tx_ring->tx_buffer_info) |
| 5393 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5394 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 5395 | /* Free all the Tx ring sk_buffs */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5396 | for (i = 0; i < tx_ring->count; i++) { |
| 5397 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5398 | ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5399 | } |
| 5400 | |
John Fastabend | dad8a3b | 2012-04-23 12:22:39 +0000 | [diff] [blame] | 5401 | netdev_tx_reset_queue(txring_txq(tx_ring)); |
| 5402 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5403 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 5404 | memset(tx_ring->tx_buffer_info, 0, size); |
| 5405 | |
| 5406 | /* Zero out the descriptor ring */ |
| 5407 | memset(tx_ring->desc, 0, tx_ring->size); |
| 5408 | |
| 5409 | tx_ring->next_to_use = 0; |
| 5410 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5411 | } |
| 5412 | |
| 5413 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5414 | * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues |
| 5415 | * @adapter: board private structure |
| 5416 | **/ |
| 5417 | static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter) |
| 5418 | { |
| 5419 | int i; |
| 5420 | |
| 5421 | for (i = 0; i < adapter->num_rx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5422 | ixgbe_clean_rx_ring(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5423 | } |
| 5424 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5425 | /** |
| 5426 | * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues |
| 5427 | * @adapter: board private structure |
| 5428 | **/ |
| 5429 | static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter) |
| 5430 | { |
| 5431 | int i; |
| 5432 | |
| 5433 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5434 | ixgbe_clean_tx_ring(adapter->tx_ring[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5435 | } |
| 5436 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5437 | static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter) |
| 5438 | { |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 5439 | struct hlist_node *node2; |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5440 | struct ixgbe_fdir_filter *filter; |
| 5441 | |
| 5442 | spin_lock(&adapter->fdir_perfect_lock); |
| 5443 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 5444 | hlist_for_each_entry_safe(filter, node2, |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5445 | &adapter->fdir_filter_list, fdir_node) { |
| 5446 | hlist_del(&filter->fdir_node); |
| 5447 | kfree(filter); |
| 5448 | } |
| 5449 | adapter->fdir_filter_count = 0; |
| 5450 | |
| 5451 | spin_unlock(&adapter->fdir_perfect_lock); |
| 5452 | } |
| 5453 | |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 5454 | static int ixgbe_disable_macvlan(struct net_device *upper, void *data) |
| 5455 | { |
| 5456 | if (netif_is_macvlan(upper)) { |
| 5457 | struct macvlan_dev *vlan = netdev_priv(upper); |
| 5458 | |
| 5459 | if (vlan->fwd_priv) { |
| 5460 | netif_tx_stop_all_queues(upper); |
| 5461 | netif_carrier_off(upper); |
| 5462 | netif_tx_disable(upper); |
| 5463 | } |
| 5464 | } |
| 5465 | |
| 5466 | return 0; |
| 5467 | } |
| 5468 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5469 | void ixgbe_down(struct ixgbe_adapter *adapter) |
| 5470 | { |
| 5471 | struct net_device *netdev = adapter->netdev; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5472 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 5473 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5474 | |
| 5475 | /* signal that we are down to the interrupt handler */ |
Mark Rustad | c3049c8 | 2014-01-14 18:53:12 -0800 | [diff] [blame] | 5476 | if (test_and_set_bit(__IXGBE_DOWN, &adapter->state)) |
| 5477 | return; /* do nothing if already down */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5478 | |
| 5479 | /* disable receives */ |
Don Skidmore | 1f9ac57 | 2015-03-13 13:54:30 -0700 | [diff] [blame] | 5480 | hw->mac.ops.disable_rx(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5481 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 5482 | /* disable all enabled rx queues */ |
| 5483 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 5484 | /* this call also flushes the previous write */ |
| 5485 | ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]); |
| 5486 | |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 5487 | usleep_range(10000, 20000); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5488 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5489 | netif_tx_stop_all_queues(netdev); |
| 5490 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5491 | /* call carrier off first to avoid false dev_watchdog timeouts */ |
John Fastabend | c0dfb90 | 2010-04-27 02:13:39 +0000 | [diff] [blame] | 5492 | netif_carrier_off(netdev); |
| 5493 | netif_tx_disable(netdev); |
| 5494 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5495 | /* disable any upper devices */ |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 5496 | netdev_walk_all_upper_dev_rcu(adapter->netdev, |
| 5497 | ixgbe_disable_macvlan, NULL); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5498 | |
John Fastabend | c0dfb90 | 2010-04-27 02:13:39 +0000 | [diff] [blame] | 5499 | ixgbe_irq_disable(adapter); |
| 5500 | |
| 5501 | ixgbe_napi_disable_all(adapter); |
| 5502 | |
Emil Tantilov | 57ca2a4 | 2016-07-29 14:46:31 -0700 | [diff] [blame] | 5503 | clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state); |
| 5504 | adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5505 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 5506 | |
| 5507 | del_timer_sync(&adapter->service_timer); |
| 5508 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 5509 | if (adapter->num_vfs) { |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 5510 | /* Clear EITR Select mapping */ |
| 5511 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0); |
| 5512 | |
| 5513 | /* Mark all the VFs as inactive */ |
| 5514 | for (i = 0 ; i < adapter->num_vfs; i++) |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 5515 | adapter->vfinfo[i].clear_to_send = false; |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 5516 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 5517 | /* 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] | 5518 | ixgbe_ping_all_vfs(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5519 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5520 | /* Disable all VFTE/VFRE TX/RX */ |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 5521 | ixgbe_disable_tx_rx(adapter); |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 5522 | } |
| 5523 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5524 | /* disable transmits in the hardware now that interrupts are off */ |
| 5525 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 5526 | u8 reg_idx = adapter->tx_ring[i]->reg_idx; |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 5527 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5528 | } |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 5529 | |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5530 | /* Disable the Tx DMA engine on 82599 and later MAC */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5531 | switch (hw->mac.type) { |
| 5532 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5533 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5534 | case ixgbe_mac_X550: |
| 5535 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 5536 | case ixgbe_mac_x550em_a: |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 5537 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 5538 | (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) & |
| 5539 | ~IXGBE_DMATXCTL_TE)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5540 | break; |
| 5541 | default: |
| 5542 | break; |
| 5543 | } |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5544 | |
Paul Larson | 6f4a0e4 | 2008-06-24 17:00:56 -0700 | [diff] [blame] | 5545 | if (!pci_channel_offline(adapter->pdev)) |
| 5546 | ixgbe_reset(adapter); |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 5547 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 5548 | /* power down the optics for 82599 SFP+ fiber */ |
| 5549 | if (hw->mac.ops.disable_tx_laser) |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 5550 | hw->mac.ops.disable_tx_laser(hw); |
| 5551 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5552 | ixgbe_clean_all_tx_rings(adapter); |
| 5553 | ixgbe_clean_all_rx_rings(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5554 | } |
| 5555 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5556 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5557 | * ixgbe_tx_timeout - Respond to a Tx Hang |
| 5558 | * @netdev: network interface device structure |
| 5559 | **/ |
| 5560 | static void ixgbe_tx_timeout(struct net_device *netdev) |
| 5561 | { |
| 5562 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5563 | |
| 5564 | /* Do the reset outside of interrupt context */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 5565 | ixgbe_tx_timeout_reset(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5566 | } |
| 5567 | |
Usha Ketineni | 8829009 | 2016-04-26 05:00:26 -0700 | [diff] [blame] | 5568 | #ifdef CONFIG_IXGBE_DCB |
| 5569 | static void ixgbe_init_dcb(struct ixgbe_adapter *adapter) |
| 5570 | { |
| 5571 | struct ixgbe_hw *hw = &adapter->hw; |
| 5572 | struct tc_configuration *tc; |
| 5573 | int j; |
| 5574 | |
| 5575 | switch (hw->mac.type) { |
| 5576 | case ixgbe_mac_82598EB: |
| 5577 | case ixgbe_mac_82599EB: |
| 5578 | adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS; |
| 5579 | adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS; |
| 5580 | break; |
| 5581 | case ixgbe_mac_X540: |
| 5582 | case ixgbe_mac_X550: |
| 5583 | adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS; |
| 5584 | adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS; |
| 5585 | break; |
| 5586 | case ixgbe_mac_X550EM_x: |
| 5587 | case ixgbe_mac_x550em_a: |
| 5588 | default: |
| 5589 | adapter->dcb_cfg.num_tcs.pg_tcs = DEF_TRAFFIC_CLASS; |
| 5590 | adapter->dcb_cfg.num_tcs.pfc_tcs = DEF_TRAFFIC_CLASS; |
| 5591 | break; |
| 5592 | } |
| 5593 | |
| 5594 | /* Configure DCB traffic classes */ |
| 5595 | for (j = 0; j < MAX_TRAFFIC_CLASS; j++) { |
| 5596 | tc = &adapter->dcb_cfg.tc_config[j]; |
| 5597 | tc->path[DCB_TX_CONFIG].bwg_id = 0; |
| 5598 | tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1); |
| 5599 | tc->path[DCB_RX_CONFIG].bwg_id = 0; |
| 5600 | tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1); |
| 5601 | tc->dcb_pfc = pfc_disabled; |
| 5602 | } |
| 5603 | |
| 5604 | /* Initialize default user to priority mapping, UPx->TC0 */ |
| 5605 | tc = &adapter->dcb_cfg.tc_config[0]; |
| 5606 | tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF; |
| 5607 | tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF; |
| 5608 | |
| 5609 | adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100; |
| 5610 | adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100; |
| 5611 | adapter->dcb_cfg.pfc_mode_enable = false; |
| 5612 | adapter->dcb_set_bitmap = 0x00; |
| 5613 | if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE) |
| 5614 | adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE; |
| 5615 | memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg, |
| 5616 | sizeof(adapter->temp_dcb_cfg)); |
| 5617 | } |
| 5618 | #endif |
| 5619 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 5620 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5621 | * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter) |
| 5622 | * @adapter: board private structure to initialize |
| 5623 | * |
| 5624 | * ixgbe_sw_init initializes the Adapter private data structure. |
| 5625 | * Fields are initialized based on PCI device information and |
| 5626 | * OS network device settings (MTU size). |
| 5627 | **/ |
Emil Tantilov | 55570b6 | 2016-10-12 12:34:25 -0700 | [diff] [blame] | 5628 | static int ixgbe_sw_init(struct ixgbe_adapter *adapter, |
| 5629 | const struct ixgbe_info *ii) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5630 | { |
| 5631 | struct ixgbe_hw *hw = &adapter->hw; |
| 5632 | struct pci_dev *pdev = adapter->pdev; |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 5633 | unsigned int rss, fdir; |
Jacob Keller | cb6d0f5 | 2012-12-04 06:03:14 +0000 | [diff] [blame] | 5634 | u32 fwsm; |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 5635 | int i; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5636 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5637 | /* PCI config space info */ |
| 5638 | |
| 5639 | hw->vendor_id = pdev->vendor; |
| 5640 | hw->device_id = pdev->device; |
| 5641 | hw->revision_id = pdev->revision; |
| 5642 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 5643 | hw->subsystem_device_id = pdev->subsystem_device; |
| 5644 | |
Emil Tantilov | 55570b6 | 2016-10-12 12:34:25 -0700 | [diff] [blame] | 5645 | /* get_invariants needs the device IDs */ |
| 5646 | ii->get_invariants(hw); |
| 5647 | |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5648 | /* Set common capability flags and settings */ |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 5649 | rss = min_t(int, ixgbe_max_rss_indices(adapter), num_online_cpus()); |
Alexander Duyck | c087663 | 2012-05-10 00:01:46 +0000 | [diff] [blame] | 5650 | adapter->ring_feature[RING_F_RSS].limit = rss; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5651 | adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5652 | adapter->max_q_vectors = MAX_Q_VECTORS_82599; |
| 5653 | adapter->atr_sample_rate = 20; |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 5654 | fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus()); |
| 5655 | adapter->ring_feature[RING_F_FDIR].limit = fdir; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5656 | adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K; |
| 5657 | #ifdef CONFIG_IXGBE_DCA |
| 5658 | adapter->flags |= IXGBE_FLAG_DCA_CAPABLE; |
| 5659 | #endif |
Usha Ketineni | 8829009 | 2016-04-26 05:00:26 -0700 | [diff] [blame] | 5660 | #ifdef CONFIG_IXGBE_DCB |
| 5661 | adapter->flags |= IXGBE_FLAG_DCB_CAPABLE; |
| 5662 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
| 5663 | #endif |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5664 | #ifdef IXGBE_FCOE |
| 5665 | adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE; |
| 5666 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 5667 | #ifdef CONFIG_IXGBE_DCB |
| 5668 | /* Default traffic class to use for FCoE */ |
| 5669 | adapter->fcoe.up = IXGBE_FCOE_DEFTC; |
| 5670 | #endif /* CONFIG_IXGBE_DCB */ |
| 5671 | #endif /* IXGBE_FCOE */ |
| 5672 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 5673 | /* initialize static ixgbe jump table entries */ |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 5674 | adapter->jump_tables[0] = kzalloc(sizeof(*adapter->jump_tables[0]), |
| 5675 | GFP_KERNEL); |
| 5676 | if (!adapter->jump_tables[0]) |
| 5677 | return -ENOMEM; |
| 5678 | adapter->jump_tables[0]->mat = ixgbe_ipv4_fields; |
| 5679 | |
| 5680 | for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) |
| 5681 | adapter->jump_tables[i] = NULL; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 5682 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 5683 | adapter->mac_table = kzalloc(sizeof(struct ixgbe_mac_addr) * |
| 5684 | hw->mac.num_rar_entries, |
| 5685 | GFP_ATOMIC); |
Alexander Duyck | 530fd82 | 2015-11-02 17:09:29 -0800 | [diff] [blame] | 5686 | if (!adapter->mac_table) |
| 5687 | return -ENOMEM; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 5688 | |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5689 | /* Set MAC specific capability flags and exceptions */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5690 | switch (hw->mac.type) { |
| 5691 | case ixgbe_mac_82598EB: |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5692 | adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5693 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5694 | if (hw->device_id == IXGBE_DEV_ID_82598AT) |
| 5695 | adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5696 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 5697 | adapter->max_q_vectors = MAX_Q_VECTORS_82598; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5698 | adapter->ring_feature[RING_F_FDIR].limit = 0; |
| 5699 | adapter->atr_sample_rate = 0; |
| 5700 | adapter->fdir_pballoc = 0; |
| 5701 | #ifdef IXGBE_FCOE |
| 5702 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
| 5703 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 5704 | #ifdef CONFIG_IXGBE_DCB |
| 5705 | adapter->fcoe.up = 0; |
| 5706 | #endif /* IXGBE_DCB */ |
| 5707 | #endif /* IXGBE_FCOE */ |
| 5708 | break; |
| 5709 | case ixgbe_mac_82599EB: |
| 5710 | if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM) |
| 5711 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5712 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5713 | case ixgbe_mac_X540: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 5714 | fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw)); |
Jacob Keller | cb6d0f5 | 2012-12-04 06:03:14 +0000 | [diff] [blame] | 5715 | if (fwsm & IXGBE_FWSM_TS_ENABLED) |
| 5716 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5717 | break; |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 5718 | case ixgbe_mac_x550em_a: |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 5719 | adapter->flags |= IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE; |
| 5720 | /* fall through */ |
| 5721 | case ixgbe_mac_X550EM_x: |
Usha Ketineni | 8829009 | 2016-04-26 05:00:26 -0700 | [diff] [blame] | 5722 | #ifdef CONFIG_IXGBE_DCB |
| 5723 | adapter->flags &= ~IXGBE_FLAG_DCB_CAPABLE; |
| 5724 | #endif |
| 5725 | #ifdef IXGBE_FCOE |
| 5726 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
| 5727 | #ifdef CONFIG_IXGBE_DCB |
| 5728 | adapter->fcoe.up = 0; |
| 5729 | #endif /* IXGBE_DCB */ |
| 5730 | #endif /* IXGBE_FCOE */ |
| 5731 | /* Fall Through */ |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5732 | case ixgbe_mac_X550: |
| 5733 | #ifdef CONFIG_IXGBE_DCA |
| 5734 | adapter->flags &= ~IXGBE_FLAG_DCA_CAPABLE; |
| 5735 | #endif |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 5736 | adapter->flags |= IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE; |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5737 | break; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5738 | default: |
| 5739 | break; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5740 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5741 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 5742 | #ifdef IXGBE_FCOE |
| 5743 | /* FCoE support exists, always init the FCoE lock */ |
| 5744 | spin_lock_init(&adapter->fcoe.lock); |
| 5745 | |
| 5746 | #endif |
Alexander Duyck | 1fc5f03 | 2011-06-02 04:28:39 +0000 | [diff] [blame] | 5747 | /* n-tuple support exists, always init our spinlock */ |
| 5748 | spin_lock_init(&adapter->fdir_perfect_lock); |
| 5749 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5750 | #ifdef CONFIG_IXGBE_DCB |
Usha Ketineni | 8829009 | 2016-04-26 05:00:26 -0700 | [diff] [blame] | 5751 | ixgbe_init_dcb(adapter); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5752 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5753 | |
| 5754 | /* default flow control settings */ |
Don Skidmore | cd7664f | 2009-03-31 21:33:44 +0000 | [diff] [blame] | 5755 | hw->fc.requested_mode = ixgbe_fc_full; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 5756 | hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */ |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5757 | ixgbe_pbthresh_setup(adapter); |
Jesse Brandeburg | 2b9ade9 | 2008-08-26 04:27:10 -0700 | [diff] [blame] | 5758 | hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE; |
| 5759 | hw->fc.send_xon = true; |
Don Skidmore | 73d80953d | 2013-07-31 02:19:24 +0000 | [diff] [blame] | 5760 | hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5761 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 5762 | #ifdef CONFIG_PCI_IOV |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 5763 | if (max_vfs > 0) |
| 5764 | 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] | 5765 | |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 5766 | /* assign number of SR-IOV VFs */ |
| 5767 | if (hw->mac.type != ixgbe_mac_82598EB) { |
ethan.zhao | dcc23e3 | 2014-01-16 19:41:04 -0800 | [diff] [blame] | 5768 | if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) { |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 5769 | adapter->num_vfs = 0; |
| 5770 | e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n"); |
| 5771 | } else { |
| 5772 | adapter->num_vfs = max_vfs; |
| 5773 | } |
| 5774 | } |
| 5775 | #endif /* CONFIG_PCI_IOV */ |
| 5776 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5777 | /* enable itr by default in dynamic mode */ |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 5778 | adapter->rx_itr_setting = 1; |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 5779 | adapter->tx_itr_setting = 1; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5780 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5781 | /* set default ring sizes */ |
| 5782 | adapter->tx_ring_count = IXGBE_DEFAULT_TXD; |
| 5783 | adapter->rx_ring_count = IXGBE_DEFAULT_RXD; |
| 5784 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 5785 | /* set default work limits */ |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 5786 | adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 5787 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5788 | /* initialize eeprom parameters */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5789 | if (ixgbe_init_eeprom_params_generic(hw)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5790 | e_dev_err("EEPROM initialization failed\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5791 | return -EIO; |
| 5792 | } |
| 5793 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5794 | /* PF holds first pool slot */ |
| 5795 | set_bit(0, &adapter->fwd_bitmask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5796 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 5797 | |
| 5798 | return 0; |
| 5799 | } |
| 5800 | |
| 5801 | /** |
| 5802 | * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5803 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5804 | * |
| 5805 | * Return 0 on success, negative on failure |
| 5806 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5807 | int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5808 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5809 | struct device *dev = tx_ring->dev; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5810 | int orig_node = dev_to_node(dev); |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5811 | int ring_node = -1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5812 | int size; |
| 5813 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5814 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5815 | |
| 5816 | if (tx_ring->q_vector) |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5817 | ring_node = tx_ring->q_vector->numa_node; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5818 | |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5819 | tx_ring->tx_buffer_info = vzalloc_node(size, ring_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5820 | if (!tx_ring->tx_buffer_info) |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5821 | tx_ring->tx_buffer_info = vzalloc(size); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5822 | if (!tx_ring->tx_buffer_info) |
| 5823 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5824 | |
John Stultz | 827da44 | 2013-10-07 15:51:58 -0700 | [diff] [blame] | 5825 | u64_stats_init(&tx_ring->syncp); |
| 5826 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5827 | /* round up to nearest 4K */ |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 5828 | tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5829 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5830 | |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5831 | set_dev_node(dev, ring_node); |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5832 | tx_ring->desc = dma_alloc_coherent(dev, |
| 5833 | tx_ring->size, |
| 5834 | &tx_ring->dma, |
| 5835 | GFP_KERNEL); |
| 5836 | set_dev_node(dev, orig_node); |
| 5837 | if (!tx_ring->desc) |
| 5838 | tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size, |
| 5839 | &tx_ring->dma, GFP_KERNEL); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5840 | if (!tx_ring->desc) |
| 5841 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5842 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5843 | tx_ring->next_to_use = 0; |
| 5844 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5845 | return 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5846 | |
| 5847 | err: |
| 5848 | vfree(tx_ring->tx_buffer_info); |
| 5849 | tx_ring->tx_buffer_info = NULL; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5850 | 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] | 5851 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5852 | } |
| 5853 | |
| 5854 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5855 | * ixgbe_setup_all_tx_resources - allocate all queues Tx resources |
| 5856 | * @adapter: board private structure |
| 5857 | * |
| 5858 | * If this function returns with an error, then it's possible one or |
| 5859 | * more of the rings is populated (while the rest are not). It is the |
| 5860 | * callers duty to clean those orphaned rings. |
| 5861 | * |
| 5862 | * Return 0 on success, negative on failure |
| 5863 | **/ |
| 5864 | static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) |
| 5865 | { |
| 5866 | int i, err = 0; |
| 5867 | |
| 5868 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5869 | err = ixgbe_setup_tx_resources(adapter->tx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5870 | if (!err) |
| 5871 | continue; |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5872 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5873 | e_err(probe, "Allocation for Tx Queue %u failed\n", i); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5874 | goto err_setup_tx; |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5875 | } |
| 5876 | |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5877 | return 0; |
| 5878 | err_setup_tx: |
| 5879 | /* rewind the index freeing the rings as we go */ |
| 5880 | while (i--) |
| 5881 | ixgbe_free_tx_resources(adapter->tx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5882 | return err; |
| 5883 | } |
| 5884 | |
| 5885 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5886 | * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5887 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5888 | * |
| 5889 | * Returns 0 on success, negative on failure |
| 5890 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5891 | int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5892 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5893 | struct device *dev = rx_ring->dev; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5894 | int orig_node = dev_to_node(dev); |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5895 | int ring_node = -1; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5896 | int size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5897 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5898 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5899 | |
| 5900 | if (rx_ring->q_vector) |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5901 | ring_node = rx_ring->q_vector->numa_node; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5902 | |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5903 | rx_ring->rx_buffer_info = vzalloc_node(size, ring_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5904 | if (!rx_ring->rx_buffer_info) |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5905 | rx_ring->rx_buffer_info = vzalloc(size); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5906 | if (!rx_ring->rx_buffer_info) |
| 5907 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5908 | |
John Stultz | 827da44 | 2013-10-07 15:51:58 -0700 | [diff] [blame] | 5909 | u64_stats_init(&rx_ring->syncp); |
| 5910 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5911 | /* Round up to nearest 4K */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5912 | rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); |
| 5913 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5914 | |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5915 | set_dev_node(dev, ring_node); |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5916 | rx_ring->desc = dma_alloc_coherent(dev, |
| 5917 | rx_ring->size, |
| 5918 | &rx_ring->dma, |
| 5919 | GFP_KERNEL); |
| 5920 | set_dev_node(dev, orig_node); |
| 5921 | if (!rx_ring->desc) |
| 5922 | rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size, |
| 5923 | &rx_ring->dma, GFP_KERNEL); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5924 | if (!rx_ring->desc) |
| 5925 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5926 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5927 | rx_ring->next_to_clean = 0; |
| 5928 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5929 | |
| 5930 | return 0; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5931 | err: |
| 5932 | vfree(rx_ring->rx_buffer_info); |
| 5933 | rx_ring->rx_buffer_info = NULL; |
| 5934 | 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] | 5935 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5936 | } |
| 5937 | |
| 5938 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5939 | * ixgbe_setup_all_rx_resources - allocate all queues Rx resources |
| 5940 | * @adapter: board private structure |
| 5941 | * |
| 5942 | * If this function returns with an error, then it's possible one or |
| 5943 | * more of the rings is populated (while the rest are not). It is the |
| 5944 | * callers duty to clean those orphaned rings. |
| 5945 | * |
| 5946 | * Return 0 on success, negative on failure |
| 5947 | **/ |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5948 | static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) |
| 5949 | { |
| 5950 | int i, err = 0; |
| 5951 | |
| 5952 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5953 | err = ixgbe_setup_rx_resources(adapter->rx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5954 | if (!err) |
| 5955 | continue; |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5956 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5957 | e_err(probe, "Allocation for Rx Queue %u failed\n", i); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5958 | goto err_setup_rx; |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5959 | } |
| 5960 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 5961 | #ifdef IXGBE_FCOE |
| 5962 | err = ixgbe_setup_fcoe_ddp_resources(adapter); |
| 5963 | if (!err) |
| 5964 | #endif |
| 5965 | return 0; |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5966 | err_setup_rx: |
| 5967 | /* rewind the index freeing the rings as we go */ |
| 5968 | while (i--) |
| 5969 | ixgbe_free_rx_resources(adapter->rx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5970 | return err; |
| 5971 | } |
| 5972 | |
| 5973 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5974 | * ixgbe_free_tx_resources - Free Tx Resources per Queue |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5975 | * @tx_ring: Tx descriptor ring for a specific queue |
| 5976 | * |
| 5977 | * Free all transmit software resources |
| 5978 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5979 | void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5980 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5981 | ixgbe_clean_tx_ring(tx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5982 | |
| 5983 | vfree(tx_ring->tx_buffer_info); |
| 5984 | tx_ring->tx_buffer_info = NULL; |
| 5985 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5986 | /* if not set, then don't free */ |
| 5987 | if (!tx_ring->desc) |
| 5988 | return; |
| 5989 | |
| 5990 | dma_free_coherent(tx_ring->dev, tx_ring->size, |
| 5991 | tx_ring->desc, tx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5992 | |
| 5993 | tx_ring->desc = NULL; |
| 5994 | } |
| 5995 | |
| 5996 | /** |
| 5997 | * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues |
| 5998 | * @adapter: board private structure |
| 5999 | * |
| 6000 | * Free all transmit software resources |
| 6001 | **/ |
| 6002 | static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter) |
| 6003 | { |
| 6004 | int i; |
| 6005 | |
| 6006 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 6007 | if (adapter->tx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6008 | ixgbe_free_tx_resources(adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6009 | } |
| 6010 | |
| 6011 | /** |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6012 | * ixgbe_free_rx_resources - Free Rx Resources |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6013 | * @rx_ring: ring to clean the resources from |
| 6014 | * |
| 6015 | * Free all receive software resources |
| 6016 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6017 | void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6018 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6019 | ixgbe_clean_rx_ring(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6020 | |
| 6021 | vfree(rx_ring->rx_buffer_info); |
| 6022 | rx_ring->rx_buffer_info = NULL; |
| 6023 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6024 | /* if not set, then don't free */ |
| 6025 | if (!rx_ring->desc) |
| 6026 | return; |
| 6027 | |
| 6028 | dma_free_coherent(rx_ring->dev, rx_ring->size, |
| 6029 | rx_ring->desc, rx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6030 | |
| 6031 | rx_ring->desc = NULL; |
| 6032 | } |
| 6033 | |
| 6034 | /** |
| 6035 | * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues |
| 6036 | * @adapter: board private structure |
| 6037 | * |
| 6038 | * Free all receive software resources |
| 6039 | **/ |
| 6040 | static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter) |
| 6041 | { |
| 6042 | int i; |
| 6043 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 6044 | #ifdef IXGBE_FCOE |
| 6045 | ixgbe_free_fcoe_ddp_resources(adapter); |
| 6046 | |
| 6047 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6048 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 6049 | if (adapter->rx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6050 | ixgbe_free_rx_resources(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6051 | } |
| 6052 | |
| 6053 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6054 | * ixgbe_change_mtu - Change the Maximum Transfer Unit |
| 6055 | * @netdev: network interface device structure |
| 6056 | * @new_mtu: new value for maximum frame size |
| 6057 | * |
| 6058 | * Returns 0 on success, negative on failure |
| 6059 | **/ |
| 6060 | static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu) |
| 6061 | { |
| 6062 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 655309e | 2012-02-08 07:50:35 +0000 | [diff] [blame] | 6063 | |
| 6064 | /* |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 6065 | * For 82599EB we cannot allow legacy VFs to enable their receive |
| 6066 | * paths when MTU greater than 1500 is configured. So display a |
| 6067 | * warning that legacy VFs will be disabled. |
Alexander Duyck | 655309e | 2012-02-08 07:50:35 +0000 | [diff] [blame] | 6068 | */ |
| 6069 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && |
| 6070 | (adapter->hw.mac.type == ixgbe_mac_82599EB) && |
Jarod Wilson | 91c527a | 2016-10-17 15:54:05 -0400 | [diff] [blame] | 6071 | (new_mtu > ETH_DATA_LEN)) |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 6072 | e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6073 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 6074 | 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] | 6075 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6076 | /* must set new MTU before calling down or up */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6077 | netdev->mtu = new_mtu; |
| 6078 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 6079 | if (netif_running(netdev)) |
| 6080 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6081 | |
| 6082 | return 0; |
| 6083 | } |
| 6084 | |
| 6085 | /** |
| 6086 | * ixgbe_open - Called when a network interface is made active |
| 6087 | * @netdev: network interface device structure |
| 6088 | * |
| 6089 | * Returns 0 on success, negative value on failure |
| 6090 | * |
| 6091 | * The open entry point is called when a network interface is made |
| 6092 | * active by the system (IFF_UP). At this point all resources needed |
| 6093 | * for transmit and receive operations are allocated, the interrupt |
| 6094 | * handler is registered with the OS, the watchdog timer is started, |
| 6095 | * and the stack is notified that the interface is ready. |
| 6096 | **/ |
Stefan Assmann | 6c211fe1 | 2016-02-03 09:20:48 +0100 | [diff] [blame] | 6097 | int ixgbe_open(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6098 | { |
| 6099 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 6100 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 6101 | int err, queues; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6102 | |
Auke Kok | 4bebfaa | 2008-02-11 09:26:01 -0800 | [diff] [blame] | 6103 | /* disallow open during test */ |
| 6104 | if (test_bit(__IXGBE_TESTING, &adapter->state)) |
| 6105 | return -EBUSY; |
| 6106 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 6107 | netif_carrier_off(netdev); |
| 6108 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6109 | /* allocate transmit descriptors */ |
| 6110 | err = ixgbe_setup_all_tx_resources(adapter); |
| 6111 | if (err) |
| 6112 | goto err_setup_tx; |
| 6113 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6114 | /* allocate receive descriptors */ |
| 6115 | err = ixgbe_setup_all_rx_resources(adapter); |
| 6116 | if (err) |
| 6117 | goto err_setup_rx; |
| 6118 | |
| 6119 | ixgbe_configure(adapter); |
| 6120 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6121 | err = ixgbe_request_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6122 | if (err) |
| 6123 | goto err_req_irq; |
| 6124 | |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6125 | /* Notify the stack of the actual queue counts. */ |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 6126 | if (adapter->num_rx_pools > 1) |
| 6127 | queues = adapter->num_rx_queues_per_pool; |
| 6128 | else |
| 6129 | queues = adapter->num_tx_queues; |
| 6130 | |
| 6131 | err = netif_set_real_num_tx_queues(netdev, queues); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6132 | if (err) |
| 6133 | goto err_set_queues; |
| 6134 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 6135 | if (adapter->num_rx_pools > 1 && |
| 6136 | adapter->num_rx_queues > IXGBE_MAX_L2A_QUEUES) |
| 6137 | queues = IXGBE_MAX_L2A_QUEUES; |
| 6138 | else |
| 6139 | queues = adapter->num_rx_queues; |
| 6140 | err = netif_set_real_num_rx_queues(netdev, queues); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6141 | if (err) |
| 6142 | goto err_set_queues; |
| 6143 | |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6144 | ixgbe_ptp_init(adapter); |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6145 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 6146 | ixgbe_up_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6147 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 6148 | ixgbe_clear_udp_tunnel_port(adapter, IXGBE_VXLANCTRL_ALL_UDPPORT_MASK); |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 6149 | udp_tunnel_get_rx_info(netdev); |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 6150 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6151 | return 0; |
| 6152 | |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6153 | err_set_queues: |
| 6154 | ixgbe_free_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6155 | err_req_irq: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 6156 | ixgbe_free_all_rx_resources(adapter); |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 6157 | if (hw->phy.ops.set_phy_power && !adapter->wol) |
| 6158 | hw->phy.ops.set_phy_power(&adapter->hw, false); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6159 | err_setup_rx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 6160 | ixgbe_free_all_tx_resources(adapter); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6161 | err_setup_tx: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6162 | ixgbe_reset(adapter); |
| 6163 | |
| 6164 | return err; |
| 6165 | } |
| 6166 | |
Jacob Keller | a0cccce | 2014-05-16 05:12:29 +0000 | [diff] [blame] | 6167 | static void ixgbe_close_suspend(struct ixgbe_adapter *adapter) |
| 6168 | { |
| 6169 | ixgbe_ptp_suspend(adapter); |
| 6170 | |
Don Skidmore | 6ac7439 | 2015-06-17 17:34:31 -0400 | [diff] [blame] | 6171 | if (adapter->hw.phy.ops.enter_lplu) { |
| 6172 | adapter->hw.phy.reset_disable = true; |
| 6173 | ixgbe_down(adapter); |
| 6174 | adapter->hw.phy.ops.enter_lplu(&adapter->hw); |
| 6175 | adapter->hw.phy.reset_disable = false; |
| 6176 | } else { |
| 6177 | ixgbe_down(adapter); |
| 6178 | } |
| 6179 | |
Jacob Keller | a0cccce | 2014-05-16 05:12:29 +0000 | [diff] [blame] | 6180 | ixgbe_free_irq(adapter); |
| 6181 | |
| 6182 | ixgbe_free_all_tx_resources(adapter); |
| 6183 | ixgbe_free_all_rx_resources(adapter); |
| 6184 | } |
| 6185 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6186 | /** |
| 6187 | * ixgbe_close - Disables a network interface |
| 6188 | * @netdev: network interface device structure |
| 6189 | * |
| 6190 | * Returns 0, this is not allowed to fail |
| 6191 | * |
| 6192 | * The close entry point is called when an interface is de-activated |
| 6193 | * by the OS. The hardware is still under the drivers control, but |
| 6194 | * needs to be disabled. A global MAC reset is issued to stop the |
| 6195 | * hardware, and all transmit and receive resources are freed. |
| 6196 | **/ |
Stefan Assmann | 6c211fe1 | 2016-02-03 09:20:48 +0100 | [diff] [blame] | 6197 | int ixgbe_close(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6198 | { |
| 6199 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6200 | |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6201 | ixgbe_ptp_stop(adapter); |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6202 | |
Jacob Keller | a0cccce | 2014-05-16 05:12:29 +0000 | [diff] [blame] | 6203 | ixgbe_close_suspend(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6204 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 6205 | ixgbe_fdir_filter_exit(adapter); |
| 6206 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 6207 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6208 | |
| 6209 | return 0; |
| 6210 | } |
| 6211 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6212 | #ifdef CONFIG_PM |
| 6213 | static int ixgbe_resume(struct pci_dev *pdev) |
| 6214 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 6215 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 6216 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6217 | u32 err; |
| 6218 | |
Mark Rustad | 0391bbe | 2014-02-28 15:48:55 -0800 | [diff] [blame] | 6219 | adapter->hw.hw_addr = adapter->io_addr; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6220 | pci_set_power_state(pdev, PCI_D0); |
| 6221 | pci_restore_state(pdev); |
Don Skidmore | 656ab81 | 2009-12-23 21:19:19 -0800 | [diff] [blame] | 6222 | /* |
| 6223 | * pci_restore_state clears dev->state_saved so call |
| 6224 | * pci_save_state to restore it. |
| 6225 | */ |
| 6226 | pci_save_state(pdev); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 6227 | |
| 6228 | err = pci_enable_device_mem(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6229 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 6230 | e_dev_err("Cannot enable PCI device from suspend\n"); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6231 | return err; |
| 6232 | } |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 6233 | smp_mb__before_atomic(); |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 6234 | clear_bit(__IXGBE_DISABLED, &adapter->state); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6235 | pci_set_master(pdev); |
| 6236 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 6237 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6238 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6239 | ixgbe_reset(adapter); |
| 6240 | |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 6241 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
| 6242 | |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6243 | rtnl_lock(); |
| 6244 | err = ixgbe_init_interrupt_scheme(adapter); |
| 6245 | if (!err && netif_running(netdev)) |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 6246 | err = ixgbe_open(netdev); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6247 | |
| 6248 | rtnl_unlock(); |
| 6249 | |
| 6250 | if (err) |
| 6251 | return err; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6252 | |
| 6253 | netif_device_attach(netdev); |
| 6254 | |
| 6255 | return 0; |
| 6256 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6257 | #endif /* CONFIG_PM */ |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6258 | |
| 6259 | static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6260 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 6261 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 6262 | struct net_device *netdev = adapter->netdev; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6263 | struct ixgbe_hw *hw = &adapter->hw; |
| 6264 | u32 ctrl, fctrl; |
| 6265 | u32 wufc = adapter->wol; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6266 | #ifdef CONFIG_PM |
| 6267 | int retval = 0; |
| 6268 | #endif |
| 6269 | |
| 6270 | netif_device_detach(netdev); |
| 6271 | |
akepner | 499ab5c | 2013-03-13 14:54:58 +0000 | [diff] [blame] | 6272 | rtnl_lock(); |
Jacob Keller | a0cccce | 2014-05-16 05:12:29 +0000 | [diff] [blame] | 6273 | if (netif_running(netdev)) |
| 6274 | ixgbe_close_suspend(adapter); |
akepner | 499ab5c | 2013-03-13 14:54:58 +0000 | [diff] [blame] | 6275 | rtnl_unlock(); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6276 | |
Alexander Duyck | 5f5ae6f | 2010-11-16 19:26:52 -0800 | [diff] [blame] | 6277 | ixgbe_clear_interrupt_scheme(adapter); |
| 6278 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6279 | #ifdef CONFIG_PM |
| 6280 | retval = pci_save_state(pdev); |
| 6281 | if (retval) |
| 6282 | return retval; |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 6283 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6284 | #endif |
Jacob Keller | f4f1040 | 2013-06-25 07:59:23 +0000 | [diff] [blame] | 6285 | if (hw->mac.ops.stop_link_on_d3) |
| 6286 | hw->mac.ops.stop_link_on_d3(hw); |
| 6287 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6288 | if (wufc) { |
| 6289 | ixgbe_set_rx_mode(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6290 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 6291 | /* enable the optics for 82599 SFP+ fiber as we can WoL */ |
| 6292 | if (hw->mac.ops.enable_tx_laser) |
Don Skidmore | c509e75 | 2012-04-05 08:12:05 +0000 | [diff] [blame] | 6293 | hw->mac.ops.enable_tx_laser(hw); |
| 6294 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6295 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 6296 | if (wufc & IXGBE_WUFC_MC) { |
| 6297 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 6298 | fctrl |= IXGBE_FCTRL_MPE; |
| 6299 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
| 6300 | } |
| 6301 | |
| 6302 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 6303 | ctrl |= IXGBE_CTRL_GIO_DIS; |
| 6304 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); |
| 6305 | |
| 6306 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc); |
| 6307 | } else { |
| 6308 | IXGBE_WRITE_REG(hw, IXGBE_WUC, 0); |
| 6309 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0); |
| 6310 | } |
| 6311 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6312 | switch (hw->mac.type) { |
| 6313 | case ixgbe_mac_82598EB: |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 6314 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6315 | break; |
| 6316 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 6317 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6318 | case ixgbe_mac_X550: |
| 6319 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 6320 | case ixgbe_mac_x550em_a: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6321 | pci_wake_from_d3(pdev, !!wufc); |
| 6322 | break; |
| 6323 | default: |
| 6324 | break; |
| 6325 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6326 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6327 | *enable_wake = !!wufc; |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 6328 | if (hw->phy.ops.set_phy_power && !*enable_wake) |
| 6329 | hw->phy.ops.set_phy_power(hw, false); |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6330 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6331 | ixgbe_release_hw_control(adapter); |
| 6332 | |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 6333 | if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state)) |
| 6334 | pci_disable_device(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6335 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6336 | return 0; |
| 6337 | } |
| 6338 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6339 | #ifdef CONFIG_PM |
| 6340 | static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state) |
| 6341 | { |
| 6342 | int retval; |
| 6343 | bool wake; |
| 6344 | |
| 6345 | retval = __ixgbe_shutdown(pdev, &wake); |
| 6346 | if (retval) |
| 6347 | return retval; |
| 6348 | |
| 6349 | if (wake) { |
| 6350 | pci_prepare_to_sleep(pdev); |
| 6351 | } else { |
| 6352 | pci_wake_from_d3(pdev, false); |
| 6353 | pci_set_power_state(pdev, PCI_D3hot); |
| 6354 | } |
| 6355 | |
| 6356 | return 0; |
| 6357 | } |
| 6358 | #endif /* CONFIG_PM */ |
| 6359 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6360 | static void ixgbe_shutdown(struct pci_dev *pdev) |
| 6361 | { |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6362 | bool wake; |
| 6363 | |
| 6364 | __ixgbe_shutdown(pdev, &wake); |
| 6365 | |
| 6366 | if (system_state == SYSTEM_POWER_OFF) { |
| 6367 | pci_wake_from_d3(pdev, wake); |
| 6368 | pci_set_power_state(pdev, PCI_D3hot); |
| 6369 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6370 | } |
| 6371 | |
| 6372 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6373 | * ixgbe_update_stats - Update the board statistics counters. |
| 6374 | * @adapter: board private structure |
| 6375 | **/ |
| 6376 | void ixgbe_update_stats(struct ixgbe_adapter *adapter) |
| 6377 | { |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 6378 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6379 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6380 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6381 | u64 total_mpc = 0; |
| 6382 | u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6383 | u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0; |
| 6384 | u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 6385 | u64 bytes = 0, packets = 0, hw_csum_rx_error = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6386 | |
Don Skidmore | d08935c | 2010-06-11 13:20:29 +0000 | [diff] [blame] | 6387 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 6388 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 6389 | return; |
| 6390 | |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 6391 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 6392 | u64 rsc_count = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 6393 | u64 rsc_flush = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 6394 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6395 | rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count; |
| 6396 | rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 6397 | } |
| 6398 | adapter->rsc_total_count = rsc_count; |
| 6399 | adapter->rsc_total_flush = rsc_flush; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 6400 | } |
| 6401 | |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6402 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 6403 | struct ixgbe_ring *rx_ring = adapter->rx_ring[i]; |
| 6404 | non_eop_descs += rx_ring->rx_stats.non_eop_descs; |
| 6405 | alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed; |
| 6406 | alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 6407 | hw_csum_rx_error += rx_ring->rx_stats.csum_err; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6408 | bytes += rx_ring->stats.bytes; |
| 6409 | packets += rx_ring->stats.packets; |
| 6410 | } |
Mallikarjuna R Chilakala | eb985f0 | 2009-12-15 11:56:59 +0000 | [diff] [blame] | 6411 | adapter->non_eop_descs = non_eop_descs; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6412 | adapter->alloc_rx_page_failed = alloc_rx_page_failed; |
| 6413 | adapter->alloc_rx_buff_failed = alloc_rx_buff_failed; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 6414 | adapter->hw_csum_rx_error = hw_csum_rx_error; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6415 | netdev->stats.rx_bytes = bytes; |
| 6416 | netdev->stats.rx_packets = packets; |
| 6417 | |
| 6418 | bytes = 0; |
| 6419 | packets = 0; |
| 6420 | /* gather some stats to the adapter struct that are per queue */ |
| 6421 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 6422 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 6423 | restart_queue += tx_ring->tx_stats.restart_queue; |
| 6424 | tx_busy += tx_ring->tx_stats.tx_busy; |
| 6425 | bytes += tx_ring->stats.bytes; |
| 6426 | packets += tx_ring->stats.packets; |
| 6427 | } |
| 6428 | adapter->restart_queue = restart_queue; |
| 6429 | adapter->tx_busy = tx_busy; |
| 6430 | netdev->stats.tx_bytes = bytes; |
| 6431 | netdev->stats.tx_packets = packets; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 6432 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6433 | hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS); |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6434 | |
| 6435 | /* 8 register reads */ |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6436 | for (i = 0; i < 8; i++) { |
| 6437 | /* for packet buffers not used, the register should read 0 */ |
| 6438 | mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i)); |
| 6439 | missed_rx += mpc; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6440 | hwstats->mpc[i] += mpc; |
| 6441 | total_mpc += hwstats->mpc[i]; |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6442 | hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i)); |
| 6443 | hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6444 | switch (hw->mac.type) { |
| 6445 | case ixgbe_mac_82598EB: |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6446 | hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i)); |
| 6447 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i)); |
| 6448 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i)); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6449 | hwstats->pxonrxc[i] += |
| 6450 | IXGBE_READ_REG(hw, IXGBE_PXONRXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6451 | break; |
| 6452 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 6453 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6454 | case ixgbe_mac_X550: |
| 6455 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 6456 | case ixgbe_mac_x550em_a: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6457 | hwstats->pxonrxc[i] += |
| 6458 | IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6459 | break; |
| 6460 | default: |
| 6461 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6462 | } |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6463 | } |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6464 | |
| 6465 | /*16 register reads */ |
| 6466 | for (i = 0; i < 16; i++) { |
| 6467 | hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i)); |
| 6468 | hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i)); |
| 6469 | if ((hw->mac.type == ixgbe_mac_82599EB) || |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6470 | (hw->mac.type == ixgbe_mac_X540) || |
| 6471 | (hw->mac.type == ixgbe_mac_X550) || |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 6472 | (hw->mac.type == ixgbe_mac_X550EM_x) || |
| 6473 | (hw->mac.type == ixgbe_mac_x550em_a)) { |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6474 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i)); |
| 6475 | IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */ |
| 6476 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i)); |
| 6477 | IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */ |
| 6478 | } |
| 6479 | } |
| 6480 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6481 | hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6482 | /* work around hardware counting issue */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6483 | hwstats->gprc -= missed_rx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6484 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 6485 | ixgbe_update_xoff_received(adapter); |
| 6486 | |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6487 | /* 82598 hardware only has a 32 bit counter in the high register */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6488 | switch (hw->mac.type) { |
| 6489 | case ixgbe_mac_82598EB: |
| 6490 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6491 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH); |
| 6492 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH); |
| 6493 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH); |
| 6494 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 6495 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6496 | case ixgbe_mac_X550: |
| 6497 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 6498 | case ixgbe_mac_x550em_a: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6499 | /* OS2BMC stats are X540 and later */ |
Emil Tantilov | 58f6bcf | 2011-04-21 08:43:43 +0000 | [diff] [blame] | 6500 | hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC); |
| 6501 | hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC); |
| 6502 | hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC); |
| 6503 | hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC); |
| 6504 | case ixgbe_mac_82599EB: |
Alexander Duyck | a4d4f62 | 2012-03-28 08:03:32 +0000 | [diff] [blame] | 6505 | for (i = 0; i < 16; i++) |
| 6506 | adapter->hw_rx_no_dma_resources += |
| 6507 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6508 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6509 | IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6510 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6511 | IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6512 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6513 | IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6514 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6515 | hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH); |
| 6516 | hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS); |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 6517 | #ifdef IXGBE_FCOE |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6518 | hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC); |
| 6519 | hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC); |
| 6520 | hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC); |
| 6521 | hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC); |
| 6522 | hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC); |
| 6523 | hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC); |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 6524 | /* Add up per cpu counters for total ddp aloc fail */ |
Alexander Duyck | 5a1ee27 | 2012-05-05 17:14:28 +0000 | [diff] [blame] | 6525 | if (adapter->fcoe.ddp_pool) { |
| 6526 | struct ixgbe_fcoe *fcoe = &adapter->fcoe; |
| 6527 | struct ixgbe_fcoe_ddp_pool *ddp_pool; |
| 6528 | unsigned int cpu; |
| 6529 | u64 noddp = 0, noddp_ext_buff = 0; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 6530 | for_each_possible_cpu(cpu) { |
Alexander Duyck | 5a1ee27 | 2012-05-05 17:14:28 +0000 | [diff] [blame] | 6531 | ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu); |
| 6532 | noddp += ddp_pool->noddp; |
| 6533 | noddp_ext_buff += ddp_pool->noddp_ext_buff; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 6534 | } |
Alexander Duyck | 5a1ee27 | 2012-05-05 17:14:28 +0000 | [diff] [blame] | 6535 | hwstats->fcoe_noddp = noddp; |
| 6536 | hwstats->fcoe_noddp_ext_buff = noddp_ext_buff; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 6537 | } |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 6538 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6539 | break; |
| 6540 | default: |
| 6541 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6542 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6543 | bprc = IXGBE_READ_REG(hw, IXGBE_BPRC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6544 | hwstats->bprc += bprc; |
| 6545 | hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6546 | if (hw->mac.type == ixgbe_mac_82598EB) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6547 | hwstats->mprc -= bprc; |
| 6548 | hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC); |
| 6549 | hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64); |
| 6550 | hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127); |
| 6551 | hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255); |
| 6552 | hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511); |
| 6553 | hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023); |
| 6554 | hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522); |
| 6555 | hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6556 | lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6557 | hwstats->lxontxc += lxon; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6558 | lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6559 | hwstats->lxofftxc += lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6560 | hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC); |
| 6561 | hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6562 | /* |
| 6563 | * 82598 errata - tx of flow control packets is included in tx counters |
| 6564 | */ |
| 6565 | xon_off_tot = lxon + lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6566 | hwstats->gptc -= xon_off_tot; |
| 6567 | hwstats->mptc -= xon_off_tot; |
| 6568 | hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN)); |
| 6569 | hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 6570 | hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC); |
| 6571 | hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC); |
| 6572 | hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR); |
| 6573 | hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64); |
| 6574 | hwstats->ptc64 -= xon_off_tot; |
| 6575 | hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127); |
| 6576 | hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255); |
| 6577 | hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511); |
| 6578 | hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023); |
| 6579 | hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522); |
| 6580 | hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6581 | |
| 6582 | /* Fill out the OS statistics structure */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6583 | netdev->stats.multicast = hwstats->mprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6584 | |
| 6585 | /* Rx Errors */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6586 | netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 6587 | netdev->stats.rx_dropped = 0; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6588 | netdev->stats.rx_length_errors = hwstats->rlec; |
| 6589 | netdev->stats.rx_crc_errors = hwstats->crcerrs; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 6590 | netdev->stats.rx_missed_errors = total_mpc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6591 | } |
| 6592 | |
| 6593 | /** |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6594 | * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6595 | * @adapter: pointer to the device adapter structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6596 | **/ |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6597 | static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6598 | { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6599 | struct ixgbe_hw *hw = &adapter->hw; |
| 6600 | int i; |
| 6601 | |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6602 | if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 6603 | return; |
| 6604 | |
| 6605 | adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 6606 | |
| 6607 | /* if interface is down do nothing */ |
| 6608 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 6609 | return; |
| 6610 | |
| 6611 | /* do nothing if we are not using signature filters */ |
| 6612 | if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) |
| 6613 | return; |
| 6614 | |
| 6615 | adapter->fdir_overflow++; |
| 6616 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6617 | if (ixgbe_reinit_fdir_tables_82599(hw) == 0) { |
| 6618 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 6619 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 6620 | &(adapter->tx_ring[i]->state)); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6621 | /* re-enable flow director interrupts */ |
| 6622 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6623 | } else { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 6624 | e_err(probe, "failed to finish FDIR re-initialization, " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 6625 | "ignored adding FDIR ATR filters\n"); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6626 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6627 | } |
| 6628 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6629 | /** |
| 6630 | * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6631 | * @adapter: pointer to the device adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6632 | * |
| 6633 | * This function serves two purposes. First it strobes the interrupt lines |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 6634 | * in order to make certain interrupts are occurring. Secondly it sets the |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6635 | * 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] | 6636 | * determine if a hang has occurred. |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6637 | */ |
| 6638 | static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter) |
| 6639 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6640 | struct ixgbe_hw *hw = &adapter->hw; |
| 6641 | u64 eics = 0; |
| 6642 | int i; |
| 6643 | |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 6644 | /* If we're down, removing or resetting, just bail */ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6645 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 6646 | test_bit(__IXGBE_REMOVING, &adapter->state) || |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6647 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 6648 | return; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6649 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6650 | /* Force detection of hung controller */ |
| 6651 | if (netif_carrier_ok(adapter->netdev)) { |
| 6652 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 6653 | set_check_for_tx_hang(adapter->tx_ring[i]); |
| 6654 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6655 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 6656 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6657 | /* |
| 6658 | * for legacy and MSI interrupts don't set any bits |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 6659 | * that are enabled for EIAM, because this operation |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6660 | * would set *both* EIMS and EICS for any bit in EIAM |
| 6661 | */ |
| 6662 | IXGBE_WRITE_REG(hw, IXGBE_EICS, |
| 6663 | (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER)); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6664 | } else { |
| 6665 | /* get one bit for every active tx/rx interrupt vector */ |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 6666 | for (i = 0; i < adapter->num_q_vectors; i++) { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6667 | struct ixgbe_q_vector *qv = adapter->q_vector[i]; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 6668 | if (qv->rx.ring || qv->tx.ring) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 6669 | eics |= BIT_ULL(i); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6670 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6671 | } |
| 6672 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6673 | /* Cause software interrupt to ensure rings are cleaned */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6674 | ixgbe_irq_rearm_queues(adapter, eics); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6675 | } |
| 6676 | |
| 6677 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6678 | * ixgbe_watchdog_update_link - update the link status |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6679 | * @adapter: pointer to the device adapter structure |
| 6680 | * @link_speed: pointer to a u32 to store the link_speed |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6681 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6682 | static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter) |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6683 | { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6684 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6685 | u32 link_speed = adapter->link_speed; |
| 6686 | bool link_up = adapter->link_up; |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 6687 | bool pfc_en = adapter->dcb_cfg.pfc_mode_enable; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6688 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6689 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) |
| 6690 | return; |
| 6691 | |
| 6692 | if (hw->mac.ops.check_link) { |
| 6693 | 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] | 6694 | } else { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6695 | /* always assume link is up, if no check link function */ |
| 6696 | link_speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 6697 | link_up = true; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6698 | } |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 6699 | |
| 6700 | if (adapter->ixgbe_ieee_pfc) |
| 6701 | pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en); |
| 6702 | |
Alexander Duyck | 3ebe8fd | 2012-04-25 04:36:38 +0000 | [diff] [blame] | 6703 | if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) { |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 6704 | hw->mac.ops.fc_enable(hw); |
Alexander Duyck | 3ebe8fd | 2012-04-25 04:36:38 +0000 | [diff] [blame] | 6705 | ixgbe_set_rx_drop_en(adapter); |
| 6706 | } |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6707 | |
| 6708 | if (link_up || |
| 6709 | time_after(jiffies, (adapter->link_check_timeout + |
| 6710 | IXGBE_TRY_LINK_TIMEOUT))) { |
| 6711 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 6712 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC); |
| 6713 | IXGBE_WRITE_FLUSH(hw); |
| 6714 | } |
| 6715 | |
| 6716 | adapter->link_up = link_up; |
| 6717 | adapter->link_speed = link_speed; |
| 6718 | } |
| 6719 | |
Alexander Duyck | 107d301 | 2012-10-02 00:17:03 +0000 | [diff] [blame] | 6720 | static void ixgbe_update_default_up(struct ixgbe_adapter *adapter) |
| 6721 | { |
| 6722 | #ifdef CONFIG_IXGBE_DCB |
| 6723 | struct net_device *netdev = adapter->netdev; |
| 6724 | struct dcb_app app = { |
| 6725 | .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE, |
| 6726 | .protocol = 0, |
| 6727 | }; |
| 6728 | u8 up = 0; |
| 6729 | |
| 6730 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE) |
| 6731 | up = dcb_ieee_getapp_mask(netdev, &app); |
| 6732 | |
| 6733 | adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0; |
| 6734 | #endif |
| 6735 | } |
| 6736 | |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 6737 | static int ixgbe_enable_macvlan(struct net_device *upper, void *data) |
| 6738 | { |
| 6739 | if (netif_is_macvlan(upper)) { |
| 6740 | struct macvlan_dev *vlan = netdev_priv(upper); |
| 6741 | |
| 6742 | if (vlan->fwd_priv) |
| 6743 | netif_tx_wake_all_queues(upper); |
| 6744 | } |
| 6745 | |
| 6746 | return 0; |
| 6747 | } |
| 6748 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6749 | /** |
| 6750 | * ixgbe_watchdog_link_is_up - update netif_carrier status and |
| 6751 | * print link up message |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6752 | * @adapter: pointer to the device adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6753 | **/ |
| 6754 | static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter) |
| 6755 | { |
| 6756 | struct net_device *netdev = adapter->netdev; |
| 6757 | struct ixgbe_hw *hw = &adapter->hw; |
| 6758 | u32 link_speed = adapter->link_speed; |
Mark Rustad | 454adb0 | 2015-07-10 14:19:22 -0700 | [diff] [blame] | 6759 | const char *speed_str; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6760 | bool flow_rx, flow_tx; |
| 6761 | |
| 6762 | /* only continue if link was previously down */ |
| 6763 | if (netif_carrier_ok(netdev)) |
| 6764 | return; |
| 6765 | |
| 6766 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 6767 | |
| 6768 | switch (hw->mac.type) { |
| 6769 | case ixgbe_mac_82598EB: { |
| 6770 | u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 6771 | u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS); |
| 6772 | flow_rx = !!(frctl & IXGBE_FCTRL_RFCE); |
| 6773 | flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X); |
| 6774 | } |
| 6775 | break; |
| 6776 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6777 | case ixgbe_mac_X550: |
| 6778 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 6779 | case ixgbe_mac_x550em_a: |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6780 | case ixgbe_mac_82599EB: { |
| 6781 | u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN); |
| 6782 | u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG); |
| 6783 | flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE); |
| 6784 | flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X); |
| 6785 | } |
| 6786 | break; |
| 6787 | default: |
| 6788 | flow_tx = false; |
| 6789 | flow_rx = false; |
| 6790 | break; |
| 6791 | } |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 6792 | |
Jacob Keller | 6cb562d | 2012-12-05 07:24:41 +0000 | [diff] [blame] | 6793 | adapter->last_rx_ptp_check = jiffies; |
| 6794 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 6795 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6796 | ixgbe_ptp_start_cyclecounter(adapter); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 6797 | |
Mark Rustad | 454adb0 | 2015-07-10 14:19:22 -0700 | [diff] [blame] | 6798 | switch (link_speed) { |
| 6799 | case IXGBE_LINK_SPEED_10GB_FULL: |
| 6800 | speed_str = "10 Gbps"; |
| 6801 | break; |
| 6802 | case IXGBE_LINK_SPEED_2_5GB_FULL: |
| 6803 | speed_str = "2.5 Gbps"; |
| 6804 | break; |
| 6805 | case IXGBE_LINK_SPEED_1GB_FULL: |
| 6806 | speed_str = "1 Gbps"; |
| 6807 | break; |
| 6808 | case IXGBE_LINK_SPEED_100_FULL: |
| 6809 | speed_str = "100 Mbps"; |
| 6810 | break; |
| 6811 | default: |
| 6812 | speed_str = "unknown speed"; |
| 6813 | break; |
| 6814 | } |
| 6815 | e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", speed_str, |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6816 | ((flow_rx && flow_tx) ? "RX/TX" : |
| 6817 | (flow_rx ? "RX" : |
| 6818 | (flow_tx ? "TX" : "None")))); |
| 6819 | |
| 6820 | netif_carrier_on(netdev); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6821 | ixgbe_check_vf_rate_limit(adapter); |
Alexander Duyck | befa2af | 2012-05-05 05:30:38 +0000 | [diff] [blame] | 6822 | |
Emil Tantilov | cdc04dc | 2014-03-20 03:47:53 +0000 | [diff] [blame] | 6823 | /* enable transmits */ |
| 6824 | netif_tx_wake_all_queues(adapter->netdev); |
| 6825 | |
| 6826 | /* enable any upper devices */ |
| 6827 | rtnl_lock(); |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 6828 | netdev_walk_all_upper_dev_rcu(adapter->netdev, |
| 6829 | ixgbe_enable_macvlan, NULL); |
Emil Tantilov | cdc04dc | 2014-03-20 03:47:53 +0000 | [diff] [blame] | 6830 | rtnl_unlock(); |
| 6831 | |
Alexander Duyck | 107d301 | 2012-10-02 00:17:03 +0000 | [diff] [blame] | 6832 | /* update the default user priority for VFs */ |
| 6833 | ixgbe_update_default_up(adapter); |
| 6834 | |
Alexander Duyck | befa2af | 2012-05-05 05:30:38 +0000 | [diff] [blame] | 6835 | /* ping all the active vfs to let them know link has changed */ |
| 6836 | ixgbe_ping_all_vfs(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6837 | } |
| 6838 | |
| 6839 | /** |
| 6840 | * ixgbe_watchdog_link_is_down - update netif_carrier status and |
| 6841 | * print link down message |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6842 | * @adapter: pointer to the adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6843 | **/ |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 6844 | static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6845 | { |
| 6846 | struct net_device *netdev = adapter->netdev; |
| 6847 | struct ixgbe_hw *hw = &adapter->hw; |
| 6848 | |
| 6849 | adapter->link_up = false; |
| 6850 | adapter->link_speed = 0; |
| 6851 | |
| 6852 | /* only continue if link was up previously */ |
| 6853 | if (!netif_carrier_ok(netdev)) |
| 6854 | return; |
| 6855 | |
| 6856 | /* poll for SFP+ cable when link is down */ |
| 6857 | if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB) |
| 6858 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 6859 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 6860 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6861 | ixgbe_ptp_start_cyclecounter(adapter); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 6862 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6863 | e_info(drv, "NIC Link is Down\n"); |
| 6864 | netif_carrier_off(netdev); |
Alexander Duyck | befa2af | 2012-05-05 05:30:38 +0000 | [diff] [blame] | 6865 | |
| 6866 | /* ping all the active vfs to let them know link has changed */ |
| 6867 | ixgbe_ping_all_vfs(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6868 | } |
| 6869 | |
Emil Tantilov | 07923c1 | 2014-08-12 07:12:08 +0000 | [diff] [blame] | 6870 | static bool ixgbe_ring_tx_pending(struct ixgbe_adapter *adapter) |
| 6871 | { |
| 6872 | int i; |
| 6873 | |
| 6874 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 6875 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 6876 | |
| 6877 | if (tx_ring->next_to_use != tx_ring->next_to_clean) |
| 6878 | return true; |
| 6879 | } |
| 6880 | |
| 6881 | return false; |
| 6882 | } |
| 6883 | |
| 6884 | static bool ixgbe_vf_tx_pending(struct ixgbe_adapter *adapter) |
| 6885 | { |
| 6886 | struct ixgbe_hw *hw = &adapter->hw; |
| 6887 | struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ]; |
| 6888 | u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask); |
| 6889 | |
| 6890 | int i, j; |
| 6891 | |
| 6892 | if (!adapter->num_vfs) |
| 6893 | return false; |
| 6894 | |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6895 | /* resetting the PF is only needed for MAC before X550 */ |
| 6896 | if (hw->mac.type >= ixgbe_mac_X550) |
| 6897 | return false; |
| 6898 | |
Emil Tantilov | 07923c1 | 2014-08-12 07:12:08 +0000 | [diff] [blame] | 6899 | for (i = 0; i < adapter->num_vfs; i++) { |
| 6900 | for (j = 0; j < q_per_pool; j++) { |
| 6901 | u32 h, t; |
| 6902 | |
| 6903 | h = IXGBE_READ_REG(hw, IXGBE_PVFTDHN(q_per_pool, i, j)); |
| 6904 | t = IXGBE_READ_REG(hw, IXGBE_PVFTDTN(q_per_pool, i, j)); |
| 6905 | |
| 6906 | if (h != t) |
| 6907 | return true; |
| 6908 | } |
| 6909 | } |
| 6910 | |
| 6911 | return false; |
| 6912 | } |
| 6913 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6914 | /** |
| 6915 | * ixgbe_watchdog_flush_tx - flush queues on link down |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6916 | * @adapter: pointer to the device adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6917 | **/ |
| 6918 | static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter) |
| 6919 | { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6920 | if (!netif_carrier_ok(adapter->netdev)) { |
Emil Tantilov | 07923c1 | 2014-08-12 07:12:08 +0000 | [diff] [blame] | 6921 | if (ixgbe_ring_tx_pending(adapter) || |
| 6922 | ixgbe_vf_tx_pending(adapter)) { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6923 | /* We've lost link, so the controller stops DMA, |
| 6924 | * but we've got queued Tx work that's never going |
| 6925 | * to get done, so reset controller to flush Tx. |
| 6926 | * (Do the reset outside of interrupt context). |
| 6927 | */ |
Jacob Keller | 12ff3f3 | 2012-12-01 07:57:17 +0000 | [diff] [blame] | 6928 | e_warn(drv, "initiating reset to clear Tx work after link loss\n"); |
Emil Tantilov | 57ca2a4 | 2016-07-29 14:46:31 -0700 | [diff] [blame] | 6929 | set_bit(__IXGBE_RESET_REQUESTED, &adapter->state); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6930 | } |
| 6931 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6932 | } |
| 6933 | |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 6934 | #ifdef CONFIG_PCI_IOV |
| 6935 | static inline void ixgbe_issue_vf_flr(struct ixgbe_adapter *adapter, |
| 6936 | struct pci_dev *vfdev) |
| 6937 | { |
| 6938 | if (!pci_wait_for_pending_transaction(vfdev)) |
| 6939 | e_dev_warn("Issuing VFLR with pending transactions\n"); |
| 6940 | |
| 6941 | e_dev_err("Issuing VFLR for VF %s\n", pci_name(vfdev)); |
| 6942 | pcie_capability_set_word(vfdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_BCR_FLR); |
| 6943 | |
| 6944 | msleep(100); |
| 6945 | } |
| 6946 | |
| 6947 | static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter) |
| 6948 | { |
| 6949 | struct ixgbe_hw *hw = &adapter->hw; |
| 6950 | struct pci_dev *pdev = adapter->pdev; |
Mark Rustad | 988d130 | 2015-10-30 15:29:34 -0700 | [diff] [blame] | 6951 | unsigned int vf; |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 6952 | u32 gpc; |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 6953 | |
| 6954 | if (!(netif_carrier_ok(adapter->netdev))) |
| 6955 | return; |
| 6956 | |
| 6957 | gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC); |
| 6958 | if (gpc) /* If incrementing then no need for the check below */ |
| 6959 | return; |
| 6960 | /* Check to see if a bad DMA write target from an errant or |
| 6961 | * malicious VF has caused a PCIe error. If so then we can |
| 6962 | * issue a VFLR to the offending VF(s) and then resume without |
| 6963 | * requesting a full slot reset. |
| 6964 | */ |
| 6965 | |
| 6966 | if (!pdev) |
| 6967 | return; |
| 6968 | |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 6969 | /* check status reg for all VFs owned by this PF */ |
Mark Rustad | 988d130 | 2015-10-30 15:29:34 -0700 | [diff] [blame] | 6970 | for (vf = 0; vf < adapter->num_vfs; ++vf) { |
| 6971 | struct pci_dev *vfdev = adapter->vfinfo[vf].vfdev; |
| 6972 | u16 status_reg; |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 6973 | |
Mark Rustad | 988d130 | 2015-10-30 15:29:34 -0700 | [diff] [blame] | 6974 | if (!vfdev) |
| 6975 | continue; |
| 6976 | pci_read_config_word(vfdev, PCI_STATUS, &status_reg); |
| 6977 | if (status_reg != IXGBE_FAILED_READ_CFG_WORD && |
| 6978 | status_reg & PCI_STATUS_REC_MASTER_ABORT) |
| 6979 | ixgbe_issue_vf_flr(adapter, vfdev); |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 6980 | } |
| 6981 | } |
| 6982 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6983 | static void ixgbe_spoof_check(struct ixgbe_adapter *adapter) |
| 6984 | { |
| 6985 | u32 ssvpc; |
| 6986 | |
Greg Rose | 0584d99 | 2012-08-08 00:00:58 +0000 | [diff] [blame] | 6987 | /* Do not perform spoof check for 82598 or if not in IOV mode */ |
| 6988 | if (adapter->hw.mac.type == ixgbe_mac_82598EB || |
| 6989 | adapter->num_vfs == 0) |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6990 | return; |
| 6991 | |
| 6992 | ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC); |
| 6993 | |
| 6994 | /* |
| 6995 | * ssvpc register is cleared on read, if zero then no |
| 6996 | * spoofed packets in the last interval. |
| 6997 | */ |
| 6998 | if (!ssvpc) |
| 6999 | return; |
| 7000 | |
Emil Tantilov | d6ea075 | 2012-08-08 06:28:37 +0000 | [diff] [blame] | 7001 | e_warn(drv, "%u Spoofed packets detected\n", ssvpc); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 7002 | } |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7003 | #else |
| 7004 | static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused *adapter) |
| 7005 | { |
| 7006 | } |
| 7007 | |
| 7008 | static void |
| 7009 | ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused *adapter) |
| 7010 | { |
| 7011 | } |
| 7012 | #endif /* CONFIG_PCI_IOV */ |
| 7013 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 7014 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7015 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7016 | * ixgbe_watchdog_subtask - check and bring link up |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7017 | * @adapter: pointer to the device adapter structure |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 7018 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7019 | static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 7020 | { |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 7021 | /* if interface is down, removing or resetting, do nothing */ |
Emil Tantilov | 7edebf9 | 2011-08-27 07:18:37 +0000 | [diff] [blame] | 7022 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 7023 | test_bit(__IXGBE_REMOVING, &adapter->state) || |
Emil Tantilov | 7edebf9 | 2011-08-27 07:18:37 +0000 | [diff] [blame] | 7024 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7025 | return; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 7026 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7027 | ixgbe_watchdog_update_link(adapter); |
John Fastabend | 10eec95 | 2010-02-03 14:23:32 +0000 | [diff] [blame] | 7028 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7029 | if (adapter->link_up) |
| 7030 | ixgbe_watchdog_link_is_up(adapter); |
| 7031 | else |
| 7032 | ixgbe_watchdog_link_is_down(adapter); |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 7033 | |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7034 | ixgbe_check_for_bad_vf(adapter); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 7035 | ixgbe_spoof_check(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7036 | ixgbe_update_stats(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7037 | |
| 7038 | ixgbe_watchdog_flush_tx(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7039 | } |
| 7040 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7041 | /** |
| 7042 | * ixgbe_sfp_detection_subtask - poll for SFP+ cable |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7043 | * @adapter: the ixgbe adapter structure |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7044 | **/ |
| 7045 | static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter) |
| 7046 | { |
| 7047 | struct ixgbe_hw *hw = &adapter->hw; |
| 7048 | s32 err; |
| 7049 | |
| 7050 | /* not searching for SFP so there is nothing to do here */ |
| 7051 | if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) && |
| 7052 | !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 7053 | return; |
| 7054 | |
Mark Rustad | 58e7cd2 | 2015-08-08 16:18:48 -0700 | [diff] [blame] | 7055 | if (adapter->sfp_poll_time && |
| 7056 | time_after(adapter->sfp_poll_time, jiffies)) |
| 7057 | return; /* If not yet time to poll for SFP */ |
| 7058 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7059 | /* someone else is in init, wait until next service event */ |
| 7060 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 7061 | return; |
| 7062 | |
Mark Rustad | 58e7cd2 | 2015-08-08 16:18:48 -0700 | [diff] [blame] | 7063 | adapter->sfp_poll_time = jiffies + IXGBE_SFP_POLL_JIFFIES - 1; |
| 7064 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7065 | err = hw->phy.ops.identify_sfp(hw); |
| 7066 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 7067 | goto sfp_out; |
| 7068 | |
| 7069 | if (err == IXGBE_ERR_SFP_NOT_PRESENT) { |
| 7070 | /* If no cable is present, then we need to reset |
| 7071 | * the next time we find a good cable. */ |
| 7072 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 7073 | } |
| 7074 | |
| 7075 | /* exit on error */ |
| 7076 | if (err) |
| 7077 | goto sfp_out; |
| 7078 | |
| 7079 | /* exit if reset not needed */ |
| 7080 | if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 7081 | goto sfp_out; |
| 7082 | |
| 7083 | adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 7084 | |
| 7085 | /* |
| 7086 | * A module may be identified correctly, but the EEPROM may not have |
| 7087 | * support for that module. setup_sfp() will fail in that case, so |
| 7088 | * we should not allow that module to load. |
| 7089 | */ |
| 7090 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 7091 | err = hw->phy.ops.reset(hw); |
| 7092 | else |
| 7093 | err = hw->mac.ops.setup_sfp(hw); |
| 7094 | |
| 7095 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 7096 | goto sfp_out; |
| 7097 | |
| 7098 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 7099 | e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type); |
| 7100 | |
| 7101 | sfp_out: |
| 7102 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 7103 | |
| 7104 | if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) && |
| 7105 | (adapter->netdev->reg_state == NETREG_REGISTERED)) { |
| 7106 | e_dev_err("failed to initialize because an unsupported " |
| 7107 | "SFP+ module type was detected.\n"); |
| 7108 | e_dev_err("Reload the driver after installing a " |
| 7109 | "supported module.\n"); |
| 7110 | unregister_netdev(adapter->netdev); |
| 7111 | } |
| 7112 | } |
| 7113 | |
| 7114 | /** |
| 7115 | * ixgbe_sfp_link_config_subtask - set up link SFP after module install |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7116 | * @adapter: the ixgbe adapter structure |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7117 | **/ |
| 7118 | static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter) |
| 7119 | { |
| 7120 | struct ixgbe_hw *hw = &adapter->hw; |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 7121 | u32 speed; |
| 7122 | bool autoneg = false; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7123 | |
| 7124 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG)) |
| 7125 | return; |
| 7126 | |
| 7127 | /* someone else is in init, wait until next service event */ |
| 7128 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 7129 | return; |
| 7130 | |
| 7131 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 7132 | |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 7133 | speed = hw->phy.autoneg_advertised; |
Emil Tantilov | ed33ff6 | 2013-08-30 07:55:24 +0000 | [diff] [blame] | 7134 | if ((!speed) && (hw->mac.ops.get_link_capabilities)) { |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 7135 | hw->mac.ops.get_link_capabilities(hw, &speed, &autoneg); |
Emil Tantilov | ed33ff6 | 2013-08-30 07:55:24 +0000 | [diff] [blame] | 7136 | |
| 7137 | /* setup the highest link when no autoneg */ |
| 7138 | if (!autoneg) { |
| 7139 | if (speed & IXGBE_LINK_SPEED_10GB_FULL) |
| 7140 | speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 7141 | } |
| 7142 | } |
| 7143 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7144 | if (hw->mac.ops.setup_link) |
Josh Hay | fd0326f | 2012-12-15 03:28:30 +0000 | [diff] [blame] | 7145 | hw->mac.ops.setup_link(hw, speed, true); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7146 | |
| 7147 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 7148 | adapter->link_check_timeout = jiffies; |
| 7149 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 7150 | } |
| 7151 | |
| 7152 | /** |
| 7153 | * ixgbe_service_timer - Timer Call-back |
| 7154 | * @data: pointer to adapter cast into an unsigned long |
| 7155 | **/ |
| 7156 | static void ixgbe_service_timer(unsigned long data) |
| 7157 | { |
| 7158 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
| 7159 | unsigned long next_event_offset; |
| 7160 | |
| 7161 | /* poll faster when waiting for link */ |
| 7162 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 7163 | next_event_offset = HZ / 10; |
| 7164 | else |
| 7165 | next_event_offset = HZ * 2; |
| 7166 | |
| 7167 | /* Reset the timer */ |
| 7168 | mod_timer(&adapter->service_timer, next_event_offset + jiffies); |
| 7169 | |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7170 | ixgbe_service_event_schedule(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7171 | } |
| 7172 | |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 7173 | static void ixgbe_phy_interrupt_subtask(struct ixgbe_adapter *adapter) |
| 7174 | { |
| 7175 | struct ixgbe_hw *hw = &adapter->hw; |
| 7176 | u32 status; |
| 7177 | |
| 7178 | if (!(adapter->flags2 & IXGBE_FLAG2_PHY_INTERRUPT)) |
| 7179 | return; |
| 7180 | |
| 7181 | adapter->flags2 &= ~IXGBE_FLAG2_PHY_INTERRUPT; |
| 7182 | |
| 7183 | if (!hw->phy.ops.handle_lasi) |
| 7184 | return; |
| 7185 | |
| 7186 | status = hw->phy.ops.handle_lasi(&adapter->hw); |
| 7187 | if (status != IXGBE_ERR_OVERTEMP) |
| 7188 | return; |
| 7189 | |
| 7190 | e_crit(drv, "%s\n", ixgbe_overheat_msg); |
| 7191 | } |
| 7192 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7193 | static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter) |
| 7194 | { |
Emil Tantilov | 57ca2a4 | 2016-07-29 14:46:31 -0700 | [diff] [blame] | 7195 | if (!test_and_clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state)) |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7196 | return; |
| 7197 | |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 7198 | /* If we're already down, removing or resetting, just bail */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7199 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 7200 | test_bit(__IXGBE_REMOVING, &adapter->state) || |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7201 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 7202 | return; |
| 7203 | |
| 7204 | ixgbe_dump(adapter); |
| 7205 | netdev_err(adapter->netdev, "Reset adapter\n"); |
| 7206 | adapter->tx_timeout_count++; |
| 7207 | |
John Fastabend | 8f4c5c9 | 2014-01-16 02:30:05 -0800 | [diff] [blame] | 7208 | rtnl_lock(); |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7209 | ixgbe_reinit_locked(adapter); |
John Fastabend | 8f4c5c9 | 2014-01-16 02:30:05 -0800 | [diff] [blame] | 7210 | rtnl_unlock(); |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7211 | } |
| 7212 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7213 | /** |
| 7214 | * ixgbe_service_task - manages and runs subtasks |
| 7215 | * @work: pointer to work_struct containing our data |
| 7216 | **/ |
| 7217 | static void ixgbe_service_task(struct work_struct *work) |
| 7218 | { |
| 7219 | struct ixgbe_adapter *adapter = container_of(work, |
| 7220 | struct ixgbe_adapter, |
| 7221 | service_task); |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 7222 | if (ixgbe_removed(adapter->hw.hw_addr)) { |
| 7223 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 7224 | rtnl_lock(); |
| 7225 | ixgbe_down(adapter); |
| 7226 | rtnl_unlock(); |
| 7227 | } |
| 7228 | ixgbe_service_event_complete(adapter); |
| 7229 | return; |
| 7230 | } |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 7231 | if (adapter->flags2 & IXGBE_FLAG2_UDP_TUN_REREG_NEEDED) { |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 7232 | rtnl_lock(); |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 7233 | adapter->flags2 &= ~IXGBE_FLAG2_UDP_TUN_REREG_NEEDED; |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 7234 | udp_tunnel_get_rx_info(adapter->netdev); |
| 7235 | rtnl_unlock(); |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7236 | } |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7237 | ixgbe_reset_subtask(adapter); |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 7238 | ixgbe_phy_interrupt_subtask(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7239 | ixgbe_sfp_detection_subtask(adapter); |
| 7240 | ixgbe_sfp_link_config_subtask(adapter); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 7241 | ixgbe_check_overtemp_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7242 | ixgbe_watchdog_subtask(adapter); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 7243 | ixgbe_fdir_reinit_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7244 | ixgbe_check_hang_subtask(adapter); |
Jacob Keller | 891dc08 | 2012-12-05 07:24:46 +0000 | [diff] [blame] | 7245 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 7246 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) { |
Jacob Keller | 891dc08 | 2012-12-05 07:24:46 +0000 | [diff] [blame] | 7247 | ixgbe_ptp_overflow_check(adapter); |
| 7248 | ixgbe_ptp_rx_hang(adapter); |
| 7249 | } |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7250 | |
| 7251 | ixgbe_service_event_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7252 | } |
| 7253 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7254 | static int ixgbe_tso(struct ixgbe_ring *tx_ring, |
| 7255 | struct ixgbe_tx_buffer *first, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7256 | u8 *hdr_len) |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7257 | { |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7258 | u32 vlan_macip_lens, type_tucmd, mss_l4len_idx; |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7259 | struct sk_buff *skb = first->skb; |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7260 | union { |
| 7261 | struct iphdr *v4; |
| 7262 | struct ipv6hdr *v6; |
| 7263 | unsigned char *hdr; |
| 7264 | } ip; |
| 7265 | union { |
| 7266 | struct tcphdr *tcp; |
| 7267 | unsigned char *hdr; |
| 7268 | } l4; |
| 7269 | u32 paylen, l4_offset; |
Francois Romieu | 2049e1f | 2014-03-30 03:14:27 +0000 | [diff] [blame] | 7270 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7271 | |
Alexander Duyck | 8f4fbb9 | 2012-10-30 06:01:40 +0000 | [diff] [blame] | 7272 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 7273 | return 0; |
| 7274 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7275 | if (!skb_is_gso(skb)) |
| 7276 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7277 | |
Francois Romieu | 2049e1f | 2014-03-30 03:14:27 +0000 | [diff] [blame] | 7278 | err = skb_cow_head(skb, 0); |
| 7279 | if (err < 0) |
| 7280 | return err; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 7281 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7282 | ip.hdr = skb_network_header(skb); |
| 7283 | l4.hdr = skb_checksum_start(skb); |
| 7284 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7285 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
| 7286 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 7287 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7288 | /* initialize outer IP header fields */ |
| 7289 | if (ip.v4->version == 4) { |
| 7290 | /* IP header will have to cancel out any data that |
| 7291 | * is not a part of the outer IP header |
| 7292 | */ |
| 7293 | ip.v4->check = csum_fold(csum_add(lco_csum(skb), |
| 7294 | csum_unfold(l4.tcp->check))); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7295 | type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7296 | |
| 7297 | ip.v4->tot_len = 0; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7298 | first->tx_flags |= IXGBE_TX_FLAGS_TSO | |
| 7299 | IXGBE_TX_FLAGS_CSUM | |
| 7300 | IXGBE_TX_FLAGS_IPV4; |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7301 | } else { |
| 7302 | ip.v6->payload_len = 0; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7303 | first->tx_flags |= IXGBE_TX_FLAGS_TSO | |
| 7304 | IXGBE_TX_FLAGS_CSUM; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7305 | } |
| 7306 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7307 | /* determine offset of inner transport header */ |
| 7308 | l4_offset = l4.hdr - skb->data; |
| 7309 | |
| 7310 | /* compute length of segmentation header */ |
| 7311 | *hdr_len = (l4.tcp->doff * 4) + l4_offset; |
| 7312 | |
| 7313 | /* remove payload length from inner checksum */ |
| 7314 | paylen = skb->len - l4_offset; |
| 7315 | csum_replace_by_diff(&l4.tcp->check, htonl(paylen)); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7316 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 7317 | /* update gso size and bytecount with header size */ |
| 7318 | first->gso_segs = skb_shinfo(skb)->gso_segs; |
| 7319 | first->bytecount += (first->gso_segs - 1) * *hdr_len; |
| 7320 | |
Alexander Duyck | c44f5f5 | 2012-10-30 06:01:45 +0000 | [diff] [blame] | 7321 | /* mss_l4len_id: use 0 as index for TSO */ |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7322 | mss_l4len_idx = (*hdr_len - l4_offset) << IXGBE_ADVTXD_L4LEN_SHIFT; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7323 | mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7324 | |
| 7325 | /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */ |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7326 | vlan_macip_lens = l4.hdr - ip.hdr; |
| 7327 | vlan_macip_lens |= (ip.hdr - skb->data) << IXGBE_ADVTXD_MACLEN_SHIFT; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7328 | vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7329 | |
| 7330 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7331 | mss_l4len_idx); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7332 | |
| 7333 | return 1; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 7334 | } |
| 7335 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7336 | static inline bool ixgbe_ipv6_csum_is_sctp(struct sk_buff *skb) |
| 7337 | { |
| 7338 | unsigned int offset = 0; |
| 7339 | |
| 7340 | ipv6_find_hdr(skb, &offset, IPPROTO_SCTP, NULL, NULL); |
| 7341 | |
| 7342 | return offset == skb_checksum_start_offset(skb); |
| 7343 | } |
| 7344 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7345 | static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring, |
| 7346 | struct ixgbe_tx_buffer *first) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7347 | { |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7348 | struct sk_buff *skb = first->skb; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7349 | u32 vlan_macip_lens = 0; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7350 | u32 type_tucmd = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7351 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7352 | if (skb->ip_summed != CHECKSUM_PARTIAL) { |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7353 | csum_failed: |
| 7354 | if (!(first->tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | |
| 7355 | IXGBE_TX_FLAGS_CC))) |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7356 | return; |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7357 | goto no_csum; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7358 | } |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 7359 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7360 | switch (skb->csum_offset) { |
| 7361 | case offsetof(struct tcphdr, check): |
| 7362 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 7363 | /* fall through */ |
| 7364 | case offsetof(struct udphdr, check): |
| 7365 | break; |
| 7366 | case offsetof(struct sctphdr, checksum): |
| 7367 | /* validate that this is actually an SCTP request */ |
| 7368 | if (((first->protocol == htons(ETH_P_IP)) && |
| 7369 | (ip_hdr(skb)->protocol == IPPROTO_SCTP)) || |
| 7370 | ((first->protocol == htons(ETH_P_IPV6)) && |
| 7371 | ixgbe_ipv6_csum_is_sctp(skb))) { |
| 7372 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
| 7373 | break; |
| 7374 | } |
| 7375 | /* fall through */ |
| 7376 | default: |
| 7377 | skb_checksum_help(skb); |
| 7378 | goto csum_failed; |
| 7379 | } |
| 7380 | |
| 7381 | /* update TX checksum flag */ |
| 7382 | first->tx_flags |= IXGBE_TX_FLAGS_CSUM; |
| 7383 | vlan_macip_lens = skb_checksum_start_offset(skb) - |
| 7384 | skb_network_offset(skb); |
Mark Rustad | 36a92d7 | 2015-11-18 09:21:28 -0800 | [diff] [blame] | 7385 | no_csum: |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7386 | /* vlan_macip_lens: MACLEN, VLAN tag */ |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7387 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7388 | vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7389 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7390 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, 0); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7391 | } |
| 7392 | |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7393 | #define IXGBE_SET_FLAG(_input, _flag, _result) \ |
| 7394 | ((_flag <= _result) ? \ |
| 7395 | ((u32)(_input & _flag) * (_result / _flag)) : \ |
| 7396 | ((u32)(_input & _flag) / (_flag / _result))) |
| 7397 | |
| 7398 | 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] | 7399 | { |
| 7400 | /* set type for advanced descriptor with frame checksum insertion */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7401 | u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA | |
| 7402 | IXGBE_ADVTXD_DCMD_DEXT | |
| 7403 | IXGBE_ADVTXD_DCMD_IFCS; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7404 | |
| 7405 | /* set HW vlan bit if vlan is present */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7406 | cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN, |
| 7407 | IXGBE_ADVTXD_DCMD_VLE); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7408 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7409 | /* set segmentation enable bits for TSO/FSO */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7410 | cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO, |
| 7411 | IXGBE_ADVTXD_DCMD_TSE); |
| 7412 | |
| 7413 | /* set timestamp bit if present */ |
| 7414 | cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP, |
| 7415 | IXGBE_ADVTXD_MAC_TSTAMP); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7416 | |
Alexander Duyck | 62748b7 | 2012-07-20 08:09:01 +0000 | [diff] [blame] | 7417 | /* insert frame checksum */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7418 | 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] | 7419 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7420 | return cmd_type; |
| 7421 | } |
| 7422 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7423 | static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc, |
| 7424 | u32 tx_flags, unsigned int paylen) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7425 | { |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7426 | u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7427 | |
| 7428 | /* enable L4 checksum for TSO and TX checksum offload */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7429 | olinfo_status |= IXGBE_SET_FLAG(tx_flags, |
| 7430 | IXGBE_TX_FLAGS_CSUM, |
| 7431 | IXGBE_ADVTXD_POPTS_TXSM); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7432 | |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 7433 | /* enble IPv4 checksum for TSO */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7434 | olinfo_status |= IXGBE_SET_FLAG(tx_flags, |
| 7435 | IXGBE_TX_FLAGS_IPV4, |
| 7436 | IXGBE_ADVTXD_POPTS_IXSM); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7437 | |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 7438 | /* |
| 7439 | * Check Context must be set if Tx switch is enabled, which it |
| 7440 | * always is for case where virtual functions are running |
| 7441 | */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7442 | olinfo_status |= IXGBE_SET_FLAG(tx_flags, |
| 7443 | IXGBE_TX_FLAGS_CC, |
| 7444 | IXGBE_ADVTXD_CC); |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 7445 | |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7446 | tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7447 | } |
| 7448 | |
Daniel Borkmann | 2367a17 | 2014-08-26 19:34:18 +0200 | [diff] [blame] | 7449 | static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size) |
| 7450 | { |
| 7451 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 7452 | |
| 7453 | /* Herbert's original patch had: |
| 7454 | * smp_mb__after_netif_stop_queue(); |
| 7455 | * but since that doesn't exist yet, just open code it. |
| 7456 | */ |
| 7457 | smp_mb(); |
| 7458 | |
| 7459 | /* We need to check again in a case another CPU has just |
| 7460 | * made room available. |
| 7461 | */ |
| 7462 | if (likely(ixgbe_desc_unused(tx_ring) < size)) |
| 7463 | return -EBUSY; |
| 7464 | |
| 7465 | /* A reprieve! - use start_queue because it doesn't call schedule */ |
| 7466 | netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 7467 | ++tx_ring->tx_stats.restart_queue; |
| 7468 | return 0; |
| 7469 | } |
| 7470 | |
| 7471 | static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size) |
| 7472 | { |
| 7473 | if (likely(ixgbe_desc_unused(tx_ring) >= size)) |
| 7474 | return 0; |
| 7475 | |
| 7476 | return __ixgbe_maybe_stop_tx(tx_ring, size); |
| 7477 | } |
| 7478 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7479 | #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \ |
| 7480 | IXGBE_TXD_CMD_RS) |
| 7481 | |
| 7482 | static void ixgbe_tx_map(struct ixgbe_ring *tx_ring, |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7483 | struct ixgbe_tx_buffer *first, |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7484 | const u8 hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7485 | { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7486 | struct sk_buff *skb = first->skb; |
| 7487 | struct ixgbe_tx_buffer *tx_buffer; |
| 7488 | union ixgbe_adv_tx_desc *tx_desc; |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7489 | struct skb_frag_struct *frag; |
| 7490 | dma_addr_t dma; |
| 7491 | unsigned int data_len, size; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7492 | u32 tx_flags = first->tx_flags; |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7493 | u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7494 | u16 i = tx_ring->next_to_use; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7495 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7496 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
| 7497 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7498 | ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len); |
| 7499 | |
| 7500 | size = skb_headlen(skb); |
| 7501 | data_len = skb->data_len; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7502 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7503 | #ifdef IXGBE_FCOE |
| 7504 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7505 | if (data_len < sizeof(struct fcoe_crc_eof)) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7506 | size -= sizeof(struct fcoe_crc_eof) - data_len; |
| 7507 | data_len = 0; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7508 | } else { |
| 7509 | data_len -= sizeof(struct fcoe_crc_eof); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 7510 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7511 | } |
| 7512 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7513 | #endif |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7514 | 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] | 7515 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7516 | tx_buffer = first; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7517 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7518 | for (frag = &skb_shinfo(skb)->frags[0];; frag++) { |
| 7519 | if (dma_mapping_error(tx_ring->dev, dma)) |
| 7520 | goto dma_error; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7521 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7522 | /* record length, and DMA address */ |
| 7523 | dma_unmap_len_set(tx_buffer, len, size); |
| 7524 | dma_unmap_addr_set(tx_buffer, dma, dma); |
| 7525 | |
| 7526 | tx_desc->read.buffer_addr = cpu_to_le64(dma); |
| 7527 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7528 | while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7529 | tx_desc->read.cmd_type_len = |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7530 | cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7531 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7532 | i++; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7533 | tx_desc++; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7534 | if (i == tx_ring->count) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 7535 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7536 | i = 0; |
| 7537 | } |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7538 | tx_desc->read.olinfo_status = 0; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7539 | |
| 7540 | dma += IXGBE_MAX_DATA_PER_TXD; |
| 7541 | size -= IXGBE_MAX_DATA_PER_TXD; |
| 7542 | |
| 7543 | tx_desc->read.buffer_addr = cpu_to_le64(dma); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7544 | } |
| 7545 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7546 | if (likely(!data_len)) |
| 7547 | break; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7548 | |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7549 | tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7550 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7551 | i++; |
| 7552 | tx_desc++; |
| 7553 | if (i == tx_ring->count) { |
| 7554 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
| 7555 | i = 0; |
| 7556 | } |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7557 | tx_desc->read.olinfo_status = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7558 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7559 | #ifdef IXGBE_FCOE |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 7560 | size = min_t(unsigned int, data_len, skb_frag_size(frag)); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7561 | #else |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 7562 | size = skb_frag_size(frag); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7563 | #endif |
| 7564 | data_len -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7565 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7566 | dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size, |
| 7567 | DMA_TO_DEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7568 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7569 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7570 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 7571 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7572 | /* write last descriptor with RS and EOP bits */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7573 | cmd_type |= size | IXGBE_TXD_CMD; |
| 7574 | tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7575 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 7576 | netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount); |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 7577 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7578 | /* set the timestamp */ |
| 7579 | first->time_stamp = jiffies; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7580 | |
| 7581 | /* |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7582 | * Force memory writes to complete before letting h/w know there |
| 7583 | * are new descriptors to fetch. (Only applicable for weak-ordered |
| 7584 | * memory model archs, such as IA-64). |
| 7585 | * |
| 7586 | * We also need this memory barrier to make certain all of the |
| 7587 | * status bits have been updated before next_to_watch is written. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7588 | */ |
| 7589 | wmb(); |
| 7590 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7591 | /* set next_to_watch value indicating a packet is present */ |
| 7592 | first->next_to_watch = tx_desc; |
| 7593 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7594 | i++; |
| 7595 | if (i == tx_ring->count) |
| 7596 | i = 0; |
| 7597 | |
| 7598 | tx_ring->next_to_use = i; |
| 7599 | |
Daniel Borkmann | 2367a17 | 2014-08-26 19:34:18 +0200 | [diff] [blame] | 7600 | ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED); |
| 7601 | |
| 7602 | if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) { |
Alexander Duyck | ad435ec | 2014-11-14 00:56:35 +0000 | [diff] [blame] | 7603 | writel(i, tx_ring->tail); |
| 7604 | |
| 7605 | /* we need this if more than one processor can write to our tail |
| 7606 | * at a time, it synchronizes IO on IA64/Altix systems |
| 7607 | */ |
| 7608 | mmiowb(); |
Daniel Borkmann | 9c938cd | 2014-08-24 15:42:16 +0200 | [diff] [blame] | 7609 | } |
Daniel Borkmann | 2367a17 | 2014-08-26 19:34:18 +0200 | [diff] [blame] | 7610 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7611 | return; |
| 7612 | dma_error: |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7613 | dev_err(tx_ring->dev, "TX DMA map failed\n"); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7614 | |
| 7615 | /* clear dma mappings for failed tx_buffer_info map */ |
| 7616 | for (;;) { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7617 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
| 7618 | ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer); |
| 7619 | if (tx_buffer == first) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7620 | break; |
| 7621 | if (i == 0) |
| 7622 | i = tx_ring->count; |
| 7623 | i--; |
| 7624 | } |
| 7625 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7626 | tx_ring->next_to_use = i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7627 | } |
| 7628 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7629 | static void ixgbe_atr(struct ixgbe_ring *ring, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7630 | struct ixgbe_tx_buffer *first) |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7631 | { |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7632 | struct ixgbe_q_vector *q_vector = ring->q_vector; |
| 7633 | union ixgbe_atr_hash_dword input = { .dword = 0 }; |
| 7634 | union ixgbe_atr_hash_dword common = { .dword = 0 }; |
| 7635 | union { |
| 7636 | unsigned char *network; |
| 7637 | struct iphdr *ipv4; |
| 7638 | struct ipv6hdr *ipv6; |
| 7639 | } hdr; |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 7640 | struct tcphdr *th; |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7641 | unsigned int hlen; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7642 | struct sk_buff *skb; |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 7643 | __be16 vlan_id; |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7644 | int l4_proto; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7645 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7646 | /* if ring doesn't have a interrupt vector, cannot perform ATR */ |
| 7647 | if (!q_vector) |
Guillaume Gaudonville | d3ead24 | 2010-06-29 18:29:00 +0000 | [diff] [blame] | 7648 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7649 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7650 | /* do nothing if sampling is disabled */ |
| 7651 | if (!ring->atr_sample_rate) |
| 7652 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7653 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7654 | ring->atr_count++; |
| 7655 | |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7656 | /* currently only IPv4/IPv6 with TCP is supported */ |
| 7657 | if ((first->protocol != htons(ETH_P_IP)) && |
| 7658 | (first->protocol != htons(ETH_P_IPV6))) |
| 7659 | return; |
| 7660 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7661 | /* snag network header to get L4 type and address */ |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7662 | skb = first->skb; |
| 7663 | hdr.network = skb_network_header(skb); |
Sowmini Varadhan | 9f3c750 | 2016-10-24 15:36:39 -0700 | [diff] [blame^] | 7664 | if (unlikely(hdr.network <= skb->data)) |
| 7665 | return; |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 7666 | if (skb->encapsulation && |
| 7667 | first->protocol == htons(ETH_P_IP) && |
Sowmini Varadhan | 5202882 | 2016-10-24 15:36:38 -0700 | [diff] [blame] | 7668 | hdr.ipv4->protocol == IPPROTO_UDP) { |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7669 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7670 | |
Sowmini Varadhan | 9f3c750 | 2016-10-24 15:36:39 -0700 | [diff] [blame^] | 7671 | if (unlikely(skb_tail_pointer(skb) < hdr.network + |
| 7672 | VXLAN_HEADROOM)) |
| 7673 | return; |
| 7674 | |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 7675 | /* verify the port is recognized as VXLAN */ |
| 7676 | if (adapter->vxlan_port && |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7677 | udp_hdr(skb)->dest == adapter->vxlan_port) |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 7678 | hdr.network = skb_inner_network_header(skb); |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 7679 | |
| 7680 | if (adapter->geneve_port && |
| 7681 | udp_hdr(skb)->dest == adapter->geneve_port) |
| 7682 | hdr.network = skb_inner_network_header(skb); |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7683 | } |
| 7684 | |
Sowmini Varadhan | 9f3c750 | 2016-10-24 15:36:39 -0700 | [diff] [blame^] | 7685 | /* Make sure we have at least [minimum IPv4 header + TCP] |
| 7686 | * or [IPv6 header] bytes |
| 7687 | */ |
| 7688 | if (unlikely(skb_tail_pointer(skb) < hdr.network + 40)) |
| 7689 | return; |
| 7690 | |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7691 | /* Currently only IPv4/IPv6 with TCP is supported */ |
| 7692 | switch (hdr.ipv4->version) { |
| 7693 | case IPVERSION: |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7694 | /* access ihl as u8 to avoid unaligned access on ia64 */ |
| 7695 | hlen = (hdr.network[0] & 0x0F) << 2; |
| 7696 | l4_proto = hdr.ipv4->protocol; |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7697 | break; |
| 7698 | case 6: |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7699 | hlen = hdr.network - skb->data; |
| 7700 | l4_proto = ipv6_find_hdr(skb, &hlen, IPPROTO_TCP, NULL, NULL); |
| 7701 | hlen -= hdr.network - skb->data; |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7702 | break; |
| 7703 | default: |
| 7704 | return; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7705 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7706 | |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7707 | if (l4_proto != IPPROTO_TCP) |
| 7708 | return; |
| 7709 | |
Sowmini Varadhan | 9f3c750 | 2016-10-24 15:36:39 -0700 | [diff] [blame^] | 7710 | if (unlikely(skb_tail_pointer(skb) < hdr.network + |
| 7711 | hlen + sizeof(struct tcphdr))) |
| 7712 | return; |
| 7713 | |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7714 | th = (struct tcphdr *)(hdr.network + hlen); |
| 7715 | |
| 7716 | /* skip this packet since the socket is closing */ |
| 7717 | if (th->fin) |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7718 | return; |
| 7719 | |
| 7720 | /* sample on all syn packets or once every atr sample count */ |
| 7721 | if (!th->syn && (ring->atr_count < ring->atr_sample_rate)) |
| 7722 | return; |
| 7723 | |
| 7724 | /* reset sample count */ |
| 7725 | ring->atr_count = 0; |
| 7726 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7727 | vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT); |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7728 | |
| 7729 | /* |
| 7730 | * src and dst are inverted, think how the receiver sees them |
| 7731 | * |
| 7732 | * The input is broken into two sections, a non-compressed section |
| 7733 | * containing vm_pool, vlan_id, and flow_type. The rest of the data |
| 7734 | * is XORed together and stored in the compressed dword. |
| 7735 | */ |
| 7736 | input.formatted.vlan_id = vlan_id; |
| 7737 | |
| 7738 | /* |
| 7739 | * since src port and flex bytes occupy the same word XOR them together |
| 7740 | * and write the value to source port portion of compressed dword |
| 7741 | */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7742 | 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] | 7743 | common.port.src ^= th->dest ^ htons(ETH_P_8021Q); |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7744 | else |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7745 | common.port.src ^= th->dest ^ first->protocol; |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7746 | common.port.dst ^= th->source; |
| 7747 | |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7748 | switch (hdr.ipv4->version) { |
| 7749 | case IPVERSION: |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7750 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4; |
| 7751 | common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr; |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7752 | break; |
| 7753 | case 6: |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7754 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6; |
| 7755 | common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^ |
| 7756 | hdr.ipv6->saddr.s6_addr32[1] ^ |
| 7757 | hdr.ipv6->saddr.s6_addr32[2] ^ |
| 7758 | hdr.ipv6->saddr.s6_addr32[3] ^ |
| 7759 | hdr.ipv6->daddr.s6_addr32[0] ^ |
| 7760 | hdr.ipv6->daddr.s6_addr32[1] ^ |
| 7761 | hdr.ipv6->daddr.s6_addr32[2] ^ |
| 7762 | hdr.ipv6->daddr.s6_addr32[3]; |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7763 | break; |
| 7764 | default: |
| 7765 | break; |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7766 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7767 | |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 7768 | if (hdr.network != skb_network_header(skb)) |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7769 | input.formatted.flow_type |= IXGBE_ATR_L4TYPE_TUNNEL_MASK; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7770 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7771 | /* 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] | 7772 | ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw, |
| 7773 | input, common, ring->queue_index); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7774 | } |
| 7775 | |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 7776 | 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] | 7777 | void *accel_priv, select_queue_fallback_t fallback) |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 7778 | { |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 7779 | struct ixgbe_fwd_adapter *fwd_adapter = accel_priv; |
| 7780 | #ifdef IXGBE_FCOE |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 7781 | struct ixgbe_adapter *adapter; |
| 7782 | struct ixgbe_ring_feature *f; |
| 7783 | int txq; |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 7784 | #endif |
| 7785 | |
| 7786 | if (fwd_adapter) |
| 7787 | return skb->queue_mapping + fwd_adapter->tx_base_queue; |
| 7788 | |
| 7789 | #ifdef IXGBE_FCOE |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 7790 | |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 7791 | /* |
| 7792 | * only execute the code below if protocol is FCoE |
| 7793 | * or FIP and we have FCoE enabled on the adapter |
| 7794 | */ |
| 7795 | switch (vlan_get_protocol(skb)) { |
Joe Perches | a1108ff | 2014-03-13 05:19:25 +0000 | [diff] [blame] | 7796 | case htons(ETH_P_FCOE): |
| 7797 | case htons(ETH_P_FIP): |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 7798 | adapter = netdev_priv(dev); |
Alexander Duyck | c087663 | 2012-05-10 00:01:46 +0000 | [diff] [blame] | 7799 | |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 7800 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 7801 | break; |
| 7802 | default: |
Daniel Borkmann | 99932d4 | 2014-02-16 15:55:20 +0100 | [diff] [blame] | 7803 | return fallback(dev, skb); |
Krishna Kumar | fdd3d63 | 2010-02-03 13:13:10 +0000 | [diff] [blame] | 7804 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7805 | |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 7806 | f = &adapter->ring_feature[RING_F_FCOE]; |
| 7807 | |
| 7808 | txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) : |
| 7809 | smp_processor_id(); |
| 7810 | |
| 7811 | while (txq >= f->indices) |
| 7812 | txq -= f->indices; |
| 7813 | |
| 7814 | return txq + f->offset; |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 7815 | #else |
Daniel Borkmann | 99932d4 | 2014-02-16 15:55:20 +0100 | [diff] [blame] | 7816 | return fallback(dev, skb); |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 7817 | #endif |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 7818 | } |
| 7819 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 7820 | netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb, |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 7821 | struct ixgbe_adapter *adapter, |
| 7822 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7823 | { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7824 | struct ixgbe_tx_buffer *first; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 7825 | int tso; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7826 | u32 tx_flags = 0; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7827 | unsigned short f; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7828 | u16 count = TXD_USE_COUNT(skb_headlen(skb)); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7829 | __be16 protocol = skb->protocol; |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 7830 | u8 hdr_len = 0; |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 7831 | |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7832 | /* |
| 7833 | * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD, |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 7834 | * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD, |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7835 | * + 2 desc gap to keep tail from touching head, |
| 7836 | * + 1 desc for context descriptor, |
| 7837 | * otherwise try next time |
| 7838 | */ |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7839 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) |
| 7840 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size); |
Alexander Duyck | 7f66162 | 2013-02-09 01:19:55 +0000 | [diff] [blame] | 7841 | |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7842 | if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) { |
| 7843 | tx_ring->tx_stats.tx_busy++; |
| 7844 | return NETDEV_TX_BUSY; |
| 7845 | } |
| 7846 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7847 | /* record the location of the first descriptor for this packet */ |
| 7848 | first = &tx_ring->tx_buffer_info[tx_ring->next_to_use]; |
| 7849 | first->skb = skb; |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 7850 | first->bytecount = skb->len; |
| 7851 | first->gso_segs = 1; |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7852 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7853 | /* 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] | 7854 | if (skb_vlan_tag_present(skb)) { |
| 7855 | tx_flags |= skb_vlan_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7856 | tx_flags |= IXGBE_TX_FLAGS_HW_VLAN; |
| 7857 | /* 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] | 7858 | } else if (protocol == htons(ETH_P_8021Q)) { |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7859 | struct vlan_hdr *vhdr, _vhdr; |
| 7860 | vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr); |
| 7861 | if (!vhdr) |
| 7862 | goto out_drop; |
| 7863 | |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 7864 | tx_flags |= ntohs(vhdr->h_vlan_TCI) << |
| 7865 | IXGBE_TX_FLAGS_VLAN_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7866 | tx_flags |= IXGBE_TX_FLAGS_SW_VLAN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7867 | } |
Toshiaki Makita | 0213668 | 2015-01-29 20:37:09 +0900 | [diff] [blame] | 7868 | protocol = vlan_get_protocol(skb); |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7869 | |
Mark Rustad | d523493 | 2014-08-09 07:02:09 +0000 | [diff] [blame] | 7870 | if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && |
| 7871 | adapter->ptp_clock && |
| 7872 | !test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS, |
| 7873 | &adapter->state)) { |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7874 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; |
| 7875 | tx_flags |= IXGBE_TX_FLAGS_TSTAMP; |
Jacob Keller | 891dc08 | 2012-12-05 07:24:46 +0000 | [diff] [blame] | 7876 | |
| 7877 | /* schedule check for Tx timestamp */ |
| 7878 | adapter->ptp_tx_skb = skb_get(skb); |
| 7879 | adapter->ptp_tx_start = jiffies; |
| 7880 | schedule_work(&adapter->ptp_tx_work); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7881 | } |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7882 | |
Jakub Kicinski | ff29a86 | 2014-03-15 14:55:16 +0000 | [diff] [blame] | 7883 | skb_tx_timestamp(skb); |
| 7884 | |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 7885 | #ifdef CONFIG_PCI_IOV |
| 7886 | /* |
| 7887 | * Use the l2switch_enable flag - would be false if the DMA |
| 7888 | * Tx switch had been disabled. |
| 7889 | */ |
| 7890 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7891 | tx_flags |= IXGBE_TX_FLAGS_CC; |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 7892 | |
| 7893 | #endif |
John Fastabend | 32701dc | 2011-09-27 03:51:56 +0000 | [diff] [blame] | 7894 | /* 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] | 7895 | if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && |
Alexander Duyck | 09dca47 | 2011-07-20 00:09:10 +0000 | [diff] [blame] | 7896 | ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) || |
| 7897 | (skb->priority != TC_PRIO_CONTROL))) { |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7898 | tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK; |
John Fastabend | 32701dc | 2011-09-27 03:51:56 +0000 | [diff] [blame] | 7899 | tx_flags |= (skb->priority & 0x7) << |
| 7900 | IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7901 | if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) { |
| 7902 | struct vlan_ethhdr *vhdr; |
Francois Romieu | 2049e1f | 2014-03-30 03:14:27 +0000 | [diff] [blame] | 7903 | |
| 7904 | if (skb_cow_head(skb, 0)) |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7905 | goto out_drop; |
| 7906 | vhdr = (struct vlan_ethhdr *)skb->data; |
| 7907 | vhdr->h_vlan_TCI = htons(tx_flags >> |
| 7908 | IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 7909 | } else { |
| 7910 | tx_flags |= IXGBE_TX_FLAGS_HW_VLAN; |
| 7911 | } |
| 7912 | } |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7913 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7914 | /* record initial flags and protocol */ |
| 7915 | first->tx_flags = tx_flags; |
| 7916 | first->protocol = protocol; |
| 7917 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7918 | #ifdef IXGBE_FCOE |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7919 | /* setup tx offload for FCoE */ |
Joe Perches | a1108ff | 2014-03-13 05:19:25 +0000 | [diff] [blame] | 7920 | if ((protocol == htons(ETH_P_FCOE)) && |
Alexander Duyck | a58915c | 2012-05-25 06:38:18 +0000 | [diff] [blame] | 7921 | (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) { |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7922 | tso = ixgbe_fso(tx_ring, first, &hdr_len); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7923 | if (tso < 0) |
| 7924 | goto out_drop; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7925 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7926 | goto xmit_fcoe; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 7927 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7928 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7929 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7930 | tso = ixgbe_tso(tx_ring, first, &hdr_len); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7931 | if (tso < 0) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7932 | goto out_drop; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7933 | else if (!tso) |
| 7934 | ixgbe_tx_csum(tx_ring, first); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7935 | |
| 7936 | /* add the ATR filter if ATR is on */ |
| 7937 | if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state)) |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7938 | ixgbe_atr(tx_ring, first); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7939 | |
| 7940 | #ifdef IXGBE_FCOE |
| 7941 | xmit_fcoe: |
| 7942 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7943 | ixgbe_tx_map(tx_ring, first, hdr_len); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7944 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7945 | return NETDEV_TX_OK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7946 | |
| 7947 | out_drop: |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7948 | dev_kfree_skb_any(first->skb); |
| 7949 | first->skb = NULL; |
| 7950 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7951 | return NETDEV_TX_OK; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7952 | } |
| 7953 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 7954 | static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb, |
| 7955 | struct net_device *netdev, |
| 7956 | struct ixgbe_ring *ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7957 | { |
| 7958 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7959 | struct ixgbe_ring *tx_ring; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7960 | |
Alexander Duyck | a50c29d | 2012-02-08 07:50:40 +0000 | [diff] [blame] | 7961 | /* |
| 7962 | * The minimum packet size for olinfo paylen is 17 so pad the skb |
| 7963 | * in order to meet this minimum size requirement. |
| 7964 | */ |
Alexander Duyck | a94d9e2 | 2014-12-03 08:17:39 -0800 | [diff] [blame] | 7965 | if (skb_put_padto(skb, 17)) |
| 7966 | return NETDEV_TX_OK; |
Alexander Duyck | a50c29d | 2012-02-08 07:50:40 +0000 | [diff] [blame] | 7967 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 7968 | tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping]; |
| 7969 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7970 | return ixgbe_xmit_frame_ring(skb, adapter, tx_ring); |
| 7971 | } |
| 7972 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 7973 | static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, |
| 7974 | struct net_device *netdev) |
| 7975 | { |
| 7976 | return __ixgbe_xmit_frame(skb, netdev, NULL); |
| 7977 | } |
| 7978 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7979 | /** |
| 7980 | * ixgbe_set_mac - Change the Ethernet Address of the NIC |
| 7981 | * @netdev: network interface device structure |
| 7982 | * @p: pointer to an address structure |
| 7983 | * |
| 7984 | * Returns 0 on success, negative on failure |
| 7985 | **/ |
| 7986 | static int ixgbe_set_mac(struct net_device *netdev, void *p) |
| 7987 | { |
| 7988 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7989 | struct ixgbe_hw *hw = &adapter->hw; |
| 7990 | struct sockaddr *addr = p; |
| 7991 | |
| 7992 | if (!is_valid_ether_addr(addr->sa_data)) |
| 7993 | return -EADDRNOTAVAIL; |
| 7994 | |
| 7995 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7996 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7997 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 7998 | ixgbe_mac_set_default_filter(adapter); |
| 7999 | |
| 8000 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8001 | } |
| 8002 | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 8003 | static int |
| 8004 | ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr) |
| 8005 | { |
| 8006 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8007 | struct ixgbe_hw *hw = &adapter->hw; |
| 8008 | u16 value; |
| 8009 | int rc; |
| 8010 | |
| 8011 | if (prtad != hw->phy.mdio.prtad) |
| 8012 | return -EINVAL; |
| 8013 | rc = hw->phy.ops.read_reg(hw, addr, devad, &value); |
| 8014 | if (!rc) |
| 8015 | rc = value; |
| 8016 | return rc; |
| 8017 | } |
| 8018 | |
| 8019 | static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad, |
| 8020 | u16 addr, u16 value) |
| 8021 | { |
| 8022 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8023 | struct ixgbe_hw *hw = &adapter->hw; |
| 8024 | |
| 8025 | if (prtad != hw->phy.mdio.prtad) |
| 8026 | return -EINVAL; |
| 8027 | return hw->phy.ops.write_reg(hw, addr, devad, value); |
| 8028 | } |
| 8029 | |
| 8030 | static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd) |
| 8031 | { |
| 8032 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8033 | |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 8034 | switch (cmd) { |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 8035 | case SIOCSHWTSTAMP: |
Jacob Keller | 93501d4 | 2014-02-28 15:48:58 -0800 | [diff] [blame] | 8036 | return ixgbe_ptp_set_ts_config(adapter, req); |
| 8037 | case SIOCGHWTSTAMP: |
| 8038 | return ixgbe_ptp_get_ts_config(adapter, req); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 8039 | default: |
| 8040 | return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd); |
| 8041 | } |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 8042 | } |
| 8043 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8044 | /** |
| 8045 | * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 8046 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8047 | * @netdev: network interface device structure |
| 8048 | * |
| 8049 | * Returns non-zero on failure |
| 8050 | **/ |
| 8051 | static int ixgbe_add_sanmac_netdev(struct net_device *dev) |
| 8052 | { |
| 8053 | int err = 0; |
| 8054 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 8055 | struct ixgbe_hw *hw = &adapter->hw; |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8056 | |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 8057 | if (is_valid_ether_addr(hw->mac.san_addr)) { |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8058 | rtnl_lock(); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 8059 | 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] | 8060 | rtnl_unlock(); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 8061 | |
| 8062 | /* update SAN MAC vmdq pool selection */ |
| 8063 | hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0)); |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8064 | } |
| 8065 | return err; |
| 8066 | } |
| 8067 | |
| 8068 | /** |
| 8069 | * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 8070 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8071 | * @netdev: network interface device structure |
| 8072 | * |
| 8073 | * Returns non-zero on failure |
| 8074 | **/ |
| 8075 | static int ixgbe_del_sanmac_netdev(struct net_device *dev) |
| 8076 | { |
| 8077 | int err = 0; |
| 8078 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 8079 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 8080 | |
| 8081 | if (is_valid_ether_addr(mac->san_addr)) { |
| 8082 | rtnl_lock(); |
| 8083 | err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 8084 | rtnl_unlock(); |
| 8085 | } |
| 8086 | return err; |
| 8087 | } |
| 8088 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8089 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 8090 | /* |
| 8091 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 8092 | * without having to re-enable interrupts. It's not called while |
| 8093 | * the interrupt routine is executing. |
| 8094 | */ |
| 8095 | static void ixgbe_netpoll(struct net_device *netdev) |
| 8096 | { |
| 8097 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 8098 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8099 | |
Alexander Duyck | 1a647bd | 2010-01-13 01:49:13 +0000 | [diff] [blame] | 8100 | /* if interface is down do nothing */ |
| 8101 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 8102 | return; |
| 8103 | |
Alexander Duyck | 856f606 | 2015-02-25 17:45:54 +0000 | [diff] [blame] | 8104 | /* loop through and schedule all active queues */ |
| 8105 | for (i = 0; i < adapter->num_q_vectors; i++) |
| 8106 | ixgbe_msix_clean_rings(0, adapter->q_vector[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8107 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8108 | |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 8109 | #endif |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8110 | static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev, |
| 8111 | struct rtnl_link_stats64 *stats) |
| 8112 | { |
| 8113 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8114 | int i; |
| 8115 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8116 | rcu_read_lock(); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8117 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8118 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8119 | u64 bytes, packets; |
| 8120 | unsigned int start; |
| 8121 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8122 | if (ring) { |
| 8123 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 8124 | start = u64_stats_fetch_begin_irq(&ring->syncp); |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8125 | packets = ring->stats.packets; |
| 8126 | bytes = ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 8127 | } while (u64_stats_fetch_retry_irq(&ring->syncp, start)); |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8128 | stats->rx_packets += packets; |
| 8129 | stats->rx_bytes += bytes; |
| 8130 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8131 | } |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 8132 | |
| 8133 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 8134 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]); |
| 8135 | u64 bytes, packets; |
| 8136 | unsigned int start; |
| 8137 | |
| 8138 | if (ring) { |
| 8139 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 8140 | start = u64_stats_fetch_begin_irq(&ring->syncp); |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 8141 | packets = ring->stats.packets; |
| 8142 | bytes = ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 8143 | } while (u64_stats_fetch_retry_irq(&ring->syncp, start)); |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 8144 | stats->tx_packets += packets; |
| 8145 | stats->tx_bytes += bytes; |
| 8146 | } |
| 8147 | } |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8148 | rcu_read_unlock(); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8149 | /* following stats updated by ixgbe_watchdog_task() */ |
| 8150 | stats->multicast = netdev->stats.multicast; |
| 8151 | stats->rx_errors = netdev->stats.rx_errors; |
| 8152 | stats->rx_length_errors = netdev->stats.rx_length_errors; |
| 8153 | stats->rx_crc_errors = netdev->stats.rx_crc_errors; |
| 8154 | stats->rx_missed_errors = netdev->stats.rx_missed_errors; |
| 8155 | return stats; |
| 8156 | } |
| 8157 | |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 8158 | #ifdef CONFIG_IXGBE_DCB |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 8159 | /** |
| 8160 | * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid. |
| 8161 | * @adapter: pointer to ixgbe_adapter |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8162 | * @tc: number of traffic classes currently enabled |
| 8163 | * |
| 8164 | * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm |
| 8165 | * 802.1Q priority maps to a packet buffer that exists. |
| 8166 | */ |
| 8167 | static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc) |
| 8168 | { |
| 8169 | struct ixgbe_hw *hw = &adapter->hw; |
| 8170 | u32 reg, rsave; |
| 8171 | int i; |
| 8172 | |
| 8173 | /* 82598 have a static priority to TC mapping that can not |
| 8174 | * be changed so no validation is needed. |
| 8175 | */ |
| 8176 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 8177 | return; |
| 8178 | |
| 8179 | reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC); |
| 8180 | rsave = reg; |
| 8181 | |
| 8182 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 8183 | u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT); |
| 8184 | |
| 8185 | /* If up2tc is out of bounds default to zero */ |
| 8186 | if (up2tc > tc) |
| 8187 | reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT); |
| 8188 | } |
| 8189 | |
| 8190 | if (reg != rsave) |
| 8191 | IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg); |
| 8192 | |
| 8193 | return; |
| 8194 | } |
| 8195 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 8196 | /** |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 8197 | * ixgbe_set_prio_tc_map - Configure netdev prio tc map |
| 8198 | * @adapter: Pointer to adapter struct |
| 8199 | * |
| 8200 | * Populate the netdev user priority to tc map |
| 8201 | */ |
| 8202 | static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter) |
| 8203 | { |
| 8204 | struct net_device *dev = adapter->netdev; |
| 8205 | struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg; |
| 8206 | struct ieee_ets *ets = adapter->ixgbe_ieee_ets; |
| 8207 | u8 prio; |
| 8208 | |
| 8209 | for (prio = 0; prio < MAX_USER_PRIORITY; prio++) { |
| 8210 | u8 tc = 0; |
| 8211 | |
| 8212 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) |
| 8213 | tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio); |
| 8214 | else if (ets) |
| 8215 | tc = ets->prio_tc[prio]; |
| 8216 | |
| 8217 | netdev_set_prio_tc_map(dev, prio, tc); |
| 8218 | } |
| 8219 | } |
| 8220 | |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 8221 | #endif /* CONFIG_IXGBE_DCB */ |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 8222 | /** |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 8223 | * ixgbe_setup_tc - configure net_device for multiple traffic classes |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8224 | * |
| 8225 | * @netdev: net device to configure |
| 8226 | * @tc: number of traffic classes to enable |
| 8227 | */ |
| 8228 | int ixgbe_setup_tc(struct net_device *dev, u8 tc) |
| 8229 | { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8230 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 8231 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8232 | bool pools; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8233 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8234 | /* Hardware supports up to 8 traffic classes */ |
Emil Tantilov | 7e3f5c8 | 2015-07-09 12:28:59 -0700 | [diff] [blame] | 8235 | if (tc > adapter->dcb_cfg.num_tcs.pg_tcs) |
| 8236 | return -EINVAL; |
| 8237 | |
| 8238 | if (hw->mac.type == ixgbe_mac_82598EB && tc && tc < MAX_TRAFFIC_CLASS) |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8239 | return -EINVAL; |
| 8240 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8241 | pools = (find_first_zero_bit(&adapter->fwd_bitmask, 32) > 1); |
| 8242 | if (tc && pools && adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS) |
| 8243 | return -EBUSY; |
| 8244 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8245 | /* Hardware has to reinitialize queues and interrupts to |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 8246 | * match packet buffer alignment. Unfortunately, the |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8247 | * hardware is not flexible enough to do this dynamically. |
| 8248 | */ |
| 8249 | if (netif_running(dev)) |
| 8250 | ixgbe_close(dev); |
Alexander Duyck | bf4d67d | 2015-10-20 13:28:17 -0700 | [diff] [blame] | 8251 | else |
| 8252 | ixgbe_reset(adapter); |
| 8253 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8254 | ixgbe_clear_interrupt_scheme(adapter); |
| 8255 | |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 8256 | #ifdef CONFIG_IXGBE_DCB |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8257 | if (tc) { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8258 | netdev_set_num_tc(dev, tc); |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 8259 | ixgbe_set_prio_tc_map(adapter); |
| 8260 | |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8261 | adapter->flags |= IXGBE_FLAG_DCB_ENABLED; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8262 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 8263 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 8264 | adapter->last_lfc_mode = adapter->hw.fc.requested_mode; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8265 | adapter->hw.fc.requested_mode = ixgbe_fc_none; |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 8266 | } |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8267 | } else { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8268 | netdev_reset_tc(dev); |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 8269 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 8270 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 8271 | adapter->hw.fc.requested_mode = adapter->last_lfc_mode; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8272 | |
| 8273 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8274 | |
| 8275 | adapter->temp_dcb_cfg.pfc_mode_enable = false; |
| 8276 | adapter->dcb_cfg.pfc_mode_enable = false; |
| 8277 | } |
| 8278 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8279 | ixgbe_validate_rtr(adapter, tc); |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 8280 | |
| 8281 | #endif /* CONFIG_IXGBE_DCB */ |
| 8282 | ixgbe_init_interrupt_scheme(adapter); |
| 8283 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8284 | if (netif_running(dev)) |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 8285 | return ixgbe_open(dev); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8286 | |
| 8287 | return 0; |
| 8288 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8289 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8290 | static int ixgbe_delete_clsu32(struct ixgbe_adapter *adapter, |
| 8291 | struct tc_cls_u32_offload *cls) |
| 8292 | { |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8293 | u32 hdl = cls->knode.handle; |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8294 | u32 uhtid = TC_U32_USERHTID(cls->knode.handle); |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8295 | u32 loc = cls->knode.handle & 0xfffff; |
| 8296 | int err = 0, i, j; |
| 8297 | struct ixgbe_jump_table *jump = NULL; |
| 8298 | |
| 8299 | if (loc > IXGBE_MAX_HW_ENTRIES) |
| 8300 | return -EINVAL; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8301 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8302 | if ((uhtid != 0x800) && (uhtid >= IXGBE_MAX_LINK_HANDLE)) |
| 8303 | return -EINVAL; |
| 8304 | |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8305 | /* Clear this filter in the link data it is associated with */ |
| 8306 | if (uhtid != 0x800) { |
| 8307 | jump = adapter->jump_tables[uhtid]; |
Amritha Nambiar | 12746fd | 2016-05-16 18:33:20 -0700 | [diff] [blame] | 8308 | if (!jump) |
| 8309 | return -EINVAL; |
| 8310 | if (!test_bit(loc - 1, jump->child_loc_map)) |
| 8311 | return -EINVAL; |
| 8312 | clear_bit(loc - 1, jump->child_loc_map); |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8313 | } |
| 8314 | |
| 8315 | /* Check if the filter being deleted is a link */ |
| 8316 | for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) { |
| 8317 | jump = adapter->jump_tables[i]; |
| 8318 | if (jump && jump->link_hdl == hdl) { |
| 8319 | /* Delete filters in the hardware in the child hash |
| 8320 | * table associated with this link |
| 8321 | */ |
| 8322 | for (j = 0; j < IXGBE_MAX_HW_ENTRIES; j++) { |
| 8323 | if (!test_bit(j, jump->child_loc_map)) |
| 8324 | continue; |
| 8325 | spin_lock(&adapter->fdir_perfect_lock); |
| 8326 | err = ixgbe_update_ethtool_fdir_entry(adapter, |
| 8327 | NULL, |
| 8328 | j + 1); |
| 8329 | spin_unlock(&adapter->fdir_perfect_lock); |
| 8330 | clear_bit(j, jump->child_loc_map); |
| 8331 | } |
| 8332 | /* Remove resources for this link */ |
| 8333 | kfree(jump->input); |
| 8334 | kfree(jump->mask); |
| 8335 | kfree(jump); |
| 8336 | adapter->jump_tables[i] = NULL; |
| 8337 | return err; |
| 8338 | } |
| 8339 | } |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8340 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8341 | spin_lock(&adapter->fdir_perfect_lock); |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8342 | err = ixgbe_update_ethtool_fdir_entry(adapter, NULL, loc); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8343 | spin_unlock(&adapter->fdir_perfect_lock); |
| 8344 | return err; |
| 8345 | } |
| 8346 | |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8347 | static int ixgbe_configure_clsu32_add_hnode(struct ixgbe_adapter *adapter, |
| 8348 | __be16 protocol, |
| 8349 | struct tc_cls_u32_offload *cls) |
| 8350 | { |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8351 | u32 uhtid = TC_U32_USERHTID(cls->hnode.handle); |
| 8352 | |
| 8353 | if (uhtid >= IXGBE_MAX_LINK_HANDLE) |
| 8354 | return -EINVAL; |
| 8355 | |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8356 | /* This ixgbe devices do not support hash tables at the moment |
| 8357 | * so abort when given hash tables. |
| 8358 | */ |
| 8359 | if (cls->hnode.divisor > 0) |
| 8360 | return -EINVAL; |
| 8361 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8362 | set_bit(uhtid - 1, &adapter->tables); |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8363 | return 0; |
| 8364 | } |
| 8365 | |
| 8366 | static int ixgbe_configure_clsu32_del_hnode(struct ixgbe_adapter *adapter, |
| 8367 | struct tc_cls_u32_offload *cls) |
| 8368 | { |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8369 | u32 uhtid = TC_U32_USERHTID(cls->hnode.handle); |
| 8370 | |
| 8371 | if (uhtid >= IXGBE_MAX_LINK_HANDLE) |
| 8372 | return -EINVAL; |
| 8373 | |
| 8374 | clear_bit(uhtid - 1, &adapter->tables); |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8375 | return 0; |
| 8376 | } |
| 8377 | |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8378 | #ifdef CONFIG_NET_CLS_ACT |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 8379 | struct upper_walk_data { |
| 8380 | struct ixgbe_adapter *adapter; |
| 8381 | u64 action; |
| 8382 | int ifindex; |
| 8383 | u8 queue; |
| 8384 | }; |
| 8385 | |
| 8386 | static int get_macvlan_queue(struct net_device *upper, void *_data) |
| 8387 | { |
| 8388 | if (netif_is_macvlan(upper)) { |
| 8389 | struct macvlan_dev *dfwd = netdev_priv(upper); |
| 8390 | struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv; |
| 8391 | struct upper_walk_data *data = _data; |
| 8392 | struct ixgbe_adapter *adapter = data->adapter; |
| 8393 | int ifindex = data->ifindex; |
| 8394 | |
| 8395 | if (vadapter && vadapter->netdev->ifindex == ifindex) { |
| 8396 | data->queue = adapter->rx_ring[vadapter->rx_base_queue]->reg_idx; |
| 8397 | data->action = data->queue; |
| 8398 | return 1; |
| 8399 | } |
| 8400 | } |
| 8401 | |
| 8402 | return 0; |
| 8403 | } |
| 8404 | |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8405 | static int handle_redirect_action(struct ixgbe_adapter *adapter, int ifindex, |
| 8406 | u8 *queue, u64 *action) |
| 8407 | { |
| 8408 | unsigned int num_vfs = adapter->num_vfs, vf; |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 8409 | struct upper_walk_data data; |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8410 | struct net_device *upper; |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8411 | |
| 8412 | /* redirect to a SRIOV VF */ |
| 8413 | for (vf = 0; vf < num_vfs; ++vf) { |
| 8414 | upper = pci_get_drvdata(adapter->vfinfo[vf].vfdev); |
| 8415 | if (upper->ifindex == ifindex) { |
| 8416 | if (adapter->num_rx_pools > 1) |
| 8417 | *queue = vf * 2; |
| 8418 | else |
| 8419 | *queue = vf * adapter->num_rx_queues_per_pool; |
| 8420 | |
| 8421 | *action = vf + 1; |
| 8422 | *action <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF; |
| 8423 | return 0; |
| 8424 | } |
| 8425 | } |
| 8426 | |
| 8427 | /* redirect to a offloaded macvlan netdev */ |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 8428 | data.adapter = adapter; |
| 8429 | data.ifindex = ifindex; |
| 8430 | data.action = 0; |
| 8431 | data.queue = 0; |
| 8432 | if (netdev_walk_all_upper_dev_rcu(adapter->netdev, |
| 8433 | get_macvlan_queue, &data)) { |
| 8434 | *action = data.action; |
| 8435 | *queue = data.queue; |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8436 | |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 8437 | return 0; |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8438 | } |
| 8439 | |
| 8440 | return -EINVAL; |
| 8441 | } |
| 8442 | |
| 8443 | static int parse_tc_actions(struct ixgbe_adapter *adapter, |
| 8444 | struct tcf_exts *exts, u64 *action, u8 *queue) |
| 8445 | { |
| 8446 | const struct tc_action *a; |
WANG Cong | 22dc13c | 2016-08-13 22:35:00 -0700 | [diff] [blame] | 8447 | LIST_HEAD(actions); |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8448 | int err; |
| 8449 | |
| 8450 | if (tc_no_actions(exts)) |
| 8451 | return -EINVAL; |
| 8452 | |
WANG Cong | 22dc13c | 2016-08-13 22:35:00 -0700 | [diff] [blame] | 8453 | tcf_exts_to_list(exts, &actions); |
| 8454 | list_for_each_entry(a, &actions, list) { |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8455 | |
| 8456 | /* Drop action */ |
| 8457 | if (is_tcf_gact_shot(a)) { |
| 8458 | *action = IXGBE_FDIR_DROP_QUEUE; |
| 8459 | *queue = IXGBE_FDIR_DROP_QUEUE; |
| 8460 | return 0; |
| 8461 | } |
| 8462 | |
| 8463 | /* Redirect to a VF or a offloaded macvlan */ |
Shmulik Ladkani | 5724b8b | 2016-10-13 09:06:43 +0300 | [diff] [blame] | 8464 | if (is_tcf_mirred_egress_redirect(a)) { |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8465 | int ifindex = tcf_mirred_ifindex(a); |
| 8466 | |
| 8467 | err = handle_redirect_action(adapter, ifindex, queue, |
| 8468 | action); |
| 8469 | if (err == 0) |
| 8470 | return err; |
| 8471 | } |
| 8472 | } |
| 8473 | |
| 8474 | return -EINVAL; |
| 8475 | } |
| 8476 | #else |
| 8477 | static int parse_tc_actions(struct ixgbe_adapter *adapter, |
| 8478 | struct tcf_exts *exts, u64 *action, u8 *queue) |
| 8479 | { |
| 8480 | return -EINVAL; |
| 8481 | } |
| 8482 | #endif /* CONFIG_NET_CLS_ACT */ |
| 8483 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8484 | static int ixgbe_clsu32_build_input(struct ixgbe_fdir_filter *input, |
| 8485 | union ixgbe_atr_input *mask, |
| 8486 | struct tc_cls_u32_offload *cls, |
| 8487 | struct ixgbe_mat_field *field_ptr, |
| 8488 | struct ixgbe_nexthdr *nexthdr) |
| 8489 | { |
| 8490 | int i, j, off; |
| 8491 | __be32 val, m; |
| 8492 | bool found_entry = false, found_jump_field = false; |
| 8493 | |
| 8494 | for (i = 0; i < cls->knode.sel->nkeys; i++) { |
| 8495 | off = cls->knode.sel->keys[i].off; |
| 8496 | val = cls->knode.sel->keys[i].val; |
| 8497 | m = cls->knode.sel->keys[i].mask; |
| 8498 | |
| 8499 | for (j = 0; field_ptr[j].val; j++) { |
| 8500 | if (field_ptr[j].off == off) { |
| 8501 | field_ptr[j].val(input, mask, val, m); |
| 8502 | input->filter.formatted.flow_type |= |
| 8503 | field_ptr[j].type; |
| 8504 | found_entry = true; |
| 8505 | break; |
| 8506 | } |
| 8507 | } |
| 8508 | if (nexthdr) { |
| 8509 | if (nexthdr->off == cls->knode.sel->keys[i].off && |
| 8510 | nexthdr->val == cls->knode.sel->keys[i].val && |
| 8511 | nexthdr->mask == cls->knode.sel->keys[i].mask) |
| 8512 | found_jump_field = true; |
| 8513 | else |
| 8514 | continue; |
| 8515 | } |
| 8516 | } |
| 8517 | |
| 8518 | if (nexthdr && !found_jump_field) |
| 8519 | return -EINVAL; |
| 8520 | |
| 8521 | if (!found_entry) |
| 8522 | return 0; |
| 8523 | |
| 8524 | mask->formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK | |
| 8525 | IXGBE_ATR_L4TYPE_MASK; |
| 8526 | |
| 8527 | if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4) |
| 8528 | mask->formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK; |
| 8529 | |
| 8530 | return 0; |
| 8531 | } |
| 8532 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8533 | static int ixgbe_configure_clsu32(struct ixgbe_adapter *adapter, |
| 8534 | __be16 protocol, |
| 8535 | struct tc_cls_u32_offload *cls) |
| 8536 | { |
| 8537 | u32 loc = cls->knode.handle & 0xfffff; |
| 8538 | struct ixgbe_hw *hw = &adapter->hw; |
| 8539 | struct ixgbe_mat_field *field_ptr; |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8540 | struct ixgbe_fdir_filter *input = NULL; |
| 8541 | union ixgbe_atr_input *mask = NULL; |
| 8542 | struct ixgbe_jump_table *jump = NULL; |
| 8543 | int i, err = -EINVAL; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8544 | u8 queue; |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8545 | u32 uhtid, link_uhtid; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8546 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8547 | uhtid = TC_U32_USERHTID(cls->knode.handle); |
| 8548 | link_uhtid = TC_U32_USERHTID(cls->knode.link_handle); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8549 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8550 | /* At the moment cls_u32 jumps to network layer and skips past |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8551 | * L2 headers. The canonical method to match L2 frames is to use |
| 8552 | * negative values. However this is error prone at best but really |
| 8553 | * just broken because there is no way to "know" what sort of hdr |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8554 | * is in front of the network layer. Fix cls_u32 to support L2 |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8555 | * headers when needed. |
| 8556 | */ |
| 8557 | if (protocol != htons(ETH_P_IP)) |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8558 | return err; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8559 | |
| 8560 | if (loc >= ((1024 << adapter->fdir_pballoc) - 2)) { |
| 8561 | e_err(drv, "Location out of range\n"); |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8562 | return err; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8563 | } |
| 8564 | |
| 8565 | /* cls u32 is a graph starting at root node 0x800. The driver tracks |
| 8566 | * links and also the fields used to advance the parser across each |
| 8567 | * link (e.g. nexthdr/eat parameters from 'tc'). This way we can map |
| 8568 | * the u32 graph onto the hardware parse graph denoted in ixgbe_model.h |
| 8569 | * To add support for new nodes update ixgbe_model.h parse structures |
| 8570 | * this function _should_ be generic try not to hardcode values here. |
| 8571 | */ |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8572 | if (uhtid == 0x800) { |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8573 | field_ptr = (adapter->jump_tables[0])->mat; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8574 | } else { |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8575 | if (uhtid >= IXGBE_MAX_LINK_HANDLE) |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8576 | return err; |
| 8577 | if (!adapter->jump_tables[uhtid]) |
| 8578 | return err; |
| 8579 | field_ptr = (adapter->jump_tables[uhtid])->mat; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8580 | } |
| 8581 | |
| 8582 | if (!field_ptr) |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8583 | return err; |
| 8584 | |
| 8585 | /* At this point we know the field_ptr is valid and need to either |
| 8586 | * build cls_u32 link or attach filter. Because adding a link to |
| 8587 | * a handle that does not exist is invalid and the same for adding |
| 8588 | * rules to handles that don't exist. |
| 8589 | */ |
| 8590 | |
| 8591 | if (link_uhtid) { |
| 8592 | struct ixgbe_nexthdr *nexthdr = ixgbe_ipv4_jumps; |
| 8593 | |
| 8594 | if (link_uhtid >= IXGBE_MAX_LINK_HANDLE) |
| 8595 | return err; |
| 8596 | |
| 8597 | if (!test_bit(link_uhtid - 1, &adapter->tables)) |
| 8598 | return err; |
| 8599 | |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8600 | /* Multiple filters as links to the same hash table are not |
| 8601 | * supported. To add a new filter with the same next header |
| 8602 | * but different match/jump conditions, create a new hash table |
| 8603 | * and link to it. |
| 8604 | */ |
| 8605 | if (adapter->jump_tables[link_uhtid] && |
| 8606 | (adapter->jump_tables[link_uhtid])->link_hdl) { |
| 8607 | e_err(drv, "Link filter exists for link: %x\n", |
| 8608 | link_uhtid); |
| 8609 | return err; |
| 8610 | } |
| 8611 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8612 | for (i = 0; nexthdr[i].jump; i++) { |
| 8613 | if (nexthdr[i].o != cls->knode.sel->offoff || |
| 8614 | nexthdr[i].s != cls->knode.sel->offshift || |
| 8615 | nexthdr[i].m != cls->knode.sel->offmask) |
| 8616 | return err; |
| 8617 | |
| 8618 | jump = kzalloc(sizeof(*jump), GFP_KERNEL); |
| 8619 | if (!jump) |
| 8620 | return -ENOMEM; |
| 8621 | input = kzalloc(sizeof(*input), GFP_KERNEL); |
| 8622 | if (!input) { |
| 8623 | err = -ENOMEM; |
| 8624 | goto free_jump; |
| 8625 | } |
| 8626 | mask = kzalloc(sizeof(*mask), GFP_KERNEL); |
| 8627 | if (!mask) { |
| 8628 | err = -ENOMEM; |
Amritha Nambiar | 12746fd | 2016-05-16 18:33:20 -0700 | [diff] [blame] | 8629 | goto free_input; |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8630 | } |
| 8631 | jump->input = input; |
| 8632 | jump->mask = mask; |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8633 | jump->link_hdl = cls->knode.handle; |
| 8634 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8635 | err = ixgbe_clsu32_build_input(input, mask, cls, |
| 8636 | field_ptr, &nexthdr[i]); |
| 8637 | if (!err) { |
| 8638 | jump->mat = nexthdr[i].jump; |
| 8639 | adapter->jump_tables[link_uhtid] = jump; |
| 8640 | break; |
| 8641 | } |
| 8642 | } |
| 8643 | return 0; |
| 8644 | } |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8645 | |
| 8646 | input = kzalloc(sizeof(*input), GFP_KERNEL); |
| 8647 | if (!input) |
| 8648 | return -ENOMEM; |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8649 | mask = kzalloc(sizeof(*mask), GFP_KERNEL); |
| 8650 | if (!mask) { |
| 8651 | err = -ENOMEM; |
Amritha Nambiar | 12746fd | 2016-05-16 18:33:20 -0700 | [diff] [blame] | 8652 | goto free_input; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8653 | } |
| 8654 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8655 | if ((uhtid != 0x800) && (adapter->jump_tables[uhtid])) { |
| 8656 | if ((adapter->jump_tables[uhtid])->input) |
| 8657 | memcpy(input, (adapter->jump_tables[uhtid])->input, |
| 8658 | sizeof(*input)); |
| 8659 | if ((adapter->jump_tables[uhtid])->mask) |
| 8660 | memcpy(mask, (adapter->jump_tables[uhtid])->mask, |
| 8661 | sizeof(*mask)); |
Amritha Nambiar | 12746fd | 2016-05-16 18:33:20 -0700 | [diff] [blame] | 8662 | |
| 8663 | /* Lookup in all child hash tables if this location is already |
| 8664 | * filled with a filter |
| 8665 | */ |
| 8666 | for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) { |
| 8667 | struct ixgbe_jump_table *link = adapter->jump_tables[i]; |
| 8668 | |
| 8669 | if (link && (test_bit(loc - 1, link->child_loc_map))) { |
| 8670 | e_err(drv, "Filter exists in location: %x\n", |
| 8671 | loc); |
| 8672 | err = -EINVAL; |
| 8673 | goto err_out; |
| 8674 | } |
| 8675 | } |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8676 | } |
| 8677 | err = ixgbe_clsu32_build_input(input, mask, cls, field_ptr, NULL); |
| 8678 | if (err) |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8679 | goto err_out; |
| 8680 | |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8681 | err = parse_tc_actions(adapter, cls->knode.exts, &input->action, |
| 8682 | &queue); |
| 8683 | if (err < 0) |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8684 | goto err_out; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8685 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8686 | input->sw_idx = loc; |
| 8687 | |
| 8688 | spin_lock(&adapter->fdir_perfect_lock); |
| 8689 | |
| 8690 | if (hlist_empty(&adapter->fdir_filter_list)) { |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8691 | memcpy(&adapter->fdir_mask, mask, sizeof(*mask)); |
| 8692 | err = ixgbe_fdir_set_input_mask_82599(hw, mask); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8693 | if (err) |
| 8694 | goto err_out_w_lock; |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8695 | } else if (memcmp(&adapter->fdir_mask, mask, sizeof(*mask))) { |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8696 | err = -EINVAL; |
| 8697 | goto err_out_w_lock; |
| 8698 | } |
| 8699 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8700 | ixgbe_atr_compute_perfect_hash_82599(&input->filter, mask); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8701 | err = ixgbe_fdir_write_perfect_filter_82599(hw, &input->filter, |
| 8702 | input->sw_idx, queue); |
| 8703 | if (!err) |
| 8704 | ixgbe_update_ethtool_fdir_entry(adapter, input, input->sw_idx); |
| 8705 | spin_unlock(&adapter->fdir_perfect_lock); |
| 8706 | |
Amritha Nambiar | 12746fd | 2016-05-16 18:33:20 -0700 | [diff] [blame] | 8707 | if ((uhtid != 0x800) && (adapter->jump_tables[uhtid])) |
| 8708 | set_bit(loc - 1, (adapter->jump_tables[uhtid])->child_loc_map); |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8709 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8710 | kfree(mask); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8711 | return err; |
| 8712 | err_out_w_lock: |
| 8713 | spin_unlock(&adapter->fdir_perfect_lock); |
| 8714 | err_out: |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8715 | kfree(mask); |
Amritha Nambiar | 12746fd | 2016-05-16 18:33:20 -0700 | [diff] [blame] | 8716 | free_input: |
| 8717 | kfree(input); |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8718 | free_jump: |
| 8719 | kfree(jump); |
| 8720 | return err; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8721 | } |
| 8722 | |
Emil Tantilov | 6e2a60b | 2016-02-17 15:55:06 -0800 | [diff] [blame] | 8723 | static int __ixgbe_setup_tc(struct net_device *dev, u32 handle, __be16 proto, |
| 8724 | struct tc_to_netdev *tc) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 8725 | { |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8726 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 8727 | |
| 8728 | if (TC_H_MAJ(handle) == TC_H_MAJ(TC_H_INGRESS) && |
| 8729 | tc->type == TC_SETUP_CLSU32) { |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8730 | switch (tc->cls_u32->command) { |
| 8731 | case TC_CLSU32_NEW_KNODE: |
| 8732 | case TC_CLSU32_REPLACE_KNODE: |
| 8733 | return ixgbe_configure_clsu32(adapter, |
| 8734 | proto, tc->cls_u32); |
| 8735 | case TC_CLSU32_DELETE_KNODE: |
| 8736 | return ixgbe_delete_clsu32(adapter, tc->cls_u32); |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8737 | case TC_CLSU32_NEW_HNODE: |
| 8738 | case TC_CLSU32_REPLACE_HNODE: |
| 8739 | return ixgbe_configure_clsu32_add_hnode(adapter, proto, |
| 8740 | tc->cls_u32); |
| 8741 | case TC_CLSU32_DELETE_HNODE: |
| 8742 | return ixgbe_configure_clsu32_del_hnode(adapter, |
| 8743 | tc->cls_u32); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8744 | default: |
| 8745 | return -EINVAL; |
| 8746 | } |
| 8747 | } |
| 8748 | |
John Fastabend | 5eb4dce | 2016-02-29 11:26:13 -0800 | [diff] [blame] | 8749 | if (tc->type != TC_SETUP_MQPRIO) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 8750 | return -EINVAL; |
| 8751 | |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 8752 | return ixgbe_setup_tc(dev, tc->tc); |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 8753 | } |
| 8754 | |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 8755 | #ifdef CONFIG_PCI_IOV |
| 8756 | void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter) |
| 8757 | { |
| 8758 | struct net_device *netdev = adapter->netdev; |
| 8759 | |
| 8760 | rtnl_lock(); |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 8761 | ixgbe_setup_tc(netdev, netdev_get_num_tc(netdev)); |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 8762 | rtnl_unlock(); |
| 8763 | } |
| 8764 | |
| 8765 | #endif |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8766 | void ixgbe_do_reset(struct net_device *netdev) |
| 8767 | { |
| 8768 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8769 | |
| 8770 | if (netif_running(netdev)) |
| 8771 | ixgbe_reinit_locked(adapter); |
| 8772 | else |
| 8773 | ixgbe_reset(adapter); |
| 8774 | } |
| 8775 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 8776 | static netdev_features_t ixgbe_fix_features(struct net_device *netdev, |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8777 | netdev_features_t features) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8778 | { |
| 8779 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8780 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8781 | /* If Rx checksum is disabled, then RSC/LRO should also be disabled */ |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8782 | if (!(features & NETIF_F_RXCSUM)) |
| 8783 | features &= ~NETIF_F_LRO; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8784 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8785 | /* Turn off LRO if not RSC capable */ |
| 8786 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) |
| 8787 | features &= ~NETIF_F_LRO; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 8788 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8789 | return features; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8790 | } |
| 8791 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 8792 | static int ixgbe_set_features(struct net_device *netdev, |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8793 | netdev_features_t features) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8794 | { |
| 8795 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8796 | netdev_features_t changed = netdev->features ^ features; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8797 | bool need_reset = false; |
| 8798 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8799 | /* Make sure RSC matches LRO, reset if change */ |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8800 | if (!(features & NETIF_F_LRO)) { |
| 8801 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8802 | need_reset = true; |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8803 | adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED; |
| 8804 | } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) && |
| 8805 | !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) { |
| 8806 | if (adapter->rx_itr_setting == 1 || |
| 8807 | adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) { |
| 8808 | adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED; |
| 8809 | need_reset = true; |
| 8810 | } else if ((changed ^ features) & NETIF_F_LRO) { |
| 8811 | e_info(probe, "rx-usecs set too low, " |
| 8812 | "disabling RSC\n"); |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8813 | } |
| 8814 | } |
| 8815 | |
| 8816 | /* |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8817 | * Check if Flow Director n-tuple support or hw_tc support was |
| 8818 | * enabled or disabled. If the state changed, we need to reset. |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8819 | */ |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8820 | if ((features & NETIF_F_NTUPLE) || (features & NETIF_F_HW_TC)) { |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8821 | /* turn off ATR, enable perfect filters and reset */ |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 8822 | if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) |
| 8823 | need_reset = true; |
| 8824 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8825 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 8826 | adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8827 | } else { |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 8828 | /* turn off perfect filters, enable ATR and reset */ |
| 8829 | if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 8830 | need_reset = true; |
| 8831 | |
| 8832 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 8833 | |
| 8834 | /* We cannot enable ATR if SR-IOV is enabled */ |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8835 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED || |
| 8836 | /* We cannot enable ATR if we have 2 or more tcs */ |
| 8837 | (netdev_get_num_tc(netdev) > 1) || |
| 8838 | /* We cannot enable ATR if RSS is disabled */ |
| 8839 | (adapter->ring_feature[RING_F_RSS].limit <= 1) || |
| 8840 | /* A sample rate of 0 indicates ATR disabled */ |
| 8841 | (!adapter->atr_sample_rate)) |
| 8842 | ; /* do nothing not supported */ |
| 8843 | else /* otherwise supported and set the flag */ |
| 8844 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8845 | } |
| 8846 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 8847 | if (changed & NETIF_F_RXALL) |
| 8848 | need_reset = true; |
| 8849 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8850 | netdev->features = features; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8851 | |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8852 | if ((adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) { |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 8853 | if (features & NETIF_F_RXCSUM) { |
| 8854 | adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED; |
| 8855 | } else { |
| 8856 | u32 port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK; |
| 8857 | |
| 8858 | ixgbe_clear_udp_tunnel_port(adapter, port_mask); |
| 8859 | } |
| 8860 | } |
| 8861 | |
| 8862 | if ((adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)) { |
| 8863 | if (features & NETIF_F_RXCSUM) { |
| 8864 | adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED; |
| 8865 | } else { |
| 8866 | u32 port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK; |
| 8867 | |
| 8868 | ixgbe_clear_udp_tunnel_port(adapter, port_mask); |
| 8869 | } |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8870 | } |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8871 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8872 | if (need_reset) |
| 8873 | ixgbe_do_reset(netdev); |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 8874 | else if (changed & (NETIF_F_HW_VLAN_CTAG_RX | |
| 8875 | NETIF_F_HW_VLAN_CTAG_FILTER)) |
| 8876 | ixgbe_set_rx_mode(netdev); |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8877 | |
| 8878 | return 0; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8879 | } |
| 8880 | |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8881 | /** |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 8882 | * ixgbe_add_udp_tunnel_port - Get notifications about adding UDP tunnel ports |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8883 | * @dev: The port's netdev |
Sabrina Dubroca | e5de25d | 2016-07-11 13:12:28 +0200 | [diff] [blame] | 8884 | * @ti: Tunnel endpoint information |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8885 | **/ |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 8886 | static void ixgbe_add_udp_tunnel_port(struct net_device *dev, |
| 8887 | struct udp_tunnel_info *ti) |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8888 | { |
| 8889 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 8890 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 8891 | __be16 port = ti->port; |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 8892 | u32 port_shift = 0; |
| 8893 | u32 reg; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8894 | |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 8895 | if (ti->sa_family != AF_INET) |
| 8896 | return; |
| 8897 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 8898 | switch (ti->type) { |
| 8899 | case UDP_TUNNEL_TYPE_VXLAN: |
| 8900 | if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) |
| 8901 | return; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8902 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 8903 | if (adapter->vxlan_port == port) |
| 8904 | return; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8905 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 8906 | if (adapter->vxlan_port) { |
| 8907 | netdev_info(dev, |
| 8908 | "VXLAN port %d set, not adding port %d\n", |
| 8909 | ntohs(adapter->vxlan_port), |
| 8910 | ntohs(port)); |
| 8911 | return; |
| 8912 | } |
| 8913 | |
| 8914 | adapter->vxlan_port = port; |
| 8915 | break; |
| 8916 | case UDP_TUNNEL_TYPE_GENEVE: |
| 8917 | if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)) |
| 8918 | return; |
| 8919 | |
| 8920 | if (adapter->geneve_port == port) |
| 8921 | return; |
| 8922 | |
| 8923 | if (adapter->geneve_port) { |
| 8924 | netdev_info(dev, |
| 8925 | "GENEVE port %d set, not adding port %d\n", |
| 8926 | ntohs(adapter->geneve_port), |
| 8927 | ntohs(port)); |
| 8928 | return; |
| 8929 | } |
| 8930 | |
| 8931 | port_shift = IXGBE_VXLANCTRL_GENEVE_UDPPORT_SHIFT; |
| 8932 | adapter->geneve_port = port; |
| 8933 | break; |
| 8934 | default: |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8935 | return; |
| 8936 | } |
| 8937 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 8938 | reg = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) | ntohs(port) << port_shift; |
| 8939 | IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, reg); |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8940 | } |
| 8941 | |
| 8942 | /** |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 8943 | * ixgbe_del_udp_tunnel_port - Get notifications about removing UDP tunnel ports |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8944 | * @dev: The port's netdev |
Sabrina Dubroca | e5de25d | 2016-07-11 13:12:28 +0200 | [diff] [blame] | 8945 | * @ti: Tunnel endpoint information |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8946 | **/ |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 8947 | static void ixgbe_del_udp_tunnel_port(struct net_device *dev, |
| 8948 | struct udp_tunnel_info *ti) |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8949 | { |
| 8950 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 8951 | u32 port_mask; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8952 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 8953 | if (ti->type != UDP_TUNNEL_TYPE_VXLAN && |
| 8954 | ti->type != UDP_TUNNEL_TYPE_GENEVE) |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 8955 | return; |
| 8956 | |
| 8957 | if (ti->sa_family != AF_INET) |
| 8958 | return; |
| 8959 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 8960 | switch (ti->type) { |
| 8961 | case UDP_TUNNEL_TYPE_VXLAN: |
| 8962 | if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) |
| 8963 | return; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8964 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 8965 | if (adapter->vxlan_port != ti->port) { |
| 8966 | netdev_info(dev, "VXLAN port %d not found\n", |
| 8967 | ntohs(ti->port)); |
| 8968 | return; |
| 8969 | } |
| 8970 | |
| 8971 | port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK; |
| 8972 | break; |
| 8973 | case UDP_TUNNEL_TYPE_GENEVE: |
| 8974 | if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)) |
| 8975 | return; |
| 8976 | |
| 8977 | if (adapter->geneve_port != ti->port) { |
| 8978 | netdev_info(dev, "GENEVE port %d not found\n", |
| 8979 | ntohs(ti->port)); |
| 8980 | return; |
| 8981 | } |
| 8982 | |
| 8983 | port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK; |
| 8984 | break; |
| 8985 | default: |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8986 | return; |
| 8987 | } |
| 8988 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 8989 | ixgbe_clear_udp_tunnel_port(adapter, port_mask); |
| 8990 | adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8991 | } |
| 8992 | |
stephen hemminger | edc7d57 | 2012-10-01 12:32:33 +0000 | [diff] [blame] | 8993 | static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 8994 | struct net_device *dev, |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 8995 | const unsigned char *addr, u16 vid, |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 8996 | u16 flags) |
| 8997 | { |
Alexander Duyck | bcfd343 | 2014-07-17 02:11:22 +0000 | [diff] [blame] | 8998 | /* guarantee we can provide a unique filter for the unicast address */ |
Ben Hutchings | 46acc46 | 2012-11-01 09:11:11 +0000 | [diff] [blame] | 8999 | if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) { |
Alexander Duyck | 2f9be16 | 2015-10-22 16:26:42 -0700 | [diff] [blame] | 9000 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 9001 | u16 pool = VMDQ_P(0); |
| 9002 | |
| 9003 | if (netdev_uc_count(dev) >= ixgbe_available_rars(adapter, pool)) |
Alexander Duyck | bcfd343 | 2014-07-17 02:11:22 +0000 | [diff] [blame] | 9004 | return -ENOMEM; |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 9005 | } |
| 9006 | |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 9007 | return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags); |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 9008 | } |
| 9009 | |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9010 | /** |
| 9011 | * ixgbe_configure_bridge_mode - set various bridge modes |
| 9012 | * @adapter - the private structure |
| 9013 | * @mode - requested bridge mode |
| 9014 | * |
| 9015 | * Configure some settings require for various bridge modes. |
| 9016 | **/ |
| 9017 | static int ixgbe_configure_bridge_mode(struct ixgbe_adapter *adapter, |
| 9018 | __u16 mode) |
| 9019 | { |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 9020 | struct ixgbe_hw *hw = &adapter->hw; |
| 9021 | unsigned int p, num_pools; |
| 9022 | u32 vmdctl; |
| 9023 | |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9024 | switch (mode) { |
| 9025 | case BRIDGE_MODE_VEPA: |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 9026 | /* disable Tx loopback, rely on switch hairpin mode */ |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9027 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, 0); |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 9028 | |
| 9029 | /* must enable Rx switching replication to allow multicast |
| 9030 | * packet reception on all VFs, and to enable source address |
| 9031 | * pruning. |
| 9032 | */ |
| 9033 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL); |
| 9034 | vmdctl |= IXGBE_VT_CTL_REPLEN; |
| 9035 | IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl); |
| 9036 | |
| 9037 | /* enable Rx source address pruning. Note, this requires |
| 9038 | * replication to be enabled or else it does nothing. |
| 9039 | */ |
| 9040 | num_pools = adapter->num_vfs + adapter->num_rx_pools; |
| 9041 | for (p = 0; p < num_pools; p++) { |
| 9042 | if (hw->mac.ops.set_source_address_pruning) |
| 9043 | hw->mac.ops.set_source_address_pruning(hw, |
| 9044 | true, |
| 9045 | p); |
| 9046 | } |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9047 | break; |
| 9048 | case BRIDGE_MODE_VEB: |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 9049 | /* enable Tx loopback for internal VF/PF communication */ |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9050 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, |
| 9051 | IXGBE_PFDTXGSWC_VT_LBEN); |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 9052 | |
| 9053 | /* disable Rx switching replication unless we have SR-IOV |
| 9054 | * virtual functions |
| 9055 | */ |
| 9056 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL); |
| 9057 | if (!adapter->num_vfs) |
| 9058 | vmdctl &= ~IXGBE_VT_CTL_REPLEN; |
| 9059 | IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl); |
| 9060 | |
| 9061 | /* disable Rx source address pruning, since we don't expect to |
| 9062 | * be receiving external loopback of our transmitted frames. |
| 9063 | */ |
| 9064 | num_pools = adapter->num_vfs + adapter->num_rx_pools; |
| 9065 | for (p = 0; p < num_pools; p++) { |
| 9066 | if (hw->mac.ops.set_source_address_pruning) |
| 9067 | hw->mac.ops.set_source_address_pruning(hw, |
| 9068 | false, |
| 9069 | p); |
| 9070 | } |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9071 | break; |
| 9072 | default: |
| 9073 | return -EINVAL; |
| 9074 | } |
| 9075 | |
| 9076 | adapter->bridge_mode = mode; |
| 9077 | |
| 9078 | e_info(drv, "enabling bridge mode: %s\n", |
| 9079 | mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
| 9080 | |
| 9081 | return 0; |
| 9082 | } |
| 9083 | |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9084 | static int ixgbe_ndo_bridge_setlink(struct net_device *dev, |
Roopa Prabhu | add511b | 2015-01-29 22:40:12 -0800 | [diff] [blame] | 9085 | struct nlmsghdr *nlh, u16 flags) |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9086 | { |
| 9087 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 9088 | struct nlattr *attr, *br_spec; |
| 9089 | int rem; |
| 9090 | |
| 9091 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 9092 | return -EOPNOTSUPP; |
| 9093 | |
| 9094 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
Thomas Graf | 4ea85e8 | 2014-11-26 13:42:18 +0100 | [diff] [blame] | 9095 | if (!br_spec) |
| 9096 | return -EINVAL; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9097 | |
| 9098 | nla_for_each_nested(attr, br_spec, rem) { |
Mark Rustad | a1e869d | 2015-04-10 10:36:36 -0700 | [diff] [blame] | 9099 | int status; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9100 | __u16 mode; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9101 | |
| 9102 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 9103 | continue; |
| 9104 | |
Thomas Graf | b7c1a31 | 2014-11-26 13:42:17 +0100 | [diff] [blame] | 9105 | if (nla_len(attr) < sizeof(mode)) |
| 9106 | return -EINVAL; |
| 9107 | |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9108 | mode = nla_get_u16(attr); |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9109 | status = ixgbe_configure_bridge_mode(adapter, mode); |
| 9110 | if (status) |
| 9111 | return status; |
Don Skidmore | aa2bacb | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9112 | |
| 9113 | break; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9114 | } |
| 9115 | |
| 9116 | return 0; |
| 9117 | } |
| 9118 | |
| 9119 | 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] | 9120 | struct net_device *dev, |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 9121 | u32 filter_mask, int nlflags) |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9122 | { |
| 9123 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9124 | |
| 9125 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 9126 | return 0; |
| 9127 | |
Don Skidmore | aa2bacb | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9128 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, |
Scott Feldman | 7d4f8d8 | 2015-06-22 00:27:17 -0700 | [diff] [blame] | 9129 | adapter->bridge_mode, 0, 0, nlflags, |
| 9130 | filter_mask, NULL); |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9131 | } |
| 9132 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9133 | static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev) |
| 9134 | { |
| 9135 | struct ixgbe_fwd_adapter *fwd_adapter = NULL; |
| 9136 | struct ixgbe_adapter *adapter = netdev_priv(pdev); |
Jacob Keller | aac2f1b | 2014-08-21 06:17:59 +0000 | [diff] [blame] | 9137 | int used_pools = adapter->num_vfs + adapter->num_rx_pools; |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 9138 | unsigned int limit; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9139 | int pool, err; |
| 9140 | |
Jacob Keller | aac2f1b | 2014-08-21 06:17:59 +0000 | [diff] [blame] | 9141 | /* Hardware has a limited number of available pools. Each VF, and the |
| 9142 | * PF require a pool. Check to ensure we don't attempt to use more |
| 9143 | * then the available number of pools. |
| 9144 | */ |
| 9145 | if (used_pools >= IXGBE_MAX_VF_FUNCTIONS) |
| 9146 | return ERR_PTR(-EINVAL); |
| 9147 | |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 9148 | #ifdef CONFIG_RPS |
| 9149 | if (vdev->num_rx_queues != vdev->num_tx_queues) { |
| 9150 | netdev_info(pdev, "%s: Only supports a single queue count for TX and RX\n", |
| 9151 | vdev->name); |
| 9152 | return ERR_PTR(-EINVAL); |
| 9153 | } |
| 9154 | #endif |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9155 | /* Check for hardware restriction on number of rx/tx queues */ |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 9156 | if (vdev->num_tx_queues > IXGBE_MAX_L2A_QUEUES || |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9157 | vdev->num_tx_queues == IXGBE_BAD_L2A_QUEUE) { |
| 9158 | netdev_info(pdev, |
| 9159 | "%s: Supports RX/TX Queue counts 1,2, and 4\n", |
| 9160 | pdev->name); |
| 9161 | return ERR_PTR(-EINVAL); |
| 9162 | } |
| 9163 | |
| 9164 | if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && |
| 9165 | adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS - 1) || |
| 9166 | (adapter->num_rx_pools > IXGBE_MAX_MACVLANS)) |
| 9167 | return ERR_PTR(-EBUSY); |
| 9168 | |
Maninder Singh | bc52f95 | 2015-06-19 09:37:55 +0530 | [diff] [blame] | 9169 | fwd_adapter = kzalloc(sizeof(*fwd_adapter), GFP_KERNEL); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9170 | if (!fwd_adapter) |
| 9171 | return ERR_PTR(-ENOMEM); |
| 9172 | |
| 9173 | pool = find_first_zero_bit(&adapter->fwd_bitmask, 32); |
| 9174 | adapter->num_rx_pools++; |
| 9175 | set_bit(pool, &adapter->fwd_bitmask); |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 9176 | limit = find_last_bit(&adapter->fwd_bitmask, 32); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9177 | |
| 9178 | /* Enable VMDq flag so device will be set in VM mode */ |
| 9179 | adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED | IXGBE_FLAG_SRIOV_ENABLED; |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 9180 | adapter->ring_feature[RING_F_VMDQ].limit = limit + 1; |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 9181 | adapter->ring_feature[RING_F_RSS].limit = vdev->num_tx_queues; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9182 | |
| 9183 | /* Force reinit of ring allocation with VMDQ enabled */ |
| 9184 | err = ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev)); |
| 9185 | if (err) |
| 9186 | goto fwd_add_err; |
| 9187 | fwd_adapter->pool = pool; |
| 9188 | fwd_adapter->real_adapter = adapter; |
Emil Tantilov | a3b8cb1 | 2016-09-22 15:06:52 -0700 | [diff] [blame] | 9189 | |
| 9190 | if (netif_running(pdev)) { |
| 9191 | err = ixgbe_fwd_ring_up(vdev, fwd_adapter); |
| 9192 | if (err) |
| 9193 | goto fwd_add_err; |
| 9194 | netif_tx_start_all_queues(vdev); |
| 9195 | } |
| 9196 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9197 | return fwd_adapter; |
| 9198 | fwd_add_err: |
| 9199 | /* unwind counter and free adapter struct */ |
| 9200 | netdev_info(pdev, |
| 9201 | "%s: dfwd hardware acceleration failed\n", vdev->name); |
| 9202 | clear_bit(pool, &adapter->fwd_bitmask); |
| 9203 | adapter->num_rx_pools--; |
| 9204 | kfree(fwd_adapter); |
| 9205 | return ERR_PTR(err); |
| 9206 | } |
| 9207 | |
| 9208 | static void ixgbe_fwd_del(struct net_device *pdev, void *priv) |
| 9209 | { |
| 9210 | struct ixgbe_fwd_adapter *fwd_adapter = priv; |
| 9211 | struct ixgbe_adapter *adapter = fwd_adapter->real_adapter; |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 9212 | unsigned int limit; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9213 | |
| 9214 | clear_bit(fwd_adapter->pool, &adapter->fwd_bitmask); |
| 9215 | adapter->num_rx_pools--; |
| 9216 | |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 9217 | limit = find_last_bit(&adapter->fwd_bitmask, 32); |
| 9218 | adapter->ring_feature[RING_F_VMDQ].limit = limit + 1; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9219 | ixgbe_fwd_ring_down(fwd_adapter->netdev, fwd_adapter); |
| 9220 | ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev)); |
| 9221 | netdev_dbg(pdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n", |
| 9222 | fwd_adapter->pool, adapter->num_rx_pools, |
| 9223 | fwd_adapter->rx_base_queue, |
| 9224 | fwd_adapter->rx_base_queue + adapter->num_rx_queues_per_pool, |
| 9225 | adapter->fwd_bitmask); |
| 9226 | kfree(fwd_adapter); |
| 9227 | } |
| 9228 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9229 | #define IXGBE_MAX_MAC_HDR_LEN 127 |
| 9230 | #define IXGBE_MAX_NETWORK_HDR_LEN 511 |
| 9231 | |
Mark Rustad | f467bc0 | 2015-06-15 11:33:20 -0700 | [diff] [blame] | 9232 | static netdev_features_t |
| 9233 | ixgbe_features_check(struct sk_buff *skb, struct net_device *dev, |
| 9234 | netdev_features_t features) |
| 9235 | { |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9236 | unsigned int network_hdr_len, mac_hdr_len; |
Mark Rustad | f467bc0 | 2015-06-15 11:33:20 -0700 | [diff] [blame] | 9237 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9238 | /* Make certain the headers can be described by a context descriptor */ |
| 9239 | mac_hdr_len = skb_network_header(skb) - skb->data; |
| 9240 | if (unlikely(mac_hdr_len > IXGBE_MAX_MAC_HDR_LEN)) |
| 9241 | return features & ~(NETIF_F_HW_CSUM | |
| 9242 | NETIF_F_SCTP_CRC | |
| 9243 | NETIF_F_HW_VLAN_CTAG_TX | |
| 9244 | NETIF_F_TSO | |
| 9245 | NETIF_F_TSO6); |
| 9246 | |
| 9247 | network_hdr_len = skb_checksum_start(skb) - skb_network_header(skb); |
| 9248 | if (unlikely(network_hdr_len > IXGBE_MAX_NETWORK_HDR_LEN)) |
| 9249 | return features & ~(NETIF_F_HW_CSUM | |
| 9250 | NETIF_F_SCTP_CRC | |
| 9251 | NETIF_F_TSO | |
| 9252 | NETIF_F_TSO6); |
| 9253 | |
| 9254 | /* We can only support IPV4 TSO in tunnels if we can mangle the |
| 9255 | * inner IP ID field, so strip TSO if MANGLEID is not supported. |
| 9256 | */ |
| 9257 | if (skb->encapsulation && !(features & NETIF_F_TSO_MANGLEID)) |
| 9258 | features &= ~NETIF_F_TSO; |
Mark Rustad | f467bc0 | 2015-06-15 11:33:20 -0700 | [diff] [blame] | 9259 | |
| 9260 | return features; |
| 9261 | } |
| 9262 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 9263 | static const struct net_device_ops ixgbe_netdev_ops = { |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 9264 | .ndo_open = ixgbe_open, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 9265 | .ndo_stop = ixgbe_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 9266 | .ndo_start_xmit = ixgbe_xmit_frame, |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 9267 | .ndo_select_queue = ixgbe_select_queue, |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 9268 | .ndo_set_rx_mode = ixgbe_set_rx_mode, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 9269 | .ndo_validate_addr = eth_validate_addr, |
| 9270 | .ndo_set_mac_address = ixgbe_set_mac, |
| 9271 | .ndo_change_mtu = ixgbe_change_mtu, |
| 9272 | .ndo_tx_timeout = ixgbe_tx_timeout, |
Rostislav Pehlivanov | c04f90e | 2016-01-27 18:33:30 +0000 | [diff] [blame] | 9273 | .ndo_set_tx_maxrate = ixgbe_tx_maxrate, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 9274 | .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid, |
| 9275 | .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid, |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 9276 | .ndo_do_ioctl = ixgbe_ioctl, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 9277 | .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac, |
| 9278 | .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan, |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 9279 | .ndo_set_vf_rate = ixgbe_ndo_set_vf_bw, |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 9280 | .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk, |
Vlad Zolotarov | e65ce0d | 2015-03-30 21:35:24 +0300 | [diff] [blame] | 9281 | .ndo_set_vf_rss_query_en = ixgbe_ndo_set_vf_rss_query_en, |
Hiroshi Shimamoto | 54011e4 | 2015-08-28 06:58:33 +0000 | [diff] [blame] | 9282 | .ndo_set_vf_trust = ixgbe_ndo_set_vf_trust, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 9283 | .ndo_get_vf_config = ixgbe_ndo_get_vf_config, |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 9284 | .ndo_get_stats64 = ixgbe_get_stats64, |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 9285 | .ndo_setup_tc = __ixgbe_setup_tc, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 9286 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 9287 | .ndo_poll_controller = ixgbe_netpoll, |
| 9288 | #endif |
Cong Wang | e0d1095 | 2013-08-01 11:10:25 +0800 | [diff] [blame] | 9289 | #ifdef CONFIG_NET_RX_BUSY_POLL |
Eliezer Tamir | 8b80cda | 2013-07-10 17:13:26 +0300 | [diff] [blame] | 9290 | .ndo_busy_poll = ixgbe_low_latency_recv, |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 9291 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 9292 | #ifdef IXGBE_FCOE |
| 9293 | .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get, |
Yi Zou | 68a683c | 2011-02-01 07:22:16 +0000 | [diff] [blame] | 9294 | .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 9295 | .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put, |
Yi Zou | 8450ff8 | 2009-08-31 12:32:14 +0000 | [diff] [blame] | 9296 | .ndo_fcoe_enable = ixgbe_fcoe_enable, |
| 9297 | .ndo_fcoe_disable = ixgbe_fcoe_disable, |
Yi Zou | 61a1fa1 | 2009-10-28 18:24:56 +0000 | [diff] [blame] | 9298 | .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn, |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 9299 | .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 9300 | #endif /* IXGBE_FCOE */ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9301 | .ndo_set_features = ixgbe_set_features, |
| 9302 | .ndo_fix_features = ixgbe_fix_features, |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 9303 | .ndo_fdb_add = ixgbe_ndo_fdb_add, |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9304 | .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink, |
| 9305 | .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink, |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9306 | .ndo_dfwd_add_station = ixgbe_fwd_add, |
| 9307 | .ndo_dfwd_del_station = ixgbe_fwd_del, |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9308 | .ndo_udp_tunnel_add = ixgbe_add_udp_tunnel_port, |
| 9309 | .ndo_udp_tunnel_del = ixgbe_del_udp_tunnel_port, |
Mark Rustad | f467bc0 | 2015-06-15 11:33:20 -0700 | [diff] [blame] | 9310 | .ndo_features_check = ixgbe_features_check, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 9311 | }; |
| 9312 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9313 | /** |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 9314 | * ixgbe_enumerate_functions - Get the number of ports this device has |
| 9315 | * @adapter: adapter structure |
| 9316 | * |
| 9317 | * This function enumerates the phsyical functions co-located on a single slot, |
| 9318 | * in order to determine how many ports a device has. This is most useful in |
| 9319 | * determining the required GT/s of PCIe bandwidth necessary for optimal |
| 9320 | * performance. |
| 9321 | **/ |
| 9322 | static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter) |
| 9323 | { |
Jacob Keller | caafb95 | 2014-07-19 07:17:17 +0000 | [diff] [blame] | 9324 | struct pci_dev *entry, *pdev = adapter->pdev; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 9325 | int physfns = 0; |
| 9326 | |
Jacob Keller | f1f9657 | 2013-08-31 02:45:38 +0000 | [diff] [blame] | 9327 | /* Some cards can not use the generic count PCIe functions method, |
| 9328 | * because they are behind a parent switch, so we hardcode these with |
| 9329 | * the correct number of functions. |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 9330 | */ |
Jacob Keller | 8818970 | 2014-07-19 07:17:16 +0000 | [diff] [blame] | 9331 | if (ixgbe_pcie_from_parent(&adapter->hw)) |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 9332 | physfns = 4; |
Jacob Keller | 8818970 | 2014-07-19 07:17:16 +0000 | [diff] [blame] | 9333 | |
| 9334 | list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) { |
| 9335 | /* don't count virtual functions */ |
Jacob Keller | caafb95 | 2014-07-19 07:17:17 +0000 | [diff] [blame] | 9336 | if (entry->is_virtfn) |
| 9337 | continue; |
| 9338 | |
| 9339 | /* When the devices on the bus don't all match our device ID, |
| 9340 | * we can't reliably determine the correct number of |
| 9341 | * functions. This can occur if a function has been direct |
| 9342 | * attached to a virtual machine using VT-d, for example. In |
| 9343 | * this case, simply return -1 to indicate this. |
| 9344 | */ |
| 9345 | if ((entry->vendor != pdev->vendor) || |
| 9346 | (entry->device != pdev->device)) |
| 9347 | return -1; |
| 9348 | |
| 9349 | physfns++; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 9350 | } |
| 9351 | |
| 9352 | return physfns; |
| 9353 | } |
| 9354 | |
| 9355 | /** |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9356 | * ixgbe_wol_supported - Check whether device supports WoL |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 9357 | * @adapter: the adapter private structure |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9358 | * @device_id: the device ID |
| 9359 | * @subdev_id: the subsystem device ID |
| 9360 | * |
| 9361 | * This function is used by probe and ethtool to determine |
| 9362 | * which devices have WoL support |
| 9363 | * |
| 9364 | **/ |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 9365 | bool ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id, |
| 9366 | u16 subdevice_id) |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9367 | { |
| 9368 | struct ixgbe_hw *hw = &adapter->hw; |
| 9369 | u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9370 | |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 9371 | /* WOL not supported on 82598 */ |
| 9372 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 9373 | return false; |
| 9374 | |
| 9375 | /* check eeprom to see if WOL is enabled for X540 and newer */ |
| 9376 | if (hw->mac.type >= ixgbe_mac_X540) { |
| 9377 | if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) || |
| 9378 | ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) && |
| 9379 | (hw->bus.func == 0))) |
| 9380 | return true; |
| 9381 | } |
| 9382 | |
| 9383 | /* WOL is determined based on device IDs for 82599 MACs */ |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9384 | switch (device_id) { |
| 9385 | case IXGBE_DEV_ID_82599_SFP: |
| 9386 | /* Only these subdevices could supports WOL */ |
| 9387 | switch (subdevice_id) { |
| 9388 | case IXGBE_SUBDEV_ID_82599_560FLR: |
Emil Tantilov | 00103a6c | 2016-04-21 11:37:06 -0700 | [diff] [blame] | 9389 | case IXGBE_SUBDEV_ID_82599_LOM_SNAP6: |
| 9390 | case IXGBE_SUBDEV_ID_82599_SFP_WOL0: |
| 9391 | case IXGBE_SUBDEV_ID_82599_SFP_2OCP: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9392 | /* only support first port */ |
| 9393 | if (hw->bus.func != 0) |
| 9394 | break; |
Emil Tantilov | 5700ff2 | 2013-04-18 08:18:55 +0000 | [diff] [blame] | 9395 | case IXGBE_SUBDEV_ID_82599_SP_560FLR: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9396 | case IXGBE_SUBDEV_ID_82599_SFP: |
Don Skidmore | b6dfd93 | 2012-07-11 07:17:42 +0000 | [diff] [blame] | 9397 | case IXGBE_SUBDEV_ID_82599_RNDC: |
Emil Tantilov | f8a06c2 | 2012-08-16 08:13:07 +0000 | [diff] [blame] | 9398 | case IXGBE_SUBDEV_ID_82599_ECNA_DP: |
Emil Tantilov | 00103a6c | 2016-04-21 11:37:06 -0700 | [diff] [blame] | 9399 | case IXGBE_SUBDEV_ID_82599_SFP_1OCP: |
| 9400 | case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM1: |
| 9401 | case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM2: |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 9402 | return true; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9403 | } |
| 9404 | break; |
Don Skidmore | 5daebbb | 2013-04-05 05:49:34 +0000 | [diff] [blame] | 9405 | case IXGBE_DEV_ID_82599EN_SFP: |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 9406 | /* Only these subdevices support WOL */ |
Don Skidmore | 5daebbb | 2013-04-05 05:49:34 +0000 | [diff] [blame] | 9407 | switch (subdevice_id) { |
| 9408 | case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1: |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 9409 | return true; |
Don Skidmore | 5daebbb | 2013-04-05 05:49:34 +0000 | [diff] [blame] | 9410 | } |
| 9411 | break; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9412 | case IXGBE_DEV_ID_82599_COMBO_BACKPLANE: |
| 9413 | /* All except this subdevice support WOL */ |
| 9414 | if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ) |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 9415 | return true; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9416 | break; |
| 9417 | case IXGBE_DEV_ID_82599_KX4: |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 9418 | return true; |
| 9419 | default: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9420 | break; |
| 9421 | } |
| 9422 | |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 9423 | return false; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9424 | } |
| 9425 | |
| 9426 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9427 | * ixgbe_probe - Device Initialization Routine |
| 9428 | * @pdev: PCI device information struct |
| 9429 | * @ent: entry in ixgbe_pci_tbl |
| 9430 | * |
| 9431 | * Returns 0 on success, negative on failure |
| 9432 | * |
| 9433 | * ixgbe_probe initializes an adapter identified by a pci_dev structure. |
| 9434 | * The OS initialization, configuring of the adapter private structure, |
| 9435 | * and a hardware reset occur. |
| 9436 | **/ |
Greg Kroah-Hartman | 1dd06ae | 2012-12-06 14:30:56 +0000 | [diff] [blame] | 9437 | 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] | 9438 | { |
| 9439 | struct net_device *netdev; |
| 9440 | struct ixgbe_adapter *adapter = NULL; |
| 9441 | struct ixgbe_hw *hw; |
| 9442 | const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data]; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 9443 | int i, err, pci_using_dac, expected_gts; |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 9444 | unsigned int indices = MAX_TX_QUEUES; |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 9445 | u8 part_str[IXGBE_PBANUM_LENGTH]; |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 9446 | bool disable_dev = false; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 9447 | #ifdef IXGBE_FCOE |
| 9448 | u16 device_caps; |
| 9449 | #endif |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 9450 | u32 eec; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9451 | |
Andy Gospodarek | bded64a | 2010-07-21 06:40:31 +0000 | [diff] [blame] | 9452 | /* Catch broken hardware that put the wrong VF device ID in |
| 9453 | * the PCIe SR-IOV capability. |
| 9454 | */ |
| 9455 | if (pdev->is_virtfn) { |
| 9456 | WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n", |
| 9457 | pci_name(pdev), pdev->vendor, pdev->device); |
| 9458 | return -EINVAL; |
| 9459 | } |
| 9460 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 9461 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9462 | if (err) |
| 9463 | return err; |
| 9464 | |
Russell King | f5f2eda | 2013-06-10 12:47:42 +0100 | [diff] [blame] | 9465 | if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9466 | pci_using_dac = 1; |
| 9467 | } else { |
Russell King | f5f2eda | 2013-06-10 12:47:42 +0100 | [diff] [blame] | 9468 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9469 | if (err) { |
Russell King | f5f2eda | 2013-06-10 12:47:42 +0100 | [diff] [blame] | 9470 | dev_err(&pdev->dev, |
| 9471 | "No usable DMA configuration, aborting\n"); |
| 9472 | goto err_dma; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9473 | } |
| 9474 | pci_using_dac = 0; |
| 9475 | } |
| 9476 | |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 9477 | err = pci_request_mem_regions(pdev, ixgbe_driver_name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9478 | if (err) { |
Dan Carpenter | b8bc042 | 2010-07-27 00:05:56 +0000 | [diff] [blame] | 9479 | dev_err(&pdev->dev, |
| 9480 | "pci_request_selected_regions failed 0x%x\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9481 | goto err_pci_reg; |
| 9482 | } |
| 9483 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 9484 | pci_enable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9485 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9486 | pci_set_master(pdev); |
Wendy Xiong | fb3b27b | 2008-04-23 11:09:24 -0700 | [diff] [blame] | 9487 | pci_save_state(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9488 | |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 9489 | if (ii->mac == ixgbe_mac_82598EB) { |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 9490 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 9491 | /* 8 TC w/ 4 queues per TC */ |
| 9492 | indices = 4 * MAX_TRAFFIC_CLASS; |
| 9493 | #else |
| 9494 | indices = IXGBE_MAX_RSS_INDICES; |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 9495 | #endif |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 9496 | } |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 9497 | |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 9498 | netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9499 | if (!netdev) { |
| 9500 | err = -ENOMEM; |
| 9501 | goto err_alloc_etherdev; |
| 9502 | } |
| 9503 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9504 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 9505 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9506 | adapter = netdev_priv(netdev); |
| 9507 | |
| 9508 | adapter->netdev = netdev; |
| 9509 | adapter->pdev = pdev; |
| 9510 | hw = &adapter->hw; |
| 9511 | hw->back = adapter; |
stephen hemminger | b3f4d59 | 2012-03-13 06:04:20 +0000 | [diff] [blame] | 9512 | adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9513 | |
Jeff Kirsher | 0585798 | 2008-09-11 19:57:00 -0700 | [diff] [blame] | 9514 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 9515 | pci_resource_len(pdev, 0)); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 9516 | adapter->io_addr = hw->hw_addr; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9517 | if (!hw->hw_addr) { |
| 9518 | err = -EIO; |
| 9519 | goto err_ioremap; |
| 9520 | } |
| 9521 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 9522 | netdev->netdev_ops = &ixgbe_netdev_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9523 | ixgbe_set_ethtool_ops(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9524 | netdev->watchdog_timeo = 5 * HZ; |
Mark Rustad | 339de30 | 2014-06-06 01:57:06 +0000 | [diff] [blame] | 9525 | strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9526 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9527 | /* Setup hw api */ |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 9528 | hw->mac.ops = *ii->mac_ops; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 9529 | hw->mac.type = ii->mac; |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 9530 | hw->mvals = ii->mvals; |
Emil Tantilov | b71f6c4 | 2016-10-10 14:54:03 -0700 | [diff] [blame] | 9531 | if (ii->link_ops) |
| 9532 | hw->link.ops = *ii->link_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9533 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9534 | /* EEPROM */ |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 9535 | hw->eeprom.ops = *ii->eeprom_ops; |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 9536 | eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw)); |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 9537 | if (ixgbe_removed(hw->hw_addr)) { |
| 9538 | err = -EIO; |
| 9539 | goto err_ioremap; |
| 9540 | } |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9541 | /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */ |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 9542 | if (!(eec & BIT(8))) |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9543 | hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic; |
| 9544 | |
| 9545 | /* PHY */ |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 9546 | hw->phy.ops = *ii->phy_ops; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 9547 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 9548 | /* ixgbe_identify_phy_generic will set prtad and mmds properly */ |
| 9549 | hw->phy.mdio.prtad = MDIO_PRTAD_NONE; |
| 9550 | hw->phy.mdio.mmds = 0; |
| 9551 | hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 9552 | hw->phy.mdio.dev = netdev; |
| 9553 | hw->phy.mdio.mdio_read = ixgbe_mdio_read; |
| 9554 | hw->phy.mdio.mdio_write = ixgbe_mdio_write; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 9555 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9556 | /* setup the private structure */ |
Emil Tantilov | 55570b6 | 2016-10-12 12:34:25 -0700 | [diff] [blame] | 9557 | err = ixgbe_sw_init(adapter, ii); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9558 | if (err) |
| 9559 | goto err_sw_init; |
| 9560 | |
Don Skidmore | dbd15b8 | 2016-03-09 16:45:00 -0500 | [diff] [blame] | 9561 | /* Make sure the SWFW semaphore is in a valid state */ |
| 9562 | if (hw->mac.ops.init_swfw_sync) |
| 9563 | hw->mac.ops.init_swfw_sync(hw); |
| 9564 | |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 9565 | /* Make it possible the adapter to be woken up via WOL */ |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 9566 | switch (adapter->hw.mac.type) { |
| 9567 | case ixgbe_mac_82599EB: |
| 9568 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 9569 | case ixgbe_mac_X550: |
| 9570 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 9571 | case ixgbe_mac_x550em_a: |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 9572 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 9573 | break; |
| 9574 | default: |
| 9575 | break; |
| 9576 | } |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 9577 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 9578 | /* |
| 9579 | * If there is a fan on this device and it has failed log the |
| 9580 | * failure. |
| 9581 | */ |
| 9582 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 9583 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 9584 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 9585 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 9586 | } |
| 9587 | |
Peter P Waskiewicz Jr | 8ef78ad | 2012-02-01 09:19:21 +0000 | [diff] [blame] | 9588 | if (allow_unsupported_sfp) |
| 9589 | hw->allow_unsupported_sfp = allow_unsupported_sfp; |
| 9590 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9591 | /* reset_hw fills in the perm_addr as well */ |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 9592 | hw->phy.reset_if_overtemp = true; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9593 | err = hw->mac.ops.reset_hw(hw); |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 9594 | hw->phy.reset_if_overtemp = false; |
Mark Rustad | 29a8dca | 2015-08-08 16:17:46 -0700 | [diff] [blame] | 9595 | if (err == IXGBE_ERR_SFP_NOT_PRESENT) { |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 9596 | err = 0; |
| 9597 | } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 1b1bf31 | 2013-07-31 05:27:04 +0000 | [diff] [blame] | 9598 | e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n"); |
| 9599 | e_dev_err("Reload the driver after installing a supported module.\n"); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 9600 | goto err_sw_init; |
| 9601 | } else if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 9602 | e_dev_err("HW Init failed: %d\n", err); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9603 | goto err_sw_init; |
| 9604 | } |
| 9605 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 9606 | #ifdef CONFIG_PCI_IOV |
Greg Rose | 60a1a68 | 2012-12-11 08:26:33 +0000 | [diff] [blame] | 9607 | /* SR-IOV not supported on the 82598 */ |
| 9608 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 9609 | goto skip_sriov; |
| 9610 | /* Mailbox */ |
| 9611 | ixgbe_init_mbx_params_pf(hw); |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 9612 | hw->mbx.ops = ii->mbx_ops; |
ethan.zhao | dcc23e3 | 2014-01-16 19:41:04 -0800 | [diff] [blame] | 9613 | pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT); |
ethan.zhao | 31ac910 | 2014-01-16 19:41:05 -0800 | [diff] [blame] | 9614 | ixgbe_enable_sriov(adapter); |
Greg Rose | 60a1a68 | 2012-12-11 08:26:33 +0000 | [diff] [blame] | 9615 | skip_sriov: |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 9616 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 9617 | #endif |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 9618 | netdev->features = NETIF_F_SG | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9619 | NETIF_F_TSO | |
| 9620 | NETIF_F_TSO6 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9621 | NETIF_F_RXHASH | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 9622 | NETIF_F_RXCSUM | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9623 | NETIF_F_HW_CSUM; |
| 9624 | |
| 9625 | #define IXGBE_GSO_PARTIAL_FEATURES (NETIF_F_GSO_GRE | \ |
| 9626 | NETIF_F_GSO_GRE_CSUM | \ |
Tom Herbert | 7e13318 | 2016-05-18 09:06:10 -0700 | [diff] [blame] | 9627 | NETIF_F_GSO_IPXIP4 | \ |
Alexander Duyck | bf2d1df | 2016-05-18 10:44:53 -0700 | [diff] [blame] | 9628 | NETIF_F_GSO_IPXIP6 | \ |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9629 | NETIF_F_GSO_UDP_TUNNEL | \ |
| 9630 | NETIF_F_GSO_UDP_TUNNEL_CSUM) |
| 9631 | |
| 9632 | netdev->gso_partial_features = IXGBE_GSO_PARTIAL_FEATURES; |
| 9633 | netdev->features |= NETIF_F_GSO_PARTIAL | |
| 9634 | IXGBE_GSO_PARTIAL_FEATURES; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9635 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 9636 | if (hw->mac.type >= ixgbe_mac_82599EB) |
Tom Herbert | 53692b1 | 2015-12-14 11:19:41 -0800 | [diff] [blame] | 9637 | netdev->features |= NETIF_F_SCTP_CRC; |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 9638 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 9639 | /* copy netdev features into list of user selectable features */ |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9640 | netdev->hw_features |= netdev->features | |
Alexander Duyck | 3d95182 | 2016-08-12 09:53:39 -0700 | [diff] [blame] | 9641 | NETIF_F_HW_VLAN_CTAG_FILTER | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9642 | NETIF_F_HW_VLAN_CTAG_RX | |
| 9643 | NETIF_F_HW_VLAN_CTAG_TX | |
| 9644 | NETIF_F_RXALL | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 9645 | NETIF_F_HW_L2FW_DOFFLOAD; |
| 9646 | |
| 9647 | if (hw->mac.type >= ixgbe_mac_82599EB) |
| 9648 | netdev->hw_features |= NETIF_F_NTUPLE | |
| 9649 | NETIF_F_HW_TC; |
| 9650 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9651 | if (pci_using_dac) |
| 9652 | netdev->features |= NETIF_F_HIGHDMA; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 9653 | |
Alexander Duyck | 5eee87c | 2016-05-11 13:23:34 -0700 | [diff] [blame] | 9654 | netdev->vlan_features |= netdev->features | NETIF_F_TSO_MANGLEID; |
| 9655 | netdev->hw_enc_features |= netdev->vlan_features; |
| 9656 | netdev->mpls_features |= NETIF_F_HW_CSUM; |
| 9657 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9658 | /* set this bit last since it cannot be part of vlan_features */ |
| 9659 | netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER | |
| 9660 | NETIF_F_HW_VLAN_CTAG_RX | |
| 9661 | NETIF_F_HW_VLAN_CTAG_TX; |
| 9662 | |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 9663 | netdev->priv_flags |= IFF_UNICAST_FLT; |
Ben Greear | f43f313 | 2012-03-06 09:42:04 +0000 | [diff] [blame] | 9664 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 9665 | |
Jarod Wilson | 91c527a | 2016-10-17 15:54:05 -0400 | [diff] [blame] | 9666 | /* MTU range: 68 - 9710 */ |
| 9667 | netdev->min_mtu = ETH_MIN_MTU; |
| 9668 | netdev->max_mtu = IXGBE_MAX_JUMBO_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN); |
| 9669 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 9670 | #ifdef CONFIG_IXGBE_DCB |
Usha Ketineni | 8829009 | 2016-04-26 05:00:26 -0700 | [diff] [blame] | 9671 | if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE) |
| 9672 | netdev->dcbnl_ops = &dcbnl_ops; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 9673 | #endif |
| 9674 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 9675 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 9676 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 9677 | unsigned int fcoe_l; |
| 9678 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 9679 | if (hw->mac.ops.get_device_caps) { |
| 9680 | hw->mac.ops.get_device_caps(hw, &device_caps); |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 9681 | if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS) |
| 9682 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 9683 | } |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 9684 | |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 9685 | |
| 9686 | fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus()); |
| 9687 | adapter->ring_feature[RING_F_FCOE].limit = fcoe_l; |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 9688 | |
Alexander Duyck | a58915c | 2012-05-25 06:38:18 +0000 | [diff] [blame] | 9689 | netdev->features |= NETIF_F_FSO | |
| 9690 | NETIF_F_FCOE_CRC; |
| 9691 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 9692 | netdev->vlan_features |= NETIF_F_FSO | |
| 9693 | NETIF_F_FCOE_CRC | |
| 9694 | NETIF_F_FCOE_MTU; |
Yi Zou | 5e09d7f | 2010-07-19 13:59:52 +0000 | [diff] [blame] | 9695 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 9696 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9697 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9698 | if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) |
| 9699 | netdev->hw_features |= NETIF_F_LRO; |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 9700 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 9701 | netdev->features |= NETIF_F_LRO; |
| 9702 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9703 | /* make sure the EEPROM is good */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9704 | if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 9705 | e_dev_err("The EEPROM Checksum Is Not Valid\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9706 | err = -EIO; |
Alexander Duyck | 35937c0 | 2012-02-08 07:51:37 +0000 | [diff] [blame] | 9707 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9708 | } |
| 9709 | |
Sowmini Varadhan | c7374b5 | 2016-01-12 19:32:30 -0800 | [diff] [blame] | 9710 | eth_platform_get_mac_address(&adapter->pdev->dev, |
| 9711 | adapter->hw.mac.perm_addr); |
Martin K Petersen | c762dff | 2014-11-15 14:24:51 +0000 | [diff] [blame] | 9712 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9713 | memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9714 | |
Jiri Pirko | aaeb6cd | 2013-01-08 01:38:26 +0000 | [diff] [blame] | 9715 | if (!is_valid_ether_addr(netdev->dev_addr)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 9716 | e_dev_err("invalid MAC address\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9717 | err = -EIO; |
Alexander Duyck | 35937c0 | 2012-02-08 07:51:37 +0000 | [diff] [blame] | 9718 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9719 | } |
| 9720 | |
Tushar Dave | 5676804 | 2016-01-07 14:17:03 -0800 | [diff] [blame] | 9721 | /* Set hw->mac.addr to permanent MAC address */ |
| 9722 | ether_addr_copy(hw->mac.addr, hw->mac.perm_addr); |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 9723 | ixgbe_mac_set_default_filter(adapter); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 9724 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 9725 | setup_timer(&adapter->service_timer, &ixgbe_service_timer, |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 9726 | (unsigned long) adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9727 | |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 9728 | if (ixgbe_removed(hw->hw_addr)) { |
| 9729 | err = -EIO; |
| 9730 | goto err_sw_init; |
| 9731 | } |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 9732 | INIT_WORK(&adapter->service_task, ixgbe_service_task); |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 9733 | set_bit(__IXGBE_SERVICE_INITED, &adapter->state); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 9734 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9735 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 9736 | err = ixgbe_init_interrupt_scheme(adapter); |
| 9737 | if (err) |
| 9738 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9739 | |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9740 | /* WOL not supported for all devices */ |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 9741 | adapter->wol = 0; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9742 | hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap); |
Jacob Keller | 6b92b0b | 2013-04-13 05:40:37 +0000 | [diff] [blame] | 9743 | hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device, |
Don Skidmore | b8f8363 | 2013-02-28 08:08:44 +0000 | [diff] [blame] | 9744 | pdev->subsystem_device); |
Jacob Keller | 6b92b0b | 2013-04-13 05:40:37 +0000 | [diff] [blame] | 9745 | if (hw->wol_enabled) |
Andy Gospodarek | 9417c46 | 2011-07-16 07:31:33 +0000 | [diff] [blame] | 9746 | adapter->wol = IXGBE_WUFC_MAG; |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 9747 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 9748 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 9749 | |
Emil Tantilov | 15e5209 | 2011-09-29 05:01:29 +0000 | [diff] [blame] | 9750 | /* save off EEPROM version number */ |
| 9751 | hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh); |
| 9752 | hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl); |
| 9753 | |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 9754 | /* pick up the PCI bus settings for reporting later */ |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 9755 | if (ixgbe_pcie_from_parent(hw)) |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 9756 | ixgbe_get_parent_bus_info(adapter); |
Don Skidmore | f9328bc | 2015-06-18 13:24:06 -0400 | [diff] [blame] | 9757 | else |
| 9758 | hw->mac.ops.get_bus_info(hw); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 9759 | |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 9760 | /* calculate the expected PCIe bandwidth required for optimal |
| 9761 | * performance. Note that some older parts will never have enough |
| 9762 | * bandwidth due to being older generation PCIe parts. We clamp these |
| 9763 | * parts to ensure no warning is displayed if it can't be fixed. |
| 9764 | */ |
| 9765 | switch (hw->mac.type) { |
| 9766 | case ixgbe_mac_82598EB: |
| 9767 | expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16); |
| 9768 | break; |
| 9769 | default: |
| 9770 | expected_gts = ixgbe_enumerate_functions(adapter) * 10; |
| 9771 | break; |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 9772 | } |
Jacob Keller | caafb95 | 2014-07-19 07:17:17 +0000 | [diff] [blame] | 9773 | |
| 9774 | /* don't check link if we failed to enumerate functions */ |
| 9775 | if (expected_gts > 0) |
| 9776 | ixgbe_check_minimum_link(adapter, expected_gts); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 9777 | |
Mark Rustad | 339de30 | 2014-06-06 01:57:06 +0000 | [diff] [blame] | 9778 | err = ixgbe_read_pba_string_generic(hw, part_str, sizeof(part_str)); |
Jacob Keller | 6a2aae5 | 2013-10-18 05:09:24 +0000 | [diff] [blame] | 9779 | if (err) |
Mark Rustad | 339de30 | 2014-06-06 01:57:06 +0000 | [diff] [blame] | 9780 | strlcpy(part_str, "Unknown", sizeof(part_str)); |
Jacob Keller | 6a2aae5 | 2013-10-18 05:09:24 +0000 | [diff] [blame] | 9781 | if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present) |
| 9782 | e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n", |
| 9783 | hw->mac.type, hw->phy.type, hw->phy.sfp_type, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 9784 | part_str); |
Jacob Keller | 6a2aae5 | 2013-10-18 05:09:24 +0000 | [diff] [blame] | 9785 | else |
| 9786 | e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n", |
| 9787 | hw->mac.type, hw->phy.type, part_str); |
| 9788 | |
| 9789 | e_dev_info("%pM\n", netdev->dev_addr); |
| 9790 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9791 | /* reset the hardware with the new settings */ |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 9792 | err = hw->mac.ops.start_hw(hw); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 9793 | if (err == IXGBE_ERR_EEPROM_VERSION) { |
| 9794 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 9795 | e_dev_warn("This device is a pre-production adapter/LOM. " |
| 9796 | "Please be aware there may be issues associated " |
| 9797 | "with your hardware. If you are experiencing " |
| 9798 | "problems please contact your Intel or hardware " |
| 9799 | "representative who provided you with this " |
| 9800 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 9801 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9802 | strcpy(netdev->name, "eth%d"); |
| 9803 | err = register_netdev(netdev); |
| 9804 | if (err) |
| 9805 | goto err_register; |
| 9806 | |
Emil Tantilov | 0fb6a55 | 2014-12-04 03:03:38 +0000 | [diff] [blame] | 9807 | pci_set_drvdata(pdev, adapter); |
| 9808 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 9809 | /* power down the optics for 82599 SFP+ fiber */ |
| 9810 | if (hw->mac.ops.disable_tx_laser) |
Emil Tantilov | 93d3ce8 | 2011-10-19 07:59:55 +0000 | [diff] [blame] | 9811 | hw->mac.ops.disable_tx_laser(hw); |
| 9812 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 9813 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 9814 | netif_carrier_off(netdev); |
| 9815 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 9816 | #ifdef CONFIG_IXGBE_DCA |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 9817 | if (dca_add_requester(&pdev->dev) == 0) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9818 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9819 | ixgbe_setup_dca(adapter); |
| 9820 | } |
| 9821 | #endif |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 9822 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 9823 | 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] | 9824 | for (i = 0; i < adapter->num_vfs; i++) |
| 9825 | ixgbe_vf_configuration(pdev, (i | 0x10000000)); |
| 9826 | } |
| 9827 | |
Jacob Keller | 2466dd9 | 2011-09-08 03:50:54 +0000 | [diff] [blame] | 9828 | /* firmware requires driver version to be 0xFFFFFFFF |
| 9829 | * since os does not support feature |
| 9830 | */ |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 9831 | if (hw->mac.ops.set_fw_drv_ver) |
Jacob Keller | 2466dd9 | 2011-09-08 03:50:54 +0000 | [diff] [blame] | 9832 | hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, |
| 9833 | 0xFF); |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 9834 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 9835 | /* add san mac addr to netdev */ |
| 9836 | ixgbe_add_sanmac_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9837 | |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 9838 | e_dev_info("%s\n", ixgbe_default_device_descr); |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 9839 | |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 9840 | #ifdef CONFIG_IXGBE_HWMON |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 9841 | if (ixgbe_sysfs_init(adapter)) |
| 9842 | e_err(probe, "failed to allocate sysfs resources\n"); |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 9843 | #endif /* CONFIG_IXGBE_HWMON */ |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 9844 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 9845 | ixgbe_dbg_adapter_init(adapter); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 9846 | |
Emil Tantilov | d1a35ee | 2014-05-13 08:24:00 +0000 | [diff] [blame] | 9847 | /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */ |
| 9848 | 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] | 9849 | hw->mac.ops.setup_link(hw, |
| 9850 | IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL, |
| 9851 | true); |
| 9852 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9853 | return 0; |
| 9854 | |
| 9855 | err_register: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 9856 | ixgbe_release_hw_control(adapter); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 9857 | ixgbe_clear_interrupt_scheme(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9858 | err_sw_init: |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 9859 | ixgbe_disable_sriov(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 9860 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 9861 | iounmap(adapter->io_addr); |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9862 | kfree(adapter->jump_tables[0]); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 9863 | kfree(adapter->mac_table); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9864 | err_ioremap: |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 9865 | disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9866 | free_netdev(netdev); |
| 9867 | err_alloc_etherdev: |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 9868 | pci_release_mem_regions(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9869 | err_pci_reg: |
| 9870 | err_dma: |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 9871 | if (!adapter || disable_dev) |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 9872 | pci_disable_device(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9873 | return err; |
| 9874 | } |
| 9875 | |
| 9876 | /** |
| 9877 | * ixgbe_remove - Device Removal Routine |
| 9878 | * @pdev: PCI device information struct |
| 9879 | * |
| 9880 | * ixgbe_remove is called by the PCI subsystem to alert the driver |
| 9881 | * that it should release a PCI device. The could be caused by a |
| 9882 | * Hot-Plug event, or because the driver is going to be removed from |
| 9883 | * memory. |
| 9884 | **/ |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 9885 | static void ixgbe_remove(struct pci_dev *pdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9886 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 9887 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
Emil Tantilov | 0fb6a55 | 2014-12-04 03:03:38 +0000 | [diff] [blame] | 9888 | struct net_device *netdev; |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 9889 | bool disable_dev; |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9890 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9891 | |
Emil Tantilov | 0fb6a55 | 2014-12-04 03:03:38 +0000 | [diff] [blame] | 9892 | /* if !adapter then we already cleaned up in probe */ |
| 9893 | if (!adapter) |
| 9894 | return; |
| 9895 | |
| 9896 | netdev = adapter->netdev; |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 9897 | ixgbe_dbg_adapter_exit(adapter); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 9898 | |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 9899 | set_bit(__IXGBE_REMOVING, &adapter->state); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 9900 | cancel_work_sync(&adapter->service_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9901 | |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 9902 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 9903 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9904 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 9905 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 9906 | dca_remove_requester(&pdev->dev); |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 9907 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 9908 | IXGBE_DCA_CTRL_DCA_DISABLE); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9909 | } |
| 9910 | |
| 9911 | #endif |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 9912 | #ifdef CONFIG_IXGBE_HWMON |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 9913 | ixgbe_sysfs_exit(adapter); |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 9914 | #endif /* CONFIG_IXGBE_HWMON */ |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 9915 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 9916 | /* remove the added san mac */ |
| 9917 | ixgbe_del_sanmac_netdev(netdev); |
| 9918 | |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 9919 | #ifdef CONFIG_PCI_IOV |
Alex Williamson | 7837e28 | 2015-07-10 15:31:34 -0600 | [diff] [blame] | 9920 | ixgbe_disable_sriov(adapter); |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 9921 | #endif |
Alex Williamson | 6b010e9 | 2015-07-29 14:38:21 -0600 | [diff] [blame] | 9922 | if (netdev->reg_state == NETREG_REGISTERED) |
| 9923 | unregister_netdev(netdev); |
| 9924 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 9925 | ixgbe_clear_interrupt_scheme(adapter); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 9926 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 9927 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9928 | |
Alexander Duyck | 2b1588c | 2012-03-17 02:39:16 +0000 | [diff] [blame] | 9929 | #ifdef CONFIG_DCB |
| 9930 | kfree(adapter->ixgbe_ieee_pfc); |
| 9931 | kfree(adapter->ixgbe_ieee_ets); |
| 9932 | |
| 9933 | #endif |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 9934 | iounmap(adapter->io_addr); |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 9935 | pci_release_mem_regions(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9936 | |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 9937 | e_dev_info("complete\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 9938 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9939 | for (i = 0; i < IXGBE_MAX_LINK_HANDLE; i++) { |
| 9940 | if (adapter->jump_tables[i]) { |
| 9941 | kfree(adapter->jump_tables[i]->input); |
| 9942 | kfree(adapter->jump_tables[i]->mask); |
| 9943 | } |
| 9944 | kfree(adapter->jump_tables[i]); |
| 9945 | } |
| 9946 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 9947 | kfree(adapter->mac_table); |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 9948 | disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9949 | free_netdev(netdev); |
| 9950 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 9951 | pci_disable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9952 | |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 9953 | if (disable_dev) |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 9954 | pci_disable_device(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9955 | } |
| 9956 | |
| 9957 | /** |
| 9958 | * ixgbe_io_error_detected - called when PCI error is detected |
| 9959 | * @pdev: Pointer to PCI device |
| 9960 | * @state: The current pci connection state |
| 9961 | * |
| 9962 | * This function is called after a PCI bus error affecting |
| 9963 | * this device has been detected. |
| 9964 | */ |
| 9965 | 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] | 9966 | pci_channel_state_t state) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9967 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 9968 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 9969 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9970 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 9971 | #ifdef CONFIG_PCI_IOV |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 9972 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 9973 | struct pci_dev *bdev, *vfdev; |
| 9974 | u32 dw0, dw1, dw2, dw3; |
| 9975 | int vf, pos; |
| 9976 | u16 req_id, pf_func; |
| 9977 | |
| 9978 | if (adapter->hw.mac.type == ixgbe_mac_82598EB || |
| 9979 | adapter->num_vfs == 0) |
| 9980 | goto skip_bad_vf_detection; |
| 9981 | |
| 9982 | bdev = pdev->bus->self; |
Yijing Wang | 62f87c0 | 2012-07-24 17:20:03 +0800 | [diff] [blame] | 9983 | while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT)) |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 9984 | bdev = bdev->bus->self; |
| 9985 | |
| 9986 | if (!bdev) |
| 9987 | goto skip_bad_vf_detection; |
| 9988 | |
| 9989 | pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR); |
| 9990 | if (!pos) |
| 9991 | goto skip_bad_vf_detection; |
| 9992 | |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 9993 | dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG); |
| 9994 | dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4); |
| 9995 | dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8); |
| 9996 | dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12); |
| 9997 | if (ixgbe_removed(hw->hw_addr)) |
| 9998 | goto skip_bad_vf_detection; |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 9999 | |
| 10000 | req_id = dw1 >> 16; |
| 10001 | /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */ |
| 10002 | if (!(req_id & 0x0080)) |
| 10003 | goto skip_bad_vf_detection; |
| 10004 | |
| 10005 | pf_func = req_id & 0x01; |
| 10006 | if ((pf_func & 1) == (pdev->devfn & 1)) { |
| 10007 | unsigned int device_id; |
| 10008 | |
| 10009 | vf = (req_id & 0x7F) >> 1; |
| 10010 | e_dev_err("VF %d has caused a PCIe error\n", vf); |
| 10011 | e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: " |
| 10012 | "%8.8x\tdw3: %8.8x\n", |
| 10013 | dw0, dw1, dw2, dw3); |
| 10014 | switch (adapter->hw.mac.type) { |
| 10015 | case ixgbe_mac_82599EB: |
| 10016 | device_id = IXGBE_82599_VF_DEVICE_ID; |
| 10017 | break; |
| 10018 | case ixgbe_mac_X540: |
| 10019 | device_id = IXGBE_X540_VF_DEVICE_ID; |
| 10020 | break; |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 10021 | case ixgbe_mac_X550: |
| 10022 | device_id = IXGBE_DEV_ID_X550_VF; |
| 10023 | break; |
| 10024 | case ixgbe_mac_X550EM_x: |
| 10025 | device_id = IXGBE_DEV_ID_X550EM_X_VF; |
| 10026 | break; |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 10027 | case ixgbe_mac_x550em_a: |
| 10028 | device_id = IXGBE_DEV_ID_X550EM_A_VF; |
| 10029 | break; |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10030 | default: |
| 10031 | device_id = 0; |
| 10032 | break; |
| 10033 | } |
| 10034 | |
| 10035 | /* Find the pci device of the offending VF */ |
Jon Mason | 36e9031 | 2012-07-19 21:02:09 +0000 | [diff] [blame] | 10036 | vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL); |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10037 | while (vfdev) { |
| 10038 | if (vfdev->devfn == (req_id & 0xFF)) |
| 10039 | break; |
Jon Mason | 36e9031 | 2012-07-19 21:02:09 +0000 | [diff] [blame] | 10040 | vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10041 | device_id, vfdev); |
| 10042 | } |
| 10043 | /* |
| 10044 | * There's a slim chance the VF could have been hot plugged, |
| 10045 | * so if it is no longer present we don't need to issue the |
| 10046 | * VFLR. Just clean up the AER in that case. |
| 10047 | */ |
| 10048 | if (vfdev) { |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 10049 | ixgbe_issue_vf_flr(adapter, vfdev); |
Greg Rose | b4fafbe | 2012-12-13 01:14:06 +0000 | [diff] [blame] | 10050 | /* Free device reference count */ |
| 10051 | pci_dev_put(vfdev); |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10052 | } |
| 10053 | |
| 10054 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 10055 | } |
| 10056 | |
| 10057 | /* |
| 10058 | * Even though the error may have occurred on the other port |
| 10059 | * we still need to increment the vf error reference count for |
| 10060 | * both ports because the I/O resume function will be called |
| 10061 | * for both of them. |
| 10062 | */ |
| 10063 | adapter->vferr_refcount++; |
| 10064 | |
| 10065 | return PCI_ERS_RESULT_RECOVERED; |
| 10066 | |
| 10067 | skip_bad_vf_detection: |
| 10068 | #endif /* CONFIG_PCI_IOV */ |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 10069 | if (!test_bit(__IXGBE_SERVICE_INITED, &adapter->state)) |
| 10070 | return PCI_ERS_RESULT_DISCONNECT; |
| 10071 | |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10072 | rtnl_lock(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10073 | netif_device_detach(netdev); |
| 10074 | |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10075 | if (state == pci_channel_io_perm_failure) { |
| 10076 | rtnl_unlock(); |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 10077 | return PCI_ERS_RESULT_DISCONNECT; |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10078 | } |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 10079 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10080 | if (netif_running(netdev)) |
| 10081 | ixgbe_down(adapter); |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10082 | |
| 10083 | if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state)) |
| 10084 | pci_disable_device(pdev); |
| 10085 | rtnl_unlock(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10086 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 10087 | /* Request a slot reset. */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10088 | return PCI_ERS_RESULT_NEED_RESET; |
| 10089 | } |
| 10090 | |
| 10091 | /** |
| 10092 | * ixgbe_io_slot_reset - called after the pci bus has been reset. |
| 10093 | * @pdev: Pointer to PCI device |
| 10094 | * |
| 10095 | * Restart the card from scratch, as if from a cold-boot. |
| 10096 | */ |
| 10097 | static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev) |
| 10098 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 10099 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10100 | pci_ers_result_t result; |
| 10101 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10102 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 10103 | if (pci_enable_device_mem(pdev)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 10104 | 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] | 10105 | result = PCI_ERS_RESULT_DISCONNECT; |
| 10106 | } else { |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 10107 | smp_mb__before_atomic(); |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10108 | clear_bit(__IXGBE_DISABLED, &adapter->state); |
Mark Rustad | 0391bbe | 2014-02-28 15:48:55 -0800 | [diff] [blame] | 10109 | adapter->hw.hw_addr = adapter->io_addr; |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10110 | pci_set_master(pdev); |
| 10111 | pci_restore_state(pdev); |
Breno Leitao | c0e1f68 | 2009-11-10 08:37:47 +0000 | [diff] [blame] | 10112 | pci_save_state(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10113 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 10114 | pci_wake_from_d3(pdev, false); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10115 | |
| 10116 | ixgbe_reset(adapter); |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 10117 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10118 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10119 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10120 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10121 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 10122 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 10123 | e_dev_err("pci_cleanup_aer_uncorrect_error_status " |
| 10124 | "failed 0x%0x\n", err); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10125 | /* non-fatal, continue */ |
| 10126 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10127 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10128 | return result; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10129 | } |
| 10130 | |
| 10131 | /** |
| 10132 | * ixgbe_io_resume - called when traffic can start flowing again. |
| 10133 | * @pdev: Pointer to PCI device |
| 10134 | * |
| 10135 | * This callback is called when the error recovery driver tells us that |
| 10136 | * its OK to resume normal operation. |
| 10137 | */ |
| 10138 | static void ixgbe_io_resume(struct pci_dev *pdev) |
| 10139 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 10140 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 10141 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10142 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10143 | #ifdef CONFIG_PCI_IOV |
| 10144 | if (adapter->vferr_refcount) { |
| 10145 | e_info(drv, "Resuming after VF err\n"); |
| 10146 | adapter->vferr_refcount--; |
| 10147 | return; |
| 10148 | } |
| 10149 | |
| 10150 | #endif |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 10151 | if (netif_running(netdev)) |
| 10152 | ixgbe_up(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10153 | |
| 10154 | netif_device_attach(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10155 | } |
| 10156 | |
Stephen Hemminger | 3646f0e | 2012-09-07 09:33:15 -0700 | [diff] [blame] | 10157 | static const struct pci_error_handlers ixgbe_err_handler = { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10158 | .error_detected = ixgbe_io_error_detected, |
| 10159 | .slot_reset = ixgbe_io_slot_reset, |
| 10160 | .resume = ixgbe_io_resume, |
| 10161 | }; |
| 10162 | |
| 10163 | static struct pci_driver ixgbe_driver = { |
| 10164 | .name = ixgbe_driver_name, |
| 10165 | .id_table = ixgbe_pci_tbl, |
| 10166 | .probe = ixgbe_probe, |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 10167 | .remove = ixgbe_remove, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10168 | #ifdef CONFIG_PM |
| 10169 | .suspend = ixgbe_suspend, |
| 10170 | .resume = ixgbe_resume, |
| 10171 | #endif |
| 10172 | .shutdown = ixgbe_shutdown, |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 10173 | .sriov_configure = ixgbe_pci_sriov_configure, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10174 | .err_handler = &ixgbe_err_handler |
| 10175 | }; |
| 10176 | |
| 10177 | /** |
| 10178 | * ixgbe_init_module - Driver Registration Routine |
| 10179 | * |
| 10180 | * ixgbe_init_module is the first routine called when the driver is |
| 10181 | * loaded. All it does is register with the PCI subsystem. |
| 10182 | **/ |
| 10183 | static int __init ixgbe_init_module(void) |
| 10184 | { |
| 10185 | int ret; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 10186 | pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version); |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 10187 | pr_info("%s\n", ixgbe_copyright); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10188 | |
Mark Rustad | 780484d | 2015-10-21 17:21:10 -0700 | [diff] [blame] | 10189 | ixgbe_wq = create_singlethread_workqueue(ixgbe_driver_name); |
| 10190 | if (!ixgbe_wq) { |
| 10191 | pr_err("%s: Failed to create workqueue\n", ixgbe_driver_name); |
| 10192 | return -ENOMEM; |
| 10193 | } |
| 10194 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 10195 | ixgbe_dbg_init(); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 10196 | |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 10197 | ret = pci_register_driver(&ixgbe_driver); |
| 10198 | if (ret) { |
Wei Yongjun | 6b83687 | 2016-07-12 15:17:02 +0000 | [diff] [blame] | 10199 | destroy_workqueue(ixgbe_wq); |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 10200 | ixgbe_dbg_exit(); |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 10201 | return ret; |
| 10202 | } |
| 10203 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 10204 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10205 | dca_register_notify(&dca_notifier); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10206 | #endif |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 10207 | |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 10208 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10209 | } |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 10210 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10211 | module_init(ixgbe_init_module); |
| 10212 | |
| 10213 | /** |
| 10214 | * ixgbe_exit_module - Driver Exit Cleanup Routine |
| 10215 | * |
| 10216 | * ixgbe_exit_module is called just before the driver is removed |
| 10217 | * from memory. |
| 10218 | **/ |
| 10219 | static void __exit ixgbe_exit_module(void) |
| 10220 | { |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 10221 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10222 | dca_unregister_notify(&dca_notifier); |
| 10223 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10224 | pci_unregister_driver(&ixgbe_driver); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 10225 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 10226 | ixgbe_dbg_exit(); |
Mark Rustad | 780484d | 2015-10-21 17:21:10 -0700 | [diff] [blame] | 10227 | if (ixgbe_wq) { |
| 10228 | destroy_workqueue(ixgbe_wq); |
| 10229 | ixgbe_wq = NULL; |
| 10230 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10231 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10232 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 10233 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10234 | static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 10235 | void *p) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10236 | { |
| 10237 | int ret_val; |
| 10238 | |
| 10239 | ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 10240 | __ixgbe_notify_dca); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10241 | |
| 10242 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; |
| 10243 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10244 | |
Alexander Duyck | b453368 | 2009-03-31 21:32:42 +0000 | [diff] [blame] | 10245 | #endif /* CONFIG_IXGBE_DCA */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 10246 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10247 | module_exit(ixgbe_exit_module); |
| 10248 | |
| 10249 | /* ixgbe_main.c */ |