Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel 10 Gigabit PCI Express Linux driver |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 4 | Copyright(c) 1999 - 2016 Intel Corporation. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms and conditions of the GNU General Public License, |
| 8 | version 2, as published by the Free Software Foundation. |
| 9 | |
| 10 | This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License along with |
| 16 | this program; if not, write to the Free Software Foundation, Inc., |
| 17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | |
| 19 | The full GNU General Public License is included in this distribution in |
| 20 | the file called "COPYING". |
| 21 | |
| 22 | Contact Information: |
Jacob Keller | b89aae7 | 2014-02-22 01:23:50 +0000 | [diff] [blame] | 23 | Linux NICS <linux.nics@intel.com> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 24 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 26 | |
| 27 | *******************************************************************************/ |
| 28 | |
| 29 | #include <linux/types.h> |
| 30 | #include <linux/module.h> |
| 31 | #include <linux/pci.h> |
| 32 | #include <linux/netdevice.h> |
| 33 | #include <linux/vmalloc.h> |
| 34 | #include <linux/string.h> |
| 35 | #include <linux/in.h> |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 36 | #include <linux/interrupt.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 37 | #include <linux/ip.h> |
| 38 | #include <linux/tcp.h> |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 39 | #include <linux/sctp.h> |
Lucy Liu | 6012786 | 2009-07-22 14:07:33 +0000 | [diff] [blame] | 40 | #include <linux/pkt_sched.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 41 | #include <linux/ipv6.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 42 | #include <linux/slab.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 43 | #include <net/checksum.h> |
| 44 | #include <net/ip6_checksum.h> |
Martin K Petersen | c762dff | 2014-11-15 14:24:51 +0000 | [diff] [blame] | 45 | #include <linux/etherdevice.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 46 | #include <linux/ethtool.h> |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 47 | #include <linux/if.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 48 | #include <linux/if_vlan.h> |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 49 | #include <linux/if_macvlan.h> |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 50 | #include <linux/if_bridge.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 51 | #include <linux/prefetch.h> |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 52 | #include <scsi/fc/fc_fcoe.h> |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 53 | #include <net/udp_tunnel.h> |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 54 | #include <net/pkt_cls.h> |
| 55 | #include <net/tc_act/tc_gact.h> |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 56 | #include <net/tc_act/tc_mirred.h> |
Sowmini Varadhan | 9f3c750 | 2016-10-24 15:36:39 -0700 | [diff] [blame] | 57 | #include <net/vxlan.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 58 | |
| 59 | #include "ixgbe.h" |
| 60 | #include "ixgbe_common.h" |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 61 | #include "ixgbe_dcb_82599.h" |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 62 | #include "ixgbe_sriov.h" |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 63 | #include "ixgbe_model.h" |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 64 | |
| 65 | char ixgbe_driver_name[] = "ixgbe"; |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 66 | static const char ixgbe_driver_string[] = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 67 | "Intel(R) 10 Gigabit PCI Express Network Driver"; |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 68 | #ifdef IXGBE_FCOE |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 69 | char ixgbe_default_device_descr[] = |
| 70 | "Intel(R) 10 Gigabit Network Connection"; |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 71 | #else |
| 72 | static char ixgbe_default_device_descr[] = |
| 73 | "Intel(R) 10 Gigabit Network Connection"; |
| 74 | #endif |
Mark Rustad | 1733284 | 2016-12-12 15:08:13 -0800 | [diff] [blame] | 75 | #define DRV_VERSION "5.0.0-k" |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 76 | const char ixgbe_driver_version[] = DRV_VERSION; |
Don Skidmore | a52055e | 2011-02-23 09:58:39 +0000 | [diff] [blame] | 77 | static const char ixgbe_copyright[] = |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 78 | "Copyright (c) 1999-2016 Intel Corporation."; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 79 | |
Don Skidmore | f44e751 | 2015-06-09 16:36:23 -0700 | [diff] [blame] | 80 | static const char ixgbe_overheat_msg[] = "Network adapter has been stopped because it has over heated. Restart the computer. If the problem persists, power off the system and replace the adapter"; |
| 81 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 82 | static const struct ixgbe_info *ixgbe_info_tbl[] = { |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 83 | [board_82598] = &ixgbe_82598_info, |
| 84 | [board_82599] = &ixgbe_82599_info, |
| 85 | [board_X540] = &ixgbe_X540_info, |
| 86 | [board_X550] = &ixgbe_X550_info, |
| 87 | [board_X550EM_x] = &ixgbe_X550EM_x_info, |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 88 | [board_x550em_a] = &ixgbe_x550em_a_info, |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 89 | [board_x550em_a_fw] = &ixgbe_x550em_a_fw_info, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | /* ixgbe_pci_tbl - PCI Device ID Table |
| 93 | * |
| 94 | * Wildcard entries (PCI_ANY_ID) should come last |
| 95 | * Last entry must be all 0s |
| 96 | * |
| 97 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 98 | * Class, Class Mask, private data (not used) } |
| 99 | */ |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 100 | static const struct pci_device_id ixgbe_pci_tbl[] = { |
Alexander Duyck | 54239c6 | 2011-07-15 03:06:06 +0000 | [diff] [blame] | 101 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 }, |
| 102 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 }, |
| 103 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 }, |
| 104 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 }, |
| 105 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 }, |
| 106 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 }, |
| 107 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 }, |
| 108 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 }, |
| 109 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 }, |
| 110 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 }, |
| 111 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 }, |
| 112 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 }, |
| 113 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 }, |
| 114 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 }, |
| 115 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 }, |
| 116 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 }, |
| 117 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 }, |
| 118 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 }, |
| 119 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 }, |
| 120 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 }, |
| 121 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 }, |
| 122 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 }, |
| 123 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 }, |
| 124 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 }, |
| 125 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 }, |
| 126 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 }, |
Don Skidmore | 8f58332 | 2013-07-27 06:25:38 +0000 | [diff] [blame] | 127 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_QSFP_SF_QP), board_82599 }, |
Emil Tantilov | 7d14528 | 2011-09-08 08:30:14 +0000 | [diff] [blame] | 128 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 }, |
Emil Tantilov | 9e791e4 | 2011-11-04 06:43:29 +0000 | [diff] [blame] | 129 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 }, |
joshua.a.hay@intel.com | df376f0 | 2012-09-21 00:08:21 +0000 | [diff] [blame] | 130 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 }, |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 131 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T), board_X550}, |
Mark Rustad | a711ad8 | 2016-03-21 11:21:31 -0700 | [diff] [blame] | 132 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T1), board_X550}, |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 133 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KX4), board_X550EM_x}, |
| 134 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KR), board_X550EM_x}, |
Don Skidmore | deda562 | 2015-06-09 17:39:46 -0700 | [diff] [blame] | 135 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_10G_T), board_X550EM_x}, |
Mark Rustad | 018d714 | 2015-08-08 16:19:19 -0700 | [diff] [blame] | 136 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_SFP), board_X550EM_x}, |
Mark Rustad | f572b2c | 2016-04-01 12:18:46 -0700 | [diff] [blame] | 137 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR), board_x550em_a }, |
| 138 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR_L), board_x550em_a }, |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 139 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP_N), board_x550em_a }, |
Mark Rustad | 200157c | 2016-04-01 12:18:40 -0700 | [diff] [blame] | 140 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII), board_x550em_a }, |
| 141 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII_L), board_x550em_a }, |
Don Skidmore | 92ed843 | 2016-08-17 20:34:40 -0400 | [diff] [blame] | 142 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_10G_T), board_x550em_a}, |
Mark Rustad | 2d40cd1 | 2016-04-01 12:18:35 -0700 | [diff] [blame] | 143 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP), board_x550em_a }, |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 144 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_1G_T), board_x550em_a_fw }, |
| 145 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_1G_T_L), board_x550em_a_fw }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 146 | /* required last entry */ |
| 147 | {0, } |
| 148 | }; |
| 149 | MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl); |
| 150 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 151 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 152 | static int ixgbe_notify_dca(struct notifier_block *, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 153 | void *p); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 154 | static struct notifier_block dca_notifier = { |
| 155 | .notifier_call = ixgbe_notify_dca, |
| 156 | .next = NULL, |
| 157 | .priority = 0 |
| 158 | }; |
| 159 | #endif |
| 160 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 161 | #ifdef CONFIG_PCI_IOV |
| 162 | static unsigned int max_vfs; |
| 163 | module_param(max_vfs, uint, 0); |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 164 | MODULE_PARM_DESC(max_vfs, |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 165 | "Maximum number of virtual functions to allocate per physical function - default is zero and maximum value is 63. (Deprecated)"); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 166 | #endif /* CONFIG_PCI_IOV */ |
| 167 | |
Peter P Waskiewicz Jr | 8ef78ad | 2012-02-01 09:19:21 +0000 | [diff] [blame] | 168 | static unsigned int allow_unsupported_sfp; |
| 169 | module_param(allow_unsupported_sfp, uint, 0); |
| 170 | MODULE_PARM_DESC(allow_unsupported_sfp, |
| 171 | "Allow unsupported and untested SFP+ modules on 82599-based adapters"); |
| 172 | |
stephen hemminger | b3f4d59 | 2012-03-13 06:04:20 +0000 | [diff] [blame] | 173 | #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK) |
| 174 | static int debug = -1; |
| 175 | module_param(debug, int, 0); |
| 176 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 177 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 178 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 179 | MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver"); |
| 180 | MODULE_LICENSE("GPL"); |
| 181 | MODULE_VERSION(DRV_VERSION); |
| 182 | |
Mark Rustad | 780484d | 2015-10-21 17:21:10 -0700 | [diff] [blame] | 183 | static struct workqueue_struct *ixgbe_wq; |
| 184 | |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 185 | static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev); |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 186 | static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *); |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 187 | |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 188 | static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter *adapter, |
| 189 | u32 reg, u16 *value) |
| 190 | { |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 191 | struct pci_dev *parent_dev; |
| 192 | struct pci_bus *parent_bus; |
| 193 | |
| 194 | parent_bus = adapter->pdev->bus->parent; |
| 195 | if (!parent_bus) |
| 196 | return -1; |
| 197 | |
| 198 | parent_dev = parent_bus->self; |
| 199 | if (!parent_dev) |
| 200 | return -1; |
| 201 | |
Yijing Wang | c0798ed | 2013-09-04 17:30:08 +0000 | [diff] [blame] | 202 | if (!pci_is_pcie(parent_dev)) |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 203 | return -1; |
| 204 | |
Yijing Wang | c0798ed | 2013-09-04 17:30:08 +0000 | [diff] [blame] | 205 | pcie_capability_read_word(parent_dev, reg, value); |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 206 | if (*value == IXGBE_FAILED_READ_CFG_WORD && |
| 207 | ixgbe_check_cfg_remove(&adapter->hw, parent_dev)) |
| 208 | return -1; |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | static s32 ixgbe_get_parent_bus_info(struct ixgbe_adapter *adapter) |
| 213 | { |
| 214 | struct ixgbe_hw *hw = &adapter->hw; |
| 215 | u16 link_status = 0; |
| 216 | int err; |
| 217 | |
| 218 | hw->bus.type = ixgbe_bus_type_pci_express; |
| 219 | |
| 220 | /* Get the negotiated link width and speed from PCI config space of the |
| 221 | * parent, as this device is behind a switch |
| 222 | */ |
| 223 | err = ixgbe_read_pci_cfg_word_parent(adapter, 18, &link_status); |
| 224 | |
| 225 | /* assume caller will handle error case */ |
| 226 | if (err) |
| 227 | return err; |
| 228 | |
| 229 | hw->bus.width = ixgbe_convert_bus_width(link_status); |
| 230 | hw->bus.speed = ixgbe_convert_bus_speed(link_status); |
| 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 235 | /** |
| 236 | * ixgbe_check_from_parent - Determine whether PCIe info should come from parent |
| 237 | * @hw: hw specific details |
| 238 | * |
| 239 | * This function is used by probe to determine whether a device's PCI-Express |
| 240 | * bandwidth details should be gathered from the parent bus instead of from the |
| 241 | * device. Used to ensure that various locations all have the correct device ID |
| 242 | * checks. |
| 243 | */ |
| 244 | static inline bool ixgbe_pcie_from_parent(struct ixgbe_hw *hw) |
| 245 | { |
| 246 | switch (hw->device_id) { |
| 247 | case IXGBE_DEV_ID_82599_SFP_SF_QP: |
Don Skidmore | 8f58332 | 2013-07-27 06:25:38 +0000 | [diff] [blame] | 248 | case IXGBE_DEV_ID_82599_QSFP_SF_QP: |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 249 | return true; |
| 250 | default: |
| 251 | return false; |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | static void ixgbe_check_minimum_link(struct ixgbe_adapter *adapter, |
| 256 | int expected_gts) |
| 257 | { |
Don Skidmore | f9328bc | 2015-06-18 13:24:06 -0400 | [diff] [blame] | 258 | struct ixgbe_hw *hw = &adapter->hw; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 259 | int max_gts = 0; |
| 260 | enum pci_bus_speed speed = PCI_SPEED_UNKNOWN; |
| 261 | enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN; |
| 262 | struct pci_dev *pdev; |
| 263 | |
Don Skidmore | f9328bc | 2015-06-18 13:24:06 -0400 | [diff] [blame] | 264 | /* Some devices are not connected over PCIe and thus do not negotiate |
| 265 | * speed. These devices do not have valid bus info, and thus any report |
| 266 | * we generate may not be correct. |
| 267 | */ |
| 268 | if (hw->bus.type == ixgbe_bus_type_internal) |
| 269 | return; |
| 270 | |
Jacob Keller | 56d1392 | 2015-06-10 11:44:45 -0700 | [diff] [blame] | 271 | /* determine whether to use the parent device */ |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 272 | if (ixgbe_pcie_from_parent(&adapter->hw)) |
| 273 | pdev = adapter->pdev->bus->parent->self; |
| 274 | else |
| 275 | pdev = adapter->pdev; |
| 276 | |
| 277 | if (pcie_get_minimum_link(pdev, &speed, &width) || |
| 278 | speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) { |
| 279 | e_dev_warn("Unable to determine PCI Express bandwidth.\n"); |
| 280 | return; |
| 281 | } |
| 282 | |
| 283 | switch (speed) { |
| 284 | case PCIE_SPEED_2_5GT: |
| 285 | /* 8b/10b encoding reduces max throughput by 20% */ |
| 286 | max_gts = 2 * width; |
| 287 | break; |
| 288 | case PCIE_SPEED_5_0GT: |
| 289 | /* 8b/10b encoding reduces max throughput by 20% */ |
| 290 | max_gts = 4 * width; |
| 291 | break; |
| 292 | case PCIE_SPEED_8_0GT: |
Jacob Keller | 9f0a433 | 2013-10-18 05:09:19 +0000 | [diff] [blame] | 293 | /* 128b/130b encoding reduces throughput by less than 2% */ |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 294 | max_gts = 8 * width; |
| 295 | break; |
| 296 | default: |
| 297 | e_dev_warn("Unable to determine PCI Express bandwidth.\n"); |
| 298 | return; |
| 299 | } |
| 300 | |
| 301 | e_dev_info("PCI Express bandwidth of %dGT/s available\n", |
| 302 | max_gts); |
| 303 | e_dev_info("(Speed:%s, Width: x%d, Encoding Loss:%s)\n", |
| 304 | (speed == PCIE_SPEED_8_0GT ? "8.0GT/s" : |
| 305 | speed == PCIE_SPEED_5_0GT ? "5.0GT/s" : |
| 306 | speed == PCIE_SPEED_2_5GT ? "2.5GT/s" : |
| 307 | "Unknown"), |
| 308 | width, |
| 309 | (speed == PCIE_SPEED_2_5GT ? "20%" : |
| 310 | speed == PCIE_SPEED_5_0GT ? "20%" : |
Jacob Keller | 9f0a433 | 2013-10-18 05:09:19 +0000 | [diff] [blame] | 311 | speed == PCIE_SPEED_8_0GT ? "<2%" : |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 312 | "Unknown")); |
| 313 | |
| 314 | if (max_gts < expected_gts) { |
| 315 | e_dev_warn("This is not sufficient for optimal performance of this card.\n"); |
| 316 | e_dev_warn("For optimal performance, at least %dGT/s of bandwidth is required.\n", |
| 317 | expected_gts); |
| 318 | e_dev_warn("A slot with more lanes and/or higher speed is suggested.\n"); |
| 319 | } |
| 320 | } |
| 321 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 322 | static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter) |
| 323 | { |
| 324 | if (!test_bit(__IXGBE_DOWN, &adapter->state) && |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 325 | !test_bit(__IXGBE_REMOVING, &adapter->state) && |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 326 | !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state)) |
Mark Rustad | 780484d | 2015-10-21 17:21:10 -0700 | [diff] [blame] | 327 | queue_work(ixgbe_wq, &adapter->service_task); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 328 | } |
| 329 | |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 330 | static void ixgbe_remove_adapter(struct ixgbe_hw *hw) |
| 331 | { |
| 332 | struct ixgbe_adapter *adapter = hw->back; |
| 333 | |
| 334 | if (!hw->hw_addr) |
| 335 | return; |
| 336 | hw->hw_addr = NULL; |
| 337 | e_dev_err("Adapter removed\n"); |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 338 | if (test_bit(__IXGBE_SERVICE_INITED, &adapter->state)) |
| 339 | ixgbe_service_event_schedule(adapter); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 340 | } |
| 341 | |
Mark Rustad | f8e2472 | 2014-03-18 07:03:40 +0000 | [diff] [blame] | 342 | static void ixgbe_check_remove(struct ixgbe_hw *hw, u32 reg) |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 343 | { |
| 344 | u32 value; |
| 345 | |
| 346 | /* The following check not only optimizes a bit by not |
| 347 | * performing a read on the status register when the |
| 348 | * register just read was a status register read that |
| 349 | * returned IXGBE_FAILED_READ_REG. It also blocks any |
| 350 | * potential recursion. |
| 351 | */ |
| 352 | if (reg == IXGBE_STATUS) { |
| 353 | ixgbe_remove_adapter(hw); |
| 354 | return; |
| 355 | } |
| 356 | value = ixgbe_read_reg(hw, IXGBE_STATUS); |
| 357 | if (value == IXGBE_FAILED_READ_REG) |
| 358 | ixgbe_remove_adapter(hw); |
| 359 | } |
| 360 | |
Mark Rustad | f8e2472 | 2014-03-18 07:03:40 +0000 | [diff] [blame] | 361 | /** |
| 362 | * ixgbe_read_reg - Read from device register |
| 363 | * @hw: hw specific details |
| 364 | * @reg: offset of register to read |
| 365 | * |
| 366 | * Returns : value read or IXGBE_FAILED_READ_REG if removed |
| 367 | * |
| 368 | * This function is used to read device registers. It checks for device |
| 369 | * removal by confirming any read that returns all ones by checking the |
| 370 | * status register value for all ones. This function avoids reading from |
| 371 | * the hardware if a removal was previously detected in which case it |
| 372 | * returns IXGBE_FAILED_READ_REG (all ones). |
| 373 | */ |
| 374 | u32 ixgbe_read_reg(struct ixgbe_hw *hw, u32 reg) |
| 375 | { |
| 376 | u8 __iomem *reg_addr = ACCESS_ONCE(hw->hw_addr); |
| 377 | u32 value; |
| 378 | |
| 379 | if (ixgbe_removed(reg_addr)) |
| 380 | return IXGBE_FAILED_READ_REG; |
Mark Rustad | 2f2219b | 2016-04-07 10:43:50 -0700 | [diff] [blame] | 381 | if (unlikely(hw->phy.nw_mng_if_sel & |
| 382 | IXGBE_NW_MNG_IF_SEL_ENABLE_10_100M)) { |
| 383 | struct ixgbe_adapter *adapter; |
| 384 | int i; |
| 385 | |
| 386 | for (i = 0; i < 200; ++i) { |
| 387 | value = readl(reg_addr + IXGBE_MAC_SGMII_BUSY); |
| 388 | if (likely(!value)) |
| 389 | goto writes_completed; |
| 390 | if (value == IXGBE_FAILED_READ_REG) { |
| 391 | ixgbe_remove_adapter(hw); |
| 392 | return IXGBE_FAILED_READ_REG; |
| 393 | } |
| 394 | udelay(5); |
| 395 | } |
| 396 | |
| 397 | adapter = hw->back; |
| 398 | e_warn(hw, "register writes incomplete %08x\n", value); |
| 399 | } |
| 400 | |
| 401 | writes_completed: |
Mark Rustad | f8e2472 | 2014-03-18 07:03:40 +0000 | [diff] [blame] | 402 | value = readl(reg_addr + reg); |
| 403 | if (unlikely(value == IXGBE_FAILED_READ_REG)) |
| 404 | ixgbe_check_remove(hw, reg); |
| 405 | return value; |
| 406 | } |
| 407 | |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 408 | static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev) |
| 409 | { |
| 410 | u16 value; |
| 411 | |
| 412 | pci_read_config_word(pdev, PCI_VENDOR_ID, &value); |
| 413 | if (value == IXGBE_FAILED_READ_CFG_WORD) { |
| 414 | ixgbe_remove_adapter(hw); |
| 415 | return true; |
| 416 | } |
| 417 | return false; |
| 418 | } |
| 419 | |
| 420 | u16 ixgbe_read_pci_cfg_word(struct ixgbe_hw *hw, u32 reg) |
| 421 | { |
| 422 | struct ixgbe_adapter *adapter = hw->back; |
| 423 | u16 value; |
| 424 | |
| 425 | if (ixgbe_removed(hw->hw_addr)) |
| 426 | return IXGBE_FAILED_READ_CFG_WORD; |
| 427 | pci_read_config_word(adapter->pdev, reg, &value); |
| 428 | if (value == IXGBE_FAILED_READ_CFG_WORD && |
| 429 | ixgbe_check_cfg_remove(hw, adapter->pdev)) |
| 430 | return IXGBE_FAILED_READ_CFG_WORD; |
| 431 | return value; |
| 432 | } |
| 433 | |
| 434 | #ifdef CONFIG_PCI_IOV |
| 435 | static u32 ixgbe_read_pci_cfg_dword(struct ixgbe_hw *hw, u32 reg) |
| 436 | { |
| 437 | struct ixgbe_adapter *adapter = hw->back; |
| 438 | u32 value; |
| 439 | |
| 440 | if (ixgbe_removed(hw->hw_addr)) |
| 441 | return IXGBE_FAILED_READ_CFG_DWORD; |
| 442 | pci_read_config_dword(adapter->pdev, reg, &value); |
| 443 | if (value == IXGBE_FAILED_READ_CFG_DWORD && |
| 444 | ixgbe_check_cfg_remove(hw, adapter->pdev)) |
| 445 | return IXGBE_FAILED_READ_CFG_DWORD; |
| 446 | return value; |
| 447 | } |
| 448 | #endif /* CONFIG_PCI_IOV */ |
| 449 | |
Jacob Keller | ed19231 | 2014-02-22 01:23:53 +0000 | [diff] [blame] | 450 | void ixgbe_write_pci_cfg_word(struct ixgbe_hw *hw, u32 reg, u16 value) |
| 451 | { |
| 452 | struct ixgbe_adapter *adapter = hw->back; |
| 453 | |
| 454 | if (ixgbe_removed(hw->hw_addr)) |
| 455 | return; |
| 456 | pci_write_config_word(adapter->pdev, reg, value); |
| 457 | } |
| 458 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 459 | static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter) |
| 460 | { |
| 461 | BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state)); |
| 462 | |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 463 | /* flush memory to make sure state is correct before next watchdog */ |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 464 | smp_mb__before_atomic(); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 465 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
| 466 | } |
| 467 | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 468 | struct ixgbe_reg_info { |
| 469 | u32 ofs; |
| 470 | char *name; |
| 471 | }; |
| 472 | |
| 473 | static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = { |
| 474 | |
| 475 | /* General Registers */ |
| 476 | {IXGBE_CTRL, "CTRL"}, |
| 477 | {IXGBE_STATUS, "STATUS"}, |
| 478 | {IXGBE_CTRL_EXT, "CTRL_EXT"}, |
| 479 | |
| 480 | /* Interrupt Registers */ |
| 481 | {IXGBE_EICR, "EICR"}, |
| 482 | |
| 483 | /* RX Registers */ |
| 484 | {IXGBE_SRRCTL(0), "SRRCTL"}, |
| 485 | {IXGBE_DCA_RXCTRL(0), "DRXCTL"}, |
| 486 | {IXGBE_RDLEN(0), "RDLEN"}, |
| 487 | {IXGBE_RDH(0), "RDH"}, |
| 488 | {IXGBE_RDT(0), "RDT"}, |
| 489 | {IXGBE_RXDCTL(0), "RXDCTL"}, |
| 490 | {IXGBE_RDBAL(0), "RDBAL"}, |
| 491 | {IXGBE_RDBAH(0), "RDBAH"}, |
| 492 | |
| 493 | /* TX Registers */ |
| 494 | {IXGBE_TDBAL(0), "TDBAL"}, |
| 495 | {IXGBE_TDBAH(0), "TDBAH"}, |
| 496 | {IXGBE_TDLEN(0), "TDLEN"}, |
| 497 | {IXGBE_TDH(0), "TDH"}, |
| 498 | {IXGBE_TDT(0), "TDT"}, |
| 499 | {IXGBE_TXDCTL(0), "TXDCTL"}, |
| 500 | |
| 501 | /* List Terminator */ |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 502 | { .name = NULL } |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 503 | }; |
| 504 | |
| 505 | |
| 506 | /* |
| 507 | * ixgbe_regdump - register printout routine |
| 508 | */ |
| 509 | static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo) |
| 510 | { |
| 511 | int i = 0, j = 0; |
| 512 | char rname[16]; |
| 513 | u32 regs[64]; |
| 514 | |
| 515 | switch (reginfo->ofs) { |
| 516 | case IXGBE_SRRCTL(0): |
| 517 | for (i = 0; i < 64; i++) |
| 518 | regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i)); |
| 519 | break; |
| 520 | case IXGBE_DCA_RXCTRL(0): |
| 521 | for (i = 0; i < 64; i++) |
| 522 | regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i)); |
| 523 | break; |
| 524 | case IXGBE_RDLEN(0): |
| 525 | for (i = 0; i < 64; i++) |
| 526 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i)); |
| 527 | break; |
| 528 | case IXGBE_RDH(0): |
| 529 | for (i = 0; i < 64; i++) |
| 530 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i)); |
| 531 | break; |
| 532 | case IXGBE_RDT(0): |
| 533 | for (i = 0; i < 64; i++) |
| 534 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i)); |
| 535 | break; |
| 536 | case IXGBE_RXDCTL(0): |
| 537 | for (i = 0; i < 64; i++) |
| 538 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i)); |
| 539 | break; |
| 540 | case IXGBE_RDBAL(0): |
| 541 | for (i = 0; i < 64; i++) |
| 542 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i)); |
| 543 | break; |
| 544 | case IXGBE_RDBAH(0): |
| 545 | for (i = 0; i < 64; i++) |
| 546 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i)); |
| 547 | break; |
| 548 | case IXGBE_TDBAL(0): |
| 549 | for (i = 0; i < 64; i++) |
| 550 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i)); |
| 551 | break; |
| 552 | case IXGBE_TDBAH(0): |
| 553 | for (i = 0; i < 64; i++) |
| 554 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i)); |
| 555 | break; |
| 556 | case IXGBE_TDLEN(0): |
| 557 | for (i = 0; i < 64; i++) |
| 558 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i)); |
| 559 | break; |
| 560 | case IXGBE_TDH(0): |
| 561 | for (i = 0; i < 64; i++) |
| 562 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i)); |
| 563 | break; |
| 564 | case IXGBE_TDT(0): |
| 565 | for (i = 0; i < 64; i++) |
| 566 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i)); |
| 567 | break; |
| 568 | case IXGBE_TXDCTL(0): |
| 569 | for (i = 0; i < 64; i++) |
| 570 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i)); |
| 571 | break; |
| 572 | default: |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 573 | pr_info("%-15s %08x\n", reginfo->name, |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 574 | IXGBE_READ_REG(hw, reginfo->ofs)); |
| 575 | return; |
| 576 | } |
| 577 | |
| 578 | for (i = 0; i < 8; i++) { |
| 579 | 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] | 580 | pr_err("%-15s", rname); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 581 | for (j = 0; j < 8; j++) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 582 | pr_cont(" %08x", regs[i*8+j]); |
| 583 | pr_cont("\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | } |
| 587 | |
| 588 | /* |
| 589 | * ixgbe_dump - Print registers, tx-rings and rx-rings |
| 590 | */ |
| 591 | static void ixgbe_dump(struct ixgbe_adapter *adapter) |
| 592 | { |
| 593 | struct net_device *netdev = adapter->netdev; |
| 594 | struct ixgbe_hw *hw = &adapter->hw; |
| 595 | struct ixgbe_reg_info *reginfo; |
| 596 | int n = 0; |
| 597 | struct ixgbe_ring *tx_ring; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 598 | struct ixgbe_tx_buffer *tx_buffer; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 599 | union ixgbe_adv_tx_desc *tx_desc; |
| 600 | struct my_u0 { u64 a; u64 b; } *u0; |
| 601 | struct ixgbe_ring *rx_ring; |
| 602 | union ixgbe_adv_rx_desc *rx_desc; |
| 603 | struct ixgbe_rx_buffer *rx_buffer_info; |
| 604 | u32 staterr; |
| 605 | int i = 0; |
| 606 | |
| 607 | if (!netif_msg_hw(adapter)) |
| 608 | return; |
| 609 | |
| 610 | /* Print netdevice Info */ |
| 611 | if (netdev) { |
| 612 | dev_info(&adapter->pdev->dev, "Net device Info\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 613 | pr_info("Device Name state " |
Tobias Klauser | 4a7c972 | 2017-01-18 17:45:01 +0100 | [diff] [blame] | 614 | "trans_start\n"); |
| 615 | pr_info("%-15s %016lX %016lX\n", |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 616 | netdev->name, |
| 617 | netdev->state, |
Tobias Klauser | 4a7c972 | 2017-01-18 17:45:01 +0100 | [diff] [blame] | 618 | dev_trans_start(netdev)); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | /* Print Registers */ |
| 622 | dev_info(&adapter->pdev->dev, "Register Dump\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 623 | pr_info(" Register Name Value\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 624 | for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl; |
| 625 | reginfo->name; reginfo++) { |
| 626 | ixgbe_regdump(hw, reginfo); |
| 627 | } |
| 628 | |
| 629 | /* Print TX Ring Summary */ |
| 630 | if (!netdev || !netif_running(netdev)) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 631 | return; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 632 | |
| 633 | dev_info(&adapter->pdev->dev, "TX Rings Summary\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 634 | pr_info(" %s %s %s %s\n", |
| 635 | "Queue [NTU] [NTC] [bi(ntc)->dma ]", |
| 636 | "leng", "ntw", "timestamp"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 637 | for (n = 0; n < adapter->num_tx_queues; n++) { |
| 638 | tx_ring = adapter->tx_ring[n]; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 639 | tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean]; |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 640 | pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n", |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 641 | n, tx_ring->next_to_use, tx_ring->next_to_clean, |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 642 | (u64)dma_unmap_addr(tx_buffer, dma), |
| 643 | dma_unmap_len(tx_buffer, len), |
| 644 | tx_buffer->next_to_watch, |
| 645 | (u64)tx_buffer->time_stamp); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | /* Print TX Rings */ |
| 649 | if (!netif_msg_tx_done(adapter)) |
| 650 | goto rx_ring_summary; |
| 651 | |
| 652 | dev_info(&adapter->pdev->dev, "TX Rings Dump\n"); |
| 653 | |
| 654 | /* Transmit Descriptor Formats |
| 655 | * |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 656 | * 82598 Advanced Transmit Descriptor |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 657 | * +--------------------------------------------------------------+ |
| 658 | * 0 | Buffer Address [63:0] | |
| 659 | * +--------------------------------------------------------------+ |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 660 | * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 661 | * +--------------------------------------------------------------+ |
| 662 | * 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] | 663 | * |
| 664 | * 82598 Advanced Transmit Descriptor (Write-Back Format) |
| 665 | * +--------------------------------------------------------------+ |
| 666 | * 0 | RSV [63:0] | |
| 667 | * +--------------------------------------------------------------+ |
| 668 | * 8 | RSV | STA | NXTSEQ | |
| 669 | * +--------------------------------------------------------------+ |
| 670 | * 63 36 35 32 31 0 |
| 671 | * |
| 672 | * 82599+ Advanced Transmit Descriptor |
| 673 | * +--------------------------------------------------------------+ |
| 674 | * 0 | Buffer Address [63:0] | |
| 675 | * +--------------------------------------------------------------+ |
| 676 | * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN | |
| 677 | * +--------------------------------------------------------------+ |
| 678 | * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0 |
| 679 | * |
| 680 | * 82599+ Advanced Transmit Descriptor (Write-Back Format) |
| 681 | * +--------------------------------------------------------------+ |
| 682 | * 0 | RSV [63:0] | |
| 683 | * +--------------------------------------------------------------+ |
| 684 | * 8 | RSV | STA | RSV | |
| 685 | * +--------------------------------------------------------------+ |
| 686 | * 63 36 35 32 31 0 |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 687 | */ |
| 688 | |
| 689 | for (n = 0; n < adapter->num_tx_queues; n++) { |
| 690 | tx_ring = adapter->tx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 691 | pr_info("------------------------------------\n"); |
| 692 | pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index); |
| 693 | pr_info("------------------------------------\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 694 | pr_info("%s%s %s %s %s %s\n", |
| 695 | "T [desc] [address 63:0 ] ", |
| 696 | "[PlPOIdStDDt Ln] [bi->dma ] ", |
| 697 | "leng", "ntw", "timestamp", "bi->skb"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 698 | |
| 699 | for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 700 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 701 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 702 | u0 = (struct my_u0 *)tx_desc; |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 703 | if (dma_unmap_len(tx_buffer, len) > 0) { |
| 704 | pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p", |
| 705 | i, |
| 706 | le64_to_cpu(u0->a), |
| 707 | le64_to_cpu(u0->b), |
| 708 | (u64)dma_unmap_addr(tx_buffer, dma), |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 709 | dma_unmap_len(tx_buffer, len), |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 710 | tx_buffer->next_to_watch, |
| 711 | (u64)tx_buffer->time_stamp, |
| 712 | tx_buffer->skb); |
| 713 | if (i == tx_ring->next_to_use && |
| 714 | i == tx_ring->next_to_clean) |
| 715 | pr_cont(" NTC/U\n"); |
| 716 | else if (i == tx_ring->next_to_use) |
| 717 | pr_cont(" NTU\n"); |
| 718 | else if (i == tx_ring->next_to_clean) |
| 719 | pr_cont(" NTC\n"); |
| 720 | else |
| 721 | pr_cont("\n"); |
| 722 | |
| 723 | if (netif_msg_pktdata(adapter) && |
| 724 | tx_buffer->skb) |
| 725 | print_hex_dump(KERN_INFO, "", |
| 726 | DUMP_PREFIX_ADDRESS, 16, 1, |
| 727 | tx_buffer->skb->data, |
| 728 | dma_unmap_len(tx_buffer, len), |
| 729 | true); |
| 730 | } |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 731 | } |
| 732 | } |
| 733 | |
| 734 | /* Print RX Rings Summary */ |
| 735 | rx_ring_summary: |
| 736 | dev_info(&adapter->pdev->dev, "RX Rings Summary\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 737 | pr_info("Queue [NTU] [NTC]\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 738 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 739 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 740 | pr_info("%5d %5X %5X\n", |
| 741 | n, rx_ring->next_to_use, rx_ring->next_to_clean); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | /* Print RX Rings */ |
| 745 | if (!netif_msg_rx_status(adapter)) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 746 | return; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 747 | |
| 748 | dev_info(&adapter->pdev->dev, "RX Rings Dump\n"); |
| 749 | |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 750 | /* Receive Descriptor Formats |
| 751 | * |
| 752 | * 82598 Advanced Receive Descriptor (Read) Format |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 753 | * 63 1 0 |
| 754 | * +-----------------------------------------------------+ |
| 755 | * 0 | Packet Buffer Address [63:1] |A0/NSE| |
| 756 | * +----------------------------------------------+------+ |
| 757 | * 8 | Header Buffer Address [63:1] | DD | |
| 758 | * +-----------------------------------------------------+ |
| 759 | * |
| 760 | * |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 761 | * 82598 Advanced Receive Descriptor (Write-Back) Format |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 762 | * |
| 763 | * 63 48 47 32 31 30 21 20 16 15 4 3 0 |
| 764 | * +------------------------------------------------------+ |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 765 | * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS | |
| 766 | * | Packet | IP | | | | Type | Type | |
| 767 | * | Checksum | Ident | | | | | | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 768 | * +------------------------------------------------------+ |
| 769 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | |
| 770 | * +------------------------------------------------------+ |
| 771 | * 63 48 47 32 31 20 19 0 |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 772 | * |
| 773 | * 82599+ Advanced Receive Descriptor (Read) Format |
| 774 | * 63 1 0 |
| 775 | * +-----------------------------------------------------+ |
| 776 | * 0 | Packet Buffer Address [63:1] |A0/NSE| |
| 777 | * +----------------------------------------------+------+ |
| 778 | * 8 | Header Buffer Address [63:1] | DD | |
| 779 | * +-----------------------------------------------------+ |
| 780 | * |
| 781 | * |
| 782 | * 82599+ Advanced Receive Descriptor (Write-Back) Format |
| 783 | * |
| 784 | * 63 48 47 32 31 30 21 20 17 16 4 3 0 |
| 785 | * +------------------------------------------------------+ |
| 786 | * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS | |
| 787 | * |/ RTT / PCoE_PARAM | | | CNT | Type | Type | |
| 788 | * |/ Flow Dir Flt ID | | | | | | |
| 789 | * +------------------------------------------------------+ |
| 790 | * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP | |
| 791 | * +------------------------------------------------------+ |
| 792 | * 63 48 47 32 31 20 19 0 |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 793 | */ |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 794 | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 795 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 796 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 797 | pr_info("------------------------------------\n"); |
| 798 | pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index); |
| 799 | pr_info("------------------------------------\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 800 | pr_info("%s%s%s", |
| 801 | "R [desc] [ PktBuf A0] ", |
| 802 | "[ HeadBuf DD] [bi->dma ] [bi->skb ] ", |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 803 | "<-- Adv Rx Read format\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 804 | pr_info("%s%s%s", |
| 805 | "RWB[desc] [PcsmIpSHl PtRs] ", |
| 806 | "[vl er S cks ln] ---------------- [bi->skb ] ", |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 807 | "<-- Adv Rx Write-Back format\n"); |
| 808 | |
| 809 | for (i = 0; i < rx_ring->count; i++) { |
| 810 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 811 | rx_desc = IXGBE_RX_DESC(rx_ring, i); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 812 | u0 = (struct my_u0 *)rx_desc; |
| 813 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 814 | if (staterr & IXGBE_RXD_STAT_DD) { |
| 815 | /* Descriptor Done */ |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 816 | pr_info("RWB[0x%03X] %016llX " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 817 | "%016llX ---------------- %p", i, |
| 818 | le64_to_cpu(u0->a), |
| 819 | le64_to_cpu(u0->b), |
| 820 | rx_buffer_info->skb); |
| 821 | } else { |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 822 | pr_info("R [0x%03X] %016llX " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 823 | "%016llX %016llX %p", i, |
| 824 | le64_to_cpu(u0->a), |
| 825 | le64_to_cpu(u0->b), |
| 826 | (u64)rx_buffer_info->dma, |
| 827 | rx_buffer_info->skb); |
| 828 | |
Emil Tantilov | 9c50c03 | 2012-07-26 01:21:24 +0000 | [diff] [blame] | 829 | if (netif_msg_pktdata(adapter) && |
| 830 | rx_buffer_info->dma) { |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 831 | print_hex_dump(KERN_INFO, "", |
| 832 | DUMP_PREFIX_ADDRESS, 16, 1, |
Emil Tantilov | 9c50c03 | 2012-07-26 01:21:24 +0000 | [diff] [blame] | 833 | page_address(rx_buffer_info->page) + |
| 834 | rx_buffer_info->page_offset, |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 835 | ixgbe_rx_bufsz(rx_ring), true); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 836 | } |
| 837 | } |
| 838 | |
| 839 | if (i == rx_ring->next_to_use) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 840 | pr_cont(" NTU\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 841 | else if (i == rx_ring->next_to_clean) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 842 | pr_cont(" NTC\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 843 | else |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 844 | pr_cont("\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 845 | |
| 846 | } |
| 847 | } |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 848 | } |
| 849 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 850 | static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter) |
| 851 | { |
| 852 | u32 ctrl_ext; |
| 853 | |
| 854 | /* Let firmware take over control of h/w */ |
| 855 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 856 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 857 | ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter) |
| 861 | { |
| 862 | u32 ctrl_ext; |
| 863 | |
| 864 | /* Let firmware know the driver has taken over */ |
| 865 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 866 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 867 | ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 868 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 869 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 870 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 871 | * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors |
| 872 | * @adapter: pointer to adapter struct |
| 873 | * @direction: 0 for Rx, 1 for Tx, -1 for other causes |
| 874 | * @queue: queue to map the corresponding interrupt to |
| 875 | * @msix_vector: the vector to map to the corresponding queue |
| 876 | * |
| 877 | */ |
| 878 | static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 879 | u8 queue, u8 msix_vector) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 880 | { |
| 881 | u32 ivar, index; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 882 | struct ixgbe_hw *hw = &adapter->hw; |
| 883 | switch (hw->mac.type) { |
| 884 | case ixgbe_mac_82598EB: |
| 885 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 886 | if (direction == -1) |
| 887 | direction = 0; |
| 888 | index = (((direction * 64) + queue) >> 2) & 0x1F; |
| 889 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index)); |
| 890 | ivar &= ~(0xFF << (8 * (queue & 0x3))); |
| 891 | ivar |= (msix_vector << (8 * (queue & 0x3))); |
| 892 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar); |
| 893 | break; |
| 894 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 895 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 896 | case ixgbe_mac_X550: |
| 897 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 898 | case ixgbe_mac_x550em_a: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 899 | if (direction == -1) { |
| 900 | /* other causes */ |
| 901 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 902 | index = ((queue & 1) * 8); |
| 903 | ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC); |
| 904 | ivar &= ~(0xFF << index); |
| 905 | ivar |= (msix_vector << index); |
| 906 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar); |
| 907 | break; |
| 908 | } else { |
| 909 | /* tx or rx causes */ |
| 910 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 911 | index = ((16 * (queue & 1)) + (8 * direction)); |
| 912 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1)); |
| 913 | ivar &= ~(0xFF << index); |
| 914 | ivar |= (msix_vector << index); |
| 915 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar); |
| 916 | break; |
| 917 | } |
| 918 | default: |
| 919 | break; |
| 920 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 921 | } |
| 922 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 923 | static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 924 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 925 | { |
| 926 | u32 mask; |
| 927 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 928 | switch (adapter->hw.mac.type) { |
| 929 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 930 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 931 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 932 | break; |
| 933 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 934 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 935 | case ixgbe_mac_X550: |
| 936 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 937 | case ixgbe_mac_x550em_a: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 938 | mask = (qmask & 0xFFFFFFFF); |
| 939 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask); |
| 940 | mask = (qmask >> 32); |
| 941 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 942 | break; |
| 943 | default: |
| 944 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 945 | } |
| 946 | } |
| 947 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 948 | static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter) |
| 949 | { |
| 950 | struct ixgbe_hw *hw = &adapter->hw; |
| 951 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
| 952 | int i; |
| 953 | u32 data; |
| 954 | |
| 955 | if ((hw->fc.current_mode != ixgbe_fc_full) && |
| 956 | (hw->fc.current_mode != ixgbe_fc_rx_pause)) |
| 957 | return; |
| 958 | |
| 959 | switch (hw->mac.type) { |
| 960 | case ixgbe_mac_82598EB: |
| 961 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); |
| 962 | break; |
| 963 | default: |
| 964 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); |
| 965 | } |
| 966 | hwstats->lxoffrxc += data; |
| 967 | |
| 968 | /* refill credits (no tx hang) if we received xoff */ |
| 969 | if (!data) |
| 970 | return; |
| 971 | |
| 972 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 973 | clear_bit(__IXGBE_HANG_CHECK_ARMED, |
| 974 | &adapter->tx_ring[i]->state); |
| 975 | } |
| 976 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 977 | static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 978 | { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 979 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 980 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 981 | u32 xoff[8] = {0}; |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 982 | u8 tc; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 983 | int i; |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 984 | bool pfc_en = adapter->dcb_cfg.pfc_mode_enable; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 985 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 986 | if (adapter->ixgbe_ieee_pfc) |
| 987 | pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 988 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 989 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) { |
| 990 | ixgbe_update_xoff_rx_lfc(adapter); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 991 | return; |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 992 | } |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 993 | |
| 994 | /* update stats for each tc, only valid with PFC enabled */ |
| 995 | for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) { |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 996 | u32 pxoffrxc; |
| 997 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 998 | switch (hw->mac.type) { |
| 999 | case ixgbe_mac_82598EB: |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 1000 | pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i)); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1001 | break; |
| 1002 | default: |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 1003 | pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i)); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1004 | } |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 1005 | hwstats->pxoffrxc[i] += pxoffrxc; |
| 1006 | /* Get the TC for given UP */ |
| 1007 | tc = netdev_get_prio_tc_map(adapter->netdev, i); |
| 1008 | xoff[tc] += pxoffrxc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1009 | } |
| 1010 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1011 | /* disarm tx queues that have received xoff frames */ |
| 1012 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 1013 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1014 | |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 1015 | tc = tx_ring->dcb_tc; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1016 | if (xoff[tc]) |
| 1017 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
| 1018 | } |
| 1019 | } |
| 1020 | |
| 1021 | static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring) |
| 1022 | { |
Alexander Duyck | 7d7ce68 | 2012-02-08 07:50:51 +0000 | [diff] [blame] | 1023 | return ring->stats.packets; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring) |
| 1027 | { |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 1028 | struct ixgbe_adapter *adapter; |
| 1029 | struct ixgbe_hw *hw; |
| 1030 | u32 head, tail; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1031 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 1032 | if (ring->l2_accel_priv) |
| 1033 | adapter = ring->l2_accel_priv->real_adapter; |
| 1034 | else |
| 1035 | adapter = netdev_priv(ring->netdev); |
| 1036 | |
| 1037 | hw = &adapter->hw; |
| 1038 | head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx)); |
| 1039 | tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx)); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1040 | |
| 1041 | if (head != tail) |
| 1042 | return (head < tail) ? |
| 1043 | tail - head : (tail + ring->count - head); |
| 1044 | |
| 1045 | return 0; |
| 1046 | } |
| 1047 | |
| 1048 | static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring) |
| 1049 | { |
| 1050 | u32 tx_done = ixgbe_get_tx_completed(tx_ring); |
| 1051 | u32 tx_done_old = tx_ring->tx_stats.tx_done_old; |
| 1052 | u32 tx_pending = ixgbe_get_tx_pending(tx_ring); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1053 | |
| 1054 | clear_check_for_tx_hang(tx_ring); |
| 1055 | |
| 1056 | /* |
| 1057 | * Check for a hung queue, but be thorough. This verifies |
| 1058 | * that a transmit has been completed since the previous |
| 1059 | * check AND there is at least one packet pending. The |
| 1060 | * ARMED bit is set to indicate a potential hang. The |
| 1061 | * bit is cleared if a pause frame is received to remove |
| 1062 | * false hang detection due to PFC or 802.3x frames. By |
| 1063 | * requiring this to fail twice we avoid races with |
| 1064 | * pfc clearing the ARMED bit and conditions where we |
| 1065 | * run the check_tx_hang logic with a transmit completion |
| 1066 | * pending but without time to complete it yet. |
| 1067 | */ |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 1068 | if (tx_done_old == tx_done && tx_pending) |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1069 | /* make sure it is true for two checks in a row */ |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 1070 | return test_and_set_bit(__IXGBE_HANG_CHECK_ARMED, |
| 1071 | &tx_ring->state); |
| 1072 | /* update completed stats and continue */ |
| 1073 | tx_ring->tx_stats.tx_done_old = tx_done; |
| 1074 | /* reset the countdown */ |
| 1075 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1076 | |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 1077 | return false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1078 | } |
| 1079 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 1080 | /** |
| 1081 | * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout |
| 1082 | * @adapter: driver private struct |
| 1083 | **/ |
| 1084 | static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter) |
| 1085 | { |
| 1086 | |
| 1087 | /* Do the reset outside of interrupt context */ |
| 1088 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
Emil Tantilov | 57ca2a4 | 2016-07-29 14:46:31 -0700 | [diff] [blame] | 1089 | set_bit(__IXGBE_RESET_REQUESTED, &adapter->state); |
Jacob Keller | 12ff3f3 | 2012-12-01 07:57:17 +0000 | [diff] [blame] | 1090 | e_warn(drv, "initiating reset due to tx timeout\n"); |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 1091 | ixgbe_service_event_schedule(adapter); |
| 1092 | } |
| 1093 | } |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1094 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1095 | /** |
Rostislav Pehlivanov | c04f90e | 2016-01-27 18:33:30 +0000 | [diff] [blame] | 1096 | * ixgbe_tx_maxrate - callback to set the maximum per-queue bitrate |
| 1097 | **/ |
| 1098 | static int ixgbe_tx_maxrate(struct net_device *netdev, |
| 1099 | int queue_index, u32 maxrate) |
| 1100 | { |
| 1101 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1102 | struct ixgbe_hw *hw = &adapter->hw; |
| 1103 | u32 bcnrc_val = ixgbe_link_mbps(adapter); |
| 1104 | |
| 1105 | if (!maxrate) |
| 1106 | return 0; |
| 1107 | |
| 1108 | /* Calculate the rate factor values to set */ |
| 1109 | bcnrc_val <<= IXGBE_RTTBCNRC_RF_INT_SHIFT; |
| 1110 | bcnrc_val /= maxrate; |
| 1111 | |
| 1112 | /* clear everything but the rate factor */ |
| 1113 | bcnrc_val &= IXGBE_RTTBCNRC_RF_INT_MASK | |
| 1114 | IXGBE_RTTBCNRC_RF_DEC_MASK; |
| 1115 | |
| 1116 | /* enable the rate scheduler */ |
| 1117 | bcnrc_val |= IXGBE_RTTBCNRC_RS_ENA; |
| 1118 | |
| 1119 | IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, queue_index); |
| 1120 | IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val); |
| 1121 | |
| 1122 | return 0; |
| 1123 | } |
| 1124 | |
| 1125 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1126 | * ixgbe_clean_tx_irq - Reclaim resources after transmit completes |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1127 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1128 | * @tx_ring: tx ring to clean |
Alexander Duyck | 8220bbc | 2016-03-07 09:30:09 -0800 | [diff] [blame] | 1129 | * @napi_budget: Used to determine if we are in netpoll |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1130 | **/ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1131 | 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] | 1132 | struct ixgbe_ring *tx_ring, int napi_budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1133 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1134 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1135 | struct ixgbe_tx_buffer *tx_buffer; |
| 1136 | union ixgbe_adv_tx_desc *tx_desc; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1137 | unsigned int total_bytes = 0, total_packets = 0; |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 1138 | unsigned int budget = q_vector->tx.work_limit; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1139 | unsigned int i = tx_ring->next_to_clean; |
| 1140 | |
| 1141 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1142 | return true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1143 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1144 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1145 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1146 | i -= tx_ring->count; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 1147 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1148 | do { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1149 | union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1150 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1151 | /* if next_to_watch is not set then there is no work pending */ |
| 1152 | if (!eop_desc) |
| 1153 | break; |
| 1154 | |
Alexander Duyck | 7f83a9e | 2012-02-08 07:49:23 +0000 | [diff] [blame] | 1155 | /* prevent any other reads prior to eop_desc */ |
Alexander Duyck | 7e63bf4 | 2013-01-08 07:00:58 +0000 | [diff] [blame] | 1156 | read_barrier_depends(); |
Alexander Duyck | 7f83a9e | 2012-02-08 07:49:23 +0000 | [diff] [blame] | 1157 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1158 | /* if DD is not set pending work has not been completed */ |
| 1159 | if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD))) |
| 1160 | break; |
| 1161 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1162 | /* clear next_to_watch to prevent false hangs */ |
| 1163 | tx_buffer->next_to_watch = NULL; |
| 1164 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 1165 | /* update the statistics for this packet */ |
| 1166 | total_bytes += tx_buffer->bytecount; |
| 1167 | total_packets += tx_buffer->gso_segs; |
| 1168 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1169 | /* free the skb */ |
Jesper Dangaard Brouer | a3a8749 | 2016-02-08 13:15:09 +0100 | [diff] [blame] | 1170 | napi_consume_skb(tx_buffer->skb, napi_budget); |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1171 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1172 | /* unmap skb header data */ |
| 1173 | dma_unmap_single(tx_ring->dev, |
| 1174 | dma_unmap_addr(tx_buffer, dma), |
| 1175 | dma_unmap_len(tx_buffer, len), |
| 1176 | DMA_TO_DEVICE); |
| 1177 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1178 | /* clear tx_buffer data */ |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1179 | dma_unmap_len_set(tx_buffer, len, 0); |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1180 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1181 | /* unmap remaining buffers */ |
| 1182 | while (tx_desc != eop_desc) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1183 | tx_buffer++; |
| 1184 | tx_desc++; |
| 1185 | i++; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1186 | if (unlikely(!i)) { |
| 1187 | i -= tx_ring->count; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1188 | tx_buffer = tx_ring->tx_buffer_info; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1189 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1190 | } |
| 1191 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1192 | /* unmap any remaining paged data */ |
| 1193 | if (dma_unmap_len(tx_buffer, len)) { |
| 1194 | dma_unmap_page(tx_ring->dev, |
| 1195 | dma_unmap_addr(tx_buffer, dma), |
| 1196 | dma_unmap_len(tx_buffer, len), |
| 1197 | DMA_TO_DEVICE); |
| 1198 | dma_unmap_len_set(tx_buffer, len, 0); |
| 1199 | } |
| 1200 | } |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 1201 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1202 | /* move us one more past the eop_desc for start of next pkt */ |
| 1203 | tx_buffer++; |
| 1204 | tx_desc++; |
| 1205 | i++; |
| 1206 | if (unlikely(!i)) { |
| 1207 | i -= tx_ring->count; |
| 1208 | tx_buffer = tx_ring->tx_buffer_info; |
| 1209 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
| 1210 | } |
| 1211 | |
| 1212 | /* issue prefetch for next Tx descriptor */ |
| 1213 | prefetch(tx_desc); |
| 1214 | |
| 1215 | /* update budget accounting */ |
| 1216 | budget--; |
| 1217 | } while (likely(budget)); |
| 1218 | |
| 1219 | i += tx_ring->count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1220 | tx_ring->next_to_clean = i; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1221 | u64_stats_update_begin(&tx_ring->syncp); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1222 | tx_ring->stats.bytes += total_bytes; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1223 | tx_ring->stats.packets += total_packets; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1224 | u64_stats_update_end(&tx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1225 | q_vector->tx.total_bytes += total_bytes; |
| 1226 | q_vector->tx.total_packets += total_packets; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1227 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1228 | 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] | 1229 | /* schedule immediate reset if we believe we hung */ |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1230 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1231 | e_err(drv, "Detected Tx Unit Hang\n" |
| 1232 | " Tx Queue <%d>\n" |
| 1233 | " TDH, TDT <%x>, <%x>\n" |
| 1234 | " next_to_use <%x>\n" |
| 1235 | " next_to_clean <%x>\n" |
| 1236 | "tx_buffer_info[next_to_clean]\n" |
| 1237 | " time_stamp <%lx>\n" |
| 1238 | " jiffies <%lx>\n", |
| 1239 | tx_ring->queue_index, |
| 1240 | IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)), |
| 1241 | IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)), |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1242 | tx_ring->next_to_use, i, |
| 1243 | tx_ring->tx_buffer_info[i].time_stamp, jiffies); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1244 | |
| 1245 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 1246 | |
| 1247 | e_info(probe, |
| 1248 | "tx hang %d detected on queue %d, resetting adapter\n", |
| 1249 | adapter->tx_timeout_count + 1, tx_ring->queue_index); |
| 1250 | |
| 1251 | /* schedule immediate reset if we believe we hung */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 1252 | ixgbe_tx_timeout_reset(adapter); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1253 | |
| 1254 | /* the adapter is about to reset, no point in enabling stuff */ |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 1255 | return true; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1256 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1257 | |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 1258 | netdev_tx_completed_queue(txring_txq(tx_ring), |
| 1259 | total_packets, total_bytes); |
| 1260 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 1261 | #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) |
Alexander Duyck | 30065e6 | 2011-07-15 03:05:14 +0000 | [diff] [blame] | 1262 | if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) && |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 1263 | (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 1264 | /* Make sure that anybody stopping the queue after this |
| 1265 | * sees the new next_to_clean. |
| 1266 | */ |
| 1267 | smp_mb(); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1268 | if (__netif_subqueue_stopped(tx_ring->netdev, |
| 1269 | tx_ring->queue_index) |
| 1270 | && !test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1271 | netif_wake_subqueue(tx_ring->netdev, |
| 1272 | tx_ring->queue_index); |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 1273 | ++tx_ring->tx_stats.restart_queue; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 1274 | } |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 1275 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1276 | |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 1277 | return !!budget; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1278 | } |
| 1279 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1280 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1281 | static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter, |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1282 | struct ixgbe_ring *tx_ring, |
| 1283 | int cpu) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1284 | { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 1285 | struct ixgbe_hw *hw = &adapter->hw; |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1286 | u32 txctrl = 0; |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1287 | u16 reg_offset; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1288 | |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1289 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1290 | txctrl = dca3_get_tag(tx_ring->dev, cpu); |
| 1291 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1292 | switch (hw->mac.type) { |
| 1293 | case ixgbe_mac_82598EB: |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1294 | reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1295 | break; |
| 1296 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1297 | case ixgbe_mac_X540: |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1298 | reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx); |
| 1299 | txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599; |
| 1300 | break; |
| 1301 | default: |
| 1302 | /* for unknown hardware do not write register */ |
| 1303 | return; |
| 1304 | } |
| 1305 | |
| 1306 | /* |
| 1307 | * We can enable relaxed ordering for reads, but not writes when |
| 1308 | * DCA is enabled. This is due to a known issue in some chipsets |
| 1309 | * which will cause the DCA tag to be cleared. |
| 1310 | */ |
| 1311 | txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN | |
| 1312 | IXGBE_DCA_TXCTRL_DATA_RRO_EN | |
| 1313 | IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
| 1314 | |
| 1315 | IXGBE_WRITE_REG(hw, reg_offset, txctrl); |
| 1316 | } |
| 1317 | |
| 1318 | static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter, |
| 1319 | struct ixgbe_ring *rx_ring, |
| 1320 | int cpu) |
| 1321 | { |
| 1322 | struct ixgbe_hw *hw = &adapter->hw; |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1323 | u32 rxctrl = 0; |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1324 | u8 reg_idx = rx_ring->reg_idx; |
| 1325 | |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1326 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1327 | rxctrl = dca3_get_tag(rx_ring->dev, cpu); |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1328 | |
| 1329 | switch (hw->mac.type) { |
| 1330 | case ixgbe_mac_82599EB: |
| 1331 | case ixgbe_mac_X540: |
| 1332 | rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1333 | break; |
| 1334 | default: |
| 1335 | break; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1336 | } |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1337 | |
| 1338 | /* |
| 1339 | * We can enable relaxed ordering for reads, but not writes when |
| 1340 | * DCA is enabled. This is due to a known issue in some chipsets |
| 1341 | * which will cause the DCA tag to be cleared. |
| 1342 | */ |
| 1343 | rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN | |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1344 | IXGBE_DCA_RXCTRL_DATA_DCA_EN | |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1345 | IXGBE_DCA_RXCTRL_DESC_DCA_EN; |
| 1346 | |
| 1347 | IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector) |
| 1351 | { |
| 1352 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1353 | struct ixgbe_ring *ring; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1354 | int cpu = get_cpu(); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1355 | |
| 1356 | if (q_vector->cpu == cpu) |
| 1357 | goto out_no_update; |
| 1358 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 1359 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1360 | ixgbe_update_tx_dca(adapter, ring, cpu); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1361 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 1362 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1363 | ixgbe_update_rx_dca(adapter, ring, cpu); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1364 | |
| 1365 | q_vector->cpu = cpu; |
| 1366 | out_no_update: |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1367 | put_cpu(); |
| 1368 | } |
| 1369 | |
| 1370 | static void ixgbe_setup_dca(struct ixgbe_adapter *adapter) |
| 1371 | { |
| 1372 | int i; |
| 1373 | |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 1374 | /* always use CB2 mode, difference is masked in the CB driver */ |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1375 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1376 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 1377 | IXGBE_DCA_CTRL_DCA_MODE_CB2); |
| 1378 | else |
| 1379 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 1380 | IXGBE_DCA_CTRL_DCA_DISABLE); |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 1381 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 1382 | for (i = 0; i < adapter->num_q_vectors; i++) { |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1383 | adapter->q_vector[i]->cpu = -1; |
| 1384 | ixgbe_update_dca(adapter->q_vector[i]); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1385 | } |
| 1386 | } |
| 1387 | |
| 1388 | static int __ixgbe_notify_dca(struct device *dev, void *data) |
| 1389 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 1390 | struct ixgbe_adapter *adapter = dev_get_drvdata(dev); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1391 | unsigned long event = *(unsigned long *)data; |
| 1392 | |
Don Skidmore | 2a72c31 | 2011-07-20 02:27:05 +0000 | [diff] [blame] | 1393 | if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE)) |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1394 | return 0; |
| 1395 | |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1396 | switch (event) { |
| 1397 | case DCA_PROVIDER_ADD: |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 1398 | /* if we're already enabled, don't do it again */ |
| 1399 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1400 | break; |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 1401 | if (dca_add_requester(dev) == 0) { |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 1402 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1403 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 1404 | IXGBE_DCA_CTRL_DCA_MODE_CB2); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1405 | break; |
| 1406 | } |
| 1407 | /* Fall Through since DCA is disabled. */ |
| 1408 | case DCA_PROVIDER_REMOVE: |
| 1409 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 1410 | dca_remove_requester(dev); |
| 1411 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1412 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 1413 | IXGBE_DCA_CTRL_DCA_DISABLE); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1414 | } |
| 1415 | break; |
| 1416 | } |
| 1417 | |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 1418 | return 0; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1419 | } |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1420 | |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1421 | #endif /* CONFIG_IXGBE_DCA */ |
Fan Du | 7edda4b8 | 2015-04-29 10:57:39 +0800 | [diff] [blame] | 1422 | |
| 1423 | #define IXGBE_RSS_L4_TYPES_MASK \ |
| 1424 | ((1ul << IXGBE_RXDADV_RSSTYPE_IPV4_TCP) | \ |
| 1425 | (1ul << IXGBE_RXDADV_RSSTYPE_IPV4_UDP) | \ |
| 1426 | (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_TCP) | \ |
| 1427 | (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_UDP)) |
| 1428 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1429 | static inline void ixgbe_rx_hash(struct ixgbe_ring *ring, |
| 1430 | union ixgbe_adv_rx_desc *rx_desc, |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1431 | struct sk_buff *skb) |
| 1432 | { |
Fan Du | 7edda4b8 | 2015-04-29 10:57:39 +0800 | [diff] [blame] | 1433 | u16 rss_type; |
| 1434 | |
| 1435 | if (!(ring->netdev->features & NETIF_F_RXHASH)) |
| 1436 | return; |
| 1437 | |
| 1438 | rss_type = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) & |
| 1439 | IXGBE_RXDADV_RSSTYPE_MASK; |
| 1440 | |
| 1441 | if (!rss_type) |
| 1442 | return; |
| 1443 | |
| 1444 | skb_set_hash(skb, le32_to_cpu(rx_desc->wb.lower.hi_dword.rss), |
| 1445 | (IXGBE_RSS_L4_TYPES_MASK & (1ul << rss_type)) ? |
| 1446 | PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3); |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1447 | } |
| 1448 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1449 | #ifdef IXGBE_FCOE |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1450 | /** |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1451 | * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1452 | * @ring: structure containing ring specific data |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1453 | * @rx_desc: advanced rx descriptor |
| 1454 | * |
| 1455 | * Returns : true if it is FCoE pkt |
| 1456 | */ |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1457 | static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring, |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1458 | union ixgbe_adv_rx_desc *rx_desc) |
| 1459 | { |
| 1460 | __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 1461 | |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1462 | return test_bit(__IXGBE_RX_FCOE, &ring->state) && |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1463 | ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) == |
| 1464 | (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE << |
| 1465 | IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT))); |
| 1466 | } |
| 1467 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1468 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1469 | /** |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1470 | * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1471 | * @ring: structure containing ring specific data |
| 1472 | * @rx_desc: current Rx descriptor being processed |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1473 | * @skb: skb currently being received and modified |
| 1474 | **/ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1475 | static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring, |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1476 | union ixgbe_adv_rx_desc *rx_desc, |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1477 | struct sk_buff *skb) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1478 | { |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1479 | __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] | 1480 | bool encap_pkt = false; |
| 1481 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1482 | skb_checksum_none_assert(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1483 | |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 1484 | /* Rx csum disabled */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1485 | if (!(ring->netdev->features & NETIF_F_RXCSUM)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1486 | return; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1487 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 1488 | /* check for VXLAN and Geneve packets */ |
| 1489 | if (pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_VXLAN)) { |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1490 | encap_pkt = true; |
| 1491 | skb->encapsulation = 1; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1492 | } |
| 1493 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1494 | /* if IP and error */ |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1495 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) && |
| 1496 | ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1497 | ring->rx_stats.csum_err++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1498 | return; |
| 1499 | } |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1500 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1501 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS)) |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1502 | return; |
| 1503 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1504 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) { |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1505 | /* |
| 1506 | * 82599 errata, UDP frames with a 0 checksum can be marked as |
| 1507 | * checksum errors. |
| 1508 | */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1509 | if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) && |
| 1510 | test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state)) |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1511 | return; |
| 1512 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1513 | ring->rx_stats.csum_err++; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1514 | return; |
| 1515 | } |
| 1516 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1517 | /* It must be a TCP or UDP packet with a valid checksum */ |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1518 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1519 | if (encap_pkt) { |
| 1520 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_OUTERIPCS)) |
| 1521 | return; |
| 1522 | |
| 1523 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_OUTERIPER)) { |
Mark Rustad | d469251 | 2015-12-04 11:26:43 -0800 | [diff] [blame] | 1524 | skb->ip_summed = CHECKSUM_NONE; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1525 | return; |
| 1526 | } |
| 1527 | /* If we checked the outer header let the stack know */ |
| 1528 | skb->csum_level = 1; |
| 1529 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1530 | } |
| 1531 | |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 1532 | static inline unsigned int ixgbe_rx_offset(struct ixgbe_ring *rx_ring) |
| 1533 | { |
| 1534 | return ring_uses_build_skb(rx_ring) ? IXGBE_SKB_PAD : 0; |
| 1535 | } |
| 1536 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1537 | static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring, |
| 1538 | struct ixgbe_rx_buffer *bi) |
| 1539 | { |
| 1540 | struct page *page = bi->page; |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1541 | dma_addr_t dma; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1542 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1543 | /* since we are recycling buffers we should seldom need to alloc */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1544 | if (likely(page)) |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1545 | return true; |
| 1546 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1547 | /* alloc new page for storage */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1548 | page = dev_alloc_pages(ixgbe_rx_pg_order(rx_ring)); |
| 1549 | if (unlikely(!page)) { |
| 1550 | rx_ring->rx_stats.alloc_rx_page_failed++; |
| 1551 | return false; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1552 | } |
| 1553 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1554 | /* map page for use */ |
Alexander Duyck | f3213d9 | 2017-01-17 08:35:54 -0800 | [diff] [blame] | 1555 | dma = dma_map_page_attrs(rx_ring->dev, page, 0, |
| 1556 | ixgbe_rx_pg_size(rx_ring), |
| 1557 | DMA_FROM_DEVICE, |
| 1558 | IXGBE_RX_DMA_ATTR); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1559 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1560 | /* |
| 1561 | * if mapping failed free memory back to system since |
| 1562 | * there isn't much point in holding memory we can't use |
| 1563 | */ |
| 1564 | if (dma_mapping_error(rx_ring->dev, dma)) { |
Alexander Duyck | dd411ec | 2012-04-06 04:24:50 +0000 | [diff] [blame] | 1565 | __free_pages(page, ixgbe_rx_pg_order(rx_ring)); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1566 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1567 | rx_ring->rx_stats.alloc_rx_page_failed++; |
| 1568 | return false; |
| 1569 | } |
| 1570 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1571 | bi->dma = dma; |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1572 | bi->page = page; |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 1573 | bi->page_offset = ixgbe_rx_offset(rx_ring); |
Alexander Duyck | 1b56cf4 | 2017-01-17 08:36:03 -0800 | [diff] [blame] | 1574 | bi->pagecnt_bias = 1; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1575 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1576 | return true; |
| 1577 | } |
| 1578 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1579 | /** |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1580 | * ixgbe_alloc_rx_buffers - Replace used receive buffers |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1581 | * @rx_ring: ring to place buffers on |
| 1582 | * @cleaned_count: number of buffers to replace |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1583 | **/ |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1584 | 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] | 1585 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1586 | union ixgbe_adv_rx_desc *rx_desc; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1587 | struct ixgbe_rx_buffer *bi; |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1588 | u16 i = rx_ring->next_to_use; |
Alexander Duyck | 4f4542b | 2017-01-17 08:36:14 -0800 | [diff] [blame] | 1589 | u16 bufsz; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1590 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1591 | /* nothing to do */ |
| 1592 | if (!cleaned_count) |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1593 | return; |
| 1594 | |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1595 | rx_desc = IXGBE_RX_DESC(rx_ring, i); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1596 | bi = &rx_ring->rx_buffer_info[i]; |
| 1597 | i -= rx_ring->count; |
| 1598 | |
Alexander Duyck | 4f4542b | 2017-01-17 08:36:14 -0800 | [diff] [blame] | 1599 | bufsz = ixgbe_rx_bufsz(rx_ring); |
| 1600 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1601 | do { |
| 1602 | if (!ixgbe_alloc_mapped_page(rx_ring, bi)) |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1603 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1604 | |
Alexander Duyck | f3213d9 | 2017-01-17 08:35:54 -0800 | [diff] [blame] | 1605 | /* sync the buffer for use by the device */ |
| 1606 | dma_sync_single_range_for_device(rx_ring->dev, bi->dma, |
Alexander Duyck | 4f4542b | 2017-01-17 08:36:14 -0800 | [diff] [blame] | 1607 | bi->page_offset, bufsz, |
Alexander Duyck | f3213d9 | 2017-01-17 08:35:54 -0800 | [diff] [blame] | 1608 | DMA_FROM_DEVICE); |
| 1609 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1610 | /* |
| 1611 | * Refresh the desc even if buffer_addrs didn't change |
| 1612 | * because each write-back erases this info. |
| 1613 | */ |
| 1614 | 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] | 1615 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1616 | rx_desc++; |
| 1617 | bi++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1618 | i++; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1619 | if (unlikely(!i)) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1620 | rx_desc = IXGBE_RX_DESC(rx_ring, 0); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1621 | bi = rx_ring->rx_buffer_info; |
| 1622 | i -= rx_ring->count; |
| 1623 | } |
| 1624 | |
Alexander Duyck | c3630cc | 2017-01-17 08:36:28 -0800 | [diff] [blame] | 1625 | /* clear the length for the next_to_use descriptor */ |
| 1626 | rx_desc->wb.upper.length = 0; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1627 | |
| 1628 | cleaned_count--; |
| 1629 | } while (cleaned_count); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1630 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1631 | i += rx_ring->count; |
| 1632 | |
Alexander Duyck | ad435ec | 2014-11-14 00:56:35 +0000 | [diff] [blame] | 1633 | if (rx_ring->next_to_use != i) { |
| 1634 | rx_ring->next_to_use = i; |
| 1635 | |
| 1636 | /* update next to alloc since we have filled the ring */ |
| 1637 | rx_ring->next_to_alloc = i; |
| 1638 | |
| 1639 | /* Force memory writes to complete before letting h/w |
| 1640 | * know there are new descriptors to fetch. (Only |
| 1641 | * applicable for weak-ordered memory model archs, |
| 1642 | * such as IA-64). |
| 1643 | */ |
| 1644 | wmb(); |
| 1645 | writel(i, rx_ring->tail); |
| 1646 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1647 | } |
| 1648 | |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1649 | static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring, |
| 1650 | struct sk_buff *skb) |
| 1651 | { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1652 | u16 hdr_len = skb_headlen(skb); |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1653 | |
| 1654 | /* set gso_size to avoid messing up TCP MSS */ |
| 1655 | skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len), |
| 1656 | IXGBE_CB(skb)->append_cnt); |
Alexander Duyck | 96be80a | 2013-02-12 09:45:44 +0000 | [diff] [blame] | 1657 | skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4; |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1658 | } |
| 1659 | |
| 1660 | static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring, |
| 1661 | struct sk_buff *skb) |
| 1662 | { |
| 1663 | /* if append_cnt is 0 then frame is not RSC */ |
| 1664 | if (!IXGBE_CB(skb)->append_cnt) |
| 1665 | return; |
| 1666 | |
| 1667 | rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt; |
| 1668 | rx_ring->rx_stats.rsc_flush++; |
| 1669 | |
| 1670 | ixgbe_set_rsc_gso_size(rx_ring, skb); |
| 1671 | |
| 1672 | /* gso_size is computed using append_cnt so always clear it last */ |
| 1673 | IXGBE_CB(skb)->append_cnt = 0; |
| 1674 | } |
| 1675 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1676 | /** |
| 1677 | * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor |
| 1678 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1679 | * @rx_desc: pointer to the EOP Rx descriptor |
| 1680 | * @skb: pointer to current skb being populated |
| 1681 | * |
| 1682 | * This function checks the ring, descriptor, and packet information in |
| 1683 | * order to populate the hash, checksum, VLAN, timestamp, protocol, and |
| 1684 | * other fields within the skb. |
| 1685 | **/ |
| 1686 | static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring, |
| 1687 | union ixgbe_adv_rx_desc *rx_desc, |
| 1688 | struct sk_buff *skb) |
| 1689 | { |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1690 | struct net_device *dev = rx_ring->netdev; |
Mark Rustad | a9763f3 | 2015-10-27 09:58:07 -0700 | [diff] [blame] | 1691 | u32 flags = rx_ring->q_vector->adapter->flags; |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1692 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1693 | ixgbe_update_rsc_stats(rx_ring, skb); |
| 1694 | |
| 1695 | ixgbe_rx_hash(rx_ring, rx_desc, skb); |
| 1696 | |
| 1697 | ixgbe_rx_checksum(rx_ring, rx_desc, skb); |
| 1698 | |
Mark Rustad | a9763f3 | 2015-10-27 09:58:07 -0700 | [diff] [blame] | 1699 | if (unlikely(flags & IXGBE_FLAG_RX_HWTSTAMP_ENABLED)) |
| 1700 | ixgbe_ptp_rx_hwtstamp(rx_ring, rx_desc, skb); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 1701 | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 1702 | if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) && |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1703 | ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1704 | u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan); |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 1705 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid); |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1706 | } |
| 1707 | |
| 1708 | skb_record_rx_queue(skb, rx_ring->queue_index); |
| 1709 | |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1710 | skb->protocol = eth_type_trans(skb, dev); |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector, |
| 1714 | struct sk_buff *skb) |
| 1715 | { |
Eric Dumazet | 3ffc1af | 2017-02-02 16:26:39 -0800 | [diff] [blame] | 1716 | napi_gro_receive(&q_vector->napi, skb); |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1717 | } |
Mallikarjuna R Chilakala | 43634e8 | 2010-02-25 23:14:37 +0000 | [diff] [blame] | 1718 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1719 | /** |
| 1720 | * ixgbe_is_non_eop - process handling of non-EOP buffers |
| 1721 | * @rx_ring: Rx ring being processed |
| 1722 | * @rx_desc: Rx descriptor for current buffer |
| 1723 | * @skb: Current socket buffer containing buffer in progress |
| 1724 | * |
| 1725 | * This function updates next to clean. If the buffer is an EOP buffer |
| 1726 | * this function exits returning false, otherwise it will place the |
| 1727 | * sk_buff in the next buffer to be chained and return true indicating |
| 1728 | * that this is in fact a non-EOP buffer. |
| 1729 | **/ |
| 1730 | static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring, |
| 1731 | union ixgbe_adv_rx_desc *rx_desc, |
| 1732 | struct sk_buff *skb) |
| 1733 | { |
| 1734 | u32 ntc = rx_ring->next_to_clean + 1; |
| 1735 | |
| 1736 | /* fetch, update, and store next to clean */ |
| 1737 | ntc = (ntc < rx_ring->count) ? ntc : 0; |
| 1738 | rx_ring->next_to_clean = ntc; |
| 1739 | |
| 1740 | prefetch(IXGBE_RX_DESC(rx_ring, ntc)); |
| 1741 | |
Alexander Duyck | 5a02cbd | 2012-07-20 08:08:51 +0000 | [diff] [blame] | 1742 | /* update RSC append count if present */ |
| 1743 | if (ring_is_rsc_enabled(rx_ring)) { |
| 1744 | __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data & |
| 1745 | cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK); |
| 1746 | |
| 1747 | if (unlikely(rsc_enabled)) { |
| 1748 | u32 rsc_cnt = le32_to_cpu(rsc_enabled); |
| 1749 | |
| 1750 | rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT; |
| 1751 | IXGBE_CB(skb)->append_cnt += rsc_cnt - 1; |
| 1752 | |
| 1753 | /* update ntc based on RSC value */ |
| 1754 | ntc = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 1755 | ntc &= IXGBE_RXDADV_NEXTP_MASK; |
| 1756 | ntc >>= IXGBE_RXDADV_NEXTP_SHIFT; |
| 1757 | } |
| 1758 | } |
| 1759 | |
| 1760 | /* 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] | 1761 | if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))) |
| 1762 | return false; |
| 1763 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1764 | /* place skb in next buffer to be received */ |
| 1765 | rx_ring->rx_buffer_info[ntc].skb = skb; |
| 1766 | rx_ring->rx_stats.non_eop_descs++; |
| 1767 | |
| 1768 | return true; |
| 1769 | } |
| 1770 | |
| 1771 | /** |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1772 | * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail |
| 1773 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1774 | * @skb: pointer to current skb being adjusted |
| 1775 | * |
| 1776 | * This function is an ixgbe specific version of __pskb_pull_tail. The |
| 1777 | * main difference between this version and the original function is that |
| 1778 | * this function can make several assumptions about the state of things |
| 1779 | * that allow for significant optimizations versus the standard function. |
| 1780 | * As a result we can do things like drop a frag and maintain an accurate |
| 1781 | * truesize for the skb. |
| 1782 | */ |
| 1783 | static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring, |
| 1784 | struct sk_buff *skb) |
| 1785 | { |
| 1786 | struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0]; |
| 1787 | unsigned char *va; |
| 1788 | unsigned int pull_len; |
| 1789 | |
| 1790 | /* |
| 1791 | * it is valid to use page_address instead of kmap since we are |
| 1792 | * working with pages allocated out of the lomem pool per |
| 1793 | * alloc_page(GFP_ATOMIC) |
| 1794 | */ |
| 1795 | va = skb_frag_address(frag); |
| 1796 | |
| 1797 | /* |
| 1798 | * we need the header to contain the greater of either ETH_HLEN or |
| 1799 | * 60 bytes if the skb->len is less than 60 for skb_pad. |
| 1800 | */ |
Alexander Duyck | 8496e338 | 2014-09-05 19:22:18 -0400 | [diff] [blame] | 1801 | pull_len = eth_get_headlen(va, IXGBE_RX_HDR_SIZE); |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1802 | |
| 1803 | /* align pull length to size of long to optimize memcpy performance */ |
| 1804 | skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long))); |
| 1805 | |
| 1806 | /* update all of the pointers */ |
| 1807 | skb_frag_size_sub(frag, pull_len); |
| 1808 | frag->page_offset += pull_len; |
| 1809 | skb->data_len -= pull_len; |
| 1810 | skb->tail += pull_len; |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | /** |
Alexander Duyck | 42073d9 | 2012-07-20 08:08:28 +0000 | [diff] [blame] | 1814 | * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB |
| 1815 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1816 | * @skb: pointer to current skb being updated |
| 1817 | * |
| 1818 | * This function provides a basic DMA sync up for the first fragment of an |
| 1819 | * skb. The reason for doing this is that the first fragment cannot be |
| 1820 | * unmapped until we have reached the end of packet descriptor for a buffer |
| 1821 | * chain. |
| 1822 | */ |
| 1823 | static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring, |
| 1824 | struct sk_buff *skb) |
| 1825 | { |
| 1826 | /* if the page was released unmap it, else just sync our portion */ |
| 1827 | if (unlikely(IXGBE_CB(skb)->page_released)) { |
Alexander Duyck | f3213d9 | 2017-01-17 08:35:54 -0800 | [diff] [blame] | 1828 | dma_unmap_page_attrs(rx_ring->dev, IXGBE_CB(skb)->dma, |
| 1829 | ixgbe_rx_pg_size(rx_ring), |
| 1830 | DMA_FROM_DEVICE, |
| 1831 | IXGBE_RX_DMA_ATTR); |
Alexander Duyck | 42073d9 | 2012-07-20 08:08:28 +0000 | [diff] [blame] | 1832 | } else { |
| 1833 | struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0]; |
| 1834 | |
| 1835 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 1836 | IXGBE_CB(skb)->dma, |
| 1837 | frag->page_offset, |
Alexander Duyck | f215af8 | 2017-01-17 08:35:44 -0800 | [diff] [blame] | 1838 | skb_frag_size(frag), |
Alexander Duyck | 42073d9 | 2012-07-20 08:08:28 +0000 | [diff] [blame] | 1839 | DMA_FROM_DEVICE); |
| 1840 | } |
Alexander Duyck | 42073d9 | 2012-07-20 08:08:28 +0000 | [diff] [blame] | 1841 | } |
| 1842 | |
| 1843 | /** |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1844 | * ixgbe_cleanup_headers - Correct corrupted or empty headers |
| 1845 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1846 | * @rx_desc: pointer to the EOP Rx descriptor |
| 1847 | * @skb: pointer to current skb being fixed |
| 1848 | * |
| 1849 | * Check for corrupted packet headers caused by senders on the local L2 |
| 1850 | * embedded NIC switch not setting up their Tx Descriptors right. These |
| 1851 | * should be very rare. |
| 1852 | * |
| 1853 | * Also address the case where we are pulling data in on pages only |
| 1854 | * and as such no data is present in the skb header. |
| 1855 | * |
| 1856 | * In addition if skb is not at least 60 bytes we need to pad it so that |
| 1857 | * it is large enough to qualify as a valid Ethernet frame. |
| 1858 | * |
| 1859 | * Returns true if an error was encountered and skb was freed. |
| 1860 | **/ |
| 1861 | static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring, |
| 1862 | union ixgbe_adv_rx_desc *rx_desc, |
| 1863 | struct sk_buff *skb) |
| 1864 | { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1865 | struct net_device *netdev = rx_ring->netdev; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1866 | |
| 1867 | /* verify that the packet does not have any known errors */ |
| 1868 | if (unlikely(ixgbe_test_staterr(rx_desc, |
| 1869 | IXGBE_RXDADV_ERR_FRAME_ERR_MASK) && |
| 1870 | !(netdev->features & NETIF_F_RXALL))) { |
| 1871 | dev_kfree_skb_any(skb); |
| 1872 | return true; |
| 1873 | } |
| 1874 | |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1875 | /* place header in linear portion of buffer */ |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 1876 | if (!skb_headlen(skb)) |
Alexander Duyck | cf3fe7a | 2012-07-20 08:08:39 +0000 | [diff] [blame] | 1877 | ixgbe_pull_tail(rx_ring, skb); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1878 | |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1879 | #ifdef IXGBE_FCOE |
| 1880 | /* do not attempt to pad FCoE Frames as this will disrupt DDP */ |
| 1881 | if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) |
| 1882 | return false; |
| 1883 | |
| 1884 | #endif |
Alexander Duyck | a94d9e2 | 2014-12-03 08:17:39 -0800 | [diff] [blame] | 1885 | /* if eth_skb_pad returns an error the skb was freed */ |
| 1886 | if (eth_skb_pad(skb)) |
| 1887 | return true; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1888 | |
| 1889 | return false; |
| 1890 | } |
| 1891 | |
| 1892 | /** |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1893 | * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring |
| 1894 | * @rx_ring: rx descriptor ring to store buffers on |
| 1895 | * @old_buff: donor buffer to have page reused |
| 1896 | * |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1897 | * Synchronizes page for reuse by the adapter |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1898 | **/ |
| 1899 | static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring, |
| 1900 | struct ixgbe_rx_buffer *old_buff) |
| 1901 | { |
| 1902 | struct ixgbe_rx_buffer *new_buff; |
| 1903 | u16 nta = rx_ring->next_to_alloc; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1904 | |
| 1905 | new_buff = &rx_ring->rx_buffer_info[nta]; |
| 1906 | |
| 1907 | /* update, and store next to alloc */ |
| 1908 | nta++; |
| 1909 | rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0; |
| 1910 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 1911 | /* Transfer page from old buffer to new buffer. |
| 1912 | * Move each member individually to avoid possible store |
| 1913 | * forwarding stalls and unnecessary copy of skb. |
| 1914 | */ |
| 1915 | new_buff->dma = old_buff->dma; |
| 1916 | new_buff->page = old_buff->page; |
| 1917 | new_buff->page_offset = old_buff->page_offset; |
| 1918 | new_buff->pagecnt_bias = old_buff->pagecnt_bias; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1919 | } |
| 1920 | |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1921 | static inline bool ixgbe_page_is_reserved(struct page *page) |
| 1922 | { |
Michal Hocko | 2f064f3 | 2015-08-21 14:11:51 -0700 | [diff] [blame] | 1923 | return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page); |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1924 | } |
| 1925 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 1926 | static bool ixgbe_can_reuse_rx_page(struct ixgbe_rx_buffer *rx_buffer) |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1927 | { |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 1928 | unsigned int pagecnt_bias = rx_buffer->pagecnt_bias; |
| 1929 | struct page *page = rx_buffer->page; |
Alexander Duyck | 1b56cf4 | 2017-01-17 08:36:03 -0800 | [diff] [blame] | 1930 | |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1931 | /* avoid re-using remote pages */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1932 | if (unlikely(ixgbe_page_is_reserved(page))) |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1933 | return false; |
| 1934 | |
| 1935 | #if (PAGE_SIZE < 8192) |
| 1936 | /* if we are only owner of page we can reuse it */ |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 1937 | if (unlikely((page_ref_count(page) - pagecnt_bias) > 1)) |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1938 | return false; |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1939 | #else |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 1940 | /* The last offset is a bit aggressive in that we assume the |
| 1941 | * worst case of FCoE being enabled and using a 3K buffer. |
| 1942 | * However this should have minimal impact as the 1K extra is |
| 1943 | * still less than one buffer in size. |
| 1944 | */ |
| 1945 | #define IXGBE_LAST_OFFSET \ |
| 1946 | (SKB_WITH_OVERHEAD(PAGE_SIZE) - IXGBE_RXBUFFER_3K) |
| 1947 | if (rx_buffer->page_offset > IXGBE_LAST_OFFSET) |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1948 | return false; |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1949 | #endif |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1950 | |
Alexander Duyck | 1b56cf4 | 2017-01-17 08:36:03 -0800 | [diff] [blame] | 1951 | /* If we have drained the page fragment pool we need to update |
| 1952 | * the pagecnt_bias and page count so that we fully restock the |
| 1953 | * number of references the driver holds. |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1954 | */ |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 1955 | if (unlikely(!pagecnt_bias)) { |
Alexander Duyck | 1b56cf4 | 2017-01-17 08:36:03 -0800 | [diff] [blame] | 1956 | page_ref_add(page, USHRT_MAX); |
| 1957 | rx_buffer->pagecnt_bias = USHRT_MAX; |
| 1958 | } |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1959 | |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1960 | return true; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1961 | } |
| 1962 | |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 1963 | /** |
| 1964 | * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff |
| 1965 | * @rx_ring: rx descriptor ring to transact packets on |
| 1966 | * @rx_buffer: buffer containing page to add |
| 1967 | * @rx_desc: descriptor containing length of buffer written by hardware |
| 1968 | * @skb: sk_buff to place the data into |
| 1969 | * |
| 1970 | * This function will add the data contained in rx_buffer->page to the skb. |
| 1971 | * This is done either through a direct copy if the data in the buffer is |
| 1972 | * less than the skb header size, otherwise it will just attach the page as |
| 1973 | * a frag to the skb. |
| 1974 | * |
| 1975 | * The function will then update the page offset if necessary and return |
| 1976 | * true if the buffer can be reused by the adapter. |
| 1977 | **/ |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 1978 | static void ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring, |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 1979 | struct ixgbe_rx_buffer *rx_buffer, |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 1980 | struct sk_buff *skb, |
| 1981 | unsigned int size) |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 1982 | { |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 1983 | #if (PAGE_SIZE < 8192) |
Alexander Duyck | 4f4542b | 2017-01-17 08:36:14 -0800 | [diff] [blame] | 1984 | unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2; |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 1985 | #else |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 1986 | unsigned int truesize = ring_uses_build_skb(rx_ring) ? |
| 1987 | SKB_DATA_ALIGN(IXGBE_SKB_PAD + size) : |
| 1988 | SKB_DATA_ALIGN(size); |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 1989 | #endif |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 1990 | skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_buffer->page, |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 1991 | rx_buffer->page_offset, size, truesize); |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 1992 | #if (PAGE_SIZE < 8192) |
| 1993 | rx_buffer->page_offset ^= truesize; |
| 1994 | #else |
| 1995 | rx_buffer->page_offset += truesize; |
| 1996 | #endif |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 1997 | } |
| 1998 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 1999 | static struct ixgbe_rx_buffer *ixgbe_get_rx_buffer(struct ixgbe_ring *rx_ring, |
| 2000 | union ixgbe_adv_rx_desc *rx_desc, |
| 2001 | struct sk_buff **skb, |
| 2002 | const unsigned int size) |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2003 | { |
| 2004 | struct ixgbe_rx_buffer *rx_buffer; |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2005 | |
| 2006 | rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean]; |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2007 | prefetchw(rx_buffer->page); |
| 2008 | *skb = rx_buffer->skb; |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2009 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2010 | /* Delay unmapping of the first packet. It carries the header |
| 2011 | * information, HW may still access the header after the writeback. |
| 2012 | * Only unmap it when EOP is reached |
| 2013 | */ |
| 2014 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)) { |
| 2015 | if (!*skb) |
| 2016 | goto skip_sync; |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2017 | } else { |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2018 | if (*skb) |
| 2019 | ixgbe_dma_sync_frag(rx_ring, *skb); |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2020 | } |
| 2021 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2022 | /* we are reusing so sync this buffer for CPU use */ |
| 2023 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 2024 | rx_buffer->dma, |
| 2025 | rx_buffer->page_offset, |
| 2026 | size, |
| 2027 | DMA_FROM_DEVICE); |
| 2028 | skip_sync: |
| 2029 | rx_buffer->pagecnt_bias--; |
| 2030 | |
| 2031 | return rx_buffer; |
| 2032 | } |
| 2033 | |
| 2034 | static void ixgbe_put_rx_buffer(struct ixgbe_ring *rx_ring, |
| 2035 | struct ixgbe_rx_buffer *rx_buffer, |
| 2036 | struct sk_buff *skb) |
| 2037 | { |
| 2038 | if (ixgbe_can_reuse_rx_page(rx_buffer)) { |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2039 | /* hand second half of page back to the ring */ |
| 2040 | ixgbe_reuse_rx_page(rx_ring, rx_buffer); |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2041 | } else { |
Alexander Duyck | 1b56cf4 | 2017-01-17 08:36:03 -0800 | [diff] [blame] | 2042 | if (IXGBE_CB(skb)->dma == rx_buffer->dma) { |
| 2043 | /* the page has been released from the ring */ |
| 2044 | IXGBE_CB(skb)->page_released = true; |
| 2045 | } else { |
| 2046 | /* we are not reusing the buffer so unmap it */ |
| 2047 | dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma, |
| 2048 | ixgbe_rx_pg_size(rx_ring), |
| 2049 | DMA_FROM_DEVICE, |
| 2050 | IXGBE_RX_DMA_ATTR); |
| 2051 | } |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2052 | __page_frag_cache_drain(rx_buffer->page, |
Alexander Duyck | 1b56cf4 | 2017-01-17 08:36:03 -0800 | [diff] [blame] | 2053 | rx_buffer->pagecnt_bias); |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2054 | } |
| 2055 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2056 | /* clear contents of rx_buffer */ |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2057 | rx_buffer->page = NULL; |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2058 | rx_buffer->skb = NULL; |
| 2059 | } |
| 2060 | |
| 2061 | static struct sk_buff *ixgbe_construct_skb(struct ixgbe_ring *rx_ring, |
| 2062 | struct ixgbe_rx_buffer *rx_buffer, |
| 2063 | union ixgbe_adv_rx_desc *rx_desc, |
| 2064 | unsigned int size) |
| 2065 | { |
| 2066 | void *va = page_address(rx_buffer->page) + rx_buffer->page_offset; |
| 2067 | #if (PAGE_SIZE < 8192) |
| 2068 | unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2; |
| 2069 | #else |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 2070 | unsigned int truesize = SKB_DATA_ALIGN(size); |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2071 | #endif |
| 2072 | struct sk_buff *skb; |
| 2073 | |
| 2074 | /* prefetch first cache line of first page */ |
| 2075 | prefetch(va); |
| 2076 | #if L1_CACHE_BYTES < 128 |
| 2077 | prefetch(va + L1_CACHE_BYTES); |
| 2078 | #endif |
| 2079 | |
| 2080 | /* allocate a skb to store the frags */ |
| 2081 | skb = napi_alloc_skb(&rx_ring->q_vector->napi, IXGBE_RX_HDR_SIZE); |
| 2082 | if (unlikely(!skb)) |
| 2083 | return NULL; |
| 2084 | |
| 2085 | if (size > IXGBE_RX_HDR_SIZE) { |
| 2086 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)) |
| 2087 | IXGBE_CB(skb)->dma = rx_buffer->dma; |
| 2088 | |
| 2089 | skb_add_rx_frag(skb, 0, rx_buffer->page, |
| 2090 | rx_buffer->page_offset, |
| 2091 | size, truesize); |
| 2092 | #if (PAGE_SIZE < 8192) |
| 2093 | rx_buffer->page_offset ^= truesize; |
| 2094 | #else |
| 2095 | rx_buffer->page_offset += truesize; |
| 2096 | #endif |
| 2097 | } else { |
| 2098 | memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long))); |
| 2099 | rx_buffer->pagecnt_bias++; |
| 2100 | } |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2101 | |
| 2102 | return skb; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2103 | } |
| 2104 | |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 2105 | static struct sk_buff *ixgbe_build_skb(struct ixgbe_ring *rx_ring, |
| 2106 | struct ixgbe_rx_buffer *rx_buffer, |
| 2107 | union ixgbe_adv_rx_desc *rx_desc, |
| 2108 | unsigned int size) |
| 2109 | { |
| 2110 | void *va = page_address(rx_buffer->page) + rx_buffer->page_offset; |
| 2111 | #if (PAGE_SIZE < 8192) |
| 2112 | unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2; |
| 2113 | #else |
| 2114 | unsigned int truesize = SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) + |
| 2115 | SKB_DATA_ALIGN(IXGBE_SKB_PAD + size); |
| 2116 | #endif |
| 2117 | struct sk_buff *skb; |
| 2118 | |
| 2119 | /* prefetch first cache line of first page */ |
| 2120 | prefetch(va); |
| 2121 | #if L1_CACHE_BYTES < 128 |
| 2122 | prefetch(va + L1_CACHE_BYTES); |
| 2123 | #endif |
| 2124 | |
Alexander Duyck | 3a1eb6d | 2017-02-15 09:15:59 -0800 | [diff] [blame] | 2125 | /* build an skb around the page buffer */ |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 2126 | skb = build_skb(va - IXGBE_SKB_PAD, truesize); |
| 2127 | if (unlikely(!skb)) |
| 2128 | return NULL; |
| 2129 | |
| 2130 | /* update pointers within the skb to store the data */ |
| 2131 | skb_reserve(skb, IXGBE_SKB_PAD); |
| 2132 | __skb_put(skb, size); |
| 2133 | |
| 2134 | /* record DMA address if this is the start of a chain of buffers */ |
| 2135 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)) |
| 2136 | IXGBE_CB(skb)->dma = rx_buffer->dma; |
| 2137 | |
| 2138 | /* update buffer offset */ |
| 2139 | #if (PAGE_SIZE < 8192) |
| 2140 | rx_buffer->page_offset ^= truesize; |
| 2141 | #else |
| 2142 | rx_buffer->page_offset += truesize; |
| 2143 | #endif |
| 2144 | |
| 2145 | return skb; |
| 2146 | } |
| 2147 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2148 | /** |
| 2149 | * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf |
| 2150 | * @q_vector: structure containing interrupt and ring information |
| 2151 | * @rx_ring: rx descriptor ring to transact packets on |
| 2152 | * @budget: Total limit on number of packets to process |
| 2153 | * |
| 2154 | * This function provides a "bounce buffer" approach to Rx interrupt |
| 2155 | * processing. The advantage to this is that on systems that have |
| 2156 | * expensive overhead for IOMMU access this provides a means of avoiding |
| 2157 | * it by maintaining the mapping of the page to the syste. |
| 2158 | * |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2159 | * Returns amount of work completed |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2160 | **/ |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2161 | static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2162 | struct ixgbe_ring *rx_ring, |
Alexander Duyck | f4de00e | 2012-09-25 00:29:37 +0000 | [diff] [blame] | 2163 | const int budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2164 | { |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 2165 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 2166 | #ifdef IXGBE_FCOE |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2167 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Mark Rustad | 4ffdf91 | 2012-07-18 06:05:50 +0000 | [diff] [blame] | 2168 | int ddp_bytes; |
| 2169 | unsigned int mss = 0; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 2170 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2171 | u16 cleaned_count = ixgbe_desc_unused(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2172 | |
Eric W. Biederman | fdabfc8a | 2014-03-14 18:00:41 -0700 | [diff] [blame] | 2173 | while (likely(total_rx_packets < budget)) { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2174 | union ixgbe_adv_rx_desc *rx_desc; |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2175 | struct ixgbe_rx_buffer *rx_buffer; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2176 | struct sk_buff *skb; |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2177 | unsigned int size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2178 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2179 | /* return some buffers to hardware, one at a time is too slow */ |
| 2180 | if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) { |
| 2181 | ixgbe_alloc_rx_buffers(rx_ring, cleaned_count); |
| 2182 | cleaned_count = 0; |
| 2183 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2184 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2185 | rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean); |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2186 | size = le16_to_cpu(rx_desc->wb.upper.length); |
| 2187 | if (!size) |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2188 | break; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 2189 | |
Alexander Duyck | 124b74c | 2014-12-11 15:02:28 -0800 | [diff] [blame] | 2190 | /* This memory barrier is needed to keep us from reading |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2191 | * any other fields out of the rx_desc until we know the |
Alexander Duyck | 124b74c | 2014-12-11 15:02:28 -0800 | [diff] [blame] | 2192 | * descriptor has been written back |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2193 | */ |
Alexander Duyck | 124b74c | 2014-12-11 15:02:28 -0800 | [diff] [blame] | 2194 | dma_rmb(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2195 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2196 | rx_buffer = ixgbe_get_rx_buffer(rx_ring, rx_desc, &skb, size); |
| 2197 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2198 | /* retrieve a buffer from the ring */ |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2199 | if (skb) |
| 2200 | ixgbe_add_rx_frag(rx_ring, rx_buffer, skb, size); |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 2201 | else if (ring_uses_build_skb(rx_ring)) |
| 2202 | skb = ixgbe_build_skb(rx_ring, rx_buffer, |
| 2203 | rx_desc, size); |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2204 | else |
| 2205 | skb = ixgbe_construct_skb(rx_ring, rx_buffer, |
| 2206 | rx_desc, size); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2207 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2208 | /* exit if we failed to retrieve a buffer */ |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2209 | if (!skb) { |
| 2210 | rx_ring->rx_stats.alloc_rx_buff_failed++; |
| 2211 | rx_buffer->pagecnt_bias++; |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2212 | break; |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2213 | } |
Alexander Duyck | 4c1975d | 2012-01-31 02:59:23 +0000 | [diff] [blame] | 2214 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2215 | ixgbe_put_rx_buffer(rx_ring, rx_buffer, skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2216 | cleaned_count++; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2217 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2218 | /* place incomplete frames back on ring for completion */ |
| 2219 | if (ixgbe_is_non_eop(rx_ring, rx_desc, skb)) |
| 2220 | continue; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2221 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2222 | /* verify the packet layout is correct */ |
| 2223 | if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb)) |
| 2224 | continue; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 2225 | |
| 2226 | /* probably a little skewed due to removing CRC */ |
| 2227 | total_rx_bytes += skb->len; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 2228 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 2229 | /* populate checksum, timestamp, VLAN, and protocol */ |
| 2230 | ixgbe_process_skb_fields(rx_ring, rx_desc, skb); |
| 2231 | |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 2232 | #ifdef IXGBE_FCOE |
| 2233 | /* if ddp, not passing to ULD unless for FCP_RSP or error */ |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 2234 | if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) { |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 2235 | ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb); |
Mark Rustad | 4ffdf91 | 2012-07-18 06:05:50 +0000 | [diff] [blame] | 2236 | /* include DDPed FCoE data */ |
| 2237 | if (ddp_bytes > 0) { |
| 2238 | if (!mss) { |
| 2239 | mss = rx_ring->netdev->mtu - |
| 2240 | sizeof(struct fcoe_hdr) - |
| 2241 | sizeof(struct fc_frame_header) - |
| 2242 | sizeof(struct fcoe_crc_eof); |
| 2243 | if (mss > 512) |
| 2244 | mss &= ~511; |
| 2245 | } |
| 2246 | total_rx_bytes += ddp_bytes; |
| 2247 | total_rx_packets += DIV_ROUND_UP(ddp_bytes, |
| 2248 | mss); |
| 2249 | } |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 2250 | if (!ddp_bytes) { |
| 2251 | dev_kfree_skb_any(skb); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2252 | continue; |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 2253 | } |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 2254 | } |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2255 | |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 2256 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 2257 | ixgbe_rx_skb(q_vector, skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2258 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2259 | /* update budget accounting */ |
Alexander Duyck | f4de00e | 2012-09-25 00:29:37 +0000 | [diff] [blame] | 2260 | total_rx_packets++; |
Eric W. Biederman | fdabfc8a | 2014-03-14 18:00:41 -0700 | [diff] [blame] | 2261 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2262 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 2263 | u64_stats_update_begin(&rx_ring->syncp); |
| 2264 | rx_ring->stats.packets += total_rx_packets; |
| 2265 | rx_ring->stats.bytes += total_rx_bytes; |
| 2266 | u64_stats_update_end(&rx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2267 | q_vector->rx.total_packets += total_rx_packets; |
| 2268 | q_vector->rx.total_bytes += total_rx_bytes; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2269 | |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2270 | return total_rx_packets; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2271 | } |
| 2272 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2273 | /** |
| 2274 | * ixgbe_configure_msix - Configure MSI-X hardware |
| 2275 | * @adapter: board private structure |
| 2276 | * |
| 2277 | * ixgbe_configure_msix sets up the hardware to properly generate MSI-X |
| 2278 | * interrupts. |
| 2279 | **/ |
| 2280 | static void ixgbe_configure_msix(struct ixgbe_adapter *adapter) |
| 2281 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2282 | struct ixgbe_q_vector *q_vector; |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2283 | int v_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2284 | u32 mask; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2285 | |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 2286 | /* Populate MSIX to EITR Select */ |
| 2287 | if (adapter->num_vfs > 32) { |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 2288 | u32 eitrsel = BIT(adapter->num_vfs - 32) - 1; |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 2289 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel); |
| 2290 | } |
| 2291 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 2292 | /* |
| 2293 | * Populate the IVAR table and set the ITR values to the |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2294 | * corresponding register. |
| 2295 | */ |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2296 | for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) { |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2297 | struct ixgbe_ring *ring; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2298 | q_vector = adapter->q_vector[v_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2299 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 2300 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2301 | ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2302 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 2303 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2304 | ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2305 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2306 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2307 | } |
| 2308 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2309 | switch (adapter->hw.mac.type) { |
| 2310 | case ixgbe_mac_82598EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2311 | ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2312 | v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2313 | break; |
| 2314 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2315 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2316 | case ixgbe_mac_X550: |
| 2317 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2318 | case ixgbe_mac_x550em_a: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2319 | ixgbe_set_ivar(adapter, -1, 1, v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2320 | break; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2321 | default: |
| 2322 | break; |
| 2323 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2324 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2325 | |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 2326 | /* set up to autoclear timer, and the vectors */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2327 | mask = IXGBE_EIMS_ENABLE_MASK; |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2328 | mask &= ~(IXGBE_EIMS_OTHER | |
| 2329 | IXGBE_EIMS_MAILBOX | |
| 2330 | IXGBE_EIMS_LSC); |
| 2331 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2332 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2333 | } |
| 2334 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2335 | enum latency_range { |
| 2336 | lowest_latency = 0, |
| 2337 | low_latency = 1, |
| 2338 | bulk_latency = 2, |
| 2339 | latency_invalid = 255 |
| 2340 | }; |
| 2341 | |
| 2342 | /** |
| 2343 | * ixgbe_update_itr - update the dynamic ITR value based on statistics |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2344 | * @q_vector: structure containing interrupt and ring information |
| 2345 | * @ring_container: structure containing ring performance data |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2346 | * |
| 2347 | * Stores a new ITR value based on packets and byte |
| 2348 | * counts during the last interrupt. The advantage of per interrupt |
| 2349 | * computation is faster updates and more accurate ITR for the current |
| 2350 | * traffic pattern. Constants in this function were computed |
| 2351 | * based on theoretical maximum wire speed and thresholds were set based |
| 2352 | * on testing data as well as attempting to minimize response time |
| 2353 | * while increasing bulk throughput. |
| 2354 | * this functionality is controlled by the InterruptThrottleRate module |
| 2355 | * parameter (see ixgbe_param.c) |
| 2356 | **/ |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2357 | static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector, |
| 2358 | struct ixgbe_ring_container *ring_container) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2359 | { |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2360 | int bytes = ring_container->total_bytes; |
| 2361 | int packets = ring_container->total_packets; |
| 2362 | u32 timepassed_us; |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2363 | u64 bytes_perint; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2364 | u8 itr_setting = ring_container->itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2365 | |
| 2366 | if (packets == 0) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2367 | return; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2368 | |
| 2369 | /* simple throttlerate management |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2370 | * 0-10MB/s lowest (100000 ints/s) |
| 2371 | * 10-20MB/s low (20000 ints/s) |
Alexander Duyck | 8ac34f1 | 2015-07-30 15:19:28 -0700 | [diff] [blame] | 2372 | * 20-1249MB/s bulk (12000 ints/s) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2373 | */ |
| 2374 | /* what was last interrupt timeslice? */ |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2375 | timepassed_us = q_vector->itr >> 2; |
Don Skidmore | bdbeefe | 2013-03-02 07:17:37 +0000 | [diff] [blame] | 2376 | if (timepassed_us == 0) |
| 2377 | return; |
| 2378 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2379 | bytes_perint = bytes / timepassed_us; /* bytes/usec */ |
| 2380 | |
| 2381 | switch (itr_setting) { |
| 2382 | case lowest_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2383 | if (bytes_perint > 10) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2384 | itr_setting = low_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2385 | break; |
| 2386 | case low_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2387 | if (bytes_perint > 20) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2388 | itr_setting = bulk_latency; |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2389 | else if (bytes_perint <= 10) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2390 | itr_setting = lowest_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2391 | break; |
| 2392 | case bulk_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2393 | if (bytes_perint <= 20) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2394 | itr_setting = low_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2395 | break; |
| 2396 | } |
| 2397 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2398 | /* clear work counters since we have the values we need */ |
| 2399 | ring_container->total_bytes = 0; |
| 2400 | ring_container->total_packets = 0; |
| 2401 | |
| 2402 | /* write updated itr to ring container */ |
| 2403 | ring_container->itr = itr_setting; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2404 | } |
| 2405 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2406 | /** |
| 2407 | * ixgbe_write_eitr - write EITR register in hardware specific way |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2408 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2409 | * |
| 2410 | * This function is made to be called by ethtool and by the driver |
| 2411 | * when it needs to update EITR registers at runtime. Hardware |
| 2412 | * specific quirks/differences are taken care of here. |
| 2413 | */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2414 | void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector) |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2415 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2416 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2417 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2418 | int v_idx = q_vector->v_idx; |
Alexander Duyck | 5d967eb | 2012-02-08 07:49:43 +0000 | [diff] [blame] | 2419 | u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2420 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2421 | switch (adapter->hw.mac.type) { |
| 2422 | case ixgbe_mac_82598EB: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2423 | /* must write high and low 16 bits to reset counter */ |
| 2424 | itr_reg |= (itr_reg << 16); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2425 | break; |
| 2426 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2427 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2428 | case ixgbe_mac_X550: |
| 2429 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2430 | case ixgbe_mac_x550em_a: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2431 | /* |
| 2432 | * set the WDIS bit to not clear the timer bits and cause an |
| 2433 | * immediate assertion of the interrupt |
| 2434 | */ |
| 2435 | itr_reg |= IXGBE_EITR_CNT_WDIS; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2436 | break; |
| 2437 | default: |
| 2438 | break; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2439 | } |
| 2440 | IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg); |
| 2441 | } |
| 2442 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2443 | static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2444 | { |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2445 | u32 new_itr = q_vector->itr; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2446 | u8 current_itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2447 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2448 | ixgbe_update_itr(q_vector, &q_vector->tx); |
| 2449 | ixgbe_update_itr(q_vector, &q_vector->rx); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2450 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2451 | current_itr = max(q_vector->rx.itr, q_vector->tx.itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2452 | |
| 2453 | switch (current_itr) { |
| 2454 | /* counts and packets in update_itr are dependent on these numbers */ |
| 2455 | case lowest_latency: |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2456 | new_itr = IXGBE_100K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2457 | break; |
| 2458 | case low_latency: |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2459 | new_itr = IXGBE_20K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2460 | break; |
| 2461 | case bulk_latency: |
Alexander Duyck | 8ac34f1 | 2015-07-30 15:19:28 -0700 | [diff] [blame] | 2462 | new_itr = IXGBE_12K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2463 | break; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2464 | default: |
| 2465 | break; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2466 | } |
| 2467 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2468 | if (new_itr != q_vector->itr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2469 | /* do an exponential smoothing */ |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2470 | new_itr = (10 * new_itr * q_vector->itr) / |
| 2471 | ((9 * new_itr) + q_vector->itr); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2472 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2473 | /* save the algorithm value here */ |
Alexander Duyck | 5d967eb | 2012-02-08 07:49:43 +0000 | [diff] [blame] | 2474 | q_vector->itr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2475 | |
| 2476 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2477 | } |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2478 | } |
| 2479 | |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2480 | /** |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2481 | * ixgbe_check_overtemp_subtask - check for over temperature |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2482 | * @adapter: pointer to adapter |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2483 | **/ |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2484 | static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter) |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2485 | { |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2486 | struct ixgbe_hw *hw = &adapter->hw; |
| 2487 | u32 eicr = adapter->interrupt_event; |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 2488 | s32 rc; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2489 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2490 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2491 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2492 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2493 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) && |
| 2494 | !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT)) |
| 2495 | return; |
| 2496 | |
| 2497 | adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2498 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2499 | switch (hw->device_id) { |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2500 | case IXGBE_DEV_ID_82599_T3_LOM: |
| 2501 | /* |
| 2502 | * Since the warning interrupt is for both ports |
| 2503 | * we don't have to check if: |
| 2504 | * - This interrupt wasn't for our port. |
| 2505 | * - We may have missed the interrupt so always have to |
| 2506 | * check if we got a LSC |
| 2507 | */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2508 | if (!(eicr & IXGBE_EICR_GPI_SDP0_8259X) && |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2509 | !(eicr & IXGBE_EICR_LSC)) |
| 2510 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2511 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2512 | if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) { |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 2513 | u32 speed; |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2514 | bool link_up = false; |
| 2515 | |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 2516 | hw->mac.ops.check_link(hw, &speed, &link_up, false); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2517 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2518 | if (link_up) |
| 2519 | return; |
| 2520 | } |
| 2521 | |
| 2522 | /* Check if this is not due to overtemp */ |
| 2523 | if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP) |
| 2524 | return; |
| 2525 | |
| 2526 | break; |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 2527 | case IXGBE_DEV_ID_X550EM_A_1G_T: |
| 2528 | case IXGBE_DEV_ID_X550EM_A_1G_T_L: |
| 2529 | rc = hw->phy.ops.check_overtemp(hw); |
| 2530 | if (rc != IXGBE_ERR_OVERTEMP) |
| 2531 | return; |
| 2532 | break; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2533 | default: |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 2534 | if (adapter->hw.mac.type >= ixgbe_mac_X540) |
| 2535 | return; |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2536 | if (!(eicr & IXGBE_EICR_GPI_SDP0(hw))) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2537 | return; |
| 2538 | break; |
| 2539 | } |
Don Skidmore | f44e751 | 2015-06-09 16:36:23 -0700 | [diff] [blame] | 2540 | e_crit(drv, "%s\n", ixgbe_overheat_msg); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2541 | |
| 2542 | adapter->interrupt_event = 0; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2543 | } |
| 2544 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2545 | static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr) |
| 2546 | { |
| 2547 | struct ixgbe_hw *hw = &adapter->hw; |
| 2548 | |
| 2549 | if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) && |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2550 | (eicr & IXGBE_EICR_GPI_SDP1(hw))) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2551 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2552 | /* write to clear the interrupt */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2553 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw)); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2554 | } |
| 2555 | } |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2556 | |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2557 | static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 2558 | { |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2559 | struct ixgbe_hw *hw = &adapter->hw; |
| 2560 | |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2561 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)) |
| 2562 | return; |
| 2563 | |
| 2564 | switch (adapter->hw.mac.type) { |
| 2565 | case ixgbe_mac_82599EB: |
| 2566 | /* |
| 2567 | * Need to check link state so complete overtemp check |
| 2568 | * on service task |
| 2569 | */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2570 | if (((eicr & IXGBE_EICR_GPI_SDP0(hw)) || |
| 2571 | (eicr & IXGBE_EICR_LSC)) && |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2572 | (!test_bit(__IXGBE_DOWN, &adapter->state))) { |
| 2573 | adapter->interrupt_event = eicr; |
| 2574 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2575 | ixgbe_service_event_schedule(adapter); |
| 2576 | return; |
| 2577 | } |
| 2578 | return; |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 2579 | case ixgbe_mac_x550em_a: |
| 2580 | if (eicr & IXGBE_EICR_GPI_SDP0_X550EM_a) { |
| 2581 | adapter->interrupt_event = eicr; |
| 2582 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2583 | ixgbe_service_event_schedule(adapter); |
| 2584 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, |
| 2585 | IXGBE_EICR_GPI_SDP0_X550EM_a); |
| 2586 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICR, |
| 2587 | IXGBE_EICR_GPI_SDP0_X550EM_a); |
| 2588 | } |
| 2589 | return; |
| 2590 | case ixgbe_mac_X550: |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2591 | case ixgbe_mac_X540: |
| 2592 | if (!(eicr & IXGBE_EICR_TS)) |
| 2593 | return; |
| 2594 | break; |
| 2595 | default: |
| 2596 | return; |
| 2597 | } |
| 2598 | |
Don Skidmore | f44e751 | 2015-06-09 16:36:23 -0700 | [diff] [blame] | 2599 | e_crit(drv, "%s\n", ixgbe_overheat_msg); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2600 | } |
| 2601 | |
Don Skidmore | 45788d2 | 2015-06-09 16:59:04 -0700 | [diff] [blame] | 2602 | static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw) |
| 2603 | { |
| 2604 | switch (hw->mac.type) { |
| 2605 | case ixgbe_mac_82598EB: |
| 2606 | if (hw->phy.type == ixgbe_phy_nl) |
| 2607 | return true; |
| 2608 | return false; |
| 2609 | case ixgbe_mac_82599EB: |
| 2610 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2611 | case ixgbe_mac_x550em_a: |
Don Skidmore | 45788d2 | 2015-06-09 16:59:04 -0700 | [diff] [blame] | 2612 | switch (hw->mac.ops.get_media_type(hw)) { |
| 2613 | case ixgbe_media_type_fiber: |
| 2614 | case ixgbe_media_type_fiber_qsfp: |
| 2615 | return true; |
| 2616 | default: |
| 2617 | return false; |
| 2618 | } |
| 2619 | default: |
| 2620 | return false; |
| 2621 | } |
| 2622 | } |
| 2623 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2624 | static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 2625 | { |
| 2626 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 4ccc650 | 2015-09-02 13:47:54 -0700 | [diff] [blame] | 2627 | u32 eicr_mask = IXGBE_EICR_GPI_SDP2(hw); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2628 | |
Don Skidmore | 4ccc650 | 2015-09-02 13:47:54 -0700 | [diff] [blame] | 2629 | if (!ixgbe_is_sfp(hw)) |
| 2630 | return; |
| 2631 | |
| 2632 | /* Later MAC's use different SDP */ |
| 2633 | if (hw->mac.type >= ixgbe_mac_X540) |
| 2634 | eicr_mask = IXGBE_EICR_GPI_SDP0_X540; |
| 2635 | |
| 2636 | if (eicr & eicr_mask) { |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2637 | /* Clear the interrupt */ |
Don Skidmore | 4ccc650 | 2015-09-02 13:47:54 -0700 | [diff] [blame] | 2638 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr_mask); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2639 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2640 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
Mark Rustad | 58e7cd2 | 2015-08-08 16:18:48 -0700 | [diff] [blame] | 2641 | adapter->sfp_poll_time = 0; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2642 | ixgbe_service_event_schedule(adapter); |
| 2643 | } |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2644 | } |
| 2645 | |
Don Skidmore | 4ccc650 | 2015-09-02 13:47:54 -0700 | [diff] [blame] | 2646 | if (adapter->hw.mac.type == ixgbe_mac_82599EB && |
| 2647 | (eicr & IXGBE_EICR_GPI_SDP1(hw))) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2648 | /* Clear the interrupt */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2649 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw)); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2650 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2651 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 2652 | ixgbe_service_event_schedule(adapter); |
| 2653 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2654 | } |
| 2655 | } |
| 2656 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2657 | static void ixgbe_check_lsc(struct ixgbe_adapter *adapter) |
| 2658 | { |
| 2659 | struct ixgbe_hw *hw = &adapter->hw; |
| 2660 | |
| 2661 | adapter->lsc_int++; |
| 2662 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 2663 | adapter->link_check_timeout = jiffies; |
| 2664 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2665 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC); |
Nelson, Shannon | 8a0717f | 2009-11-12 18:47:11 +0000 | [diff] [blame] | 2666 | IXGBE_WRITE_FLUSH(hw); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 2667 | ixgbe_service_event_schedule(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2668 | } |
| 2669 | } |
| 2670 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2671 | static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter, |
| 2672 | u64 qmask) |
| 2673 | { |
| 2674 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2675 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2676 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2677 | switch (hw->mac.type) { |
| 2678 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2679 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2680 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask); |
| 2681 | break; |
| 2682 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2683 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2684 | case ixgbe_mac_X550: |
| 2685 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2686 | case ixgbe_mac_x550em_a: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2687 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2688 | if (mask) |
| 2689 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2690 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2691 | if (mask) |
| 2692 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask); |
| 2693 | break; |
| 2694 | default: |
| 2695 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2696 | } |
| 2697 | /* skip the flush */ |
| 2698 | } |
| 2699 | |
| 2700 | static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2701 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2702 | { |
| 2703 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2704 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2705 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2706 | switch (hw->mac.type) { |
| 2707 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2708 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2709 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask); |
| 2710 | break; |
| 2711 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2712 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2713 | case ixgbe_mac_X550: |
| 2714 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2715 | case ixgbe_mac_x550em_a: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2716 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2717 | if (mask) |
| 2718 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2719 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2720 | if (mask) |
| 2721 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask); |
| 2722 | break; |
| 2723 | default: |
| 2724 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2725 | } |
| 2726 | /* skip the flush */ |
| 2727 | } |
| 2728 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2729 | /** |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2730 | * ixgbe_irq_enable - Enable default interrupt generation settings |
| 2731 | * @adapter: board private structure |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2732 | **/ |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2733 | static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues, |
| 2734 | bool flush) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2735 | { |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2736 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2737 | u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE); |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 2738 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2739 | /* don't reenable LSC while waiting for link */ |
| 2740 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 2741 | mask &= ~IXGBE_EIMS_LSC; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2742 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2743 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2744 | switch (adapter->hw.mac.type) { |
| 2745 | case ixgbe_mac_82599EB: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2746 | mask |= IXGBE_EIMS_GPI_SDP0(hw); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2747 | break; |
| 2748 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2749 | case ixgbe_mac_X550: |
| 2750 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2751 | case ixgbe_mac_x550em_a: |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2752 | mask |= IXGBE_EIMS_TS; |
| 2753 | break; |
| 2754 | default: |
| 2755 | break; |
| 2756 | } |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2757 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2758 | mask |= IXGBE_EIMS_GPI_SDP1(hw); |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2759 | switch (adapter->hw.mac.type) { |
| 2760 | case ixgbe_mac_82599EB: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2761 | mask |= IXGBE_EIMS_GPI_SDP1(hw); |
| 2762 | mask |= IXGBE_EIMS_GPI_SDP2(hw); |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2763 | /* fall through */ |
Don Skidmore | 858bc08 | 2011-08-04 09:28:30 +0000 | [diff] [blame] | 2764 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2765 | case ixgbe_mac_X550: |
| 2766 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2767 | case ixgbe_mac_x550em_a: |
| 2768 | if (adapter->hw.device_id == IXGBE_DEV_ID_X550EM_X_SFP || |
Mark Rustad | 2d40cd1 | 2016-04-01 12:18:35 -0700 | [diff] [blame] | 2769 | adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP || |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2770 | adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP_N) |
Mark Rustad | cbd45ec | 2015-08-08 16:17:51 -0700 | [diff] [blame] | 2771 | mask |= IXGBE_EIMS_GPI_SDP0(&adapter->hw); |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 2772 | if (adapter->hw.phy.type == ixgbe_phy_x550em_ext_t) |
| 2773 | mask |= IXGBE_EICR_GPI_SDP0_X540; |
Don Skidmore | 858bc08 | 2011-08-04 09:28:30 +0000 | [diff] [blame] | 2774 | mask |= IXGBE_EIMS_ECC; |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2775 | mask |= IXGBE_EIMS_MAILBOX; |
| 2776 | break; |
| 2777 | default: |
| 2778 | break; |
| 2779 | } |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2780 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2781 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) && |
| 2782 | !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 2783 | mask |= IXGBE_EIMS_FLOW_DIR; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2784 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2785 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
| 2786 | if (queues) |
| 2787 | ixgbe_irq_enable_queues(adapter, ~0); |
| 2788 | if (flush) |
| 2789 | IXGBE_WRITE_FLUSH(&adapter->hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2790 | } |
| 2791 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2792 | static irqreturn_t ixgbe_msix_other(int irq, void *data) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2793 | { |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2794 | struct ixgbe_adapter *adapter = data; |
| 2795 | struct ixgbe_hw *hw = &adapter->hw; |
| 2796 | u32 eicr; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2797 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2798 | /* |
| 2799 | * Workaround for Silicon errata. Use clear-by-write instead |
| 2800 | * of clear-by-read. Reading with EICS will return the |
| 2801 | * interrupt causes without clearing, which later be done |
| 2802 | * with the write to EICR. |
| 2803 | */ |
| 2804 | eicr = IXGBE_READ_REG(hw, IXGBE_EICS); |
Jacob Keller | d87d830 | 2013-03-02 07:51:42 +0000 | [diff] [blame] | 2805 | |
| 2806 | /* The lower 16bits of the EICR register are for the queue interrupts |
Joe Perches | dbedd44 | 2015-03-06 20:49:12 -0800 | [diff] [blame] | 2807 | * 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] | 2808 | * the bits are high when ixgbe_msix_other is called. There is a race |
| 2809 | * condition otherwise which results in possible performance loss |
| 2810 | * especially if the ixgbe_msix_other interrupt is triggering |
| 2811 | * consistently (as it would when PPS is turned on for the X540 device) |
| 2812 | */ |
| 2813 | eicr &= 0xFFFF0000; |
| 2814 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2815 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2816 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2817 | if (eicr & IXGBE_EICR_LSC) |
| 2818 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2819 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2820 | if (eicr & IXGBE_EICR_MAILBOX) |
| 2821 | ixgbe_msg_task(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2822 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2823 | switch (hw->mac.type) { |
| 2824 | case ixgbe_mac_82599EB: |
| 2825 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2826 | case ixgbe_mac_X550: |
| 2827 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2828 | case ixgbe_mac_x550em_a: |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 2829 | if (hw->phy.type == ixgbe_phy_x550em_ext_t && |
| 2830 | (eicr & IXGBE_EICR_GPI_SDP0_X540)) { |
| 2831 | adapter->flags2 |= IXGBE_FLAG2_PHY_INTERRUPT; |
| 2832 | ixgbe_service_event_schedule(adapter); |
| 2833 | IXGBE_WRITE_REG(hw, IXGBE_EICR, |
| 2834 | IXGBE_EICR_GPI_SDP0_X540); |
| 2835 | } |
Don Skidmore | d773ce2 | 2014-02-25 17:58:53 -0800 | [diff] [blame] | 2836 | if (eicr & IXGBE_EICR_ECC) { |
| 2837 | e_info(link, "Received ECC Err, initiating reset\n"); |
Emil Tantilov | 57ca2a4 | 2016-07-29 14:46:31 -0700 | [diff] [blame] | 2838 | set_bit(__IXGBE_RESET_REQUESTED, &adapter->state); |
Don Skidmore | d773ce2 | 2014-02-25 17:58:53 -0800 | [diff] [blame] | 2839 | ixgbe_service_event_schedule(adapter); |
| 2840 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC); |
| 2841 | } |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2842 | /* Handle Flow Director Full threshold interrupt */ |
| 2843 | if (eicr & IXGBE_EICR_FLOW_DIR) { |
| 2844 | int reinit_count = 0; |
| 2845 | int i; |
| 2846 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2847 | struct ixgbe_ring *ring = adapter->tx_ring[i]; |
| 2848 | if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE, |
| 2849 | &ring->state)) |
| 2850 | reinit_count++; |
| 2851 | } |
| 2852 | if (reinit_count) { |
| 2853 | /* no more flow director interrupts until after init */ |
| 2854 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR); |
| 2855 | adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 2856 | ixgbe_service_event_schedule(adapter); |
| 2857 | } |
| 2858 | } |
| 2859 | ixgbe_check_sfp_event(adapter, eicr); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2860 | ixgbe_check_overtemp_event(adapter, eicr); |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2861 | break; |
| 2862 | default: |
| 2863 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2864 | } |
| 2865 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2866 | ixgbe_check_fan_failure(adapter, eicr); |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2867 | |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2868 | if (unlikely(eicr & IXGBE_EICR_TIMESYNC)) |
Mark Rustad | a9763f3 | 2015-10-27 09:58:07 -0700 | [diff] [blame] | 2869 | ixgbe_ptp_check_pps_event(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2870 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2871 | /* re-enable the original interrupt state, no lsc, no queues */ |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2872 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2873 | ixgbe_irq_enable(adapter, false, false); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2874 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2875 | return IRQ_HANDLED; |
| 2876 | } |
| 2877 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2878 | static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2879 | { |
| 2880 | struct ixgbe_q_vector *q_vector = data; |
| 2881 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2882 | /* EIAM disabled interrupts (on this vector) for us */ |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2883 | |
| 2884 | if (q_vector->rx.ring || q_vector->tx.ring) |
Alexander Duyck | ef2662b | 2015-09-29 15:19:43 -0700 | [diff] [blame] | 2885 | napi_schedule_irqoff(&q_vector->napi); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2886 | |
| 2887 | return IRQ_HANDLED; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2888 | } |
| 2889 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2890 | /** |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2891 | * ixgbe_poll - NAPI Rx polling callback |
| 2892 | * @napi: structure for representing this polling device |
| 2893 | * @budget: how many packets driver is allowed to clean |
| 2894 | * |
| 2895 | * This function is used for legacy and MSI, NAPI mode |
| 2896 | **/ |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 2897 | int ixgbe_poll(struct napi_struct *napi, int budget) |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2898 | { |
| 2899 | struct ixgbe_q_vector *q_vector = |
| 2900 | container_of(napi, struct ixgbe_q_vector, napi); |
| 2901 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 2902 | struct ixgbe_ring *ring; |
Jesse Brandeburg | 32b3e08 | 2015-09-24 16:35:47 -0700 | [diff] [blame] | 2903 | int per_ring_budget, work_done = 0; |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2904 | bool clean_complete = true; |
| 2905 | |
| 2906 | #ifdef CONFIG_IXGBE_DCA |
| 2907 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 2908 | ixgbe_update_dca(q_vector); |
| 2909 | #endif |
| 2910 | |
Alexander Duyck | 8220bbc | 2016-03-07 09:30:09 -0800 | [diff] [blame] | 2911 | ixgbe_for_each_ring(ring, q_vector->tx) { |
| 2912 | if (!ixgbe_clean_tx_irq(q_vector, ring, budget)) |
| 2913 | clean_complete = false; |
| 2914 | } |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2915 | |
Eric Dumazet | 3ffc1af | 2017-02-02 16:26:39 -0800 | [diff] [blame] | 2916 | /* Exit if we are called by netpoll */ |
| 2917 | if (budget <= 0) |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2918 | return budget; |
| 2919 | |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2920 | /* attempt to distribute budget to each queue fairly, but don't allow |
| 2921 | * the budget to go below 1 because we'll exit polling */ |
| 2922 | if (q_vector->rx.count > 1) |
| 2923 | per_ring_budget = max(budget/q_vector->rx.count, 1); |
| 2924 | else |
| 2925 | per_ring_budget = budget; |
| 2926 | |
Jesse Brandeburg | 32b3e08 | 2015-09-24 16:35:47 -0700 | [diff] [blame] | 2927 | ixgbe_for_each_ring(ring, q_vector->rx) { |
| 2928 | int cleaned = ixgbe_clean_rx_irq(q_vector, ring, |
| 2929 | per_ring_budget); |
| 2930 | |
| 2931 | work_done += cleaned; |
Alexander Duyck | 8220bbc | 2016-03-07 09:30:09 -0800 | [diff] [blame] | 2932 | if (cleaned >= per_ring_budget) |
| 2933 | clean_complete = false; |
Jesse Brandeburg | 32b3e08 | 2015-09-24 16:35:47 -0700 | [diff] [blame] | 2934 | } |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2935 | |
| 2936 | /* If all work not completed, return budget and keep polling */ |
| 2937 | if (!clean_complete) |
| 2938 | return budget; |
| 2939 | |
| 2940 | /* all work done, exit the polling mode */ |
Jesse Brandeburg | 32b3e08 | 2015-09-24 16:35:47 -0700 | [diff] [blame] | 2941 | napi_complete_done(napi, work_done); |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2942 | if (adapter->rx_itr_setting & 1) |
| 2943 | ixgbe_set_itr(q_vector); |
| 2944 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 2945 | ixgbe_irq_enable_queues(adapter, BIT_ULL(q_vector->v_idx)); |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2946 | |
Paolo Abeni | 4b732cd | 2016-06-15 15:37:59 +0200 | [diff] [blame] | 2947 | return min(work_done, budget - 1); |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2948 | } |
| 2949 | |
| 2950 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2951 | * ixgbe_request_msix_irqs - Initialize MSI-X interrupts |
| 2952 | * @adapter: board private structure |
| 2953 | * |
| 2954 | * ixgbe_request_msix_irqs allocates MSI-X vectors and requests |
| 2955 | * interrupts from the kernel. |
| 2956 | **/ |
| 2957 | static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter) |
| 2958 | { |
| 2959 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2960 | int vector, err; |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2961 | int ri = 0, ti = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2962 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2963 | for (vector = 0; vector < adapter->num_q_vectors; vector++) { |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2964 | struct ixgbe_q_vector *q_vector = adapter->q_vector[vector]; |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2965 | struct msix_entry *entry = &adapter->msix_entries[vector]; |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 2966 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2967 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 2968 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2969 | "%s-%s-%d", netdev->name, "TxRx", ri++); |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2970 | ti++; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2971 | } else if (q_vector->rx.ring) { |
| 2972 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2973 | "%s-%s-%d", netdev->name, "rx", ri++); |
| 2974 | } else if (q_vector->tx.ring) { |
| 2975 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2976 | "%s-%s-%d", netdev->name, "tx", ti++); |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2977 | } else { |
| 2978 | /* skip this unused q_vector */ |
| 2979 | continue; |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2980 | } |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2981 | err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0, |
| 2982 | q_vector->name, q_vector); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2983 | if (err) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2984 | e_err(probe, "request_irq failed for MSIX interrupt " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 2985 | "Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2986 | goto free_queue_irqs; |
| 2987 | } |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2988 | /* If Flow Director is enabled, set interrupt affinity */ |
| 2989 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 2990 | /* assign the mask for this irq */ |
| 2991 | irq_set_affinity_hint(entry->vector, |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2992 | &q_vector->affinity_mask); |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2993 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2994 | } |
| 2995 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2996 | err = request_irq(adapter->msix_entries[vector].vector, |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2997 | ixgbe_msix_other, 0, netdev->name, adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2998 | if (err) { |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2999 | e_err(probe, "request_irq for msix_other failed: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3000 | goto free_queue_irqs; |
| 3001 | } |
| 3002 | |
| 3003 | return 0; |
| 3004 | |
| 3005 | free_queue_irqs: |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 3006 | while (vector) { |
| 3007 | vector--; |
| 3008 | irq_set_affinity_hint(adapter->msix_entries[vector].vector, |
| 3009 | NULL); |
| 3010 | free_irq(adapter->msix_entries[vector].vector, |
| 3011 | adapter->q_vector[vector]); |
| 3012 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3013 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 3014 | pci_disable_msix(adapter->pdev); |
| 3015 | kfree(adapter->msix_entries); |
| 3016 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3017 | return err; |
| 3018 | } |
| 3019 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 3020 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3021 | * ixgbe_intr - legacy mode Interrupt Handler |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3022 | * @irq: interrupt number |
| 3023 | * @data: pointer to a network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3024 | **/ |
| 3025 | static irqreturn_t ixgbe_intr(int irq, void *data) |
| 3026 | { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 3027 | struct ixgbe_adapter *adapter = data; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3028 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3029 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3030 | u32 eicr; |
| 3031 | |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 3032 | /* |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 3033 | * Workaround for silicon errata #26 on 82598. Mask the interrupt |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 3034 | * before the read of EICR. |
| 3035 | */ |
| 3036 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); |
| 3037 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3038 | /* 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] | 3039 | * therefore no explicit interrupt disable is necessary */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3040 | eicr = IXGBE_READ_REG(hw, IXGBE_EICR); |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 3041 | if (!eicr) { |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 3042 | /* |
| 3043 | * shared interrupt alert! |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 3044 | * make sure interrupts are enabled because the read will |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 3045 | * have disabled interrupts due to EIAM |
| 3046 | * finish the workaround of silicon errata on 82598. Unmask |
| 3047 | * the interrupt that we masked before the EICR read. |
| 3048 | */ |
| 3049 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 3050 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3051 | return IRQ_NONE; /* Not our interrupt */ |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 3052 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3053 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 3054 | if (eicr & IXGBE_EICR_LSC) |
| 3055 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3056 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3057 | switch (hw->mac.type) { |
| 3058 | case ixgbe_mac_82599EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3059 | ixgbe_check_sfp_event(adapter, eicr); |
Don Skidmore | 0ccb974 | 2011-08-04 02:07:48 +0000 | [diff] [blame] | 3060 | /* Fall through */ |
| 3061 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 3062 | case ixgbe_mac_X550: |
| 3063 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 3064 | case ixgbe_mac_x550em_a: |
Don Skidmore | d773ce2 | 2014-02-25 17:58:53 -0800 | [diff] [blame] | 3065 | if (eicr & IXGBE_EICR_ECC) { |
| 3066 | e_info(link, "Received ECC Err, initiating reset\n"); |
Emil Tantilov | 57ca2a4 | 2016-07-29 14:46:31 -0700 | [diff] [blame] | 3067 | set_bit(__IXGBE_RESET_REQUESTED, &adapter->state); |
Don Skidmore | d773ce2 | 2014-02-25 17:58:53 -0800 | [diff] [blame] | 3068 | ixgbe_service_event_schedule(adapter); |
| 3069 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC); |
| 3070 | } |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 3071 | ixgbe_check_overtemp_event(adapter, eicr); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3072 | break; |
| 3073 | default: |
| 3074 | break; |
| 3075 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3076 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 3077 | ixgbe_check_fan_failure(adapter, eicr); |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 3078 | if (unlikely(eicr & IXGBE_EICR_TIMESYNC)) |
Mark Rustad | a9763f3 | 2015-10-27 09:58:07 -0700 | [diff] [blame] | 3079 | ixgbe_ptp_check_pps_event(adapter); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 3080 | |
Alexander Duyck | b9f6ed2 | 2012-02-08 07:49:54 +0000 | [diff] [blame] | 3081 | /* would disable interrupts here but EIAM disabled it */ |
Alexander Duyck | ef2662b | 2015-09-29 15:19:43 -0700 | [diff] [blame] | 3082 | napi_schedule_irqoff(&q_vector->napi); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3083 | |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 3084 | /* |
| 3085 | * re-enable link(maybe) and non-queue interrupts, no flush. |
| 3086 | * ixgbe_poll will re-enable the queue interrupts |
| 3087 | */ |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 3088 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 3089 | ixgbe_irq_enable(adapter, false, false); |
| 3090 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3091 | return IRQ_HANDLED; |
| 3092 | } |
| 3093 | |
| 3094 | /** |
| 3095 | * ixgbe_request_irq - initialize interrupts |
| 3096 | * @adapter: board private structure |
| 3097 | * |
| 3098 | * Attempts to configure interrupts using the best available |
| 3099 | * capabilities of the hardware and kernel. |
| 3100 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3101 | static int ixgbe_request_irq(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3102 | { |
| 3103 | struct net_device *netdev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3104 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3105 | |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 3106 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3107 | err = ixgbe_request_msix_irqs(adapter); |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 3108 | else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 3109 | err = request_irq(adapter->pdev->irq, ixgbe_intr, 0, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 3110 | netdev->name, adapter); |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 3111 | else |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 3112 | err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 3113 | netdev->name, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3114 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 3115 | if (err) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 3116 | e_err(probe, "request_irq failed, Error %d\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3117 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3118 | return err; |
| 3119 | } |
| 3120 | |
| 3121 | static void ixgbe_free_irq(struct ixgbe_adapter *adapter) |
| 3122 | { |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3123 | int vector; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3124 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3125 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 3126 | free_irq(adapter->pdev->irq, adapter); |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3127 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3128 | } |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3129 | |
Mark Rustad | 1fa7125 | 2016-09-28 15:36:38 -0700 | [diff] [blame] | 3130 | if (!adapter->msix_entries) |
| 3131 | return; |
| 3132 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3133 | for (vector = 0; vector < adapter->num_q_vectors; vector++) { |
| 3134 | struct ixgbe_q_vector *q_vector = adapter->q_vector[vector]; |
| 3135 | struct msix_entry *entry = &adapter->msix_entries[vector]; |
| 3136 | |
| 3137 | /* free only the irqs that were actually requested */ |
| 3138 | if (!q_vector->rx.ring && !q_vector->tx.ring) |
| 3139 | continue; |
| 3140 | |
| 3141 | /* clear the affinity_mask in the IRQ descriptor */ |
| 3142 | irq_set_affinity_hint(entry->vector, NULL); |
| 3143 | |
| 3144 | free_irq(entry->vector, q_vector); |
| 3145 | } |
| 3146 | |
Babu Moger | 90c6f87 | 2016-06-18 17:40:47 -0700 | [diff] [blame] | 3147 | free_irq(adapter->msix_entries[vector].vector, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3148 | } |
| 3149 | |
| 3150 | /** |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3151 | * ixgbe_irq_disable - Mask off interrupt generation on the NIC |
| 3152 | * @adapter: board private structure |
| 3153 | **/ |
| 3154 | static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter) |
| 3155 | { |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3156 | switch (adapter->hw.mac.type) { |
| 3157 | case ixgbe_mac_82598EB: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 3158 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3159 | break; |
| 3160 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3161 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 3162 | case ixgbe_mac_X550: |
| 3163 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 3164 | case ixgbe_mac_x550em_a: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 3165 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000); |
| 3166 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3167 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3168 | break; |
| 3169 | default: |
| 3170 | break; |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3171 | } |
| 3172 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 3173 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3174 | int vector; |
| 3175 | |
| 3176 | for (vector = 0; vector < adapter->num_q_vectors; vector++) |
| 3177 | synchronize_irq(adapter->msix_entries[vector].vector); |
| 3178 | |
| 3179 | synchronize_irq(adapter->msix_entries[vector++].vector); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3180 | } else { |
| 3181 | synchronize_irq(adapter->pdev->irq); |
| 3182 | } |
| 3183 | } |
| 3184 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3185 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3186 | * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts |
| 3187 | * |
| 3188 | **/ |
| 3189 | static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter) |
| 3190 | { |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 3191 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3192 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 3193 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3194 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3195 | ixgbe_set_ivar(adapter, 0, 0, 0); |
| 3196 | ixgbe_set_ivar(adapter, 1, 0, 0); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3197 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 3198 | e_info(hw, "Legacy interrupt IVAR setup done\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3199 | } |
| 3200 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3201 | /** |
| 3202 | * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset |
| 3203 | * @adapter: board private structure |
| 3204 | * @ring: structure containing ring specific data |
| 3205 | * |
| 3206 | * Configure the Tx descriptor ring after a reset. |
| 3207 | **/ |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 3208 | void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter, |
| 3209 | struct ixgbe_ring *ring) |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3210 | { |
| 3211 | struct ixgbe_hw *hw = &adapter->hw; |
| 3212 | u64 tdba = ring->dma; |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3213 | int wait_loop = 10; |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3214 | u32 txdctl = IXGBE_TXDCTL_ENABLE; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3215 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3216 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3217 | /* disable queue to avoid issues while updating state */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3218 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3219 | IXGBE_WRITE_FLUSH(hw); |
| 3220 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3221 | IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3222 | (tdba & DMA_BIT_MASK(32))); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3223 | IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32)); |
| 3224 | IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx), |
| 3225 | ring->count * sizeof(union ixgbe_adv_tx_desc)); |
| 3226 | IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0); |
| 3227 | IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 3228 | ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3229 | |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3230 | /* |
| 3231 | * set WTHRESH to encourage burst writeback, it should not be set |
Emil Tantilov | 67da097 | 2013-01-25 06:19:20 +0000 | [diff] [blame] | 3232 | * higher than 1 when: |
| 3233 | * - ITR is 0 as it could cause false TX hangs |
| 3234 | * - ITR is set to > 100k int/sec and BQL is enabled |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3235 | * |
| 3236 | * In order to avoid issues WTHRESH + PTHRESH should always be equal |
| 3237 | * to or less than the number of on chip descriptors, which is |
| 3238 | * currently 40. |
| 3239 | */ |
Emil Tantilov | 67da097 | 2013-01-25 06:19:20 +0000 | [diff] [blame] | 3240 | if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR)) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 3241 | txdctl |= 1u << 16; /* WTHRESH = 1 */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3242 | else |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 3243 | txdctl |= 8u << 16; /* WTHRESH = 8 */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3244 | |
Alexander Duyck | e954b37 | 2012-02-08 07:49:38 +0000 | [diff] [blame] | 3245 | /* |
| 3246 | * Setting PTHRESH to 32 both improves performance |
| 3247 | * and avoids a TX hang with DFP enabled |
| 3248 | */ |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 3249 | txdctl |= (1u << 8) | /* HTHRESH = 1 */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3250 | 32; /* PTHRESH = 32 */ |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3251 | |
| 3252 | /* reinitialize flowdirector state */ |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 3253 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 3254 | ring->atr_sample_rate = adapter->atr_sample_rate; |
| 3255 | ring->atr_count = 0; |
| 3256 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state); |
| 3257 | } else { |
| 3258 | ring->atr_sample_rate = 0; |
| 3259 | } |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3260 | |
Alexander Duyck | fd786b7 | 2013-01-12 06:33:31 +0000 | [diff] [blame] | 3261 | /* initialize XPS */ |
| 3262 | if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) { |
| 3263 | struct ixgbe_q_vector *q_vector = ring->q_vector; |
| 3264 | |
| 3265 | if (q_vector) |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 3266 | netif_set_xps_queue(ring->netdev, |
Alexander Duyck | fd786b7 | 2013-01-12 06:33:31 +0000 | [diff] [blame] | 3267 | &q_vector->affinity_mask, |
| 3268 | ring->queue_index); |
| 3269 | } |
| 3270 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 3271 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state); |
| 3272 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 3273 | /* reinitialize tx_buffer_info */ |
| 3274 | memset(ring->tx_buffer_info, 0, |
| 3275 | sizeof(struct ixgbe_tx_buffer) * ring->count); |
| 3276 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3277 | /* enable queue */ |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3278 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl); |
| 3279 | |
| 3280 | /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 3281 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 3282 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 3283 | return; |
| 3284 | |
| 3285 | /* poll to verify queue is enabled */ |
| 3286 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 3287 | usleep_range(1000, 2000); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3288 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx)); |
| 3289 | } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE)); |
| 3290 | if (!wait_loop) |
Emil Tantilov | a55defd | 2016-07-29 10:30:06 -0700 | [diff] [blame] | 3291 | hw_dbg(hw, "Could not enable Tx Queue %d\n", reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3292 | } |
| 3293 | |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 3294 | static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter) |
| 3295 | { |
| 3296 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3297 | u32 rttdcs, mtqc; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3298 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 3299 | |
| 3300 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3301 | return; |
| 3302 | |
| 3303 | /* disable the arbiter while setting MTQC */ |
| 3304 | rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS); |
| 3305 | rttdcs |= IXGBE_RTTDCS_ARBDIS; |
| 3306 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 3307 | |
| 3308 | /* set transmit pool layout */ |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3309 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 3310 | mtqc = IXGBE_MTQC_VT_ENA; |
| 3311 | if (tcs > 4) |
| 3312 | mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ; |
| 3313 | else if (tcs > 1) |
| 3314 | mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ; |
Alexander Duyck | e24fcf2 | 2016-09-07 20:28:24 -0700 | [diff] [blame] | 3315 | else if (adapter->ring_feature[RING_F_VMDQ].mask == |
| 3316 | IXGBE_82599_VMDQ_4Q_MASK) |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3317 | mtqc |= IXGBE_MTQC_32VF; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3318 | else |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3319 | mtqc |= IXGBE_MTQC_64VF; |
| 3320 | } else { |
| 3321 | if (tcs > 4) |
| 3322 | mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ; |
| 3323 | else if (tcs > 1) |
| 3324 | mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ; |
| 3325 | else |
| 3326 | mtqc = IXGBE_MTQC_64Q_1PB; |
| 3327 | } |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3328 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3329 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3330 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3331 | /* Enable Security TX Buffer IFG for multiple pb */ |
| 3332 | if (tcs) { |
| 3333 | u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG); |
| 3334 | sectx |= IXGBE_SECTX_DCB; |
| 3335 | IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx); |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 3336 | } |
| 3337 | |
| 3338 | /* re-enable the arbiter */ |
| 3339 | rttdcs &= ~IXGBE_RTTDCS_ARBDIS; |
| 3340 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 3341 | } |
| 3342 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3343 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3344 | * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3345 | * @adapter: board private structure |
| 3346 | * |
| 3347 | * Configure the Tx unit of the MAC after a reset. |
| 3348 | **/ |
| 3349 | static void ixgbe_configure_tx(struct ixgbe_adapter *adapter) |
| 3350 | { |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3351 | struct ixgbe_hw *hw = &adapter->hw; |
| 3352 | u32 dmatxctl; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3353 | u32 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3354 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3355 | ixgbe_setup_mtqc(adapter); |
| 3356 | |
| 3357 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 3358 | /* DMATXCTL.EN must be before Tx queues are enabled */ |
| 3359 | dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); |
| 3360 | dmatxctl |= IXGBE_DMATXCTL_TE; |
| 3361 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl); |
| 3362 | } |
| 3363 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3364 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3365 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 3366 | ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3367 | } |
| 3368 | |
Alexander Duyck | 3ebe8fd | 2012-04-25 04:36:38 +0000 | [diff] [blame] | 3369 | static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter, |
| 3370 | struct ixgbe_ring *ring) |
| 3371 | { |
| 3372 | struct ixgbe_hw *hw = &adapter->hw; |
| 3373 | u8 reg_idx = ring->reg_idx; |
| 3374 | u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx)); |
| 3375 | |
| 3376 | srrctl |= IXGBE_SRRCTL_DROP_EN; |
| 3377 | |
| 3378 | IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl); |
| 3379 | } |
| 3380 | |
| 3381 | static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter, |
| 3382 | struct ixgbe_ring *ring) |
| 3383 | { |
| 3384 | struct ixgbe_hw *hw = &adapter->hw; |
| 3385 | u8 reg_idx = ring->reg_idx; |
| 3386 | u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx)); |
| 3387 | |
| 3388 | srrctl &= ~IXGBE_SRRCTL_DROP_EN; |
| 3389 | |
| 3390 | IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl); |
| 3391 | } |
| 3392 | |
| 3393 | #ifdef CONFIG_IXGBE_DCB |
| 3394 | void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter) |
| 3395 | #else |
| 3396 | static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter) |
| 3397 | #endif |
| 3398 | { |
| 3399 | int i; |
| 3400 | bool pfc_en = adapter->dcb_cfg.pfc_mode_enable; |
| 3401 | |
| 3402 | if (adapter->ixgbe_ieee_pfc) |
| 3403 | pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en); |
| 3404 | |
| 3405 | /* |
| 3406 | * We should set the drop enable bit if: |
| 3407 | * SR-IOV is enabled |
| 3408 | * or |
| 3409 | * Number of Rx queues > 1 and flow control is disabled |
| 3410 | * |
| 3411 | * This allows us to avoid head of line blocking for security |
| 3412 | * and performance reasons. |
| 3413 | */ |
| 3414 | if (adapter->num_vfs || (adapter->num_rx_queues > 1 && |
| 3415 | !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) { |
| 3416 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3417 | ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]); |
| 3418 | } else { |
| 3419 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3420 | ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]); |
| 3421 | } |
| 3422 | } |
| 3423 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3424 | #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3425 | |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 3426 | static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3427 | struct ixgbe_ring *rx_ring) |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3428 | { |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3429 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3430 | u32 srrctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3431 | u8 reg_idx = rx_ring->reg_idx; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3432 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3433 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 3434 | u16 mask = adapter->ring_feature[RING_F_RSS].mask; |
| 3435 | |
| 3436 | /* |
| 3437 | * if VMDq is not active we must program one srrctl register |
| 3438 | * per RSS queue since we have enabled RDRXCTL.MVMEN |
| 3439 | */ |
| 3440 | reg_idx &= mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3441 | } |
| 3442 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3443 | /* configure header buffer length, needed for RSC */ |
| 3444 | srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3445 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3446 | /* configure the packet buffer length */ |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 3447 | if (test_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state)) |
| 3448 | srrctl |= IXGBE_RXBUFFER_3K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 3449 | else |
| 3450 | srrctl |= IXGBE_RXBUFFER_2K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3451 | |
| 3452 | /* configure descriptor type */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 3453 | srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3454 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3455 | IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3456 | } |
| 3457 | |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3458 | /** |
Jean Sacren | a897a2a | 2015-09-19 05:08:44 -0600 | [diff] [blame] | 3459 | * ixgbe_rss_indir_tbl_entries - Return RSS indirection table entries |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3460 | * @adapter: device handle |
| 3461 | * |
| 3462 | * - 82598/82599/X540: 128 |
| 3463 | * - X550(non-SRIOV mode): 512 |
| 3464 | * - X550(SRIOV mode): 64 |
| 3465 | */ |
Vlad Zolotarov | 7f276ef | 2015-03-30 21:18:58 +0300 | [diff] [blame] | 3466 | u32 ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3467 | { |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3468 | if (adapter->hw.mac.type < ixgbe_mac_X550) |
| 3469 | return 128; |
| 3470 | else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 3471 | return 64; |
| 3472 | else |
| 3473 | return 512; |
| 3474 | } |
| 3475 | |
| 3476 | /** |
Paolo Abeni | d3aa9c9 | 2016-12-15 15:20:34 +0100 | [diff] [blame] | 3477 | * ixgbe_store_key - Write the RSS key to HW |
| 3478 | * @adapter: device handle |
| 3479 | * |
| 3480 | * Write the RSS key stored in adapter.rss_key to HW. |
| 3481 | */ |
| 3482 | void ixgbe_store_key(struct ixgbe_adapter *adapter) |
| 3483 | { |
| 3484 | struct ixgbe_hw *hw = &adapter->hw; |
| 3485 | int i; |
| 3486 | |
| 3487 | for (i = 0; i < 10; i++) |
| 3488 | IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), adapter->rss_key[i]); |
| 3489 | } |
| 3490 | |
| 3491 | /** |
Jean Sacren | a897a2a | 2015-09-19 05:08:44 -0600 | [diff] [blame] | 3492 | * ixgbe_store_reta - Write the RETA table to HW |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3493 | * @adapter: device handle |
| 3494 | * |
| 3495 | * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW. |
| 3496 | */ |
Tom Barbette | 1c7cf07 | 2015-06-26 15:40:18 +0200 | [diff] [blame] | 3497 | void ixgbe_store_reta(struct ixgbe_adapter *adapter) |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3498 | { |
| 3499 | u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter); |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3500 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3501 | u32 reta = 0; |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3502 | u32 indices_multi; |
| 3503 | u8 *indir_tbl = adapter->rss_indir_tbl; |
John Fastabend | 86b4db3 | 2011-04-26 07:26:19 +0000 | [diff] [blame] | 3504 | |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3505 | /* Fill out the redirection table as follows: |
| 3506 | * - 82598: 8 bit wide entries containing pair of 4 bit RSS |
| 3507 | * indices. |
| 3508 | * - 82599/X540: 8 bit wide entries containing 4 bit RSS index |
| 3509 | * - X550: 8 bit wide entries containing 6 bit RSS index |
| 3510 | */ |
| 3511 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 3512 | indices_multi = 0x11; |
| 3513 | else |
| 3514 | indices_multi = 0x1; |
| 3515 | |
| 3516 | /* Write redirection table to HW */ |
| 3517 | for (i = 0; i < reta_entries; i++) { |
| 3518 | reta |= indices_multi * indir_tbl[i] << (i & 0x3) * 8; |
| 3519 | if ((i & 3) == 3) { |
| 3520 | if (i < 128) |
| 3521 | IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); |
| 3522 | else |
| 3523 | IXGBE_WRITE_REG(hw, IXGBE_ERETA((i >> 2) - 32), |
| 3524 | reta); |
| 3525 | reta = 0; |
| 3526 | } |
| 3527 | } |
| 3528 | } |
| 3529 | |
| 3530 | /** |
Jean Sacren | a897a2a | 2015-09-19 05:08:44 -0600 | [diff] [blame] | 3531 | * 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] | 3532 | * @adapter: device handle |
| 3533 | * |
| 3534 | * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW. |
| 3535 | */ |
| 3536 | static void ixgbe_store_vfreta(struct ixgbe_adapter *adapter) |
| 3537 | { |
| 3538 | u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter); |
| 3539 | struct ixgbe_hw *hw = &adapter->hw; |
| 3540 | u32 vfreta = 0; |
| 3541 | unsigned int pf_pool = adapter->num_vfs; |
| 3542 | |
| 3543 | /* Write redirection table to HW */ |
| 3544 | for (i = 0; i < reta_entries; i++) { |
| 3545 | vfreta |= (u32)adapter->rss_indir_tbl[i] << (i & 0x3) * 8; |
| 3546 | if ((i & 3) == 3) { |
| 3547 | IXGBE_WRITE_REG(hw, IXGBE_PFVFRETA(i >> 2, pf_pool), |
| 3548 | vfreta); |
| 3549 | vfreta = 0; |
| 3550 | } |
| 3551 | } |
| 3552 | } |
| 3553 | |
| 3554 | static void ixgbe_setup_reta(struct ixgbe_adapter *adapter) |
| 3555 | { |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3556 | u32 i, j; |
| 3557 | u32 reta_entries = ixgbe_rss_indir_tbl_entries(adapter); |
| 3558 | u16 rss_i = adapter->ring_feature[RING_F_RSS].indices; |
| 3559 | |
Alexander Duyck | e24fcf2 | 2016-09-07 20:28:24 -0700 | [diff] [blame] | 3560 | /* 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] | 3561 | * make full use of any rings they may have. We will use the |
| 3562 | * PSRTYPE register to control how many rings we use within the PF. |
| 3563 | */ |
Alexander Duyck | e24fcf2 | 2016-09-07 20:28:24 -0700 | [diff] [blame] | 3564 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 4)) |
| 3565 | rss_i = 4; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3566 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3567 | /* Fill out hash function seeds */ |
Paolo Abeni | d3aa9c9 | 2016-12-15 15:20:34 +0100 | [diff] [blame] | 3568 | ixgbe_store_key(adapter); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3569 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3570 | /* Fill out redirection table */ |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3571 | memset(adapter->rss_indir_tbl, 0, sizeof(adapter->rss_indir_tbl)); |
| 3572 | |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3573 | for (i = 0, j = 0; i < reta_entries; i++, j++) { |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3574 | if (j == rss_i) |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3575 | j = 0; |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3576 | |
| 3577 | adapter->rss_indir_tbl[i] = j; |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3578 | } |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3579 | |
| 3580 | ixgbe_store_reta(adapter); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3581 | } |
| 3582 | |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3583 | static void ixgbe_setup_vfreta(struct ixgbe_adapter *adapter) |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3584 | { |
| 3585 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3586 | u16 rss_i = adapter->ring_feature[RING_F_RSS].indices; |
| 3587 | unsigned int pf_pool = adapter->num_vfs; |
| 3588 | int i, j; |
| 3589 | |
| 3590 | /* Fill out hash function seeds */ |
| 3591 | for (i = 0; i < 10; i++) |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3592 | IXGBE_WRITE_REG(hw, IXGBE_PFVFRSSRK(i, pf_pool), |
| 3593 | adapter->rss_key[i]); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3594 | |
| 3595 | /* Fill out the redirection table */ |
| 3596 | for (i = 0, j = 0; i < 64; i++, j++) { |
| 3597 | if (j == rss_i) |
| 3598 | j = 0; |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3599 | |
| 3600 | adapter->rss_indir_tbl[i] = j; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3601 | } |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3602 | |
| 3603 | ixgbe_store_vfreta(adapter); |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3604 | } |
| 3605 | |
| 3606 | static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter) |
| 3607 | { |
| 3608 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3609 | u32 mrqc = 0, rss_field = 0, vfmrqc = 0; |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3610 | u32 rxcsum; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3611 | |
| 3612 | /* Disable indicating checksum in descriptor, enables RSS hash */ |
| 3613 | rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); |
| 3614 | rxcsum |= IXGBE_RXCSUM_PCSD; |
| 3615 | IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); |
| 3616 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3617 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 3618 | if (adapter->ring_feature[RING_F_RSS].mask) |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3619 | mrqc = IXGBE_MRQC_RSSEN; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3620 | } else { |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3621 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3622 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3623 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 3624 | if (tcs > 4) |
| 3625 | mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */ |
| 3626 | else if (tcs > 1) |
| 3627 | mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */ |
Alexander Duyck | e24fcf2 | 2016-09-07 20:28:24 -0700 | [diff] [blame] | 3628 | else if (adapter->ring_feature[RING_F_VMDQ].mask == |
| 3629 | IXGBE_82599_VMDQ_4Q_MASK) |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3630 | mrqc = IXGBE_MRQC_VMDQRSS32EN; |
| 3631 | else |
| 3632 | mrqc = IXGBE_MRQC_VMDQRSS64EN; |
| 3633 | } else { |
| 3634 | if (tcs > 4) |
| 3635 | mrqc = IXGBE_MRQC_RTRSS8TCEN; |
| 3636 | else if (tcs > 1) |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3637 | mrqc = IXGBE_MRQC_RTRSS4TCEN; |
| 3638 | else |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3639 | mrqc = IXGBE_MRQC_RSSEN; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3640 | } |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3641 | } |
| 3642 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3643 | /* Perform hash on these packet types */ |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3644 | rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4 | |
| 3645 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP | |
| 3646 | IXGBE_MRQC_RSS_FIELD_IPV6 | |
| 3647 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3648 | |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 3649 | if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP) |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3650 | rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP; |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 3651 | if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP) |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3652 | rss_field |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP; |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 3653 | |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3654 | netdev_rss_key_fill(adapter->rss_key, sizeof(adapter->rss_key)); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3655 | if ((hw->mac.type >= ixgbe_mac_X550) && |
| 3656 | (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) { |
| 3657 | unsigned int pf_pool = adapter->num_vfs; |
| 3658 | |
| 3659 | /* Enable VF RSS mode */ |
| 3660 | mrqc |= IXGBE_MRQC_MULTIPLE_RSS; |
| 3661 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
| 3662 | |
| 3663 | /* Setup RSS through the VF registers */ |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3664 | ixgbe_setup_vfreta(adapter); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3665 | vfmrqc = IXGBE_MRQC_RSSEN; |
| 3666 | vfmrqc |= rss_field; |
| 3667 | IXGBE_WRITE_REG(hw, IXGBE_PFVFMRQC(pf_pool), vfmrqc); |
| 3668 | } else { |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3669 | ixgbe_setup_reta(adapter); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3670 | mrqc |= rss_field; |
| 3671 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
| 3672 | } |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3673 | } |
| 3674 | |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3675 | /** |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3676 | * ixgbe_configure_rscctl - enable RSC for the indicated ring |
| 3677 | * @adapter: address of board private structure |
| 3678 | * @index: index of ring to set |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3679 | **/ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 3680 | static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3681 | struct ixgbe_ring *ring) |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3682 | { |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3683 | struct ixgbe_hw *hw = &adapter->hw; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3684 | u32 rscctrl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3685 | u8 reg_idx = ring->reg_idx; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3686 | |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3687 | if (!ring_is_rsc_enabled(ring)) |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3688 | return; |
| 3689 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3690 | rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx)); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3691 | rscctrl |= IXGBE_RSCCTL_RSCEN; |
| 3692 | /* |
| 3693 | * we must limit the number of descriptors so that the |
| 3694 | * total size of max desc * buf_len is not greater |
Alexander Duyck | 642c680 | 2011-11-10 09:09:17 +0000 | [diff] [blame] | 3695 | * than 65536 |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3696 | */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 3697 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3698 | IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3699 | } |
| 3700 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3701 | #define IXGBE_MAX_RX_DESC_POLL 10 |
| 3702 | static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter, |
| 3703 | struct ixgbe_ring *ring) |
| 3704 | { |
| 3705 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3706 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 3707 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3708 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3709 | |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 3710 | if (ixgbe_removed(hw->hw_addr)) |
| 3711 | return; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3712 | /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 3713 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 3714 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 3715 | return; |
| 3716 | |
| 3717 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 3718 | usleep_range(1000, 2000); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3719 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 3720 | } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 3721 | |
| 3722 | if (!wait_loop) { |
| 3723 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within " |
| 3724 | "the polling period\n", reg_idx); |
| 3725 | } |
| 3726 | } |
| 3727 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 3728 | void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter, |
| 3729 | struct ixgbe_ring *ring) |
| 3730 | { |
| 3731 | struct ixgbe_hw *hw = &adapter->hw; |
| 3732 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 3733 | u32 rxdctl; |
| 3734 | u8 reg_idx = ring->reg_idx; |
| 3735 | |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 3736 | if (ixgbe_removed(hw->hw_addr)) |
| 3737 | return; |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 3738 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 3739 | rxdctl &= ~IXGBE_RXDCTL_ENABLE; |
| 3740 | |
| 3741 | /* write value back with RXDCTL.ENABLE bit cleared */ |
| 3742 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 3743 | |
| 3744 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 3745 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 3746 | return; |
| 3747 | |
| 3748 | /* the hardware may take up to 100us to really disable the rx queue */ |
| 3749 | do { |
| 3750 | udelay(10); |
| 3751 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 3752 | } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 3753 | |
| 3754 | if (!wait_loop) { |
| 3755 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within " |
| 3756 | "the polling period\n", reg_idx); |
| 3757 | } |
| 3758 | } |
| 3759 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 3760 | void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter, |
| 3761 | struct ixgbe_ring *ring) |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3762 | { |
| 3763 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | c3630cc | 2017-01-17 08:36:28 -0800 | [diff] [blame] | 3764 | union ixgbe_adv_rx_desc *rx_desc; |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3765 | u64 rdba = ring->dma; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3766 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3767 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3768 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3769 | /* disable queue to avoid issues while updating state */ |
| 3770 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 3771 | ixgbe_disable_rx_queue(adapter, ring); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3772 | |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3773 | IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32))); |
| 3774 | IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32)); |
| 3775 | IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx), |
| 3776 | ring->count * sizeof(union ixgbe_adv_rx_desc)); |
Neerav Parikh | 8b75451 | 2015-12-08 22:13:58 -0800 | [diff] [blame] | 3777 | /* Force flushing of IXGBE_RDLEN to prevent MDD */ |
| 3778 | IXGBE_WRITE_FLUSH(hw); |
| 3779 | |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3780 | IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0); |
| 3781 | IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 3782 | ring->tail = adapter->io_addr + IXGBE_RDT(reg_idx); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3783 | |
| 3784 | ixgbe_configure_srrctl(adapter, ring); |
| 3785 | ixgbe_configure_rscctl(adapter, ring); |
| 3786 | |
| 3787 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 3788 | /* |
| 3789 | * enable cache line friendly hardware writes: |
| 3790 | * PTHRESH=32 descriptors (half the internal cache), |
| 3791 | * this also removes ugly rx_no_buffer_count increment |
| 3792 | * HTHRESH=4 descriptors (to minimize latency on fetch) |
| 3793 | * WTHRESH=8 burst writeback up to two cache lines |
| 3794 | */ |
| 3795 | rxdctl &= ~0x3FFFFF; |
| 3796 | rxdctl |= 0x080420; |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 3797 | #if (PAGE_SIZE < 8192) |
| 3798 | } else { |
| 3799 | rxdctl &= ~(IXGBE_RXDCTL_RLPMLMASK | |
| 3800 | IXGBE_RXDCTL_RLPML_EN); |
| 3801 | |
| 3802 | /* Limit the maximum frame size so we don't overrun the skb */ |
| 3803 | if (ring_uses_build_skb(ring) && |
| 3804 | !test_bit(__IXGBE_RX_3K_BUFFER, &ring->state)) |
| 3805 | rxdctl |= IXGBE_MAX_FRAME_BUILD_SKB | |
| 3806 | IXGBE_RXDCTL_RLPML_EN; |
| 3807 | #endif |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3808 | } |
| 3809 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 3810 | /* initialize rx_buffer_info */ |
| 3811 | memset(ring->rx_buffer_info, 0, |
| 3812 | sizeof(struct ixgbe_rx_buffer) * ring->count); |
| 3813 | |
Alexander Duyck | c3630cc | 2017-01-17 08:36:28 -0800 | [diff] [blame] | 3814 | /* initialize Rx descriptor 0 */ |
| 3815 | rx_desc = IXGBE_RX_DESC(ring, 0); |
| 3816 | rx_desc->wb.upper.length = 0; |
| 3817 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3818 | /* enable receive descriptor ring */ |
| 3819 | rxdctl |= IXGBE_RXDCTL_ENABLE; |
| 3820 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 3821 | |
| 3822 | ixgbe_rx_desc_queue_enable(adapter, ring); |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 3823 | ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring)); |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3824 | } |
| 3825 | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3826 | static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter) |
| 3827 | { |
| 3828 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 3829 | int rss_i = adapter->ring_feature[RING_F_RSS].indices; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 3830 | u16 pool; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3831 | |
| 3832 | /* PSRTYPE must be initialized in non 82598 adapters */ |
| 3833 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3834 | IXGBE_PSRTYPE_UDPHDR | |
| 3835 | IXGBE_PSRTYPE_IPV4HDR | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3836 | IXGBE_PSRTYPE_L2HDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3837 | IXGBE_PSRTYPE_IPV6HDR; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3838 | |
| 3839 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3840 | return; |
| 3841 | |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 3842 | if (rss_i > 3) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 3843 | psrtype |= 2u << 29; |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 3844 | else if (rss_i > 1) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 3845 | psrtype |= 1u << 29; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3846 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 3847 | for_each_set_bit(pool, &adapter->fwd_bitmask, 32) |
| 3848 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype); |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3849 | } |
| 3850 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3851 | static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter) |
| 3852 | { |
| 3853 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3854 | u32 reg_offset, vf_shift; |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3855 | u32 gcr_ext, vmdctl; |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 3856 | int i; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3857 | |
| 3858 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 3859 | return; |
| 3860 | |
| 3861 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL); |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3862 | vmdctl |= IXGBE_VMD_CTL_VMDQ_EN; |
| 3863 | vmdctl &= ~IXGBE_VT_CTL_POOL_MASK; |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3864 | vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT; |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3865 | vmdctl |= IXGBE_VT_CTL_REPLEN; |
| 3866 | IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3867 | |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3868 | vf_shift = VMDQ_P(0) % 32; |
| 3869 | reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3870 | |
| 3871 | /* Enable only the PF's pool for Tx/Rx */ |
Emil Tantilov | 11f2b49 | 2016-05-04 15:01:27 -0700 | [diff] [blame] | 3872 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), GENMASK(31, vf_shift)); |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3873 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1); |
Emil Tantilov | 11f2b49 | 2016-05-04 15:01:27 -0700 | [diff] [blame] | 3874 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), GENMASK(31, vf_shift)); |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3875 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1); |
Don Skidmore | aa2bacb | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 3876 | if (adapter->bridge_mode == BRIDGE_MODE_VEB) |
Greg Rose | 9b73598 | 2012-11-08 02:41:35 +0000 | [diff] [blame] | 3877 | IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3878 | |
| 3879 | /* 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] | 3880 | hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0)); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3881 | |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 3882 | /* clear VLAN promisc flag so VFTA will be updated if necessary */ |
| 3883 | adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC; |
| 3884 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3885 | /* |
| 3886 | * Set up VF register offsets for selected VT Mode, |
| 3887 | * i.e. 32 or 64 VFs for SR-IOV |
| 3888 | */ |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 3889 | switch (adapter->ring_feature[RING_F_VMDQ].mask) { |
| 3890 | case IXGBE_82599_VMDQ_8Q_MASK: |
| 3891 | gcr_ext = IXGBE_GCR_EXT_VT_MODE_16; |
| 3892 | break; |
| 3893 | case IXGBE_82599_VMDQ_4Q_MASK: |
| 3894 | gcr_ext = IXGBE_GCR_EXT_VT_MODE_32; |
| 3895 | break; |
| 3896 | default: |
| 3897 | gcr_ext = IXGBE_GCR_EXT_VT_MODE_64; |
| 3898 | break; |
| 3899 | } |
| 3900 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3901 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext); |
| 3902 | |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 3903 | for (i = 0; i < adapter->num_vfs; i++) { |
Emil Tantilov | 77f192a | 2016-03-18 16:11:14 -0700 | [diff] [blame] | 3904 | /* configure spoof checking */ |
| 3905 | ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, |
| 3906 | adapter->vfinfo[i].spoofchk_enabled); |
Vlad Zolotarov | e65ce0d | 2015-03-30 21:35:24 +0300 | [diff] [blame] | 3907 | |
| 3908 | /* Enable/Disable RSS query feature */ |
| 3909 | ixgbe_ndo_set_vf_rss_query_en(adapter->netdev, i, |
| 3910 | adapter->vfinfo[i].rss_query_enabled); |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 3911 | } |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3912 | } |
| 3913 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3914 | static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3915 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3916 | struct ixgbe_hw *hw = &adapter->hw; |
| 3917 | struct net_device *netdev = adapter->netdev; |
| 3918 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3919 | struct ixgbe_ring *rx_ring; |
| 3920 | int i; |
| 3921 | u32 mhadd, hlreg0; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3922 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3923 | #ifdef IXGBE_FCOE |
| 3924 | /* adjust max frame to be able to do baby jumbo for FCoE */ |
| 3925 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 3926 | (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE)) |
| 3927 | max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 3928 | |
| 3929 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 3930 | |
| 3931 | /* adjust max frame to be at least the size of a standard frame */ |
| 3932 | if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN)) |
| 3933 | max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN); |
| 3934 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3935 | mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD); |
| 3936 | if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) { |
| 3937 | mhadd &= ~IXGBE_MHADD_MFS_MASK; |
| 3938 | mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT; |
| 3939 | |
| 3940 | IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3941 | } |
| 3942 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3943 | hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3944 | /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */ |
| 3945 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3946 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0); |
| 3947 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3948 | /* |
| 3949 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3950 | * the Base and Length of the Rx Descriptor Ring |
| 3951 | */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3952 | for (i = 0; i < adapter->num_rx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3953 | rx_ring = adapter->rx_ring[i]; |
Alexander Duyck | 4f4542b | 2017-01-17 08:36:14 -0800 | [diff] [blame] | 3954 | |
| 3955 | clear_ring_rsc_enabled(rx_ring); |
| 3956 | clear_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state); |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 3957 | clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state); |
Alexander Duyck | 4f4542b | 2017-01-17 08:36:14 -0800 | [diff] [blame] | 3958 | |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3959 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
| 3960 | set_ring_rsc_enabled(rx_ring); |
Alexander Duyck | 4f4542b | 2017-01-17 08:36:14 -0800 | [diff] [blame] | 3961 | |
| 3962 | if (test_bit(__IXGBE_RX_FCOE, &rx_ring->state)) |
| 3963 | set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state); |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 3964 | |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 3965 | clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state); |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 3966 | if (adapter->flags2 & IXGBE_FLAG2_RX_LEGACY) |
| 3967 | continue; |
| 3968 | |
| 3969 | set_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state); |
| 3970 | |
| 3971 | #if (PAGE_SIZE < 8192) |
| 3972 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
| 3973 | set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state); |
| 3974 | |
Alexander Duyck | c74042f | 2017-02-03 09:19:40 -0800 | [diff] [blame] | 3975 | if ((max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)) || |
| 3976 | (max_frame > IXGBE_MAX_FRAME_BUILD_SKB)) |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 3977 | set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state); |
| 3978 | #endif |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3979 | } |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3980 | } |
| 3981 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3982 | static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter) |
| 3983 | { |
| 3984 | struct ixgbe_hw *hw = &adapter->hw; |
| 3985 | u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 3986 | |
| 3987 | switch (hw->mac.type) { |
| 3988 | case ixgbe_mac_82598EB: |
| 3989 | /* |
| 3990 | * For VMDq support of different descriptor types or |
| 3991 | * buffer sizes through the use of multiple SRRCTL |
| 3992 | * registers, RDRXCTL.MVMEN must be set to 1 |
| 3993 | * |
| 3994 | * also, the manual doesn't mention it clearly but DCA hints |
| 3995 | * will only use queue 0's tags unless this bit is set. Side |
| 3996 | * effects of setting this bit are only that SRRCTL must be |
| 3997 | * fully programmed [0..15] |
| 3998 | */ |
| 3999 | rdrxctl |= IXGBE_RDRXCTL_MVMEN; |
| 4000 | break; |
Mark Rustad | 052a1a7 | 2015-08-08 16:19:04 -0700 | [diff] [blame] | 4001 | case ixgbe_mac_X550: |
| 4002 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 4003 | case ixgbe_mac_x550em_a: |
Mark Rustad | f961dda | 2015-08-08 16:19:09 -0700 | [diff] [blame] | 4004 | if (adapter->num_vfs) |
| 4005 | rdrxctl |= IXGBE_RDRXCTL_PSP; |
| 4006 | /* fall through for older HW */ |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 4007 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4008 | case ixgbe_mac_X540: |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 4009 | /* Disable RSC for ACK packets */ |
| 4010 | IXGBE_WRITE_REG(hw, IXGBE_RSCDBU, |
| 4011 | (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU))); |
| 4012 | rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE; |
| 4013 | /* hardware requires some bits to be set by default */ |
| 4014 | rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX); |
| 4015 | rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP; |
| 4016 | break; |
| 4017 | default: |
| 4018 | /* We should do nothing since we don't know this hardware */ |
| 4019 | return; |
| 4020 | } |
| 4021 | |
| 4022 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
| 4023 | } |
| 4024 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4025 | /** |
| 4026 | * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset |
| 4027 | * @adapter: board private structure |
| 4028 | * |
| 4029 | * Configure the Rx unit of the MAC after a reset. |
| 4030 | **/ |
| 4031 | static void ixgbe_configure_rx(struct ixgbe_adapter *adapter) |
| 4032 | { |
| 4033 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4034 | int i; |
Jacob Keller | 6dcc28b | 2013-07-17 02:53:23 +0000 | [diff] [blame] | 4035 | u32 rxctrl, rfctl; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4036 | |
| 4037 | /* disable receives while setting up the descriptors */ |
Don Skidmore | 1f9ac57 | 2015-03-13 13:54:30 -0700 | [diff] [blame] | 4038 | hw->mac.ops.disable_rx(hw); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4039 | |
| 4040 | ixgbe_setup_psrtype(adapter); |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 4041 | ixgbe_setup_rdrxctl(adapter); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4042 | |
Jacob Keller | 6dcc28b | 2013-07-17 02:53:23 +0000 | [diff] [blame] | 4043 | /* RSC Setup */ |
| 4044 | rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL); |
| 4045 | rfctl &= ~IXGBE_RFCTL_RSC_DIS; |
| 4046 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) |
| 4047 | rfctl |= IXGBE_RFCTL_RSC_DIS; |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 4048 | |
| 4049 | /* disable NFS filtering */ |
| 4050 | rfctl |= (IXGBE_RFCTL_NFSW_DIS | IXGBE_RFCTL_NFSR_DIS); |
Jacob Keller | 6dcc28b | 2013-07-17 02:53:23 +0000 | [diff] [blame] | 4051 | IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl); |
| 4052 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4053 | /* Program registers for the distribution of queues */ |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 4054 | ixgbe_setup_mrqc(adapter); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 4055 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4056 | /* set_rx_buffer_len must be called before ring initialization */ |
| 4057 | ixgbe_set_rx_buffer_len(adapter); |
| 4058 | |
| 4059 | /* |
| 4060 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 4061 | * the Base and Length of the Rx Descriptor Ring |
| 4062 | */ |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4063 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 4064 | ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 4065 | |
Don Skidmore | 1f9ac57 | 2015-03-13 13:54:30 -0700 | [diff] [blame] | 4066 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4067 | /* disable drop enable for 82598 parts */ |
| 4068 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4069 | rxctrl |= IXGBE_RXCTRL_DMBYPS; |
| 4070 | |
| 4071 | /* enable all receives */ |
| 4072 | rxctrl |= IXGBE_RXCTRL_RXEN; |
| 4073 | hw->mac.ops.enable_rx_dma(hw, rxctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4074 | } |
| 4075 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 4076 | static int ixgbe_vlan_rx_add_vid(struct net_device *netdev, |
| 4077 | __be16 proto, u16 vid) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4078 | { |
| 4079 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4080 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4081 | |
| 4082 | /* add VID to filter table */ |
Alexander Duyck | 18be4fc | 2016-01-06 22:48:44 -0800 | [diff] [blame] | 4083 | if (!vid || !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)) |
| 4084 | hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true, !!vid); |
| 4085 | |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4086 | set_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 4087 | |
| 4088 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4089 | } |
| 4090 | |
Alexander Duyck | e1d0a2a | 2015-11-02 17:10:19 -0800 | [diff] [blame] | 4091 | static int ixgbe_find_vlvf_entry(struct ixgbe_hw *hw, u32 vlan) |
| 4092 | { |
| 4093 | u32 vlvf; |
| 4094 | int idx; |
| 4095 | |
| 4096 | /* short cut the special case */ |
| 4097 | if (vlan == 0) |
| 4098 | return 0; |
| 4099 | |
| 4100 | /* Search for the vlan id in the VLVF entries */ |
| 4101 | for (idx = IXGBE_VLVF_ENTRIES; --idx;) { |
| 4102 | vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(idx)); |
| 4103 | if ((vlvf & VLAN_VID_MASK) == vlan) |
| 4104 | break; |
| 4105 | } |
| 4106 | |
| 4107 | return idx; |
| 4108 | } |
| 4109 | |
| 4110 | void ixgbe_update_pf_promisc_vlvf(struct ixgbe_adapter *adapter, u32 vid) |
| 4111 | { |
| 4112 | struct ixgbe_hw *hw = &adapter->hw; |
| 4113 | u32 bits, word; |
| 4114 | int idx; |
| 4115 | |
| 4116 | idx = ixgbe_find_vlvf_entry(hw, vid); |
| 4117 | if (!idx) |
| 4118 | return; |
| 4119 | |
| 4120 | /* See if any other pools are set for this VLAN filter |
| 4121 | * entry other than the PF. |
| 4122 | */ |
| 4123 | word = idx * 2 + (VMDQ_P(0) / 32); |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 4124 | bits = ~BIT(VMDQ_P(0) % 32); |
Alexander Duyck | e1d0a2a | 2015-11-02 17:10:19 -0800 | [diff] [blame] | 4125 | bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word)); |
| 4126 | |
| 4127 | /* Disable the filter so this falls into the default pool. */ |
| 4128 | if (!bits && !IXGBE_READ_REG(hw, IXGBE_VLVFB(word ^ 1))) { |
| 4129 | if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)) |
| 4130 | IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), 0); |
| 4131 | IXGBE_WRITE_REG(hw, IXGBE_VLVF(idx), 0); |
| 4132 | } |
| 4133 | } |
| 4134 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 4135 | static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev, |
| 4136 | __be16 proto, u16 vid) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4137 | { |
| 4138 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4139 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4140 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4141 | /* remove VID from filter table */ |
Alexander Duyck | 18be4fc | 2016-01-06 22:48:44 -0800 | [diff] [blame] | 4142 | if (vid && !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)) |
Alexander Duyck | e1d0a2a | 2015-11-02 17:10:19 -0800 | [diff] [blame] | 4143 | hw->mac.ops.set_vfta(hw, vid, VMDQ_P(0), false, true); |
| 4144 | |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4145 | clear_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 4146 | |
| 4147 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4148 | } |
| 4149 | |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4150 | /** |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4151 | * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping |
| 4152 | * @adapter: driver data |
| 4153 | */ |
| 4154 | static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter) |
| 4155 | { |
| 4156 | struct ixgbe_hw *hw = &adapter->hw; |
| 4157 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4158 | int i, j; |
| 4159 | |
| 4160 | switch (hw->mac.type) { |
| 4161 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4162 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 4163 | vlnctrl &= ~IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4164 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4165 | break; |
| 4166 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4167 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 4168 | case ixgbe_mac_X550: |
| 4169 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 4170 | case ixgbe_mac_x550em_a: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4171 | for (i = 0; i < adapter->num_rx_queues; i++) { |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4172 | struct ixgbe_ring *ring = adapter->rx_ring[i]; |
| 4173 | |
| 4174 | if (ring->l2_accel_priv) |
| 4175 | continue; |
| 4176 | j = ring->reg_idx; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4177 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 4178 | vlnctrl &= ~IXGBE_RXDCTL_VME; |
| 4179 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 4180 | } |
| 4181 | break; |
| 4182 | default: |
| 4183 | break; |
| 4184 | } |
| 4185 | } |
| 4186 | |
| 4187 | /** |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4188 | * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4189 | * @adapter: driver data |
| 4190 | */ |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4191 | static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4192 | { |
| 4193 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4194 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4195 | int i, j; |
| 4196 | |
| 4197 | switch (hw->mac.type) { |
| 4198 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4199 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 4200 | vlnctrl |= IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4201 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4202 | break; |
| 4203 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4204 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 4205 | case ixgbe_mac_X550: |
| 4206 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 4207 | case ixgbe_mac_x550em_a: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4208 | for (i = 0; i < adapter->num_rx_queues; i++) { |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4209 | struct ixgbe_ring *ring = adapter->rx_ring[i]; |
| 4210 | |
| 4211 | if (ring->l2_accel_priv) |
| 4212 | continue; |
| 4213 | j = ring->reg_idx; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4214 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 4215 | vlnctrl |= IXGBE_RXDCTL_VME; |
| 4216 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 4217 | } |
| 4218 | break; |
| 4219 | default: |
| 4220 | break; |
| 4221 | } |
| 4222 | } |
| 4223 | |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4224 | static void ixgbe_vlan_promisc_enable(struct ixgbe_adapter *adapter) |
| 4225 | { |
| 4226 | struct ixgbe_hw *hw = &adapter->hw; |
| 4227 | u32 vlnctrl, i; |
| 4228 | |
Alexander Duyck | f60439b | 2016-08-11 14:51:56 -0700 | [diff] [blame] | 4229 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 4230 | |
Emil Tantilov | 691e412 | 2016-08-22 16:17:46 -0700 | [diff] [blame] | 4231 | if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) { |
| 4232 | /* For VMDq and SR-IOV we must leave VLAN filtering enabled */ |
| 4233 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
| 4234 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4235 | } else { |
Alexander Duyck | f60439b | 2016-08-11 14:51:56 -0700 | [diff] [blame] | 4236 | vlnctrl &= ~IXGBE_VLNCTRL_VFE; |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4237 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4238 | return; |
| 4239 | } |
| 4240 | |
Emil Tantilov | 691e412 | 2016-08-22 16:17:46 -0700 | [diff] [blame] | 4241 | /* Nothing to do for 82598 */ |
| 4242 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4243 | return; |
| 4244 | |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4245 | /* We are already in VLAN promisc, nothing to do */ |
| 4246 | if (adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC) |
| 4247 | return; |
| 4248 | |
| 4249 | /* Set flag so we don't redo unnecessary work */ |
| 4250 | adapter->flags2 |= IXGBE_FLAG2_VLAN_PROMISC; |
| 4251 | |
| 4252 | /* Add PF to all active pools */ |
| 4253 | for (i = IXGBE_VLVF_ENTRIES; --i;) { |
| 4254 | u32 reg_offset = IXGBE_VLVFB(i * 2 + VMDQ_P(0) / 32); |
| 4255 | u32 vlvfb = IXGBE_READ_REG(hw, reg_offset); |
| 4256 | |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 4257 | vlvfb |= BIT(VMDQ_P(0) % 32); |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4258 | IXGBE_WRITE_REG(hw, reg_offset, vlvfb); |
| 4259 | } |
| 4260 | |
| 4261 | /* Set all bits in the VLAN filter table array */ |
| 4262 | for (i = hw->mac.vft_size; i--;) |
| 4263 | IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), ~0U); |
| 4264 | } |
| 4265 | |
| 4266 | #define VFTA_BLOCK_SIZE 8 |
| 4267 | static void ixgbe_scrub_vfta(struct ixgbe_adapter *adapter, u32 vfta_offset) |
| 4268 | { |
| 4269 | struct ixgbe_hw *hw = &adapter->hw; |
| 4270 | u32 vfta[VFTA_BLOCK_SIZE] = { 0 }; |
| 4271 | u32 vid_start = vfta_offset * 32; |
| 4272 | u32 vid_end = vid_start + (VFTA_BLOCK_SIZE * 32); |
| 4273 | u32 i, vid, word, bits; |
| 4274 | |
| 4275 | for (i = IXGBE_VLVF_ENTRIES; --i;) { |
| 4276 | u32 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(i)); |
| 4277 | |
| 4278 | /* pull VLAN ID from VLVF */ |
| 4279 | vid = vlvf & VLAN_VID_MASK; |
| 4280 | |
| 4281 | /* only concern outselves with a certain range */ |
| 4282 | if (vid < vid_start || vid >= vid_end) |
| 4283 | continue; |
| 4284 | |
| 4285 | if (vlvf) { |
| 4286 | /* record VLAN ID in VFTA */ |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 4287 | vfta[(vid - vid_start) / 32] |= BIT(vid % 32); |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4288 | |
| 4289 | /* if PF is part of this then continue */ |
| 4290 | if (test_bit(vid, adapter->active_vlans)) |
| 4291 | continue; |
| 4292 | } |
| 4293 | |
| 4294 | /* remove PF from the pool */ |
| 4295 | word = i * 2 + VMDQ_P(0) / 32; |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 4296 | bits = ~BIT(VMDQ_P(0) % 32); |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4297 | bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word)); |
| 4298 | IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), bits); |
| 4299 | } |
| 4300 | |
| 4301 | /* extract values from active_vlans and write back to VFTA */ |
| 4302 | for (i = VFTA_BLOCK_SIZE; i--;) { |
| 4303 | vid = (vfta_offset + i) * 32; |
| 4304 | word = vid / BITS_PER_LONG; |
| 4305 | bits = vid % BITS_PER_LONG; |
| 4306 | |
| 4307 | vfta[i] |= adapter->active_vlans[word] >> bits; |
| 4308 | |
| 4309 | IXGBE_WRITE_REG(hw, IXGBE_VFTA(vfta_offset + i), vfta[i]); |
| 4310 | } |
| 4311 | } |
| 4312 | |
| 4313 | static void ixgbe_vlan_promisc_disable(struct ixgbe_adapter *adapter) |
| 4314 | { |
| 4315 | struct ixgbe_hw *hw = &adapter->hw; |
| 4316 | u32 vlnctrl, i; |
| 4317 | |
Alexander Duyck | f60439b | 2016-08-11 14:51:56 -0700 | [diff] [blame] | 4318 | /* Set VLAN filtering to enabled */ |
| 4319 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 4320 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
| 4321 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4322 | |
Emil Tantilov | 691e412 | 2016-08-22 16:17:46 -0700 | [diff] [blame] | 4323 | if (!(adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) || |
| 4324 | hw->mac.type == ixgbe_mac_82598EB) |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4325 | return; |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4326 | |
| 4327 | /* We are not in VLAN promisc, nothing to do */ |
| 4328 | if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)) |
| 4329 | return; |
| 4330 | |
| 4331 | /* Set flag so we don't redo unnecessary work */ |
| 4332 | adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC; |
| 4333 | |
| 4334 | for (i = 0; i < hw->mac.vft_size; i += VFTA_BLOCK_SIZE) |
| 4335 | ixgbe_scrub_vfta(adapter, i); |
| 4336 | } |
| 4337 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4338 | static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter) |
| 4339 | { |
Alexander Duyck | 06bb1c3 | 2016-01-06 22:48:50 -0800 | [diff] [blame] | 4340 | u16 vid = 1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4341 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 4342 | ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4343 | |
Alexander Duyck | 06bb1c3 | 2016-01-06 22:48:50 -0800 | [diff] [blame] | 4344 | for_each_set_bit_from(vid, adapter->active_vlans, VLAN_N_VID) |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 4345 | ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4346 | } |
| 4347 | |
| 4348 | /** |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4349 | * ixgbe_write_mc_addr_list - write multicast addresses to MTA |
| 4350 | * @netdev: network interface device structure |
| 4351 | * |
| 4352 | * Writes multicast address list to the MTA hash table. |
| 4353 | * Returns: -ENOMEM on failure |
| 4354 | * 0 on no addresses written |
| 4355 | * X on writing X addresses to MTA |
| 4356 | **/ |
| 4357 | static int ixgbe_write_mc_addr_list(struct net_device *netdev) |
| 4358 | { |
| 4359 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4360 | struct ixgbe_hw *hw = &adapter->hw; |
| 4361 | |
| 4362 | if (!netif_running(netdev)) |
| 4363 | return 0; |
| 4364 | |
| 4365 | if (hw->mac.ops.update_mc_addr_list) |
| 4366 | hw->mac.ops.update_mc_addr_list(hw, netdev); |
| 4367 | else |
| 4368 | return -ENOMEM; |
| 4369 | |
| 4370 | #ifdef CONFIG_PCI_IOV |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4371 | ixgbe_restore_vf_multicasts(adapter); |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4372 | #endif |
| 4373 | |
| 4374 | return netdev_mc_count(netdev); |
| 4375 | } |
| 4376 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4377 | #ifdef CONFIG_PCI_IOV |
| 4378 | void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter) |
| 4379 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4380 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4381 | struct ixgbe_hw *hw = &adapter->hw; |
| 4382 | int i; |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4383 | |
| 4384 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4385 | mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED; |
| 4386 | |
| 4387 | if (mac_table->state & IXGBE_MAC_STATE_IN_USE) |
| 4388 | hw->mac.ops.set_rar(hw, i, |
| 4389 | mac_table->addr, |
| 4390 | mac_table->pool, |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4391 | IXGBE_RAH_AV); |
| 4392 | else |
| 4393 | hw->mac.ops.clear_rar(hw, i); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4394 | } |
| 4395 | } |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4396 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4397 | #endif |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4398 | static void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter) |
| 4399 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4400 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4401 | struct ixgbe_hw *hw = &adapter->hw; |
| 4402 | int i; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4403 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4404 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4405 | if (!(mac_table->state & IXGBE_MAC_STATE_MODIFIED)) |
| 4406 | continue; |
| 4407 | |
| 4408 | mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED; |
| 4409 | |
| 4410 | if (mac_table->state & IXGBE_MAC_STATE_IN_USE) |
| 4411 | hw->mac.ops.set_rar(hw, i, |
| 4412 | mac_table->addr, |
| 4413 | mac_table->pool, |
| 4414 | IXGBE_RAH_AV); |
| 4415 | else |
| 4416 | hw->mac.ops.clear_rar(hw, i); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4417 | } |
| 4418 | } |
| 4419 | |
| 4420 | static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter) |
| 4421 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4422 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4423 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4424 | int i; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4425 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4426 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4427 | mac_table->state |= IXGBE_MAC_STATE_MODIFIED; |
| 4428 | mac_table->state &= ~IXGBE_MAC_STATE_IN_USE; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4429 | } |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4430 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4431 | ixgbe_sync_mac_table(adapter); |
| 4432 | } |
| 4433 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4434 | static int ixgbe_available_rars(struct ixgbe_adapter *adapter, u16 pool) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4435 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4436 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4437 | struct ixgbe_hw *hw = &adapter->hw; |
| 4438 | int i, count = 0; |
| 4439 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4440 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4441 | /* do not count default RAR as available */ |
| 4442 | if (mac_table->state & IXGBE_MAC_STATE_DEFAULT) |
| 4443 | continue; |
| 4444 | |
| 4445 | /* only count unused and addresses that belong to us */ |
| 4446 | if (mac_table->state & IXGBE_MAC_STATE_IN_USE) { |
| 4447 | if (mac_table->pool != pool) |
| 4448 | continue; |
| 4449 | } |
| 4450 | |
| 4451 | count++; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4452 | } |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4453 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4454 | return count; |
| 4455 | } |
| 4456 | |
| 4457 | /* this function destroys the first RAR entry */ |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4458 | static void ixgbe_mac_set_default_filter(struct ixgbe_adapter *adapter) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4459 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4460 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4461 | struct ixgbe_hw *hw = &adapter->hw; |
| 4462 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4463 | memcpy(&mac_table->addr, hw->mac.addr, ETH_ALEN); |
| 4464 | mac_table->pool = VMDQ_P(0); |
| 4465 | |
| 4466 | mac_table->state = IXGBE_MAC_STATE_DEFAULT | IXGBE_MAC_STATE_IN_USE; |
| 4467 | |
| 4468 | 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] | 4469 | IXGBE_RAH_AV); |
| 4470 | } |
| 4471 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4472 | int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter, |
| 4473 | const u8 *addr, u16 pool) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4474 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4475 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4476 | struct ixgbe_hw *hw = &adapter->hw; |
| 4477 | int i; |
| 4478 | |
| 4479 | if (is_zero_ether_addr(addr)) |
| 4480 | return -EINVAL; |
| 4481 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4482 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4483 | if (mac_table->state & IXGBE_MAC_STATE_IN_USE) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4484 | continue; |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4485 | |
| 4486 | ether_addr_copy(mac_table->addr, addr); |
| 4487 | mac_table->pool = pool; |
| 4488 | |
| 4489 | mac_table->state |= IXGBE_MAC_STATE_MODIFIED | |
| 4490 | IXGBE_MAC_STATE_IN_USE; |
| 4491 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4492 | ixgbe_sync_mac_table(adapter); |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4493 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4494 | return i; |
| 4495 | } |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4496 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4497 | return -ENOMEM; |
| 4498 | } |
| 4499 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4500 | int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter, |
| 4501 | const u8 *addr, u16 pool) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4502 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4503 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4504 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4505 | int i; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4506 | |
| 4507 | if (is_zero_ether_addr(addr)) |
| 4508 | return -EINVAL; |
| 4509 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4510 | /* search table for addr, if found clear IN_USE flag and sync */ |
| 4511 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4512 | /* we can only delete an entry if it is in use */ |
| 4513 | if (!(mac_table->state & IXGBE_MAC_STATE_IN_USE)) |
| 4514 | continue; |
| 4515 | /* we only care about entries that belong to the given pool */ |
| 4516 | if (mac_table->pool != pool) |
| 4517 | continue; |
| 4518 | /* we only care about a specific MAC address */ |
| 4519 | if (!ether_addr_equal(addr, mac_table->addr)) |
| 4520 | continue; |
| 4521 | |
| 4522 | mac_table->state |= IXGBE_MAC_STATE_MODIFIED; |
| 4523 | mac_table->state &= ~IXGBE_MAC_STATE_IN_USE; |
| 4524 | |
| 4525 | ixgbe_sync_mac_table(adapter); |
| 4526 | |
| 4527 | return 0; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4528 | } |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4529 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4530 | return -ENOMEM; |
| 4531 | } |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4532 | /** |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4533 | * ixgbe_write_uc_addr_list - write unicast addresses to RAR table |
| 4534 | * @netdev: network interface device structure |
| 4535 | * |
| 4536 | * Writes unicast address list to the RAR table. |
| 4537 | * Returns: -ENOMEM on failure/insufficient address space |
| 4538 | * 0 on no addresses written |
| 4539 | * X on writing X addresses to the RAR table |
| 4540 | **/ |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4541 | 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] | 4542 | { |
| 4543 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4544 | int count = 0; |
| 4545 | |
| 4546 | /* return ENOMEM indicating insufficient memory for addresses */ |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4547 | if (netdev_uc_count(netdev) > ixgbe_available_rars(adapter, vfn)) |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4548 | return -ENOMEM; |
| 4549 | |
John Fastabend | 9544746 | 2012-05-31 12:42:26 +0000 | [diff] [blame] | 4550 | if (!netdev_uc_empty(netdev)) { |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4551 | struct netdev_hw_addr *ha; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4552 | netdev_for_each_uc_addr(ha, netdev) { |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4553 | ixgbe_del_mac_filter(adapter, ha->addr, vfn); |
| 4554 | ixgbe_add_mac_filter(adapter, ha->addr, vfn); |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4555 | count++; |
| 4556 | } |
| 4557 | } |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4558 | return count; |
| 4559 | } |
| 4560 | |
Alexander Duyck | 0f079d2 | 2015-10-22 16:26:36 -0700 | [diff] [blame] | 4561 | static int ixgbe_uc_sync(struct net_device *netdev, const unsigned char *addr) |
| 4562 | { |
| 4563 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4564 | int ret; |
| 4565 | |
| 4566 | ret = ixgbe_add_mac_filter(adapter, addr, VMDQ_P(0)); |
| 4567 | |
| 4568 | return min_t(int, ret, 0); |
| 4569 | } |
| 4570 | |
| 4571 | static int ixgbe_uc_unsync(struct net_device *netdev, const unsigned char *addr) |
| 4572 | { |
| 4573 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4574 | |
| 4575 | ixgbe_del_mac_filter(adapter, addr, VMDQ_P(0)); |
| 4576 | |
| 4577 | return 0; |
| 4578 | } |
| 4579 | |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4580 | /** |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 4581 | * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4582 | * @netdev: network interface device structure |
| 4583 | * |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 4584 | * The set_rx_method entry point is called whenever the unicast/multicast |
| 4585 | * address list or the network interface flags are updated. This routine is |
| 4586 | * responsible for configuring the hardware for proper unicast, multicast and |
| 4587 | * promiscuous mode. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4588 | **/ |
Greg Rose | 7f87047 | 2010-01-09 02:25:29 +0000 | [diff] [blame] | 4589 | void ixgbe_set_rx_mode(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4590 | { |
| 4591 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4592 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4593 | u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE; |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 4594 | netdev_features_t features = netdev->features; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4595 | int count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4596 | |
| 4597 | /* Check for Promiscuous and All Multicast modes */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4598 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 4599 | |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 4600 | /* set all bits that we expect to always be set */ |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 4601 | fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */ |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 4602 | fctrl |= IXGBE_FCTRL_BAM; |
| 4603 | fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */ |
| 4604 | fctrl |= IXGBE_FCTRL_PMCF; |
| 4605 | |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4606 | /* clear the bits we are changing the status of */ |
| 4607 | fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4608 | if (netdev->flags & IFF_PROMISC) { |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 4609 | hw->addr_ctrl.user_set_promisc = true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4610 | fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4611 | vmolr |= IXGBE_VMOLR_MPE; |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 4612 | features &= ~NETIF_F_HW_VLAN_CTAG_FILTER; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4613 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 4614 | if (netdev->flags & IFF_ALLMULTI) { |
| 4615 | fctrl |= IXGBE_FCTRL_MPE; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4616 | vmolr |= IXGBE_VMOLR_MPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 4617 | } |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 4618 | hw->addr_ctrl.user_set_promisc = false; |
John Fastabend | 9dcb373 | 2012-04-15 06:44:25 +0000 | [diff] [blame] | 4619 | } |
| 4620 | |
| 4621 | /* |
| 4622 | * Write addresses to available RAR registers, if there is not |
| 4623 | * sufficient space to store all the addresses then enable |
| 4624 | * unicast promiscuous mode |
| 4625 | */ |
Alexander Duyck | 0f079d2 | 2015-10-22 16:26:36 -0700 | [diff] [blame] | 4626 | if (__dev_uc_sync(netdev, ixgbe_uc_sync, ixgbe_uc_unsync)) { |
John Fastabend | 9dcb373 | 2012-04-15 06:44:25 +0000 | [diff] [blame] | 4627 | fctrl |= IXGBE_FCTRL_UPE; |
| 4628 | vmolr |= IXGBE_VMOLR_ROPE; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4629 | } |
| 4630 | |
Emil Tantilov | cf78959 | 2013-10-26 08:13:20 +0000 | [diff] [blame] | 4631 | /* Write addresses to the MTA, if the attempt fails |
| 4632 | * then we should just turn on promiscuous mode so |
| 4633 | * that we can at least receive multicast traffic |
| 4634 | */ |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4635 | count = ixgbe_write_mc_addr_list(netdev); |
| 4636 | if (count < 0) { |
| 4637 | fctrl |= IXGBE_FCTRL_MPE; |
| 4638 | vmolr |= IXGBE_VMOLR_MPE; |
| 4639 | } else if (count) { |
| 4640 | vmolr |= IXGBE_VMOLR_ROMPE; |
| 4641 | } |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 4642 | |
| 4643 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 4644 | vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) & |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4645 | ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE | |
| 4646 | IXGBE_VMOLR_ROPE); |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 4647 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4648 | } |
| 4649 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 4650 | /* This is useful for sniffing bad packets. */ |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 4651 | if (features & NETIF_F_RXALL) { |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 4652 | /* UPE and MPE will be handled by normal PROMISC logic |
| 4653 | * in e1000e_set_rx_mode */ |
| 4654 | fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */ |
| 4655 | IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */ |
| 4656 | IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */ |
| 4657 | |
| 4658 | fctrl &= ~(IXGBE_FCTRL_DPF); |
| 4659 | /* NOTE: VLAN filtering is disabled by setting PROMISC */ |
| 4660 | } |
| 4661 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4662 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4663 | |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 4664 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4665 | ixgbe_vlan_strip_enable(adapter); |
| 4666 | else |
| 4667 | ixgbe_vlan_strip_disable(adapter); |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 4668 | |
| 4669 | if (features & NETIF_F_HW_VLAN_CTAG_FILTER) |
| 4670 | ixgbe_vlan_promisc_disable(adapter); |
| 4671 | else |
| 4672 | ixgbe_vlan_promisc_enable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4673 | } |
| 4674 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4675 | static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter) |
| 4676 | { |
| 4677 | int q_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4678 | |
Eric Dumazet | 3ffc1af | 2017-02-02 16:26:39 -0800 | [diff] [blame] | 4679 | for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 4680 | napi_enable(&adapter->q_vector[q_idx]->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4681 | } |
| 4682 | |
| 4683 | static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter) |
| 4684 | { |
| 4685 | int q_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4686 | |
Eric Dumazet | 3ffc1af | 2017-02-02 16:26:39 -0800 | [diff] [blame] | 4687 | for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 4688 | napi_disable(&adapter->q_vector[q_idx]->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4689 | } |
| 4690 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 4691 | 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] | 4692 | { |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 4693 | struct ixgbe_hw *hw = &adapter->hw; |
| 4694 | u32 vxlanctrl; |
| 4695 | |
| 4696 | if (!(adapter->flags & (IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE | |
| 4697 | IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))) |
| 4698 | return; |
| 4699 | |
| 4700 | vxlanctrl = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) && ~mask; |
| 4701 | IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, vxlanctrl); |
| 4702 | |
| 4703 | if (mask & IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK) |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 4704 | adapter->vxlan_port = 0; |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 4705 | |
| 4706 | if (mask & IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK) |
| 4707 | adapter->geneve_port = 0; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 4708 | } |
| 4709 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 4710 | #ifdef CONFIG_IXGBE_DCB |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4711 | /** |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4712 | * ixgbe_configure_dcb - Configure DCB hardware |
| 4713 | * @adapter: ixgbe adapter struct |
| 4714 | * |
| 4715 | * This is called by the driver on open to configure the DCB hardware. |
| 4716 | * This is also called by the gennetlink interface when reconfiguring |
| 4717 | * the DCB state. |
| 4718 | */ |
| 4719 | static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter) |
| 4720 | { |
| 4721 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 9806307a | 2010-10-28 00:59:57 +0000 | [diff] [blame] | 4722 | int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4723 | |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 4724 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) { |
| 4725 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4726 | netif_set_gso_max_size(adapter->netdev, 65536); |
| 4727 | return; |
| 4728 | } |
| 4729 | |
| 4730 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4731 | netif_set_gso_max_size(adapter->netdev, 32768); |
| 4732 | |
John Fastabend | b120818 | 2011-10-15 05:00:10 +0000 | [diff] [blame] | 4733 | #ifdef IXGBE_FCOE |
| 4734 | if (adapter->netdev->features & NETIF_F_FCOE_MTU) |
| 4735 | max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE); |
| 4736 | #endif |
| 4737 | |
Alexander Duyck | 01fa7d9 | 2010-11-16 19:26:53 -0800 | [diff] [blame] | 4738 | /* reconfigure the hardware */ |
John Fastabend | 6f70f6a | 2011-04-26 07:26:25 +0000 | [diff] [blame] | 4739 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) { |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 4740 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 4741 | DCB_TX_CONFIG); |
| 4742 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 4743 | DCB_RX_CONFIG); |
| 4744 | ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg); |
John Fastabend | b120818 | 2011-10-15 05:00:10 +0000 | [diff] [blame] | 4745 | } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) { |
| 4746 | ixgbe_dcb_hw_ets(&adapter->hw, |
| 4747 | adapter->ixgbe_ieee_ets, |
| 4748 | max_frame); |
| 4749 | ixgbe_dcb_hw_pfc_config(&adapter->hw, |
| 4750 | adapter->ixgbe_ieee_pfc->pfc_en, |
| 4751 | adapter->ixgbe_ieee_ets->prio_tc); |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 4752 | } |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 4753 | |
| 4754 | /* Enable RSS Hash per TC */ |
| 4755 | if (hw->mac.type != ixgbe_mac_82598EB) { |
Alexander Duyck | 4ae6373 | 2012-06-22 06:46:33 +0000 | [diff] [blame] | 4756 | u32 msb = 0; |
| 4757 | u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1; |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 4758 | |
Alexander Duyck | d411a93 | 2012-06-30 00:14:01 +0000 | [diff] [blame] | 4759 | while (rss_i) { |
| 4760 | msb++; |
| 4761 | rss_i >>= 1; |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 4762 | } |
Alexander Duyck | d411a93 | 2012-06-30 00:14:01 +0000 | [diff] [blame] | 4763 | |
Alexander Duyck | 4ae6373 | 2012-06-22 06:46:33 +0000 | [diff] [blame] | 4764 | /* write msb to all 8 TCs in one write */ |
| 4765 | IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111); |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 4766 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4767 | } |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4768 | #endif |
| 4769 | |
| 4770 | /* Additional bittime to account for IXGBE framing */ |
| 4771 | #define IXGBE_ETH_FRAMING 20 |
| 4772 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4773 | /** |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4774 | * ixgbe_hpbthresh - calculate high water mark for flow control |
| 4775 | * |
| 4776 | * @adapter: board private structure to calculate for |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4777 | * @pb: packet buffer to calculate |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4778 | */ |
| 4779 | static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb) |
| 4780 | { |
| 4781 | struct ixgbe_hw *hw = &adapter->hw; |
| 4782 | struct net_device *dev = adapter->netdev; |
| 4783 | int link, tc, kb, marker; |
| 4784 | u32 dv_id, rx_pba; |
| 4785 | |
| 4786 | /* Calculate max LAN frame size */ |
| 4787 | tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING; |
| 4788 | |
| 4789 | #ifdef IXGBE_FCOE |
| 4790 | /* FCoE traffic class uses FCOE jumbo frames */ |
Alexander Duyck | 800bd60 | 2012-06-02 00:11:02 +0000 | [diff] [blame] | 4791 | if ((dev->features & NETIF_F_FCOE_MTU) && |
| 4792 | (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) && |
| 4793 | (pb == ixgbe_fcoe_get_tc(adapter))) |
| 4794 | tc = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4795 | #endif |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4796 | |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4797 | /* Calculate delay value for device */ |
| 4798 | switch (hw->mac.type) { |
| 4799 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 4800 | case ixgbe_mac_X550: |
| 4801 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 4802 | case ixgbe_mac_x550em_a: |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4803 | dv_id = IXGBE_DV_X540(link, tc); |
| 4804 | break; |
| 4805 | default: |
| 4806 | dv_id = IXGBE_DV(link, tc); |
| 4807 | break; |
| 4808 | } |
| 4809 | |
| 4810 | /* Loopback switch introduces additional latency */ |
| 4811 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 4812 | dv_id += IXGBE_B2BT(tc); |
| 4813 | |
| 4814 | /* Delay value is calculated in bit times convert to KB */ |
| 4815 | kb = IXGBE_BT2KB(dv_id); |
| 4816 | rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10; |
| 4817 | |
| 4818 | marker = rx_pba - kb; |
| 4819 | |
| 4820 | /* It is possible that the packet buffer is not large enough |
| 4821 | * to provide required headroom. In this case throw an error |
| 4822 | * to user and a do the best we can. |
| 4823 | */ |
| 4824 | if (marker < 0) { |
| 4825 | e_warn(drv, "Packet Buffer(%i) can not provide enough" |
| 4826 | "headroom to support flow control." |
| 4827 | "Decrease MTU or number of traffic classes\n", pb); |
| 4828 | marker = tc + 1; |
| 4829 | } |
| 4830 | |
| 4831 | return marker; |
| 4832 | } |
| 4833 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4834 | /** |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4835 | * ixgbe_lpbthresh - calculate low water mark for for flow control |
| 4836 | * |
| 4837 | * @adapter: board private structure to calculate for |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4838 | * @pb: packet buffer to calculate |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4839 | */ |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4840 | static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb) |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4841 | { |
| 4842 | struct ixgbe_hw *hw = &adapter->hw; |
| 4843 | struct net_device *dev = adapter->netdev; |
| 4844 | int tc; |
| 4845 | u32 dv_id; |
| 4846 | |
| 4847 | /* Calculate max LAN frame size */ |
| 4848 | tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN; |
| 4849 | |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4850 | #ifdef IXGBE_FCOE |
| 4851 | /* FCoE traffic class uses FCOE jumbo frames */ |
| 4852 | if ((dev->features & NETIF_F_FCOE_MTU) && |
| 4853 | (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) && |
| 4854 | (pb == netdev_get_prio_tc_map(dev, adapter->fcoe.up))) |
| 4855 | tc = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 4856 | #endif |
| 4857 | |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4858 | /* Calculate delay value for device */ |
| 4859 | switch (hw->mac.type) { |
| 4860 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 4861 | case ixgbe_mac_X550: |
| 4862 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 4863 | case ixgbe_mac_x550em_a: |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4864 | dv_id = IXGBE_LOW_DV_X540(tc); |
| 4865 | break; |
| 4866 | default: |
| 4867 | dv_id = IXGBE_LOW_DV(tc); |
| 4868 | break; |
| 4869 | } |
| 4870 | |
| 4871 | /* Delay value is calculated in bit times convert to KB */ |
| 4872 | return IXGBE_BT2KB(dv_id); |
| 4873 | } |
| 4874 | |
| 4875 | /* |
| 4876 | * ixgbe_pbthresh_setup - calculate and setup high low water marks |
| 4877 | */ |
| 4878 | static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter) |
| 4879 | { |
| 4880 | struct ixgbe_hw *hw = &adapter->hw; |
| 4881 | int num_tc = netdev_get_num_tc(adapter->netdev); |
| 4882 | int i; |
| 4883 | |
| 4884 | if (!num_tc) |
| 4885 | num_tc = 1; |
| 4886 | |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4887 | for (i = 0; i < num_tc; i++) { |
| 4888 | hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i); |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4889 | hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i); |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4890 | |
| 4891 | /* Low water marks must not be larger than high water marks */ |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4892 | if (hw->fc.low_water[i] > hw->fc.high_water[i]) |
| 4893 | hw->fc.low_water[i] = 0; |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4894 | } |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4895 | |
| 4896 | for (; i < MAX_TRAFFIC_CLASS; i++) |
| 4897 | hw->fc.high_water[i] = 0; |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4898 | } |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4899 | |
| 4900 | static void ixgbe_configure_pb(struct ixgbe_adapter *adapter) |
| 4901 | { |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4902 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 4903 | int hdrm; |
| 4904 | u8 tc = netdev_get_num_tc(adapter->netdev); |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4905 | |
| 4906 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 4907 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 4908 | hdrm = 32 << adapter->fdir_pballoc; |
| 4909 | else |
| 4910 | hdrm = 0; |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4911 | |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 4912 | hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL); |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4913 | ixgbe_pbthresh_setup(adapter); |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4914 | } |
| 4915 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4916 | static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter) |
| 4917 | { |
| 4918 | struct ixgbe_hw *hw = &adapter->hw; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 4919 | struct hlist_node *node2; |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4920 | struct ixgbe_fdir_filter *filter; |
| 4921 | |
| 4922 | spin_lock(&adapter->fdir_perfect_lock); |
| 4923 | |
| 4924 | if (!hlist_empty(&adapter->fdir_filter_list)) |
| 4925 | ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask); |
| 4926 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 4927 | hlist_for_each_entry_safe(filter, node2, |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4928 | &adapter->fdir_filter_list, fdir_node) { |
| 4929 | ixgbe_fdir_write_perfect_filter_82599(hw, |
Alexander Duyck | 1f4d518 | 2011-05-14 01:16:02 +0000 | [diff] [blame] | 4930 | &filter->filter, |
| 4931 | filter->sw_idx, |
| 4932 | (filter->action == IXGBE_FDIR_DROP_QUEUE) ? |
| 4933 | IXGBE_FDIR_DROP_QUEUE : |
| 4934 | adapter->rx_ring[filter->action]->reg_idx); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4935 | } |
| 4936 | |
| 4937 | spin_unlock(&adapter->fdir_perfect_lock); |
| 4938 | } |
| 4939 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4940 | static void ixgbe_macvlan_set_rx_mode(struct net_device *dev, unsigned int pool, |
| 4941 | struct ixgbe_adapter *adapter) |
| 4942 | { |
| 4943 | struct ixgbe_hw *hw = &adapter->hw; |
| 4944 | u32 vmolr; |
| 4945 | |
| 4946 | /* No unicast promiscuous support for VMDQ devices. */ |
| 4947 | vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(pool)); |
| 4948 | vmolr |= (IXGBE_VMOLR_ROMPE | IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE); |
| 4949 | |
| 4950 | /* clear the affected bit */ |
| 4951 | vmolr &= ~IXGBE_VMOLR_MPE; |
| 4952 | |
| 4953 | if (dev->flags & IFF_ALLMULTI) { |
| 4954 | vmolr |= IXGBE_VMOLR_MPE; |
| 4955 | } else { |
| 4956 | vmolr |= IXGBE_VMOLR_ROMPE; |
| 4957 | hw->mac.ops.update_mc_addr_list(hw, dev); |
| 4958 | } |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4959 | ixgbe_write_uc_addr_list(adapter->netdev, pool); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4960 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(pool), vmolr); |
| 4961 | } |
| 4962 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4963 | static void ixgbe_fwd_psrtype(struct ixgbe_fwd_adapter *vadapter) |
| 4964 | { |
| 4965 | struct ixgbe_adapter *adapter = vadapter->real_adapter; |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 4966 | int rss_i = adapter->num_rx_queues_per_pool; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4967 | struct ixgbe_hw *hw = &adapter->hw; |
| 4968 | u16 pool = vadapter->pool; |
| 4969 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
| 4970 | IXGBE_PSRTYPE_UDPHDR | |
| 4971 | IXGBE_PSRTYPE_IPV4HDR | |
| 4972 | IXGBE_PSRTYPE_L2HDR | |
| 4973 | IXGBE_PSRTYPE_IPV6HDR; |
| 4974 | |
| 4975 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4976 | return; |
| 4977 | |
| 4978 | if (rss_i > 3) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 4979 | psrtype |= 2u << 29; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4980 | else if (rss_i > 1) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 4981 | psrtype |= 1u << 29; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4982 | |
| 4983 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype); |
| 4984 | } |
| 4985 | |
| 4986 | /** |
| 4987 | * ixgbe_clean_rx_ring - Free Rx Buffers per Queue |
| 4988 | * @rx_ring: ring to free buffers from |
| 4989 | **/ |
| 4990 | static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring) |
| 4991 | { |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 4992 | u16 i = rx_ring->next_to_clean; |
| 4993 | struct ixgbe_rx_buffer *rx_buffer = &rx_ring->rx_buffer_info[i]; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4994 | |
| 4995 | /* Free all the Rx ring sk_buffs */ |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 4996 | while (i != rx_ring->next_to_alloc) { |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4997 | if (rx_buffer->skb) { |
| 4998 | struct sk_buff *skb = rx_buffer->skb; |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 4999 | if (IXGBE_CB(skb)->page_released) |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5000 | dma_unmap_page_attrs(rx_ring->dev, |
Alexander Duyck | f3213d9 | 2017-01-17 08:35:54 -0800 | [diff] [blame] | 5001 | IXGBE_CB(skb)->dma, |
| 5002 | ixgbe_rx_pg_size(rx_ring), |
| 5003 | DMA_FROM_DEVICE, |
| 5004 | IXGBE_RX_DMA_ATTR); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5005 | dev_kfree_skb(skb); |
| 5006 | } |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 5007 | |
Alexander Duyck | f3213d9 | 2017-01-17 08:35:54 -0800 | [diff] [blame] | 5008 | /* Invalidate cache lines that may have been written to by |
| 5009 | * device so that we avoid corrupting memory. |
| 5010 | */ |
| 5011 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 5012 | rx_buffer->dma, |
| 5013 | rx_buffer->page_offset, |
| 5014 | ixgbe_rx_bufsz(rx_ring), |
| 5015 | DMA_FROM_DEVICE); |
| 5016 | |
| 5017 | /* free resources associated with mapping */ |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5018 | dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma, |
Alexander Duyck | f3213d9 | 2017-01-17 08:35:54 -0800 | [diff] [blame] | 5019 | ixgbe_rx_pg_size(rx_ring), |
| 5020 | DMA_FROM_DEVICE, |
| 5021 | IXGBE_RX_DMA_ATTR); |
Alexander Duyck | 1b56cf4 | 2017-01-17 08:36:03 -0800 | [diff] [blame] | 5022 | __page_frag_cache_drain(rx_buffer->page, |
| 5023 | rx_buffer->pagecnt_bias); |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 5024 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5025 | i++; |
| 5026 | rx_buffer++; |
| 5027 | if (i == rx_ring->count) { |
| 5028 | i = 0; |
| 5029 | rx_buffer = rx_ring->rx_buffer_info; |
| 5030 | } |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5031 | } |
| 5032 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5033 | rx_ring->next_to_alloc = 0; |
| 5034 | rx_ring->next_to_clean = 0; |
| 5035 | rx_ring->next_to_use = 0; |
| 5036 | } |
| 5037 | |
| 5038 | static void ixgbe_disable_fwd_ring(struct ixgbe_fwd_adapter *vadapter, |
| 5039 | struct ixgbe_ring *rx_ring) |
| 5040 | { |
| 5041 | struct ixgbe_adapter *adapter = vadapter->real_adapter; |
| 5042 | int index = rx_ring->queue_index + vadapter->rx_base_queue; |
| 5043 | |
| 5044 | /* shutdown specific queue receive and wait for dma to settle */ |
| 5045 | ixgbe_disable_rx_queue(adapter, rx_ring); |
| 5046 | usleep_range(10000, 20000); |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 5047 | ixgbe_irq_disable_queues(adapter, BIT_ULL(index)); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5048 | ixgbe_clean_rx_ring(rx_ring); |
| 5049 | rx_ring->l2_accel_priv = NULL; |
| 5050 | } |
| 5051 | |
John Fastabend | ae72c8d | 2013-11-09 07:11:26 +0000 | [diff] [blame] | 5052 | static int ixgbe_fwd_ring_down(struct net_device *vdev, |
| 5053 | struct ixgbe_fwd_adapter *accel) |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5054 | { |
| 5055 | struct ixgbe_adapter *adapter = accel->real_adapter; |
| 5056 | unsigned int rxbase = accel->rx_base_queue; |
| 5057 | unsigned int txbase = accel->tx_base_queue; |
| 5058 | int i; |
| 5059 | |
| 5060 | netif_tx_stop_all_queues(vdev); |
| 5061 | |
| 5062 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 5063 | ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]); |
| 5064 | adapter->rx_ring[rxbase + i]->netdev = adapter->netdev; |
| 5065 | } |
| 5066 | |
| 5067 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 5068 | adapter->tx_ring[txbase + i]->l2_accel_priv = NULL; |
| 5069 | adapter->tx_ring[txbase + i]->netdev = adapter->netdev; |
| 5070 | } |
| 5071 | |
| 5072 | |
| 5073 | return 0; |
| 5074 | } |
| 5075 | |
| 5076 | static int ixgbe_fwd_ring_up(struct net_device *vdev, |
| 5077 | struct ixgbe_fwd_adapter *accel) |
| 5078 | { |
| 5079 | struct ixgbe_adapter *adapter = accel->real_adapter; |
| 5080 | unsigned int rxbase, txbase, queues; |
| 5081 | int i, baseq, err = 0; |
| 5082 | |
| 5083 | if (!test_bit(accel->pool, &adapter->fwd_bitmask)) |
| 5084 | return 0; |
| 5085 | |
| 5086 | baseq = accel->pool * adapter->num_rx_queues_per_pool; |
| 5087 | netdev_dbg(vdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n", |
| 5088 | accel->pool, adapter->num_rx_pools, |
| 5089 | baseq, baseq + adapter->num_rx_queues_per_pool, |
| 5090 | adapter->fwd_bitmask); |
| 5091 | |
| 5092 | accel->netdev = vdev; |
| 5093 | accel->rx_base_queue = rxbase = baseq; |
| 5094 | accel->tx_base_queue = txbase = baseq; |
| 5095 | |
| 5096 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) |
| 5097 | ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]); |
| 5098 | |
| 5099 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 5100 | adapter->rx_ring[rxbase + i]->netdev = vdev; |
| 5101 | adapter->rx_ring[rxbase + i]->l2_accel_priv = accel; |
| 5102 | ixgbe_configure_rx_ring(adapter, adapter->rx_ring[rxbase + i]); |
| 5103 | } |
| 5104 | |
| 5105 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 5106 | adapter->tx_ring[txbase + i]->netdev = vdev; |
| 5107 | adapter->tx_ring[txbase + i]->l2_accel_priv = accel; |
| 5108 | } |
| 5109 | |
| 5110 | queues = min_t(unsigned int, |
| 5111 | adapter->num_rx_queues_per_pool, vdev->num_tx_queues); |
| 5112 | err = netif_set_real_num_tx_queues(vdev, queues); |
| 5113 | if (err) |
| 5114 | goto fwd_queue_err; |
| 5115 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5116 | err = netif_set_real_num_rx_queues(vdev, queues); |
| 5117 | if (err) |
| 5118 | goto fwd_queue_err; |
| 5119 | |
| 5120 | if (is_valid_ether_addr(vdev->dev_addr)) |
| 5121 | ixgbe_add_mac_filter(adapter, vdev->dev_addr, accel->pool); |
| 5122 | |
| 5123 | ixgbe_fwd_psrtype(accel); |
| 5124 | ixgbe_macvlan_set_rx_mode(vdev, accel->pool, adapter); |
| 5125 | return err; |
| 5126 | fwd_queue_err: |
| 5127 | ixgbe_fwd_ring_down(vdev, accel); |
| 5128 | return err; |
| 5129 | } |
| 5130 | |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 5131 | static int ixgbe_upper_dev_walk(struct net_device *upper, void *data) |
| 5132 | { |
| 5133 | if (netif_is_macvlan(upper)) { |
| 5134 | struct macvlan_dev *dfwd = netdev_priv(upper); |
| 5135 | struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv; |
| 5136 | |
| 5137 | if (dfwd->fwd_priv) |
| 5138 | ixgbe_fwd_ring_up(upper, vadapter); |
| 5139 | } |
| 5140 | |
| 5141 | return 0; |
| 5142 | } |
| 5143 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5144 | static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter) |
| 5145 | { |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 5146 | netdev_walk_all_upper_dev_rcu(adapter->netdev, |
| 5147 | ixgbe_upper_dev_walk, NULL); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5148 | } |
| 5149 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5150 | static void ixgbe_configure(struct ixgbe_adapter *adapter) |
| 5151 | { |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 5152 | struct ixgbe_hw *hw = &adapter->hw; |
| 5153 | |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 5154 | ixgbe_configure_pb(adapter); |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5155 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 5156 | ixgbe_configure_dcb(adapter); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5157 | #endif |
Alexander Duyck | b35d4d4 | 2012-05-23 05:39:25 +0000 | [diff] [blame] | 5158 | /* |
| 5159 | * We must restore virtualization before VLANs or else |
| 5160 | * the VLVF registers will not be populated |
| 5161 | */ |
| 5162 | ixgbe_configure_virtualization(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5163 | |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 5164 | ixgbe_set_rx_mode(adapter->netdev); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 5165 | ixgbe_restore_vlan(adapter); |
| 5166 | |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 5167 | switch (hw->mac.type) { |
| 5168 | case ixgbe_mac_82599EB: |
| 5169 | case ixgbe_mac_X540: |
| 5170 | hw->mac.ops.disable_rx_buff(hw); |
| 5171 | break; |
| 5172 | default: |
| 5173 | break; |
| 5174 | } |
| 5175 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5176 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 5177 | ixgbe_init_fdir_signature_82599(&adapter->hw, |
| 5178 | adapter->fdir_pballoc); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5179 | } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) { |
| 5180 | ixgbe_init_fdir_perfect_82599(&adapter->hw, |
| 5181 | adapter->fdir_pballoc); |
| 5182 | ixgbe_fdir_filter_restore(adapter); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5183 | } |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 5184 | |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 5185 | switch (hw->mac.type) { |
| 5186 | case ixgbe_mac_82599EB: |
| 5187 | case ixgbe_mac_X540: |
| 5188 | hw->mac.ops.enable_rx_buff(hw); |
| 5189 | break; |
| 5190 | default: |
| 5191 | break; |
| 5192 | } |
| 5193 | |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 5194 | #ifdef CONFIG_IXGBE_DCA |
| 5195 | /* configure DCA */ |
| 5196 | if (adapter->flags & IXGBE_FLAG_DCA_CAPABLE) |
| 5197 | ixgbe_setup_dca(adapter); |
| 5198 | #endif /* CONFIG_IXGBE_DCA */ |
| 5199 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 5200 | #ifdef IXGBE_FCOE |
| 5201 | /* configure FCoE L2 filters, redirection table, and Rx control */ |
| 5202 | ixgbe_configure_fcoe(adapter); |
| 5203 | |
| 5204 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5205 | ixgbe_configure_tx(adapter); |
| 5206 | ixgbe_configure_rx(adapter); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5207 | ixgbe_configure_dfwd(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5208 | } |
| 5209 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5210 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5211 | * ixgbe_sfp_link_config - set up SFP+ link |
| 5212 | * @adapter: pointer to private adapter struct |
| 5213 | **/ |
| 5214 | static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter) |
| 5215 | { |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5216 | /* |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 5217 | * We are assuming the worst case scenario here, and that |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5218 | * is that an SFP was inserted/removed after the reset |
| 5219 | * but before SFP detection was enabled. As such the best |
| 5220 | * solution is to just start searching as soon as we start |
| 5221 | */ |
| 5222 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 5223 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5224 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5225 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
Mark Rustad | 58e7cd2 | 2015-08-08 16:18:48 -0700 | [diff] [blame] | 5226 | adapter->sfp_poll_time = 0; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5227 | } |
| 5228 | |
| 5229 | /** |
| 5230 | * ixgbe_non_sfp_link_config - set up non-SFP+ link |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5231 | * @hw: pointer to private hardware struct |
| 5232 | * |
| 5233 | * Returns 0 on success, negative on failure |
| 5234 | **/ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5235 | 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] | 5236 | { |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 5237 | u32 speed; |
| 5238 | bool autoneg, link_up = false; |
Mark Rustad | a1e869d | 2015-04-10 10:36:36 -0700 | [diff] [blame] | 5239 | int ret = IXGBE_ERR_LINK_SETUP; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5240 | |
| 5241 | if (hw->mac.ops.check_link) |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 5242 | 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] | 5243 | |
| 5244 | if (ret) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 5245 | return ret; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5246 | |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 5247 | speed = hw->phy.autoneg_advertised; |
| 5248 | if ((!speed) && (hw->mac.ops.get_link_capabilities)) |
| 5249 | ret = hw->mac.ops.get_link_capabilities(hw, &speed, |
| 5250 | &autoneg); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5251 | if (ret) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 5252 | return ret; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5253 | |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 5254 | if (hw->mac.ops.setup_link) |
Josh Hay | fd0326f | 2012-12-15 03:28:30 +0000 | [diff] [blame] | 5255 | ret = hw->mac.ops.setup_link(hw, speed, link_up); |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 5256 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5257 | return ret; |
| 5258 | } |
| 5259 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5260 | static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5261 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5262 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5263 | u32 gpie = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5264 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 5265 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5266 | gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT | |
| 5267 | IXGBE_GPIE_OCD; |
| 5268 | gpie |= IXGBE_GPIE_EIAME; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 5269 | /* |
| 5270 | * use EIAM to auto-mask when MSI-X interrupt is asserted |
| 5271 | * this saves a register write for every interrupt |
| 5272 | */ |
| 5273 | switch (hw->mac.type) { |
| 5274 | case ixgbe_mac_82598EB: |
| 5275 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
| 5276 | break; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 5277 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5278 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5279 | case ixgbe_mac_X550: |
| 5280 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 5281 | case ixgbe_mac_x550em_a: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5282 | default: |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 5283 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF); |
| 5284 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF); |
| 5285 | break; |
| 5286 | } |
| 5287 | } else { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5288 | /* legacy interrupts, use EIAM to auto-mask when reading EICR, |
| 5289 | * specifically only auto mask tx and rx interrupts */ |
| 5290 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5291 | } |
| 5292 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5293 | /* XXX: to interrupt immediately for EICS writes, enable this */ |
| 5294 | /* gpie |= IXGBE_GPIE_EIMEN; */ |
| 5295 | |
| 5296 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 5297 | gpie &= ~IXGBE_GPIE_VTMODE_MASK; |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 5298 | |
| 5299 | switch (adapter->ring_feature[RING_F_VMDQ].mask) { |
| 5300 | case IXGBE_82599_VMDQ_8Q_MASK: |
| 5301 | gpie |= IXGBE_GPIE_VTMODE_16; |
| 5302 | break; |
| 5303 | case IXGBE_82599_VMDQ_4Q_MASK: |
| 5304 | gpie |= IXGBE_GPIE_VTMODE_32; |
| 5305 | break; |
| 5306 | default: |
| 5307 | gpie |= IXGBE_GPIE_VTMODE_64; |
| 5308 | break; |
| 5309 | } |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 5310 | } |
| 5311 | |
Alexander Duyck | 5fdd31f | 2011-07-21 00:40:45 +0000 | [diff] [blame] | 5312 | /* Enable Thermal over heat sensor interrupt */ |
Don Skidmore | f3df98e | 2011-08-17 10:15:21 +0000 | [diff] [blame] | 5313 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) { |
| 5314 | switch (adapter->hw.mac.type) { |
| 5315 | case ixgbe_mac_82599EB: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 5316 | gpie |= IXGBE_SDP0_GPIEN_8259X; |
Don Skidmore | f3df98e | 2011-08-17 10:15:21 +0000 | [diff] [blame] | 5317 | break; |
Don Skidmore | f3df98e | 2011-08-17 10:15:21 +0000 | [diff] [blame] | 5318 | default: |
| 5319 | break; |
| 5320 | } |
| 5321 | } |
Alexander Duyck | 5fdd31f | 2011-07-21 00:40:45 +0000 | [diff] [blame] | 5322 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5323 | /* Enable fan failure interrupt */ |
| 5324 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 5325 | gpie |= IXGBE_SDP1_GPIEN(hw); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 5326 | |
Don Skidmore | a023bbd | 2015-06-24 16:38:53 -0400 | [diff] [blame] | 5327 | switch (hw->mac.type) { |
| 5328 | case ixgbe_mac_82599EB: |
| 5329 | gpie |= IXGBE_SDP1_GPIEN_8259X | IXGBE_SDP2_GPIEN_8259X; |
| 5330 | break; |
| 5331 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 5332 | case ixgbe_mac_x550em_a: |
Don Skidmore | a023bbd | 2015-06-24 16:38:53 -0400 | [diff] [blame] | 5333 | gpie |= IXGBE_SDP0_GPIEN_X540; |
| 5334 | break; |
| 5335 | default: |
| 5336 | break; |
Don Skidmore | 2698b20 | 2011-04-13 07:01:52 +0000 | [diff] [blame] | 5337 | } |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5338 | |
| 5339 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 5340 | } |
| 5341 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 5342 | static void ixgbe_up_complete(struct ixgbe_adapter *adapter) |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5343 | { |
| 5344 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5345 | int err; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5346 | u32 ctrl_ext; |
| 5347 | |
| 5348 | ixgbe_get_hw_control(adapter); |
| 5349 | ixgbe_setup_gpie(adapter); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5350 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5351 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 5352 | ixgbe_configure_msix(adapter); |
| 5353 | else |
| 5354 | ixgbe_configure_msi_and_legacy(adapter); |
| 5355 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 5356 | /* enable the optics for 82599 SFP+ fiber */ |
| 5357 | if (hw->mac.ops.enable_tx_laser) |
Peter Waskiewicz | 61fac74 | 2010-04-27 00:38:15 +0000 | [diff] [blame] | 5358 | hw->mac.ops.enable_tx_laser(hw); |
| 5359 | |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 5360 | if (hw->phy.ops.set_phy_power) |
| 5361 | hw->phy.ops.set_phy_power(hw, true); |
| 5362 | |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 5363 | smp_mb__before_atomic(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5364 | clear_bit(__IXGBE_DOWN, &adapter->state); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5365 | ixgbe_napi_enable_all(adapter); |
| 5366 | |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 5367 | if (ixgbe_is_sfp(hw)) { |
| 5368 | ixgbe_sfp_link_config(adapter); |
| 5369 | } else { |
| 5370 | err = ixgbe_non_sfp_link_config(hw); |
| 5371 | if (err) |
| 5372 | e_err(probe, "link_config FAILED %d\n", err); |
| 5373 | } |
| 5374 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5375 | /* clear any pending interrupts, may auto mask */ |
| 5376 | IXGBE_READ_REG(hw, IXGBE_EICR); |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 5377 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5378 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5379 | /* |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5380 | * If this adapter has a fan, check to see if we had a failure |
| 5381 | * before we enabled the interrupt. |
| 5382 | */ |
| 5383 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 5384 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 5385 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5386 | e_crit(drv, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5387 | } |
| 5388 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5389 | /* bring the link up in the watchdog, this could race with our first |
| 5390 | * link up interrupt but shouldn't be a problem */ |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5391 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 5392 | adapter->link_check_timeout = jiffies; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5393 | mod_timer(&adapter->service_timer, jiffies); |
Greg Rose | c920569 | 2010-01-22 22:46:22 +0000 | [diff] [blame] | 5394 | |
| 5395 | /* Set PF Reset Done bit so PF/VF Mail Ops can work */ |
| 5396 | ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); |
| 5397 | ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD; |
| 5398 | IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5399 | } |
| 5400 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5401 | void ixgbe_reinit_locked(struct ixgbe_adapter *adapter) |
| 5402 | { |
| 5403 | WARN_ON(in_interrupt()); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5404 | /* put off any impending NetWatchDogTimeout */ |
Florian Westphal | 860e953 | 2016-05-03 16:33:13 +0200 | [diff] [blame] | 5405 | netif_trans_update(adapter->netdev); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5406 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5407 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 5408 | usleep_range(1000, 2000); |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 5409 | if (adapter->hw.phy.type == ixgbe_phy_fw) |
| 5410 | ixgbe_watchdog_link_is_down(adapter); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5411 | ixgbe_down(adapter); |
Greg Rose | 5809a1a | 2010-03-24 09:36:08 +0000 | [diff] [blame] | 5412 | /* |
| 5413 | * If SR-IOV enabled then wait a bit before bringing the adapter |
| 5414 | * back up to give the VFs time to respond to the reset. The |
| 5415 | * two second wait is based upon the watchdog timer cycle in |
| 5416 | * the VF driver. |
| 5417 | */ |
| 5418 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 5419 | msleep(2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5420 | ixgbe_up(adapter); |
| 5421 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
| 5422 | } |
| 5423 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 5424 | void ixgbe_up(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5425 | { |
| 5426 | /* hardware has been reset, we need to reload some things */ |
| 5427 | ixgbe_configure(adapter); |
| 5428 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 5429 | ixgbe_up_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5430 | } |
| 5431 | |
| 5432 | void ixgbe_reset(struct ixgbe_adapter *adapter) |
| 5433 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5434 | struct ixgbe_hw *hw = &adapter->hw; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 5435 | struct net_device *netdev = adapter->netdev; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 5436 | int err; |
| 5437 | |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 5438 | if (ixgbe_removed(hw->hw_addr)) |
| 5439 | return; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5440 | /* lock SFP init bit to prevent race conditions with the watchdog */ |
| 5441 | while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 5442 | usleep_range(1000, 2000); |
| 5443 | |
| 5444 | /* clear all SFP and link config related flags while holding SFP_INIT */ |
| 5445 | adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP | |
| 5446 | IXGBE_FLAG2_SFP_NEEDS_RESET); |
| 5447 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 5448 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 5449 | err = hw->mac.ops.init_hw(hw); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5450 | switch (err) { |
| 5451 | case 0: |
| 5452 | case IXGBE_ERR_SFP_NOT_PRESENT: |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5453 | case IXGBE_ERR_SFP_NOT_SUPPORTED: |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5454 | break; |
| 5455 | case IXGBE_ERR_MASTER_REQUESTS_PENDING: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5456 | e_dev_err("master disable timed out\n"); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5457 | break; |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 5458 | case IXGBE_ERR_EEPROM_VERSION: |
| 5459 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5460 | e_dev_warn("This device is a pre-production adapter/LOM. " |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 5461 | "Please be aware there may be issues associated with " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5462 | "your hardware. If you are experiencing problems " |
| 5463 | "please contact your Intel or hardware " |
| 5464 | "representative who provided you with this " |
| 5465 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 5466 | break; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5467 | default: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5468 | e_dev_err("Hardware Error: %d\n", err); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5469 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5470 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5471 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
Alexander Duyck | 0f079d2 | 2015-10-22 16:26:36 -0700 | [diff] [blame] | 5472 | |
| 5473 | /* flush entries out of MAC table */ |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 5474 | ixgbe_flush_sw_mac_table(adapter); |
Alexander Duyck | 0f079d2 | 2015-10-22 16:26:36 -0700 | [diff] [blame] | 5475 | __dev_uc_unsync(netdev, NULL); |
| 5476 | |
| 5477 | /* do not flush user set addresses */ |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 5478 | ixgbe_mac_set_default_filter(adapter); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 5479 | |
| 5480 | /* update SAN MAC vmdq pool selection */ |
| 5481 | if (hw->mac.san_mac_rar_index) |
| 5482 | hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0)); |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 5483 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 5484 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 5485 | ixgbe_ptp_reset(adapter); |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 5486 | |
| 5487 | if (hw->phy.ops.set_phy_power) { |
| 5488 | if (!netif_running(adapter->netdev) && !adapter->wol) |
| 5489 | hw->phy.ops.set_phy_power(hw, false); |
| 5490 | else |
| 5491 | hw->phy.ops.set_phy_power(hw, true); |
| 5492 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5493 | } |
| 5494 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5495 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5496 | * ixgbe_clean_tx_ring - Free Tx Buffers |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5497 | * @tx_ring: ring to be cleaned |
| 5498 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5499 | static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5500 | { |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5501 | u16 i = tx_ring->next_to_clean; |
| 5502 | struct ixgbe_tx_buffer *tx_buffer = &tx_ring->tx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5503 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5504 | while (i != tx_ring->next_to_use) { |
| 5505 | union ixgbe_adv_tx_desc *eop_desc, *tx_desc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5506 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5507 | /* Free all the Tx ring sk_buffs */ |
| 5508 | dev_kfree_skb_any(tx_buffer->skb); |
| 5509 | |
| 5510 | /* unmap skb header data */ |
| 5511 | dma_unmap_single(tx_ring->dev, |
| 5512 | dma_unmap_addr(tx_buffer, dma), |
| 5513 | dma_unmap_len(tx_buffer, len), |
| 5514 | DMA_TO_DEVICE); |
| 5515 | |
| 5516 | /* check for eop_desc to determine the end of the packet */ |
| 5517 | eop_desc = tx_buffer->next_to_watch; |
| 5518 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
| 5519 | |
| 5520 | /* unmap remaining buffers */ |
| 5521 | while (tx_desc != eop_desc) { |
| 5522 | tx_buffer++; |
| 5523 | tx_desc++; |
| 5524 | i++; |
| 5525 | if (unlikely(i == tx_ring->count)) { |
| 5526 | i = 0; |
| 5527 | tx_buffer = tx_ring->tx_buffer_info; |
| 5528 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
| 5529 | } |
| 5530 | |
| 5531 | /* unmap any remaining paged data */ |
| 5532 | if (dma_unmap_len(tx_buffer, len)) |
| 5533 | dma_unmap_page(tx_ring->dev, |
| 5534 | dma_unmap_addr(tx_buffer, dma), |
| 5535 | dma_unmap_len(tx_buffer, len), |
| 5536 | DMA_TO_DEVICE); |
| 5537 | } |
| 5538 | |
| 5539 | /* move us one more past the eop_desc for start of next pkt */ |
| 5540 | tx_buffer++; |
| 5541 | i++; |
| 5542 | if (unlikely(i == tx_ring->count)) { |
| 5543 | i = 0; |
| 5544 | tx_buffer = tx_ring->tx_buffer_info; |
| 5545 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5546 | } |
| 5547 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5548 | /* reset BQL for queue */ |
John Fastabend | dad8a3b | 2012-04-23 12:22:39 +0000 | [diff] [blame] | 5549 | netdev_tx_reset_queue(txring_txq(tx_ring)); |
| 5550 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5551 | /* reset next_to_use and next_to_clean */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5552 | tx_ring->next_to_use = 0; |
| 5553 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5554 | } |
| 5555 | |
| 5556 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5557 | * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues |
| 5558 | * @adapter: board private structure |
| 5559 | **/ |
| 5560 | static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter) |
| 5561 | { |
| 5562 | int i; |
| 5563 | |
| 5564 | for (i = 0; i < adapter->num_rx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5565 | ixgbe_clean_rx_ring(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5566 | } |
| 5567 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5568 | /** |
| 5569 | * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues |
| 5570 | * @adapter: board private structure |
| 5571 | **/ |
| 5572 | static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter) |
| 5573 | { |
| 5574 | int i; |
| 5575 | |
| 5576 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5577 | ixgbe_clean_tx_ring(adapter->tx_ring[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5578 | } |
| 5579 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5580 | static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter) |
| 5581 | { |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 5582 | struct hlist_node *node2; |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5583 | struct ixgbe_fdir_filter *filter; |
| 5584 | |
| 5585 | spin_lock(&adapter->fdir_perfect_lock); |
| 5586 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 5587 | hlist_for_each_entry_safe(filter, node2, |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5588 | &adapter->fdir_filter_list, fdir_node) { |
| 5589 | hlist_del(&filter->fdir_node); |
| 5590 | kfree(filter); |
| 5591 | } |
| 5592 | adapter->fdir_filter_count = 0; |
| 5593 | |
| 5594 | spin_unlock(&adapter->fdir_perfect_lock); |
| 5595 | } |
| 5596 | |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 5597 | static int ixgbe_disable_macvlan(struct net_device *upper, void *data) |
| 5598 | { |
| 5599 | if (netif_is_macvlan(upper)) { |
| 5600 | struct macvlan_dev *vlan = netdev_priv(upper); |
| 5601 | |
| 5602 | if (vlan->fwd_priv) { |
| 5603 | netif_tx_stop_all_queues(upper); |
| 5604 | netif_carrier_off(upper); |
| 5605 | netif_tx_disable(upper); |
| 5606 | } |
| 5607 | } |
| 5608 | |
| 5609 | return 0; |
| 5610 | } |
| 5611 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5612 | void ixgbe_down(struct ixgbe_adapter *adapter) |
| 5613 | { |
| 5614 | struct net_device *netdev = adapter->netdev; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5615 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 5616 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5617 | |
| 5618 | /* signal that we are down to the interrupt handler */ |
Mark Rustad | c3049c8 | 2014-01-14 18:53:12 -0800 | [diff] [blame] | 5619 | if (test_and_set_bit(__IXGBE_DOWN, &adapter->state)) |
| 5620 | return; /* do nothing if already down */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5621 | |
| 5622 | /* disable receives */ |
Don Skidmore | 1f9ac57 | 2015-03-13 13:54:30 -0700 | [diff] [blame] | 5623 | hw->mac.ops.disable_rx(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5624 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 5625 | /* disable all enabled rx queues */ |
| 5626 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 5627 | /* this call also flushes the previous write */ |
| 5628 | ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]); |
| 5629 | |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 5630 | usleep_range(10000, 20000); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5631 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5632 | netif_tx_stop_all_queues(netdev); |
| 5633 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5634 | /* call carrier off first to avoid false dev_watchdog timeouts */ |
John Fastabend | c0dfb90 | 2010-04-27 02:13:39 +0000 | [diff] [blame] | 5635 | netif_carrier_off(netdev); |
| 5636 | netif_tx_disable(netdev); |
| 5637 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5638 | /* disable any upper devices */ |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 5639 | netdev_walk_all_upper_dev_rcu(adapter->netdev, |
| 5640 | ixgbe_disable_macvlan, NULL); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5641 | |
John Fastabend | c0dfb90 | 2010-04-27 02:13:39 +0000 | [diff] [blame] | 5642 | ixgbe_irq_disable(adapter); |
| 5643 | |
| 5644 | ixgbe_napi_disable_all(adapter); |
| 5645 | |
Emil Tantilov | 57ca2a4 | 2016-07-29 14:46:31 -0700 | [diff] [blame] | 5646 | clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state); |
| 5647 | adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5648 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 5649 | |
| 5650 | del_timer_sync(&adapter->service_timer); |
| 5651 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 5652 | if (adapter->num_vfs) { |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 5653 | /* Clear EITR Select mapping */ |
| 5654 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0); |
| 5655 | |
| 5656 | /* Mark all the VFs as inactive */ |
| 5657 | for (i = 0 ; i < adapter->num_vfs; i++) |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 5658 | adapter->vfinfo[i].clear_to_send = false; |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 5659 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 5660 | /* 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] | 5661 | ixgbe_ping_all_vfs(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5662 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5663 | /* Disable all VFTE/VFRE TX/RX */ |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 5664 | ixgbe_disable_tx_rx(adapter); |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 5665 | } |
| 5666 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5667 | /* disable transmits in the hardware now that interrupts are off */ |
| 5668 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 5669 | u8 reg_idx = adapter->tx_ring[i]->reg_idx; |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 5670 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5671 | } |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 5672 | |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5673 | /* Disable the Tx DMA engine on 82599 and later MAC */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5674 | switch (hw->mac.type) { |
| 5675 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5676 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5677 | case ixgbe_mac_X550: |
| 5678 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 5679 | case ixgbe_mac_x550em_a: |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 5680 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 5681 | (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) & |
| 5682 | ~IXGBE_DMATXCTL_TE)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5683 | break; |
| 5684 | default: |
| 5685 | break; |
| 5686 | } |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5687 | |
Paul Larson | 6f4a0e4 | 2008-06-24 17:00:56 -0700 | [diff] [blame] | 5688 | if (!pci_channel_offline(adapter->pdev)) |
| 5689 | ixgbe_reset(adapter); |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 5690 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 5691 | /* power down the optics for 82599 SFP+ fiber */ |
| 5692 | if (hw->mac.ops.disable_tx_laser) |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 5693 | hw->mac.ops.disable_tx_laser(hw); |
| 5694 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5695 | ixgbe_clean_all_tx_rings(adapter); |
| 5696 | ixgbe_clean_all_rx_rings(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5697 | } |
| 5698 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5699 | /** |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 5700 | * ixgbe_eee_capable - helper function to determine EEE support on X550 |
| 5701 | * @adapter: board private structure |
| 5702 | */ |
| 5703 | static void ixgbe_set_eee_capable(struct ixgbe_adapter *adapter) |
| 5704 | { |
| 5705 | struct ixgbe_hw *hw = &adapter->hw; |
| 5706 | |
| 5707 | switch (hw->device_id) { |
| 5708 | case IXGBE_DEV_ID_X550EM_A_1G_T: |
| 5709 | case IXGBE_DEV_ID_X550EM_A_1G_T_L: |
| 5710 | if (!hw->phy.eee_speeds_supported) |
| 5711 | break; |
| 5712 | adapter->flags2 |= IXGBE_FLAG2_EEE_CAPABLE; |
| 5713 | if (!hw->phy.eee_speeds_advertised) |
| 5714 | break; |
| 5715 | adapter->flags2 |= IXGBE_FLAG2_EEE_ENABLED; |
| 5716 | break; |
| 5717 | default: |
| 5718 | adapter->flags2 &= ~IXGBE_FLAG2_EEE_CAPABLE; |
| 5719 | adapter->flags2 &= ~IXGBE_FLAG2_EEE_ENABLED; |
| 5720 | break; |
| 5721 | } |
| 5722 | } |
| 5723 | |
| 5724 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5725 | * ixgbe_tx_timeout - Respond to a Tx Hang |
| 5726 | * @netdev: network interface device structure |
| 5727 | **/ |
| 5728 | static void ixgbe_tx_timeout(struct net_device *netdev) |
| 5729 | { |
| 5730 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5731 | |
| 5732 | /* Do the reset outside of interrupt context */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 5733 | ixgbe_tx_timeout_reset(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5734 | } |
| 5735 | |
Usha Ketineni | 8829009 | 2016-04-26 05:00:26 -0700 | [diff] [blame] | 5736 | #ifdef CONFIG_IXGBE_DCB |
| 5737 | static void ixgbe_init_dcb(struct ixgbe_adapter *adapter) |
| 5738 | { |
| 5739 | struct ixgbe_hw *hw = &adapter->hw; |
| 5740 | struct tc_configuration *tc; |
| 5741 | int j; |
| 5742 | |
| 5743 | switch (hw->mac.type) { |
| 5744 | case ixgbe_mac_82598EB: |
| 5745 | case ixgbe_mac_82599EB: |
| 5746 | adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS; |
| 5747 | adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS; |
| 5748 | break; |
| 5749 | case ixgbe_mac_X540: |
| 5750 | case ixgbe_mac_X550: |
| 5751 | adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS; |
| 5752 | adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS; |
| 5753 | break; |
| 5754 | case ixgbe_mac_X550EM_x: |
| 5755 | case ixgbe_mac_x550em_a: |
| 5756 | default: |
| 5757 | adapter->dcb_cfg.num_tcs.pg_tcs = DEF_TRAFFIC_CLASS; |
| 5758 | adapter->dcb_cfg.num_tcs.pfc_tcs = DEF_TRAFFIC_CLASS; |
| 5759 | break; |
| 5760 | } |
| 5761 | |
| 5762 | /* Configure DCB traffic classes */ |
| 5763 | for (j = 0; j < MAX_TRAFFIC_CLASS; j++) { |
| 5764 | tc = &adapter->dcb_cfg.tc_config[j]; |
| 5765 | tc->path[DCB_TX_CONFIG].bwg_id = 0; |
| 5766 | tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1); |
| 5767 | tc->path[DCB_RX_CONFIG].bwg_id = 0; |
| 5768 | tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1); |
| 5769 | tc->dcb_pfc = pfc_disabled; |
| 5770 | } |
| 5771 | |
| 5772 | /* Initialize default user to priority mapping, UPx->TC0 */ |
| 5773 | tc = &adapter->dcb_cfg.tc_config[0]; |
| 5774 | tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF; |
| 5775 | tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF; |
| 5776 | |
| 5777 | adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100; |
| 5778 | adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100; |
| 5779 | adapter->dcb_cfg.pfc_mode_enable = false; |
| 5780 | adapter->dcb_set_bitmap = 0x00; |
| 5781 | if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE) |
| 5782 | adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE; |
| 5783 | memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg, |
| 5784 | sizeof(adapter->temp_dcb_cfg)); |
| 5785 | } |
| 5786 | #endif |
| 5787 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 5788 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5789 | * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter) |
| 5790 | * @adapter: board private structure to initialize |
| 5791 | * |
| 5792 | * ixgbe_sw_init initializes the Adapter private data structure. |
| 5793 | * Fields are initialized based on PCI device information and |
| 5794 | * OS network device settings (MTU size). |
| 5795 | **/ |
Emil Tantilov | 55570b6 | 2016-10-12 12:34:25 -0700 | [diff] [blame] | 5796 | static int ixgbe_sw_init(struct ixgbe_adapter *adapter, |
| 5797 | const struct ixgbe_info *ii) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5798 | { |
| 5799 | struct ixgbe_hw *hw = &adapter->hw; |
| 5800 | struct pci_dev *pdev = adapter->pdev; |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 5801 | unsigned int rss, fdir; |
Jacob Keller | cb6d0f5 | 2012-12-04 06:03:14 +0000 | [diff] [blame] | 5802 | u32 fwsm; |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 5803 | int i; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5804 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5805 | /* PCI config space info */ |
| 5806 | |
| 5807 | hw->vendor_id = pdev->vendor; |
| 5808 | hw->device_id = pdev->device; |
| 5809 | hw->revision_id = pdev->revision; |
| 5810 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 5811 | hw->subsystem_device_id = pdev->subsystem_device; |
| 5812 | |
Emil Tantilov | 55570b6 | 2016-10-12 12:34:25 -0700 | [diff] [blame] | 5813 | /* get_invariants needs the device IDs */ |
| 5814 | ii->get_invariants(hw); |
| 5815 | |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5816 | /* Set common capability flags and settings */ |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 5817 | rss = min_t(int, ixgbe_max_rss_indices(adapter), num_online_cpus()); |
Alexander Duyck | c087663 | 2012-05-10 00:01:46 +0000 | [diff] [blame] | 5818 | adapter->ring_feature[RING_F_RSS].limit = rss; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5819 | adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5820 | adapter->max_q_vectors = MAX_Q_VECTORS_82599; |
| 5821 | adapter->atr_sample_rate = 20; |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 5822 | fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus()); |
| 5823 | adapter->ring_feature[RING_F_FDIR].limit = fdir; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5824 | adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K; |
| 5825 | #ifdef CONFIG_IXGBE_DCA |
| 5826 | adapter->flags |= IXGBE_FLAG_DCA_CAPABLE; |
| 5827 | #endif |
Usha Ketineni | 8829009 | 2016-04-26 05:00:26 -0700 | [diff] [blame] | 5828 | #ifdef CONFIG_IXGBE_DCB |
| 5829 | adapter->flags |= IXGBE_FLAG_DCB_CAPABLE; |
| 5830 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
| 5831 | #endif |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5832 | #ifdef IXGBE_FCOE |
| 5833 | adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE; |
| 5834 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 5835 | #ifdef CONFIG_IXGBE_DCB |
| 5836 | /* Default traffic class to use for FCoE */ |
| 5837 | adapter->fcoe.up = IXGBE_FCOE_DEFTC; |
| 5838 | #endif /* CONFIG_IXGBE_DCB */ |
| 5839 | #endif /* IXGBE_FCOE */ |
| 5840 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 5841 | /* initialize static ixgbe jump table entries */ |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 5842 | adapter->jump_tables[0] = kzalloc(sizeof(*adapter->jump_tables[0]), |
| 5843 | GFP_KERNEL); |
| 5844 | if (!adapter->jump_tables[0]) |
| 5845 | return -ENOMEM; |
| 5846 | adapter->jump_tables[0]->mat = ixgbe_ipv4_fields; |
| 5847 | |
| 5848 | for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) |
| 5849 | adapter->jump_tables[i] = NULL; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 5850 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 5851 | adapter->mac_table = kzalloc(sizeof(struct ixgbe_mac_addr) * |
| 5852 | hw->mac.num_rar_entries, |
| 5853 | GFP_ATOMIC); |
Alexander Duyck | 530fd82 | 2015-11-02 17:09:29 -0800 | [diff] [blame] | 5854 | if (!adapter->mac_table) |
| 5855 | return -ENOMEM; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 5856 | |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5857 | /* Set MAC specific capability flags and exceptions */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5858 | switch (hw->mac.type) { |
| 5859 | case ixgbe_mac_82598EB: |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5860 | adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5861 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5862 | if (hw->device_id == IXGBE_DEV_ID_82598AT) |
| 5863 | adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5864 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 5865 | adapter->max_q_vectors = MAX_Q_VECTORS_82598; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5866 | adapter->ring_feature[RING_F_FDIR].limit = 0; |
| 5867 | adapter->atr_sample_rate = 0; |
| 5868 | adapter->fdir_pballoc = 0; |
| 5869 | #ifdef IXGBE_FCOE |
| 5870 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
| 5871 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 5872 | #ifdef CONFIG_IXGBE_DCB |
| 5873 | adapter->fcoe.up = 0; |
| 5874 | #endif /* IXGBE_DCB */ |
| 5875 | #endif /* IXGBE_FCOE */ |
| 5876 | break; |
| 5877 | case ixgbe_mac_82599EB: |
| 5878 | if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM) |
| 5879 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5880 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5881 | case ixgbe_mac_X540: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 5882 | fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw)); |
Jacob Keller | cb6d0f5 | 2012-12-04 06:03:14 +0000 | [diff] [blame] | 5883 | if (fwsm & IXGBE_FWSM_TS_ENABLED) |
| 5884 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5885 | break; |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 5886 | case ixgbe_mac_x550em_a: |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 5887 | adapter->flags |= IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE; |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 5888 | switch (hw->device_id) { |
| 5889 | case IXGBE_DEV_ID_X550EM_A_1G_T: |
| 5890 | case IXGBE_DEV_ID_X550EM_A_1G_T_L: |
| 5891 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
| 5892 | break; |
| 5893 | default: |
| 5894 | break; |
| 5895 | } |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 5896 | /* fall through */ |
| 5897 | case ixgbe_mac_X550EM_x: |
Usha Ketineni | 8829009 | 2016-04-26 05:00:26 -0700 | [diff] [blame] | 5898 | #ifdef CONFIG_IXGBE_DCB |
| 5899 | adapter->flags &= ~IXGBE_FLAG_DCB_CAPABLE; |
| 5900 | #endif |
| 5901 | #ifdef IXGBE_FCOE |
| 5902 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
| 5903 | #ifdef CONFIG_IXGBE_DCB |
| 5904 | adapter->fcoe.up = 0; |
| 5905 | #endif /* IXGBE_DCB */ |
| 5906 | #endif /* IXGBE_FCOE */ |
| 5907 | /* Fall Through */ |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5908 | case ixgbe_mac_X550: |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 5909 | if (hw->mac.type == ixgbe_mac_X550) |
| 5910 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5911 | #ifdef CONFIG_IXGBE_DCA |
| 5912 | adapter->flags &= ~IXGBE_FLAG_DCA_CAPABLE; |
| 5913 | #endif |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 5914 | adapter->flags |= IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE; |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5915 | break; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5916 | default: |
| 5917 | break; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5918 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5919 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 5920 | #ifdef IXGBE_FCOE |
| 5921 | /* FCoE support exists, always init the FCoE lock */ |
| 5922 | spin_lock_init(&adapter->fcoe.lock); |
| 5923 | |
| 5924 | #endif |
Alexander Duyck | 1fc5f03 | 2011-06-02 04:28:39 +0000 | [diff] [blame] | 5925 | /* n-tuple support exists, always init our spinlock */ |
| 5926 | spin_lock_init(&adapter->fdir_perfect_lock); |
| 5927 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5928 | #ifdef CONFIG_IXGBE_DCB |
Usha Ketineni | 8829009 | 2016-04-26 05:00:26 -0700 | [diff] [blame] | 5929 | ixgbe_init_dcb(adapter); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5930 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5931 | |
| 5932 | /* default flow control settings */ |
Don Skidmore | cd7664f | 2009-03-31 21:33:44 +0000 | [diff] [blame] | 5933 | hw->fc.requested_mode = ixgbe_fc_full; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 5934 | hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */ |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5935 | ixgbe_pbthresh_setup(adapter); |
Jesse Brandeburg | 2b9ade9 | 2008-08-26 04:27:10 -0700 | [diff] [blame] | 5936 | hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE; |
| 5937 | hw->fc.send_xon = true; |
Don Skidmore | 73d80953d | 2013-07-31 02:19:24 +0000 | [diff] [blame] | 5938 | hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5939 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 5940 | #ifdef CONFIG_PCI_IOV |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 5941 | if (max_vfs > 0) |
| 5942 | 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] | 5943 | |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 5944 | /* assign number of SR-IOV VFs */ |
| 5945 | if (hw->mac.type != ixgbe_mac_82598EB) { |
ethan.zhao | dcc23e3 | 2014-01-16 19:41:04 -0800 | [diff] [blame] | 5946 | if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) { |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 5947 | adapter->num_vfs = 0; |
| 5948 | e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n"); |
| 5949 | } else { |
| 5950 | adapter->num_vfs = max_vfs; |
| 5951 | } |
| 5952 | } |
| 5953 | #endif /* CONFIG_PCI_IOV */ |
| 5954 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5955 | /* enable itr by default in dynamic mode */ |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 5956 | adapter->rx_itr_setting = 1; |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 5957 | adapter->tx_itr_setting = 1; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5958 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5959 | /* set default ring sizes */ |
| 5960 | adapter->tx_ring_count = IXGBE_DEFAULT_TXD; |
| 5961 | adapter->rx_ring_count = IXGBE_DEFAULT_RXD; |
| 5962 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 5963 | /* set default work limits */ |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 5964 | adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 5965 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5966 | /* initialize eeprom parameters */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5967 | if (ixgbe_init_eeprom_params_generic(hw)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5968 | e_dev_err("EEPROM initialization failed\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5969 | return -EIO; |
| 5970 | } |
| 5971 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5972 | /* PF holds first pool slot */ |
| 5973 | set_bit(0, &adapter->fwd_bitmask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5974 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 5975 | |
| 5976 | return 0; |
| 5977 | } |
| 5978 | |
| 5979 | /** |
| 5980 | * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5981 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5982 | * |
| 5983 | * Return 0 on success, negative on failure |
| 5984 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5985 | int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5986 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5987 | struct device *dev = tx_ring->dev; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5988 | int orig_node = dev_to_node(dev); |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5989 | int ring_node = -1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5990 | int size; |
| 5991 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5992 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5993 | |
| 5994 | if (tx_ring->q_vector) |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5995 | ring_node = tx_ring->q_vector->numa_node; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5996 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5997 | tx_ring->tx_buffer_info = vmalloc_node(size, ring_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5998 | if (!tx_ring->tx_buffer_info) |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5999 | tx_ring->tx_buffer_info = vmalloc(size); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 6000 | if (!tx_ring->tx_buffer_info) |
| 6001 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6002 | |
John Stultz | 827da44 | 2013-10-07 15:51:58 -0700 | [diff] [blame] | 6003 | u64_stats_init(&tx_ring->syncp); |
| 6004 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6005 | /* round up to nearest 4K */ |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 6006 | tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 6007 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6008 | |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 6009 | set_dev_node(dev, ring_node); |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 6010 | tx_ring->desc = dma_alloc_coherent(dev, |
| 6011 | tx_ring->size, |
| 6012 | &tx_ring->dma, |
| 6013 | GFP_KERNEL); |
| 6014 | set_dev_node(dev, orig_node); |
| 6015 | if (!tx_ring->desc) |
| 6016 | tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size, |
| 6017 | &tx_ring->dma, GFP_KERNEL); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 6018 | if (!tx_ring->desc) |
| 6019 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6020 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 6021 | tx_ring->next_to_use = 0; |
| 6022 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6023 | return 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 6024 | |
| 6025 | err: |
| 6026 | vfree(tx_ring->tx_buffer_info); |
| 6027 | tx_ring->tx_buffer_info = NULL; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6028 | 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] | 6029 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6030 | } |
| 6031 | |
| 6032 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6033 | * ixgbe_setup_all_tx_resources - allocate all queues Tx resources |
| 6034 | * @adapter: board private structure |
| 6035 | * |
| 6036 | * If this function returns with an error, then it's possible one or |
| 6037 | * more of the rings is populated (while the rest are not). It is the |
| 6038 | * callers duty to clean those orphaned rings. |
| 6039 | * |
| 6040 | * Return 0 on success, negative on failure |
| 6041 | **/ |
| 6042 | static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) |
| 6043 | { |
| 6044 | int i, err = 0; |
| 6045 | |
| 6046 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6047 | err = ixgbe_setup_tx_resources(adapter->tx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6048 | if (!err) |
| 6049 | continue; |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6050 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 6051 | e_err(probe, "Allocation for Tx Queue %u failed\n", i); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6052 | goto err_setup_tx; |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6053 | } |
| 6054 | |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6055 | return 0; |
| 6056 | err_setup_tx: |
| 6057 | /* rewind the index freeing the rings as we go */ |
| 6058 | while (i--) |
| 6059 | ixgbe_free_tx_resources(adapter->tx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6060 | return err; |
| 6061 | } |
| 6062 | |
| 6063 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6064 | * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 6065 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6066 | * |
| 6067 | * Returns 0 on success, negative on failure |
| 6068 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6069 | int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6070 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6071 | struct device *dev = rx_ring->dev; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 6072 | int orig_node = dev_to_node(dev); |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 6073 | int ring_node = -1; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6074 | int size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6075 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 6076 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 6077 | |
| 6078 | if (rx_ring->q_vector) |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 6079 | ring_node = rx_ring->q_vector->numa_node; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 6080 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 6081 | rx_ring->rx_buffer_info = vmalloc_node(size, ring_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 6082 | if (!rx_ring->rx_buffer_info) |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 6083 | rx_ring->rx_buffer_info = vmalloc(size); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6084 | if (!rx_ring->rx_buffer_info) |
| 6085 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6086 | |
John Stultz | 827da44 | 2013-10-07 15:51:58 -0700 | [diff] [blame] | 6087 | u64_stats_init(&rx_ring->syncp); |
| 6088 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6089 | /* Round up to nearest 4K */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 6090 | rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); |
| 6091 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6092 | |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 6093 | set_dev_node(dev, ring_node); |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 6094 | rx_ring->desc = dma_alloc_coherent(dev, |
| 6095 | rx_ring->size, |
| 6096 | &rx_ring->dma, |
| 6097 | GFP_KERNEL); |
| 6098 | set_dev_node(dev, orig_node); |
| 6099 | if (!rx_ring->desc) |
| 6100 | rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size, |
| 6101 | &rx_ring->dma, GFP_KERNEL); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6102 | if (!rx_ring->desc) |
| 6103 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6104 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 6105 | rx_ring->next_to_clean = 0; |
| 6106 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6107 | |
| 6108 | return 0; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6109 | err: |
| 6110 | vfree(rx_ring->rx_buffer_info); |
| 6111 | rx_ring->rx_buffer_info = NULL; |
| 6112 | 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] | 6113 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6114 | } |
| 6115 | |
| 6116 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6117 | * ixgbe_setup_all_rx_resources - allocate all queues Rx resources |
| 6118 | * @adapter: board private structure |
| 6119 | * |
| 6120 | * If this function returns with an error, then it's possible one or |
| 6121 | * more of the rings is populated (while the rest are not). It is the |
| 6122 | * callers duty to clean those orphaned rings. |
| 6123 | * |
| 6124 | * Return 0 on success, negative on failure |
| 6125 | **/ |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6126 | static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) |
| 6127 | { |
| 6128 | int i, err = 0; |
| 6129 | |
| 6130 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6131 | err = ixgbe_setup_rx_resources(adapter->rx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6132 | if (!err) |
| 6133 | continue; |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6134 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 6135 | e_err(probe, "Allocation for Rx Queue %u failed\n", i); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6136 | goto err_setup_rx; |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6137 | } |
| 6138 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 6139 | #ifdef IXGBE_FCOE |
| 6140 | err = ixgbe_setup_fcoe_ddp_resources(adapter); |
| 6141 | if (!err) |
| 6142 | #endif |
| 6143 | return 0; |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6144 | err_setup_rx: |
| 6145 | /* rewind the index freeing the rings as we go */ |
| 6146 | while (i--) |
| 6147 | ixgbe_free_rx_resources(adapter->rx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6148 | return err; |
| 6149 | } |
| 6150 | |
| 6151 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6152 | * ixgbe_free_tx_resources - Free Tx Resources per Queue |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6153 | * @tx_ring: Tx descriptor ring for a specific queue |
| 6154 | * |
| 6155 | * Free all transmit software resources |
| 6156 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6157 | void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6158 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6159 | ixgbe_clean_tx_ring(tx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6160 | |
| 6161 | vfree(tx_ring->tx_buffer_info); |
| 6162 | tx_ring->tx_buffer_info = NULL; |
| 6163 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6164 | /* if not set, then don't free */ |
| 6165 | if (!tx_ring->desc) |
| 6166 | return; |
| 6167 | |
| 6168 | dma_free_coherent(tx_ring->dev, tx_ring->size, |
| 6169 | tx_ring->desc, tx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6170 | |
| 6171 | tx_ring->desc = NULL; |
| 6172 | } |
| 6173 | |
| 6174 | /** |
| 6175 | * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues |
| 6176 | * @adapter: board private structure |
| 6177 | * |
| 6178 | * Free all transmit software resources |
| 6179 | **/ |
| 6180 | static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter) |
| 6181 | { |
| 6182 | int i; |
| 6183 | |
| 6184 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 6185 | if (adapter->tx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6186 | ixgbe_free_tx_resources(adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6187 | } |
| 6188 | |
| 6189 | /** |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6190 | * ixgbe_free_rx_resources - Free Rx Resources |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6191 | * @rx_ring: ring to clean the resources from |
| 6192 | * |
| 6193 | * Free all receive software resources |
| 6194 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6195 | void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6196 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6197 | ixgbe_clean_rx_ring(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6198 | |
| 6199 | vfree(rx_ring->rx_buffer_info); |
| 6200 | rx_ring->rx_buffer_info = NULL; |
| 6201 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6202 | /* if not set, then don't free */ |
| 6203 | if (!rx_ring->desc) |
| 6204 | return; |
| 6205 | |
| 6206 | dma_free_coherent(rx_ring->dev, rx_ring->size, |
| 6207 | rx_ring->desc, rx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6208 | |
| 6209 | rx_ring->desc = NULL; |
| 6210 | } |
| 6211 | |
| 6212 | /** |
| 6213 | * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues |
| 6214 | * @adapter: board private structure |
| 6215 | * |
| 6216 | * Free all receive software resources |
| 6217 | **/ |
| 6218 | static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter) |
| 6219 | { |
| 6220 | int i; |
| 6221 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 6222 | #ifdef IXGBE_FCOE |
| 6223 | ixgbe_free_fcoe_ddp_resources(adapter); |
| 6224 | |
| 6225 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6226 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 6227 | if (adapter->rx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6228 | ixgbe_free_rx_resources(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6229 | } |
| 6230 | |
| 6231 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6232 | * ixgbe_change_mtu - Change the Maximum Transfer Unit |
| 6233 | * @netdev: network interface device structure |
| 6234 | * @new_mtu: new value for maximum frame size |
| 6235 | * |
| 6236 | * Returns 0 on success, negative on failure |
| 6237 | **/ |
| 6238 | static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu) |
| 6239 | { |
| 6240 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 655309e | 2012-02-08 07:50:35 +0000 | [diff] [blame] | 6241 | |
| 6242 | /* |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 6243 | * For 82599EB we cannot allow legacy VFs to enable their receive |
| 6244 | * paths when MTU greater than 1500 is configured. So display a |
| 6245 | * warning that legacy VFs will be disabled. |
Alexander Duyck | 655309e | 2012-02-08 07:50:35 +0000 | [diff] [blame] | 6246 | */ |
| 6247 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && |
| 6248 | (adapter->hw.mac.type == ixgbe_mac_82599EB) && |
Jarod Wilson | 91c527a | 2016-10-17 15:54:05 -0400 | [diff] [blame] | 6249 | (new_mtu > ETH_DATA_LEN)) |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 6250 | e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6251 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 6252 | 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] | 6253 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6254 | /* must set new MTU before calling down or up */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6255 | netdev->mtu = new_mtu; |
| 6256 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 6257 | if (netif_running(netdev)) |
| 6258 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6259 | |
| 6260 | return 0; |
| 6261 | } |
| 6262 | |
| 6263 | /** |
| 6264 | * ixgbe_open - Called when a network interface is made active |
| 6265 | * @netdev: network interface device structure |
| 6266 | * |
| 6267 | * Returns 0 on success, negative value on failure |
| 6268 | * |
| 6269 | * The open entry point is called when a network interface is made |
| 6270 | * active by the system (IFF_UP). At this point all resources needed |
| 6271 | * for transmit and receive operations are allocated, the interrupt |
| 6272 | * handler is registered with the OS, the watchdog timer is started, |
| 6273 | * and the stack is notified that the interface is ready. |
| 6274 | **/ |
Stefan Assmann | 6c211fe1 | 2016-02-03 09:20:48 +0100 | [diff] [blame] | 6275 | int ixgbe_open(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6276 | { |
| 6277 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 6278 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 6279 | int err, queues; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6280 | |
Auke Kok | 4bebfaa | 2008-02-11 09:26:01 -0800 | [diff] [blame] | 6281 | /* disallow open during test */ |
| 6282 | if (test_bit(__IXGBE_TESTING, &adapter->state)) |
| 6283 | return -EBUSY; |
| 6284 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 6285 | netif_carrier_off(netdev); |
| 6286 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6287 | /* allocate transmit descriptors */ |
| 6288 | err = ixgbe_setup_all_tx_resources(adapter); |
| 6289 | if (err) |
| 6290 | goto err_setup_tx; |
| 6291 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6292 | /* allocate receive descriptors */ |
| 6293 | err = ixgbe_setup_all_rx_resources(adapter); |
| 6294 | if (err) |
| 6295 | goto err_setup_rx; |
| 6296 | |
| 6297 | ixgbe_configure(adapter); |
| 6298 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6299 | err = ixgbe_request_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6300 | if (err) |
| 6301 | goto err_req_irq; |
| 6302 | |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6303 | /* Notify the stack of the actual queue counts. */ |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 6304 | if (adapter->num_rx_pools > 1) |
| 6305 | queues = adapter->num_rx_queues_per_pool; |
| 6306 | else |
| 6307 | queues = adapter->num_tx_queues; |
| 6308 | |
| 6309 | err = netif_set_real_num_tx_queues(netdev, queues); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6310 | if (err) |
| 6311 | goto err_set_queues; |
| 6312 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 6313 | if (adapter->num_rx_pools > 1 && |
| 6314 | adapter->num_rx_queues > IXGBE_MAX_L2A_QUEUES) |
| 6315 | queues = IXGBE_MAX_L2A_QUEUES; |
| 6316 | else |
| 6317 | queues = adapter->num_rx_queues; |
| 6318 | err = netif_set_real_num_rx_queues(netdev, queues); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6319 | if (err) |
| 6320 | goto err_set_queues; |
| 6321 | |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6322 | ixgbe_ptp_init(adapter); |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6323 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 6324 | ixgbe_up_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6325 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 6326 | ixgbe_clear_udp_tunnel_port(adapter, IXGBE_VXLANCTRL_ALL_UDPPORT_MASK); |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 6327 | udp_tunnel_get_rx_info(netdev); |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 6328 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6329 | return 0; |
| 6330 | |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6331 | err_set_queues: |
| 6332 | ixgbe_free_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6333 | err_req_irq: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 6334 | ixgbe_free_all_rx_resources(adapter); |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 6335 | if (hw->phy.ops.set_phy_power && !adapter->wol) |
| 6336 | hw->phy.ops.set_phy_power(&adapter->hw, false); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6337 | err_setup_rx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 6338 | ixgbe_free_all_tx_resources(adapter); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6339 | err_setup_tx: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6340 | ixgbe_reset(adapter); |
| 6341 | |
| 6342 | return err; |
| 6343 | } |
| 6344 | |
Jacob Keller | a0cccce | 2014-05-16 05:12:29 +0000 | [diff] [blame] | 6345 | static void ixgbe_close_suspend(struct ixgbe_adapter *adapter) |
| 6346 | { |
| 6347 | ixgbe_ptp_suspend(adapter); |
| 6348 | |
Don Skidmore | 6ac7439 | 2015-06-17 17:34:31 -0400 | [diff] [blame] | 6349 | if (adapter->hw.phy.ops.enter_lplu) { |
| 6350 | adapter->hw.phy.reset_disable = true; |
| 6351 | ixgbe_down(adapter); |
| 6352 | adapter->hw.phy.ops.enter_lplu(&adapter->hw); |
| 6353 | adapter->hw.phy.reset_disable = false; |
| 6354 | } else { |
| 6355 | ixgbe_down(adapter); |
| 6356 | } |
| 6357 | |
Jacob Keller | a0cccce | 2014-05-16 05:12:29 +0000 | [diff] [blame] | 6358 | ixgbe_free_irq(adapter); |
| 6359 | |
| 6360 | ixgbe_free_all_tx_resources(adapter); |
| 6361 | ixgbe_free_all_rx_resources(adapter); |
| 6362 | } |
| 6363 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6364 | /** |
| 6365 | * ixgbe_close - Disables a network interface |
| 6366 | * @netdev: network interface device structure |
| 6367 | * |
| 6368 | * Returns 0, this is not allowed to fail |
| 6369 | * |
| 6370 | * The close entry point is called when an interface is de-activated |
| 6371 | * by the OS. The hardware is still under the drivers control, but |
| 6372 | * needs to be disabled. A global MAC reset is issued to stop the |
| 6373 | * hardware, and all transmit and receive resources are freed. |
| 6374 | **/ |
Stefan Assmann | 6c211fe1 | 2016-02-03 09:20:48 +0100 | [diff] [blame] | 6375 | int ixgbe_close(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6376 | { |
| 6377 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6378 | |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6379 | ixgbe_ptp_stop(adapter); |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6380 | |
Emil Tantilov | f7f37e7 | 2016-11-11 10:07:47 -0800 | [diff] [blame] | 6381 | if (netif_device_present(netdev)) |
| 6382 | ixgbe_close_suspend(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6383 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 6384 | ixgbe_fdir_filter_exit(adapter); |
| 6385 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 6386 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6387 | |
| 6388 | return 0; |
| 6389 | } |
| 6390 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6391 | #ifdef CONFIG_PM |
| 6392 | static int ixgbe_resume(struct pci_dev *pdev) |
| 6393 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 6394 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 6395 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6396 | u32 err; |
| 6397 | |
Mark Rustad | 0391bbe | 2014-02-28 15:48:55 -0800 | [diff] [blame] | 6398 | adapter->hw.hw_addr = adapter->io_addr; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6399 | pci_set_power_state(pdev, PCI_D0); |
| 6400 | pci_restore_state(pdev); |
Don Skidmore | 656ab81 | 2009-12-23 21:19:19 -0800 | [diff] [blame] | 6401 | /* |
| 6402 | * pci_restore_state clears dev->state_saved so call |
| 6403 | * pci_save_state to restore it. |
| 6404 | */ |
| 6405 | pci_save_state(pdev); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 6406 | |
| 6407 | err = pci_enable_device_mem(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6408 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 6409 | e_dev_err("Cannot enable PCI device from suspend\n"); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6410 | return err; |
| 6411 | } |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 6412 | smp_mb__before_atomic(); |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 6413 | clear_bit(__IXGBE_DISABLED, &adapter->state); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6414 | pci_set_master(pdev); |
| 6415 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 6416 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6417 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6418 | ixgbe_reset(adapter); |
| 6419 | |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 6420 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
| 6421 | |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6422 | rtnl_lock(); |
| 6423 | err = ixgbe_init_interrupt_scheme(adapter); |
| 6424 | if (!err && netif_running(netdev)) |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 6425 | err = ixgbe_open(netdev); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6426 | |
Emil Tantilov | f7f37e7 | 2016-11-11 10:07:47 -0800 | [diff] [blame] | 6427 | |
| 6428 | if (!err) |
| 6429 | netif_device_attach(netdev); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6430 | rtnl_unlock(); |
| 6431 | |
Emil Tantilov | f7f37e7 | 2016-11-11 10:07:47 -0800 | [diff] [blame] | 6432 | return err; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6433 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6434 | #endif /* CONFIG_PM */ |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6435 | |
| 6436 | static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6437 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 6438 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 6439 | struct net_device *netdev = adapter->netdev; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6440 | struct ixgbe_hw *hw = &adapter->hw; |
| 6441 | u32 ctrl, fctrl; |
| 6442 | u32 wufc = adapter->wol; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6443 | #ifdef CONFIG_PM |
| 6444 | int retval = 0; |
| 6445 | #endif |
| 6446 | |
Emil Tantilov | f7f37e7 | 2016-11-11 10:07:47 -0800 | [diff] [blame] | 6447 | rtnl_lock(); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6448 | netif_device_detach(netdev); |
| 6449 | |
Jacob Keller | a0cccce | 2014-05-16 05:12:29 +0000 | [diff] [blame] | 6450 | if (netif_running(netdev)) |
| 6451 | ixgbe_close_suspend(adapter); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6452 | |
Alexander Duyck | 5f5ae6f | 2010-11-16 19:26:52 -0800 | [diff] [blame] | 6453 | ixgbe_clear_interrupt_scheme(adapter); |
Emil Tantilov | f7f37e7 | 2016-11-11 10:07:47 -0800 | [diff] [blame] | 6454 | rtnl_unlock(); |
Alexander Duyck | 5f5ae6f | 2010-11-16 19:26:52 -0800 | [diff] [blame] | 6455 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6456 | #ifdef CONFIG_PM |
| 6457 | retval = pci_save_state(pdev); |
| 6458 | if (retval) |
| 6459 | return retval; |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 6460 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6461 | #endif |
Jacob Keller | f4f1040 | 2013-06-25 07:59:23 +0000 | [diff] [blame] | 6462 | if (hw->mac.ops.stop_link_on_d3) |
| 6463 | hw->mac.ops.stop_link_on_d3(hw); |
| 6464 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6465 | if (wufc) { |
| 6466 | ixgbe_set_rx_mode(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6467 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 6468 | /* enable the optics for 82599 SFP+ fiber as we can WoL */ |
| 6469 | if (hw->mac.ops.enable_tx_laser) |
Don Skidmore | c509e75 | 2012-04-05 08:12:05 +0000 | [diff] [blame] | 6470 | hw->mac.ops.enable_tx_laser(hw); |
| 6471 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6472 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 6473 | if (wufc & IXGBE_WUFC_MC) { |
| 6474 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 6475 | fctrl |= IXGBE_FCTRL_MPE; |
| 6476 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
| 6477 | } |
| 6478 | |
| 6479 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 6480 | ctrl |= IXGBE_CTRL_GIO_DIS; |
| 6481 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); |
| 6482 | |
| 6483 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc); |
| 6484 | } else { |
| 6485 | IXGBE_WRITE_REG(hw, IXGBE_WUC, 0); |
| 6486 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0); |
| 6487 | } |
| 6488 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6489 | switch (hw->mac.type) { |
| 6490 | case ixgbe_mac_82598EB: |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 6491 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6492 | break; |
| 6493 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 6494 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6495 | case ixgbe_mac_X550: |
| 6496 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 6497 | case ixgbe_mac_x550em_a: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6498 | pci_wake_from_d3(pdev, !!wufc); |
| 6499 | break; |
| 6500 | default: |
| 6501 | break; |
| 6502 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6503 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6504 | *enable_wake = !!wufc; |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 6505 | if (hw->phy.ops.set_phy_power && !*enable_wake) |
| 6506 | hw->phy.ops.set_phy_power(hw, false); |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6507 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6508 | ixgbe_release_hw_control(adapter); |
| 6509 | |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 6510 | if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state)) |
| 6511 | pci_disable_device(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6512 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6513 | return 0; |
| 6514 | } |
| 6515 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6516 | #ifdef CONFIG_PM |
| 6517 | static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state) |
| 6518 | { |
| 6519 | int retval; |
| 6520 | bool wake; |
| 6521 | |
| 6522 | retval = __ixgbe_shutdown(pdev, &wake); |
| 6523 | if (retval) |
| 6524 | return retval; |
| 6525 | |
| 6526 | if (wake) { |
| 6527 | pci_prepare_to_sleep(pdev); |
| 6528 | } else { |
| 6529 | pci_wake_from_d3(pdev, false); |
| 6530 | pci_set_power_state(pdev, PCI_D3hot); |
| 6531 | } |
| 6532 | |
| 6533 | return 0; |
| 6534 | } |
| 6535 | #endif /* CONFIG_PM */ |
| 6536 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6537 | static void ixgbe_shutdown(struct pci_dev *pdev) |
| 6538 | { |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6539 | bool wake; |
| 6540 | |
| 6541 | __ixgbe_shutdown(pdev, &wake); |
| 6542 | |
| 6543 | if (system_state == SYSTEM_POWER_OFF) { |
| 6544 | pci_wake_from_d3(pdev, wake); |
| 6545 | pci_set_power_state(pdev, PCI_D3hot); |
| 6546 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6547 | } |
| 6548 | |
| 6549 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6550 | * ixgbe_update_stats - Update the board statistics counters. |
| 6551 | * @adapter: board private structure |
| 6552 | **/ |
| 6553 | void ixgbe_update_stats(struct ixgbe_adapter *adapter) |
| 6554 | { |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 6555 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6556 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6557 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6558 | u64 total_mpc = 0; |
| 6559 | u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6560 | u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0; |
| 6561 | u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 6562 | u64 bytes = 0, packets = 0, hw_csum_rx_error = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6563 | |
Don Skidmore | d08935c | 2010-06-11 13:20:29 +0000 | [diff] [blame] | 6564 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 6565 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 6566 | return; |
| 6567 | |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 6568 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 6569 | u64 rsc_count = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 6570 | u64 rsc_flush = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 6571 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6572 | rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count; |
| 6573 | rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 6574 | } |
| 6575 | adapter->rsc_total_count = rsc_count; |
| 6576 | adapter->rsc_total_flush = rsc_flush; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 6577 | } |
| 6578 | |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6579 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 6580 | struct ixgbe_ring *rx_ring = adapter->rx_ring[i]; |
| 6581 | non_eop_descs += rx_ring->rx_stats.non_eop_descs; |
| 6582 | alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed; |
| 6583 | alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 6584 | hw_csum_rx_error += rx_ring->rx_stats.csum_err; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6585 | bytes += rx_ring->stats.bytes; |
| 6586 | packets += rx_ring->stats.packets; |
| 6587 | } |
Mallikarjuna R Chilakala | eb985f0 | 2009-12-15 11:56:59 +0000 | [diff] [blame] | 6588 | adapter->non_eop_descs = non_eop_descs; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6589 | adapter->alloc_rx_page_failed = alloc_rx_page_failed; |
| 6590 | adapter->alloc_rx_buff_failed = alloc_rx_buff_failed; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 6591 | adapter->hw_csum_rx_error = hw_csum_rx_error; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6592 | netdev->stats.rx_bytes = bytes; |
| 6593 | netdev->stats.rx_packets = packets; |
| 6594 | |
| 6595 | bytes = 0; |
| 6596 | packets = 0; |
| 6597 | /* gather some stats to the adapter struct that are per queue */ |
| 6598 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 6599 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 6600 | restart_queue += tx_ring->tx_stats.restart_queue; |
| 6601 | tx_busy += tx_ring->tx_stats.tx_busy; |
| 6602 | bytes += tx_ring->stats.bytes; |
| 6603 | packets += tx_ring->stats.packets; |
| 6604 | } |
| 6605 | adapter->restart_queue = restart_queue; |
| 6606 | adapter->tx_busy = tx_busy; |
| 6607 | netdev->stats.tx_bytes = bytes; |
| 6608 | netdev->stats.tx_packets = packets; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 6609 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6610 | hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS); |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6611 | |
| 6612 | /* 8 register reads */ |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6613 | for (i = 0; i < 8; i++) { |
| 6614 | /* for packet buffers not used, the register should read 0 */ |
| 6615 | mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i)); |
| 6616 | missed_rx += mpc; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6617 | hwstats->mpc[i] += mpc; |
| 6618 | total_mpc += hwstats->mpc[i]; |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6619 | hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i)); |
| 6620 | hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6621 | switch (hw->mac.type) { |
| 6622 | case ixgbe_mac_82598EB: |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6623 | hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i)); |
| 6624 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i)); |
| 6625 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i)); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6626 | hwstats->pxonrxc[i] += |
| 6627 | IXGBE_READ_REG(hw, IXGBE_PXONRXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6628 | break; |
| 6629 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 6630 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6631 | case ixgbe_mac_X550: |
| 6632 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 6633 | case ixgbe_mac_x550em_a: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6634 | hwstats->pxonrxc[i] += |
| 6635 | IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6636 | break; |
| 6637 | default: |
| 6638 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6639 | } |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6640 | } |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6641 | |
| 6642 | /*16 register reads */ |
| 6643 | for (i = 0; i < 16; i++) { |
| 6644 | hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i)); |
| 6645 | hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i)); |
| 6646 | if ((hw->mac.type == ixgbe_mac_82599EB) || |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6647 | (hw->mac.type == ixgbe_mac_X540) || |
| 6648 | (hw->mac.type == ixgbe_mac_X550) || |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 6649 | (hw->mac.type == ixgbe_mac_X550EM_x) || |
| 6650 | (hw->mac.type == ixgbe_mac_x550em_a)) { |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6651 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i)); |
| 6652 | IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */ |
| 6653 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i)); |
| 6654 | IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */ |
| 6655 | } |
| 6656 | } |
| 6657 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6658 | hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6659 | /* work around hardware counting issue */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6660 | hwstats->gprc -= missed_rx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6661 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 6662 | ixgbe_update_xoff_received(adapter); |
| 6663 | |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6664 | /* 82598 hardware only has a 32 bit counter in the high register */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6665 | switch (hw->mac.type) { |
| 6666 | case ixgbe_mac_82598EB: |
| 6667 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6668 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH); |
| 6669 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH); |
| 6670 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH); |
| 6671 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 6672 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6673 | case ixgbe_mac_X550: |
| 6674 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 6675 | case ixgbe_mac_x550em_a: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6676 | /* OS2BMC stats are X540 and later */ |
Emil Tantilov | 58f6bcf | 2011-04-21 08:43:43 +0000 | [diff] [blame] | 6677 | hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC); |
| 6678 | hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC); |
| 6679 | hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC); |
| 6680 | hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC); |
| 6681 | case ixgbe_mac_82599EB: |
Alexander Duyck | a4d4f62 | 2012-03-28 08:03:32 +0000 | [diff] [blame] | 6682 | for (i = 0; i < 16; i++) |
| 6683 | adapter->hw_rx_no_dma_resources += |
| 6684 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6685 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6686 | IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6687 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6688 | IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6689 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6690 | IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6691 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6692 | hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH); |
| 6693 | hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS); |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 6694 | #ifdef IXGBE_FCOE |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6695 | hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC); |
| 6696 | hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC); |
| 6697 | hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC); |
| 6698 | hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC); |
| 6699 | hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC); |
| 6700 | hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC); |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 6701 | /* Add up per cpu counters for total ddp aloc fail */ |
Alexander Duyck | 5a1ee27 | 2012-05-05 17:14:28 +0000 | [diff] [blame] | 6702 | if (adapter->fcoe.ddp_pool) { |
| 6703 | struct ixgbe_fcoe *fcoe = &adapter->fcoe; |
| 6704 | struct ixgbe_fcoe_ddp_pool *ddp_pool; |
| 6705 | unsigned int cpu; |
| 6706 | u64 noddp = 0, noddp_ext_buff = 0; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 6707 | for_each_possible_cpu(cpu) { |
Alexander Duyck | 5a1ee27 | 2012-05-05 17:14:28 +0000 | [diff] [blame] | 6708 | ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu); |
| 6709 | noddp += ddp_pool->noddp; |
| 6710 | noddp_ext_buff += ddp_pool->noddp_ext_buff; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 6711 | } |
Alexander Duyck | 5a1ee27 | 2012-05-05 17:14:28 +0000 | [diff] [blame] | 6712 | hwstats->fcoe_noddp = noddp; |
| 6713 | hwstats->fcoe_noddp_ext_buff = noddp_ext_buff; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 6714 | } |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 6715 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6716 | break; |
| 6717 | default: |
| 6718 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6719 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6720 | bprc = IXGBE_READ_REG(hw, IXGBE_BPRC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6721 | hwstats->bprc += bprc; |
| 6722 | hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6723 | if (hw->mac.type == ixgbe_mac_82598EB) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6724 | hwstats->mprc -= bprc; |
| 6725 | hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC); |
| 6726 | hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64); |
| 6727 | hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127); |
| 6728 | hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255); |
| 6729 | hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511); |
| 6730 | hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023); |
| 6731 | hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522); |
| 6732 | hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6733 | lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6734 | hwstats->lxontxc += lxon; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6735 | lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6736 | hwstats->lxofftxc += lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6737 | hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC); |
| 6738 | hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6739 | /* |
| 6740 | * 82598 errata - tx of flow control packets is included in tx counters |
| 6741 | */ |
| 6742 | xon_off_tot = lxon + lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6743 | hwstats->gptc -= xon_off_tot; |
| 6744 | hwstats->mptc -= xon_off_tot; |
| 6745 | hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN)); |
| 6746 | hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 6747 | hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC); |
| 6748 | hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC); |
| 6749 | hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR); |
| 6750 | hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64); |
| 6751 | hwstats->ptc64 -= xon_off_tot; |
| 6752 | hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127); |
| 6753 | hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255); |
| 6754 | hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511); |
| 6755 | hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023); |
| 6756 | hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522); |
| 6757 | hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6758 | |
| 6759 | /* Fill out the OS statistics structure */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6760 | netdev->stats.multicast = hwstats->mprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6761 | |
| 6762 | /* Rx Errors */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6763 | netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 6764 | netdev->stats.rx_dropped = 0; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6765 | netdev->stats.rx_length_errors = hwstats->rlec; |
| 6766 | netdev->stats.rx_crc_errors = hwstats->crcerrs; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 6767 | netdev->stats.rx_missed_errors = total_mpc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6768 | } |
| 6769 | |
| 6770 | /** |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6771 | * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6772 | * @adapter: pointer to the device adapter structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6773 | **/ |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6774 | static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6775 | { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6776 | struct ixgbe_hw *hw = &adapter->hw; |
| 6777 | int i; |
| 6778 | |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6779 | if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 6780 | return; |
| 6781 | |
| 6782 | adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 6783 | |
| 6784 | /* if interface is down do nothing */ |
| 6785 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 6786 | return; |
| 6787 | |
| 6788 | /* do nothing if we are not using signature filters */ |
| 6789 | if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) |
| 6790 | return; |
| 6791 | |
| 6792 | adapter->fdir_overflow++; |
| 6793 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6794 | if (ixgbe_reinit_fdir_tables_82599(hw) == 0) { |
| 6795 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 6796 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 6797 | &(adapter->tx_ring[i]->state)); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6798 | /* re-enable flow director interrupts */ |
| 6799 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6800 | } else { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 6801 | e_err(probe, "failed to finish FDIR re-initialization, " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 6802 | "ignored adding FDIR ATR filters\n"); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6803 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6804 | } |
| 6805 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6806 | /** |
| 6807 | * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6808 | * @adapter: pointer to the device adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6809 | * |
| 6810 | * This function serves two purposes. First it strobes the interrupt lines |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 6811 | * in order to make certain interrupts are occurring. Secondly it sets the |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6812 | * 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] | 6813 | * determine if a hang has occurred. |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6814 | */ |
| 6815 | static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter) |
| 6816 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6817 | struct ixgbe_hw *hw = &adapter->hw; |
| 6818 | u64 eics = 0; |
| 6819 | int i; |
| 6820 | |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 6821 | /* If we're down, removing or resetting, just bail */ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6822 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 6823 | test_bit(__IXGBE_REMOVING, &adapter->state) || |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6824 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 6825 | return; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6826 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6827 | /* Force detection of hung controller */ |
| 6828 | if (netif_carrier_ok(adapter->netdev)) { |
| 6829 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 6830 | set_check_for_tx_hang(adapter->tx_ring[i]); |
| 6831 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6832 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 6833 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6834 | /* |
| 6835 | * for legacy and MSI interrupts don't set any bits |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 6836 | * that are enabled for EIAM, because this operation |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6837 | * would set *both* EIMS and EICS for any bit in EIAM |
| 6838 | */ |
| 6839 | IXGBE_WRITE_REG(hw, IXGBE_EICS, |
| 6840 | (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER)); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6841 | } else { |
| 6842 | /* get one bit for every active tx/rx interrupt vector */ |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 6843 | for (i = 0; i < adapter->num_q_vectors; i++) { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6844 | struct ixgbe_q_vector *qv = adapter->q_vector[i]; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 6845 | if (qv->rx.ring || qv->tx.ring) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 6846 | eics |= BIT_ULL(i); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6847 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6848 | } |
| 6849 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6850 | /* Cause software interrupt to ensure rings are cleaned */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6851 | ixgbe_irq_rearm_queues(adapter, eics); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6852 | } |
| 6853 | |
| 6854 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6855 | * ixgbe_watchdog_update_link - update the link status |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6856 | * @adapter: pointer to the device adapter structure |
| 6857 | * @link_speed: pointer to a u32 to store the link_speed |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6858 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6859 | static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter) |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6860 | { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6861 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6862 | u32 link_speed = adapter->link_speed; |
| 6863 | bool link_up = adapter->link_up; |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 6864 | bool pfc_en = adapter->dcb_cfg.pfc_mode_enable; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6865 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6866 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) |
| 6867 | return; |
| 6868 | |
| 6869 | if (hw->mac.ops.check_link) { |
| 6870 | 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] | 6871 | } else { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6872 | /* always assume link is up, if no check link function */ |
| 6873 | link_speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 6874 | link_up = true; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6875 | } |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 6876 | |
| 6877 | if (adapter->ixgbe_ieee_pfc) |
| 6878 | pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en); |
| 6879 | |
Alexander Duyck | 3ebe8fd | 2012-04-25 04:36:38 +0000 | [diff] [blame] | 6880 | if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) { |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 6881 | hw->mac.ops.fc_enable(hw); |
Alexander Duyck | 3ebe8fd | 2012-04-25 04:36:38 +0000 | [diff] [blame] | 6882 | ixgbe_set_rx_drop_en(adapter); |
| 6883 | } |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6884 | |
| 6885 | if (link_up || |
| 6886 | time_after(jiffies, (adapter->link_check_timeout + |
| 6887 | IXGBE_TRY_LINK_TIMEOUT))) { |
| 6888 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 6889 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC); |
| 6890 | IXGBE_WRITE_FLUSH(hw); |
| 6891 | } |
| 6892 | |
| 6893 | adapter->link_up = link_up; |
| 6894 | adapter->link_speed = link_speed; |
| 6895 | } |
| 6896 | |
Alexander Duyck | 107d301 | 2012-10-02 00:17:03 +0000 | [diff] [blame] | 6897 | static void ixgbe_update_default_up(struct ixgbe_adapter *adapter) |
| 6898 | { |
| 6899 | #ifdef CONFIG_IXGBE_DCB |
| 6900 | struct net_device *netdev = adapter->netdev; |
| 6901 | struct dcb_app app = { |
| 6902 | .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE, |
| 6903 | .protocol = 0, |
| 6904 | }; |
| 6905 | u8 up = 0; |
| 6906 | |
| 6907 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE) |
| 6908 | up = dcb_ieee_getapp_mask(netdev, &app); |
| 6909 | |
| 6910 | adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0; |
| 6911 | #endif |
| 6912 | } |
| 6913 | |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 6914 | static int ixgbe_enable_macvlan(struct net_device *upper, void *data) |
| 6915 | { |
| 6916 | if (netif_is_macvlan(upper)) { |
| 6917 | struct macvlan_dev *vlan = netdev_priv(upper); |
| 6918 | |
| 6919 | if (vlan->fwd_priv) |
| 6920 | netif_tx_wake_all_queues(upper); |
| 6921 | } |
| 6922 | |
| 6923 | return 0; |
| 6924 | } |
| 6925 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6926 | /** |
| 6927 | * ixgbe_watchdog_link_is_up - update netif_carrier status and |
| 6928 | * print link up message |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6929 | * @adapter: pointer to the device adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6930 | **/ |
| 6931 | static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter) |
| 6932 | { |
| 6933 | struct net_device *netdev = adapter->netdev; |
| 6934 | struct ixgbe_hw *hw = &adapter->hw; |
| 6935 | u32 link_speed = adapter->link_speed; |
Mark Rustad | 454adb0 | 2015-07-10 14:19:22 -0700 | [diff] [blame] | 6936 | const char *speed_str; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6937 | bool flow_rx, flow_tx; |
| 6938 | |
| 6939 | /* only continue if link was previously down */ |
| 6940 | if (netif_carrier_ok(netdev)) |
| 6941 | return; |
| 6942 | |
| 6943 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 6944 | |
| 6945 | switch (hw->mac.type) { |
| 6946 | case ixgbe_mac_82598EB: { |
| 6947 | u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 6948 | u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS); |
| 6949 | flow_rx = !!(frctl & IXGBE_FCTRL_RFCE); |
| 6950 | flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X); |
| 6951 | } |
| 6952 | break; |
| 6953 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6954 | case ixgbe_mac_X550: |
| 6955 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 6956 | case ixgbe_mac_x550em_a: |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6957 | case ixgbe_mac_82599EB: { |
| 6958 | u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN); |
| 6959 | u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG); |
| 6960 | flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE); |
| 6961 | flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X); |
| 6962 | } |
| 6963 | break; |
| 6964 | default: |
| 6965 | flow_tx = false; |
| 6966 | flow_rx = false; |
| 6967 | break; |
| 6968 | } |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 6969 | |
Jacob Keller | 6cb562d | 2012-12-05 07:24:41 +0000 | [diff] [blame] | 6970 | adapter->last_rx_ptp_check = jiffies; |
| 6971 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 6972 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6973 | ixgbe_ptp_start_cyclecounter(adapter); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 6974 | |
Mark Rustad | 454adb0 | 2015-07-10 14:19:22 -0700 | [diff] [blame] | 6975 | switch (link_speed) { |
| 6976 | case IXGBE_LINK_SPEED_10GB_FULL: |
| 6977 | speed_str = "10 Gbps"; |
| 6978 | break; |
| 6979 | case IXGBE_LINK_SPEED_2_5GB_FULL: |
| 6980 | speed_str = "2.5 Gbps"; |
| 6981 | break; |
| 6982 | case IXGBE_LINK_SPEED_1GB_FULL: |
| 6983 | speed_str = "1 Gbps"; |
| 6984 | break; |
| 6985 | case IXGBE_LINK_SPEED_100_FULL: |
| 6986 | speed_str = "100 Mbps"; |
| 6987 | break; |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 6988 | case IXGBE_LINK_SPEED_10_FULL: |
| 6989 | speed_str = "10 Mbps"; |
| 6990 | break; |
Mark Rustad | 454adb0 | 2015-07-10 14:19:22 -0700 | [diff] [blame] | 6991 | default: |
| 6992 | speed_str = "unknown speed"; |
| 6993 | break; |
| 6994 | } |
| 6995 | 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] | 6996 | ((flow_rx && flow_tx) ? "RX/TX" : |
| 6997 | (flow_rx ? "RX" : |
| 6998 | (flow_tx ? "TX" : "None")))); |
| 6999 | |
| 7000 | netif_carrier_on(netdev); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7001 | ixgbe_check_vf_rate_limit(adapter); |
Alexander Duyck | befa2af | 2012-05-05 05:30:38 +0000 | [diff] [blame] | 7002 | |
Emil Tantilov | cdc04dc | 2014-03-20 03:47:53 +0000 | [diff] [blame] | 7003 | /* enable transmits */ |
| 7004 | netif_tx_wake_all_queues(adapter->netdev); |
| 7005 | |
| 7006 | /* enable any upper devices */ |
| 7007 | rtnl_lock(); |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 7008 | netdev_walk_all_upper_dev_rcu(adapter->netdev, |
| 7009 | ixgbe_enable_macvlan, NULL); |
Emil Tantilov | cdc04dc | 2014-03-20 03:47:53 +0000 | [diff] [blame] | 7010 | rtnl_unlock(); |
| 7011 | |
Alexander Duyck | 107d301 | 2012-10-02 00:17:03 +0000 | [diff] [blame] | 7012 | /* update the default user priority for VFs */ |
| 7013 | ixgbe_update_default_up(adapter); |
| 7014 | |
Alexander Duyck | befa2af | 2012-05-05 05:30:38 +0000 | [diff] [blame] | 7015 | /* ping all the active vfs to let them know link has changed */ |
| 7016 | ixgbe_ping_all_vfs(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7017 | } |
| 7018 | |
| 7019 | /** |
| 7020 | * ixgbe_watchdog_link_is_down - update netif_carrier status and |
| 7021 | * print link down message |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7022 | * @adapter: pointer to the adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7023 | **/ |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 7024 | static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7025 | { |
| 7026 | struct net_device *netdev = adapter->netdev; |
| 7027 | struct ixgbe_hw *hw = &adapter->hw; |
| 7028 | |
| 7029 | adapter->link_up = false; |
| 7030 | adapter->link_speed = 0; |
| 7031 | |
| 7032 | /* only continue if link was up previously */ |
| 7033 | if (!netif_carrier_ok(netdev)) |
| 7034 | return; |
| 7035 | |
| 7036 | /* poll for SFP+ cable when link is down */ |
| 7037 | if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB) |
| 7038 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 7039 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 7040 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 7041 | ixgbe_ptp_start_cyclecounter(adapter); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7042 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7043 | e_info(drv, "NIC Link is Down\n"); |
| 7044 | netif_carrier_off(netdev); |
Alexander Duyck | befa2af | 2012-05-05 05:30:38 +0000 | [diff] [blame] | 7045 | |
| 7046 | /* ping all the active vfs to let them know link has changed */ |
| 7047 | ixgbe_ping_all_vfs(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7048 | } |
| 7049 | |
Emil Tantilov | 07923c1 | 2014-08-12 07:12:08 +0000 | [diff] [blame] | 7050 | static bool ixgbe_ring_tx_pending(struct ixgbe_adapter *adapter) |
| 7051 | { |
| 7052 | int i; |
| 7053 | |
| 7054 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 7055 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 7056 | |
| 7057 | if (tx_ring->next_to_use != tx_ring->next_to_clean) |
| 7058 | return true; |
| 7059 | } |
| 7060 | |
| 7061 | return false; |
| 7062 | } |
| 7063 | |
| 7064 | static bool ixgbe_vf_tx_pending(struct ixgbe_adapter *adapter) |
| 7065 | { |
| 7066 | struct ixgbe_hw *hw = &adapter->hw; |
| 7067 | struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ]; |
| 7068 | u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask); |
| 7069 | |
| 7070 | int i, j; |
| 7071 | |
| 7072 | if (!adapter->num_vfs) |
| 7073 | return false; |
| 7074 | |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 7075 | /* resetting the PF is only needed for MAC before X550 */ |
| 7076 | if (hw->mac.type >= ixgbe_mac_X550) |
| 7077 | return false; |
| 7078 | |
Emil Tantilov | 07923c1 | 2014-08-12 07:12:08 +0000 | [diff] [blame] | 7079 | for (i = 0; i < adapter->num_vfs; i++) { |
| 7080 | for (j = 0; j < q_per_pool; j++) { |
| 7081 | u32 h, t; |
| 7082 | |
| 7083 | h = IXGBE_READ_REG(hw, IXGBE_PVFTDHN(q_per_pool, i, j)); |
| 7084 | t = IXGBE_READ_REG(hw, IXGBE_PVFTDTN(q_per_pool, i, j)); |
| 7085 | |
| 7086 | if (h != t) |
| 7087 | return true; |
| 7088 | } |
| 7089 | } |
| 7090 | |
| 7091 | return false; |
| 7092 | } |
| 7093 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7094 | /** |
| 7095 | * ixgbe_watchdog_flush_tx - flush queues on link down |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7096 | * @adapter: pointer to the device adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7097 | **/ |
| 7098 | static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter) |
| 7099 | { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7100 | if (!netif_carrier_ok(adapter->netdev)) { |
Emil Tantilov | 07923c1 | 2014-08-12 07:12:08 +0000 | [diff] [blame] | 7101 | if (ixgbe_ring_tx_pending(adapter) || |
| 7102 | ixgbe_vf_tx_pending(adapter)) { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7103 | /* We've lost link, so the controller stops DMA, |
| 7104 | * but we've got queued Tx work that's never going |
| 7105 | * to get done, so reset controller to flush Tx. |
| 7106 | * (Do the reset outside of interrupt context). |
| 7107 | */ |
Jacob Keller | 12ff3f3 | 2012-12-01 07:57:17 +0000 | [diff] [blame] | 7108 | 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] | 7109 | set_bit(__IXGBE_RESET_REQUESTED, &adapter->state); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7110 | } |
| 7111 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7112 | } |
| 7113 | |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7114 | #ifdef CONFIG_PCI_IOV |
| 7115 | static inline void ixgbe_issue_vf_flr(struct ixgbe_adapter *adapter, |
| 7116 | struct pci_dev *vfdev) |
| 7117 | { |
| 7118 | if (!pci_wait_for_pending_transaction(vfdev)) |
| 7119 | e_dev_warn("Issuing VFLR with pending transactions\n"); |
| 7120 | |
| 7121 | e_dev_err("Issuing VFLR for VF %s\n", pci_name(vfdev)); |
| 7122 | pcie_capability_set_word(vfdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_BCR_FLR); |
| 7123 | |
| 7124 | msleep(100); |
| 7125 | } |
| 7126 | |
| 7127 | static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter) |
| 7128 | { |
| 7129 | struct ixgbe_hw *hw = &adapter->hw; |
| 7130 | struct pci_dev *pdev = adapter->pdev; |
Mark Rustad | 988d130 | 2015-10-30 15:29:34 -0700 | [diff] [blame] | 7131 | unsigned int vf; |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7132 | u32 gpc; |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7133 | |
| 7134 | if (!(netif_carrier_ok(adapter->netdev))) |
| 7135 | return; |
| 7136 | |
| 7137 | gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC); |
| 7138 | if (gpc) /* If incrementing then no need for the check below */ |
| 7139 | return; |
| 7140 | /* Check to see if a bad DMA write target from an errant or |
| 7141 | * malicious VF has caused a PCIe error. If so then we can |
| 7142 | * issue a VFLR to the offending VF(s) and then resume without |
| 7143 | * requesting a full slot reset. |
| 7144 | */ |
| 7145 | |
| 7146 | if (!pdev) |
| 7147 | return; |
| 7148 | |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7149 | /* check status reg for all VFs owned by this PF */ |
Mark Rustad | 988d130 | 2015-10-30 15:29:34 -0700 | [diff] [blame] | 7150 | for (vf = 0; vf < adapter->num_vfs; ++vf) { |
| 7151 | struct pci_dev *vfdev = adapter->vfinfo[vf].vfdev; |
| 7152 | u16 status_reg; |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7153 | |
Mark Rustad | 988d130 | 2015-10-30 15:29:34 -0700 | [diff] [blame] | 7154 | if (!vfdev) |
| 7155 | continue; |
| 7156 | pci_read_config_word(vfdev, PCI_STATUS, &status_reg); |
| 7157 | if (status_reg != IXGBE_FAILED_READ_CFG_WORD && |
| 7158 | status_reg & PCI_STATUS_REC_MASTER_ABORT) |
| 7159 | ixgbe_issue_vf_flr(adapter, vfdev); |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7160 | } |
| 7161 | } |
| 7162 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 7163 | static void ixgbe_spoof_check(struct ixgbe_adapter *adapter) |
| 7164 | { |
| 7165 | u32 ssvpc; |
| 7166 | |
Greg Rose | 0584d99 | 2012-08-08 00:00:58 +0000 | [diff] [blame] | 7167 | /* Do not perform spoof check for 82598 or if not in IOV mode */ |
| 7168 | if (adapter->hw.mac.type == ixgbe_mac_82598EB || |
| 7169 | adapter->num_vfs == 0) |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 7170 | return; |
| 7171 | |
| 7172 | ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC); |
| 7173 | |
| 7174 | /* |
| 7175 | * ssvpc register is cleared on read, if zero then no |
| 7176 | * spoofed packets in the last interval. |
| 7177 | */ |
| 7178 | if (!ssvpc) |
| 7179 | return; |
| 7180 | |
Emil Tantilov | d6ea075 | 2012-08-08 06:28:37 +0000 | [diff] [blame] | 7181 | e_warn(drv, "%u Spoofed packets detected\n", ssvpc); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 7182 | } |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7183 | #else |
| 7184 | static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused *adapter) |
| 7185 | { |
| 7186 | } |
| 7187 | |
| 7188 | static void |
| 7189 | ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused *adapter) |
| 7190 | { |
| 7191 | } |
| 7192 | #endif /* CONFIG_PCI_IOV */ |
| 7193 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 7194 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7195 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7196 | * ixgbe_watchdog_subtask - check and bring link up |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7197 | * @adapter: pointer to the device adapter structure |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 7198 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7199 | static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 7200 | { |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 7201 | /* if interface is down, removing or resetting, do nothing */ |
Emil Tantilov | 7edebf9 | 2011-08-27 07:18:37 +0000 | [diff] [blame] | 7202 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 7203 | test_bit(__IXGBE_REMOVING, &adapter->state) || |
Emil Tantilov | 7edebf9 | 2011-08-27 07:18:37 +0000 | [diff] [blame] | 7204 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7205 | return; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 7206 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7207 | ixgbe_watchdog_update_link(adapter); |
John Fastabend | 10eec95 | 2010-02-03 14:23:32 +0000 | [diff] [blame] | 7208 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7209 | if (adapter->link_up) |
| 7210 | ixgbe_watchdog_link_is_up(adapter); |
| 7211 | else |
| 7212 | ixgbe_watchdog_link_is_down(adapter); |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 7213 | |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7214 | ixgbe_check_for_bad_vf(adapter); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 7215 | ixgbe_spoof_check(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7216 | ixgbe_update_stats(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7217 | |
| 7218 | ixgbe_watchdog_flush_tx(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7219 | } |
| 7220 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7221 | /** |
| 7222 | * ixgbe_sfp_detection_subtask - poll for SFP+ cable |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7223 | * @adapter: the ixgbe adapter structure |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7224 | **/ |
| 7225 | static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter) |
| 7226 | { |
| 7227 | struct ixgbe_hw *hw = &adapter->hw; |
| 7228 | s32 err; |
| 7229 | |
| 7230 | /* not searching for SFP so there is nothing to do here */ |
| 7231 | if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) && |
| 7232 | !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 7233 | return; |
| 7234 | |
Mark Rustad | 58e7cd2 | 2015-08-08 16:18:48 -0700 | [diff] [blame] | 7235 | if (adapter->sfp_poll_time && |
| 7236 | time_after(adapter->sfp_poll_time, jiffies)) |
| 7237 | return; /* If not yet time to poll for SFP */ |
| 7238 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7239 | /* someone else is in init, wait until next service event */ |
| 7240 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 7241 | return; |
| 7242 | |
Mark Rustad | 58e7cd2 | 2015-08-08 16:18:48 -0700 | [diff] [blame] | 7243 | adapter->sfp_poll_time = jiffies + IXGBE_SFP_POLL_JIFFIES - 1; |
| 7244 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7245 | err = hw->phy.ops.identify_sfp(hw); |
| 7246 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 7247 | goto sfp_out; |
| 7248 | |
| 7249 | if (err == IXGBE_ERR_SFP_NOT_PRESENT) { |
| 7250 | /* If no cable is present, then we need to reset |
| 7251 | * the next time we find a good cable. */ |
| 7252 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 7253 | } |
| 7254 | |
| 7255 | /* exit on error */ |
| 7256 | if (err) |
| 7257 | goto sfp_out; |
| 7258 | |
| 7259 | /* exit if reset not needed */ |
| 7260 | if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 7261 | goto sfp_out; |
| 7262 | |
| 7263 | adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 7264 | |
| 7265 | /* |
| 7266 | * A module may be identified correctly, but the EEPROM may not have |
| 7267 | * support for that module. setup_sfp() will fail in that case, so |
| 7268 | * we should not allow that module to load. |
| 7269 | */ |
| 7270 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 7271 | err = hw->phy.ops.reset(hw); |
| 7272 | else |
| 7273 | err = hw->mac.ops.setup_sfp(hw); |
| 7274 | |
| 7275 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 7276 | goto sfp_out; |
| 7277 | |
| 7278 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 7279 | e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type); |
| 7280 | |
| 7281 | sfp_out: |
| 7282 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 7283 | |
| 7284 | if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) && |
| 7285 | (adapter->netdev->reg_state == NETREG_REGISTERED)) { |
| 7286 | e_dev_err("failed to initialize because an unsupported " |
| 7287 | "SFP+ module type was detected.\n"); |
| 7288 | e_dev_err("Reload the driver after installing a " |
| 7289 | "supported module.\n"); |
| 7290 | unregister_netdev(adapter->netdev); |
| 7291 | } |
| 7292 | } |
| 7293 | |
| 7294 | /** |
| 7295 | * ixgbe_sfp_link_config_subtask - set up link SFP after module install |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7296 | * @adapter: the ixgbe adapter structure |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7297 | **/ |
| 7298 | static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter) |
| 7299 | { |
| 7300 | struct ixgbe_hw *hw = &adapter->hw; |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 7301 | u32 speed; |
| 7302 | bool autoneg = false; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7303 | |
| 7304 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG)) |
| 7305 | return; |
| 7306 | |
| 7307 | /* someone else is in init, wait until next service event */ |
| 7308 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 7309 | return; |
| 7310 | |
| 7311 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 7312 | |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 7313 | speed = hw->phy.autoneg_advertised; |
Emil Tantilov | ed33ff6 | 2013-08-30 07:55:24 +0000 | [diff] [blame] | 7314 | if ((!speed) && (hw->mac.ops.get_link_capabilities)) { |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 7315 | hw->mac.ops.get_link_capabilities(hw, &speed, &autoneg); |
Emil Tantilov | ed33ff6 | 2013-08-30 07:55:24 +0000 | [diff] [blame] | 7316 | |
| 7317 | /* setup the highest link when no autoneg */ |
| 7318 | if (!autoneg) { |
| 7319 | if (speed & IXGBE_LINK_SPEED_10GB_FULL) |
| 7320 | speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 7321 | } |
| 7322 | } |
| 7323 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7324 | if (hw->mac.ops.setup_link) |
Josh Hay | fd0326f | 2012-12-15 03:28:30 +0000 | [diff] [blame] | 7325 | hw->mac.ops.setup_link(hw, speed, true); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7326 | |
| 7327 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 7328 | adapter->link_check_timeout = jiffies; |
| 7329 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 7330 | } |
| 7331 | |
| 7332 | /** |
| 7333 | * ixgbe_service_timer - Timer Call-back |
| 7334 | * @data: pointer to adapter cast into an unsigned long |
| 7335 | **/ |
| 7336 | static void ixgbe_service_timer(unsigned long data) |
| 7337 | { |
| 7338 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
| 7339 | unsigned long next_event_offset; |
| 7340 | |
| 7341 | /* poll faster when waiting for link */ |
| 7342 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 7343 | next_event_offset = HZ / 10; |
| 7344 | else |
| 7345 | next_event_offset = HZ * 2; |
| 7346 | |
| 7347 | /* Reset the timer */ |
| 7348 | mod_timer(&adapter->service_timer, next_event_offset + jiffies); |
| 7349 | |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7350 | ixgbe_service_event_schedule(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7351 | } |
| 7352 | |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 7353 | static void ixgbe_phy_interrupt_subtask(struct ixgbe_adapter *adapter) |
| 7354 | { |
| 7355 | struct ixgbe_hw *hw = &adapter->hw; |
| 7356 | u32 status; |
| 7357 | |
| 7358 | if (!(adapter->flags2 & IXGBE_FLAG2_PHY_INTERRUPT)) |
| 7359 | return; |
| 7360 | |
| 7361 | adapter->flags2 &= ~IXGBE_FLAG2_PHY_INTERRUPT; |
| 7362 | |
| 7363 | if (!hw->phy.ops.handle_lasi) |
| 7364 | return; |
| 7365 | |
| 7366 | status = hw->phy.ops.handle_lasi(&adapter->hw); |
| 7367 | if (status != IXGBE_ERR_OVERTEMP) |
| 7368 | return; |
| 7369 | |
| 7370 | e_crit(drv, "%s\n", ixgbe_overheat_msg); |
| 7371 | } |
| 7372 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7373 | static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter) |
| 7374 | { |
Emil Tantilov | 57ca2a4 | 2016-07-29 14:46:31 -0700 | [diff] [blame] | 7375 | if (!test_and_clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state)) |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7376 | return; |
| 7377 | |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 7378 | /* If we're already down, removing or resetting, just bail */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7379 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 7380 | test_bit(__IXGBE_REMOVING, &adapter->state) || |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7381 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 7382 | return; |
| 7383 | |
| 7384 | ixgbe_dump(adapter); |
| 7385 | netdev_err(adapter->netdev, "Reset adapter\n"); |
| 7386 | adapter->tx_timeout_count++; |
| 7387 | |
John Fastabend | 8f4c5c9 | 2014-01-16 02:30:05 -0800 | [diff] [blame] | 7388 | rtnl_lock(); |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7389 | ixgbe_reinit_locked(adapter); |
John Fastabend | 8f4c5c9 | 2014-01-16 02:30:05 -0800 | [diff] [blame] | 7390 | rtnl_unlock(); |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7391 | } |
| 7392 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7393 | /** |
| 7394 | * ixgbe_service_task - manages and runs subtasks |
| 7395 | * @work: pointer to work_struct containing our data |
| 7396 | **/ |
| 7397 | static void ixgbe_service_task(struct work_struct *work) |
| 7398 | { |
| 7399 | struct ixgbe_adapter *adapter = container_of(work, |
| 7400 | struct ixgbe_adapter, |
| 7401 | service_task); |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 7402 | if (ixgbe_removed(adapter->hw.hw_addr)) { |
| 7403 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 7404 | rtnl_lock(); |
| 7405 | ixgbe_down(adapter); |
| 7406 | rtnl_unlock(); |
| 7407 | } |
| 7408 | ixgbe_service_event_complete(adapter); |
| 7409 | return; |
| 7410 | } |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 7411 | if (adapter->flags2 & IXGBE_FLAG2_UDP_TUN_REREG_NEEDED) { |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 7412 | rtnl_lock(); |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 7413 | adapter->flags2 &= ~IXGBE_FLAG2_UDP_TUN_REREG_NEEDED; |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 7414 | udp_tunnel_get_rx_info(adapter->netdev); |
| 7415 | rtnl_unlock(); |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7416 | } |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7417 | ixgbe_reset_subtask(adapter); |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 7418 | ixgbe_phy_interrupt_subtask(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7419 | ixgbe_sfp_detection_subtask(adapter); |
| 7420 | ixgbe_sfp_link_config_subtask(adapter); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 7421 | ixgbe_check_overtemp_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7422 | ixgbe_watchdog_subtask(adapter); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 7423 | ixgbe_fdir_reinit_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7424 | ixgbe_check_hang_subtask(adapter); |
Jacob Keller | 891dc08 | 2012-12-05 07:24:46 +0000 | [diff] [blame] | 7425 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 7426 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) { |
Jacob Keller | 891dc08 | 2012-12-05 07:24:46 +0000 | [diff] [blame] | 7427 | ixgbe_ptp_overflow_check(adapter); |
| 7428 | ixgbe_ptp_rx_hang(adapter); |
| 7429 | } |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7430 | |
| 7431 | ixgbe_service_event_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7432 | } |
| 7433 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7434 | static int ixgbe_tso(struct ixgbe_ring *tx_ring, |
| 7435 | struct ixgbe_tx_buffer *first, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7436 | u8 *hdr_len) |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7437 | { |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7438 | u32 vlan_macip_lens, type_tucmd, mss_l4len_idx; |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7439 | struct sk_buff *skb = first->skb; |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7440 | union { |
| 7441 | struct iphdr *v4; |
| 7442 | struct ipv6hdr *v6; |
| 7443 | unsigned char *hdr; |
| 7444 | } ip; |
| 7445 | union { |
| 7446 | struct tcphdr *tcp; |
| 7447 | unsigned char *hdr; |
| 7448 | } l4; |
| 7449 | u32 paylen, l4_offset; |
Francois Romieu | 2049e1f | 2014-03-30 03:14:27 +0000 | [diff] [blame] | 7450 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7451 | |
Alexander Duyck | 8f4fbb9 | 2012-10-30 06:01:40 +0000 | [diff] [blame] | 7452 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 7453 | return 0; |
| 7454 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7455 | if (!skb_is_gso(skb)) |
| 7456 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7457 | |
Francois Romieu | 2049e1f | 2014-03-30 03:14:27 +0000 | [diff] [blame] | 7458 | err = skb_cow_head(skb, 0); |
| 7459 | if (err < 0) |
| 7460 | return err; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 7461 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7462 | ip.hdr = skb_network_header(skb); |
| 7463 | l4.hdr = skb_checksum_start(skb); |
| 7464 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7465 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
| 7466 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 7467 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7468 | /* initialize outer IP header fields */ |
| 7469 | if (ip.v4->version == 4) { |
Alexander Duyck | c54cdc3 | 2016-11-28 10:42:29 -0500 | [diff] [blame] | 7470 | unsigned char *csum_start = skb_checksum_start(skb); |
| 7471 | unsigned char *trans_start = ip.hdr + (ip.v4->ihl * 4); |
| 7472 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7473 | /* IP header will have to cancel out any data that |
| 7474 | * is not a part of the outer IP header |
| 7475 | */ |
Alexander Duyck | c54cdc3 | 2016-11-28 10:42:29 -0500 | [diff] [blame] | 7476 | ip.v4->check = csum_fold(csum_partial(trans_start, |
| 7477 | csum_start - trans_start, |
| 7478 | 0)); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7479 | type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7480 | |
| 7481 | ip.v4->tot_len = 0; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7482 | first->tx_flags |= IXGBE_TX_FLAGS_TSO | |
| 7483 | IXGBE_TX_FLAGS_CSUM | |
| 7484 | IXGBE_TX_FLAGS_IPV4; |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7485 | } else { |
| 7486 | ip.v6->payload_len = 0; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7487 | first->tx_flags |= IXGBE_TX_FLAGS_TSO | |
| 7488 | IXGBE_TX_FLAGS_CSUM; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7489 | } |
| 7490 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7491 | /* determine offset of inner transport header */ |
| 7492 | l4_offset = l4.hdr - skb->data; |
| 7493 | |
| 7494 | /* compute length of segmentation header */ |
| 7495 | *hdr_len = (l4.tcp->doff * 4) + l4_offset; |
| 7496 | |
| 7497 | /* remove payload length from inner checksum */ |
| 7498 | paylen = skb->len - l4_offset; |
| 7499 | csum_replace_by_diff(&l4.tcp->check, htonl(paylen)); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7500 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 7501 | /* update gso size and bytecount with header size */ |
| 7502 | first->gso_segs = skb_shinfo(skb)->gso_segs; |
| 7503 | first->bytecount += (first->gso_segs - 1) * *hdr_len; |
| 7504 | |
Alexander Duyck | c44f5f5 | 2012-10-30 06:01:45 +0000 | [diff] [blame] | 7505 | /* mss_l4len_id: use 0 as index for TSO */ |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7506 | mss_l4len_idx = (*hdr_len - l4_offset) << IXGBE_ADVTXD_L4LEN_SHIFT; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7507 | mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7508 | |
| 7509 | /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */ |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7510 | vlan_macip_lens = l4.hdr - ip.hdr; |
| 7511 | vlan_macip_lens |= (ip.hdr - skb->data) << IXGBE_ADVTXD_MACLEN_SHIFT; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7512 | vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7513 | |
| 7514 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7515 | mss_l4len_idx); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7516 | |
| 7517 | return 1; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 7518 | } |
| 7519 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7520 | static inline bool ixgbe_ipv6_csum_is_sctp(struct sk_buff *skb) |
| 7521 | { |
| 7522 | unsigned int offset = 0; |
| 7523 | |
| 7524 | ipv6_find_hdr(skb, &offset, IPPROTO_SCTP, NULL, NULL); |
| 7525 | |
| 7526 | return offset == skb_checksum_start_offset(skb); |
| 7527 | } |
| 7528 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7529 | static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring, |
| 7530 | struct ixgbe_tx_buffer *first) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7531 | { |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7532 | struct sk_buff *skb = first->skb; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7533 | u32 vlan_macip_lens = 0; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7534 | u32 type_tucmd = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7535 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7536 | if (skb->ip_summed != CHECKSUM_PARTIAL) { |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7537 | csum_failed: |
| 7538 | if (!(first->tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | |
| 7539 | IXGBE_TX_FLAGS_CC))) |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7540 | return; |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7541 | goto no_csum; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7542 | } |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 7543 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7544 | switch (skb->csum_offset) { |
| 7545 | case offsetof(struct tcphdr, check): |
| 7546 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 7547 | /* fall through */ |
| 7548 | case offsetof(struct udphdr, check): |
| 7549 | break; |
| 7550 | case offsetof(struct sctphdr, checksum): |
| 7551 | /* validate that this is actually an SCTP request */ |
| 7552 | if (((first->protocol == htons(ETH_P_IP)) && |
| 7553 | (ip_hdr(skb)->protocol == IPPROTO_SCTP)) || |
| 7554 | ((first->protocol == htons(ETH_P_IPV6)) && |
| 7555 | ixgbe_ipv6_csum_is_sctp(skb))) { |
| 7556 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
| 7557 | break; |
| 7558 | } |
| 7559 | /* fall through */ |
| 7560 | default: |
| 7561 | skb_checksum_help(skb); |
| 7562 | goto csum_failed; |
| 7563 | } |
| 7564 | |
| 7565 | /* update TX checksum flag */ |
| 7566 | first->tx_flags |= IXGBE_TX_FLAGS_CSUM; |
| 7567 | vlan_macip_lens = skb_checksum_start_offset(skb) - |
| 7568 | skb_network_offset(skb); |
Mark Rustad | 36a92d7 | 2015-11-18 09:21:28 -0800 | [diff] [blame] | 7569 | no_csum: |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7570 | /* vlan_macip_lens: MACLEN, VLAN tag */ |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7571 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7572 | vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7573 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7574 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, 0); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7575 | } |
| 7576 | |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7577 | #define IXGBE_SET_FLAG(_input, _flag, _result) \ |
| 7578 | ((_flag <= _result) ? \ |
| 7579 | ((u32)(_input & _flag) * (_result / _flag)) : \ |
| 7580 | ((u32)(_input & _flag) / (_flag / _result))) |
| 7581 | |
| 7582 | 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] | 7583 | { |
| 7584 | /* set type for advanced descriptor with frame checksum insertion */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7585 | u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA | |
| 7586 | IXGBE_ADVTXD_DCMD_DEXT | |
| 7587 | IXGBE_ADVTXD_DCMD_IFCS; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7588 | |
| 7589 | /* set HW vlan bit if vlan is present */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7590 | cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN, |
| 7591 | IXGBE_ADVTXD_DCMD_VLE); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7592 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7593 | /* set segmentation enable bits for TSO/FSO */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7594 | cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO, |
| 7595 | IXGBE_ADVTXD_DCMD_TSE); |
| 7596 | |
| 7597 | /* set timestamp bit if present */ |
| 7598 | cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP, |
| 7599 | IXGBE_ADVTXD_MAC_TSTAMP); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7600 | |
Alexander Duyck | 62748b7 | 2012-07-20 08:09:01 +0000 | [diff] [blame] | 7601 | /* insert frame checksum */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7602 | 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] | 7603 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7604 | return cmd_type; |
| 7605 | } |
| 7606 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7607 | static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc, |
| 7608 | u32 tx_flags, unsigned int paylen) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7609 | { |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7610 | u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7611 | |
| 7612 | /* enable L4 checksum for TSO and TX checksum offload */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7613 | olinfo_status |= IXGBE_SET_FLAG(tx_flags, |
| 7614 | IXGBE_TX_FLAGS_CSUM, |
| 7615 | IXGBE_ADVTXD_POPTS_TXSM); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7616 | |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 7617 | /* enble IPv4 checksum for TSO */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7618 | olinfo_status |= IXGBE_SET_FLAG(tx_flags, |
| 7619 | IXGBE_TX_FLAGS_IPV4, |
| 7620 | IXGBE_ADVTXD_POPTS_IXSM); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7621 | |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 7622 | /* |
| 7623 | * Check Context must be set if Tx switch is enabled, which it |
| 7624 | * always is for case where virtual functions are running |
| 7625 | */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7626 | olinfo_status |= IXGBE_SET_FLAG(tx_flags, |
| 7627 | IXGBE_TX_FLAGS_CC, |
| 7628 | IXGBE_ADVTXD_CC); |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 7629 | |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7630 | tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7631 | } |
| 7632 | |
Daniel Borkmann | 2367a17 | 2014-08-26 19:34:18 +0200 | [diff] [blame] | 7633 | static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size) |
| 7634 | { |
| 7635 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 7636 | |
| 7637 | /* Herbert's original patch had: |
| 7638 | * smp_mb__after_netif_stop_queue(); |
| 7639 | * but since that doesn't exist yet, just open code it. |
| 7640 | */ |
| 7641 | smp_mb(); |
| 7642 | |
| 7643 | /* We need to check again in a case another CPU has just |
| 7644 | * made room available. |
| 7645 | */ |
| 7646 | if (likely(ixgbe_desc_unused(tx_ring) < size)) |
| 7647 | return -EBUSY; |
| 7648 | |
| 7649 | /* A reprieve! - use start_queue because it doesn't call schedule */ |
| 7650 | netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 7651 | ++tx_ring->tx_stats.restart_queue; |
| 7652 | return 0; |
| 7653 | } |
| 7654 | |
| 7655 | static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size) |
| 7656 | { |
| 7657 | if (likely(ixgbe_desc_unused(tx_ring) >= size)) |
| 7658 | return 0; |
| 7659 | |
| 7660 | return __ixgbe_maybe_stop_tx(tx_ring, size); |
| 7661 | } |
| 7662 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7663 | #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \ |
| 7664 | IXGBE_TXD_CMD_RS) |
| 7665 | |
| 7666 | static void ixgbe_tx_map(struct ixgbe_ring *tx_ring, |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7667 | struct ixgbe_tx_buffer *first, |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7668 | const u8 hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7669 | { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7670 | struct sk_buff *skb = first->skb; |
| 7671 | struct ixgbe_tx_buffer *tx_buffer; |
| 7672 | union ixgbe_adv_tx_desc *tx_desc; |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7673 | struct skb_frag_struct *frag; |
| 7674 | dma_addr_t dma; |
| 7675 | unsigned int data_len, size; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7676 | u32 tx_flags = first->tx_flags; |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7677 | u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7678 | u16 i = tx_ring->next_to_use; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7679 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7680 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
| 7681 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7682 | ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len); |
| 7683 | |
| 7684 | size = skb_headlen(skb); |
| 7685 | data_len = skb->data_len; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7686 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7687 | #ifdef IXGBE_FCOE |
| 7688 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7689 | if (data_len < sizeof(struct fcoe_crc_eof)) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7690 | size -= sizeof(struct fcoe_crc_eof) - data_len; |
| 7691 | data_len = 0; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7692 | } else { |
| 7693 | data_len -= sizeof(struct fcoe_crc_eof); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 7694 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7695 | } |
| 7696 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7697 | #endif |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7698 | 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] | 7699 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7700 | tx_buffer = first; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7701 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7702 | for (frag = &skb_shinfo(skb)->frags[0];; frag++) { |
| 7703 | if (dma_mapping_error(tx_ring->dev, dma)) |
| 7704 | goto dma_error; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7705 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7706 | /* record length, and DMA address */ |
| 7707 | dma_unmap_len_set(tx_buffer, len, size); |
| 7708 | dma_unmap_addr_set(tx_buffer, dma, dma); |
| 7709 | |
| 7710 | tx_desc->read.buffer_addr = cpu_to_le64(dma); |
| 7711 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7712 | while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7713 | tx_desc->read.cmd_type_len = |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7714 | cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7715 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7716 | i++; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7717 | tx_desc++; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7718 | if (i == tx_ring->count) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 7719 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7720 | i = 0; |
| 7721 | } |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7722 | tx_desc->read.olinfo_status = 0; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7723 | |
| 7724 | dma += IXGBE_MAX_DATA_PER_TXD; |
| 7725 | size -= IXGBE_MAX_DATA_PER_TXD; |
| 7726 | |
| 7727 | tx_desc->read.buffer_addr = cpu_to_le64(dma); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7728 | } |
| 7729 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7730 | if (likely(!data_len)) |
| 7731 | break; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7732 | |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7733 | tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7734 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7735 | i++; |
| 7736 | tx_desc++; |
| 7737 | if (i == tx_ring->count) { |
| 7738 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
| 7739 | i = 0; |
| 7740 | } |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7741 | tx_desc->read.olinfo_status = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7742 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7743 | #ifdef IXGBE_FCOE |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 7744 | size = min_t(unsigned int, data_len, skb_frag_size(frag)); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7745 | #else |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 7746 | size = skb_frag_size(frag); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7747 | #endif |
| 7748 | data_len -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7749 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7750 | dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size, |
| 7751 | DMA_TO_DEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7752 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7753 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7754 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 7755 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7756 | /* write last descriptor with RS and EOP bits */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7757 | cmd_type |= size | IXGBE_TXD_CMD; |
| 7758 | tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7759 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 7760 | netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount); |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 7761 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7762 | /* set the timestamp */ |
| 7763 | first->time_stamp = jiffies; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7764 | |
| 7765 | /* |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7766 | * Force memory writes to complete before letting h/w know there |
| 7767 | * are new descriptors to fetch. (Only applicable for weak-ordered |
| 7768 | * memory model archs, such as IA-64). |
| 7769 | * |
| 7770 | * We also need this memory barrier to make certain all of the |
| 7771 | * status bits have been updated before next_to_watch is written. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7772 | */ |
| 7773 | wmb(); |
| 7774 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7775 | /* set next_to_watch value indicating a packet is present */ |
| 7776 | first->next_to_watch = tx_desc; |
| 7777 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7778 | i++; |
| 7779 | if (i == tx_ring->count) |
| 7780 | i = 0; |
| 7781 | |
| 7782 | tx_ring->next_to_use = i; |
| 7783 | |
Daniel Borkmann | 2367a17 | 2014-08-26 19:34:18 +0200 | [diff] [blame] | 7784 | ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED); |
| 7785 | |
| 7786 | if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) { |
Alexander Duyck | ad435ec | 2014-11-14 00:56:35 +0000 | [diff] [blame] | 7787 | writel(i, tx_ring->tail); |
| 7788 | |
| 7789 | /* we need this if more than one processor can write to our tail |
| 7790 | * at a time, it synchronizes IO on IA64/Altix systems |
| 7791 | */ |
| 7792 | mmiowb(); |
Daniel Borkmann | 9c938cd | 2014-08-24 15:42:16 +0200 | [diff] [blame] | 7793 | } |
Daniel Borkmann | 2367a17 | 2014-08-26 19:34:18 +0200 | [diff] [blame] | 7794 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7795 | return; |
| 7796 | dma_error: |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7797 | dev_err(tx_ring->dev, "TX DMA map failed\n"); |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 7798 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7799 | |
| 7800 | /* clear dma mappings for failed tx_buffer_info map */ |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 7801 | while (tx_buffer != first) { |
| 7802 | if (dma_unmap_len(tx_buffer, len)) |
| 7803 | dma_unmap_page(tx_ring->dev, |
| 7804 | dma_unmap_addr(tx_buffer, dma), |
| 7805 | dma_unmap_len(tx_buffer, len), |
| 7806 | DMA_TO_DEVICE); |
| 7807 | dma_unmap_len_set(tx_buffer, len, 0); |
| 7808 | |
| 7809 | if (i--) |
| 7810 | i += tx_ring->count; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7811 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7812 | } |
| 7813 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 7814 | if (dma_unmap_len(tx_buffer, len)) |
| 7815 | dma_unmap_single(tx_ring->dev, |
| 7816 | dma_unmap_addr(tx_buffer, dma), |
| 7817 | dma_unmap_len(tx_buffer, len), |
| 7818 | DMA_TO_DEVICE); |
| 7819 | dma_unmap_len_set(tx_buffer, len, 0); |
| 7820 | |
| 7821 | dev_kfree_skb_any(first->skb); |
| 7822 | first->skb = NULL; |
| 7823 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7824 | tx_ring->next_to_use = i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7825 | } |
| 7826 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7827 | static void ixgbe_atr(struct ixgbe_ring *ring, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7828 | struct ixgbe_tx_buffer *first) |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7829 | { |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7830 | struct ixgbe_q_vector *q_vector = ring->q_vector; |
| 7831 | union ixgbe_atr_hash_dword input = { .dword = 0 }; |
| 7832 | union ixgbe_atr_hash_dword common = { .dword = 0 }; |
| 7833 | union { |
| 7834 | unsigned char *network; |
| 7835 | struct iphdr *ipv4; |
| 7836 | struct ipv6hdr *ipv6; |
| 7837 | } hdr; |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 7838 | struct tcphdr *th; |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7839 | unsigned int hlen; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7840 | struct sk_buff *skb; |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 7841 | __be16 vlan_id; |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7842 | int l4_proto; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7843 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7844 | /* if ring doesn't have a interrupt vector, cannot perform ATR */ |
| 7845 | if (!q_vector) |
Guillaume Gaudonville | d3ead24 | 2010-06-29 18:29:00 +0000 | [diff] [blame] | 7846 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7847 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7848 | /* do nothing if sampling is disabled */ |
| 7849 | if (!ring->atr_sample_rate) |
| 7850 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7851 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7852 | ring->atr_count++; |
| 7853 | |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7854 | /* currently only IPv4/IPv6 with TCP is supported */ |
| 7855 | if ((first->protocol != htons(ETH_P_IP)) && |
| 7856 | (first->protocol != htons(ETH_P_IPV6))) |
| 7857 | return; |
| 7858 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7859 | /* snag network header to get L4 type and address */ |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7860 | skb = first->skb; |
| 7861 | hdr.network = skb_network_header(skb); |
Sowmini Varadhan | 9f3c750 | 2016-10-24 15:36:39 -0700 | [diff] [blame] | 7862 | if (unlikely(hdr.network <= skb->data)) |
| 7863 | return; |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 7864 | if (skb->encapsulation && |
| 7865 | first->protocol == htons(ETH_P_IP) && |
Sowmini Varadhan | 5202882 | 2016-10-24 15:36:38 -0700 | [diff] [blame] | 7866 | hdr.ipv4->protocol == IPPROTO_UDP) { |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7867 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7868 | |
Sowmini Varadhan | 9f3c750 | 2016-10-24 15:36:39 -0700 | [diff] [blame] | 7869 | if (unlikely(skb_tail_pointer(skb) < hdr.network + |
| 7870 | VXLAN_HEADROOM)) |
| 7871 | return; |
| 7872 | |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 7873 | /* verify the port is recognized as VXLAN */ |
| 7874 | if (adapter->vxlan_port && |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7875 | udp_hdr(skb)->dest == adapter->vxlan_port) |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 7876 | hdr.network = skb_inner_network_header(skb); |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 7877 | |
| 7878 | if (adapter->geneve_port && |
| 7879 | udp_hdr(skb)->dest == adapter->geneve_port) |
| 7880 | hdr.network = skb_inner_network_header(skb); |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7881 | } |
| 7882 | |
Sowmini Varadhan | 9f3c750 | 2016-10-24 15:36:39 -0700 | [diff] [blame] | 7883 | /* Make sure we have at least [minimum IPv4 header + TCP] |
| 7884 | * or [IPv6 header] bytes |
| 7885 | */ |
| 7886 | if (unlikely(skb_tail_pointer(skb) < hdr.network + 40)) |
| 7887 | return; |
| 7888 | |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7889 | /* Currently only IPv4/IPv6 with TCP is supported */ |
| 7890 | switch (hdr.ipv4->version) { |
| 7891 | case IPVERSION: |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7892 | /* access ihl as u8 to avoid unaligned access on ia64 */ |
| 7893 | hlen = (hdr.network[0] & 0x0F) << 2; |
| 7894 | l4_proto = hdr.ipv4->protocol; |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7895 | break; |
| 7896 | case 6: |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7897 | hlen = hdr.network - skb->data; |
| 7898 | l4_proto = ipv6_find_hdr(skb, &hlen, IPPROTO_TCP, NULL, NULL); |
| 7899 | hlen -= hdr.network - skb->data; |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7900 | break; |
| 7901 | default: |
| 7902 | return; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7903 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7904 | |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7905 | if (l4_proto != IPPROTO_TCP) |
| 7906 | return; |
| 7907 | |
Sowmini Varadhan | 9f3c750 | 2016-10-24 15:36:39 -0700 | [diff] [blame] | 7908 | if (unlikely(skb_tail_pointer(skb) < hdr.network + |
| 7909 | hlen + sizeof(struct tcphdr))) |
| 7910 | return; |
| 7911 | |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7912 | th = (struct tcphdr *)(hdr.network + hlen); |
| 7913 | |
| 7914 | /* skip this packet since the socket is closing */ |
| 7915 | if (th->fin) |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7916 | return; |
| 7917 | |
| 7918 | /* sample on all syn packets or once every atr sample count */ |
| 7919 | if (!th->syn && (ring->atr_count < ring->atr_sample_rate)) |
| 7920 | return; |
| 7921 | |
| 7922 | /* reset sample count */ |
| 7923 | ring->atr_count = 0; |
| 7924 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7925 | vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT); |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7926 | |
| 7927 | /* |
| 7928 | * src and dst are inverted, think how the receiver sees them |
| 7929 | * |
| 7930 | * The input is broken into two sections, a non-compressed section |
| 7931 | * containing vm_pool, vlan_id, and flow_type. The rest of the data |
| 7932 | * is XORed together and stored in the compressed dword. |
| 7933 | */ |
| 7934 | input.formatted.vlan_id = vlan_id; |
| 7935 | |
| 7936 | /* |
| 7937 | * since src port and flex bytes occupy the same word XOR them together |
| 7938 | * and write the value to source port portion of compressed dword |
| 7939 | */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7940 | 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] | 7941 | common.port.src ^= th->dest ^ htons(ETH_P_8021Q); |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7942 | else |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7943 | common.port.src ^= th->dest ^ first->protocol; |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7944 | common.port.dst ^= th->source; |
| 7945 | |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7946 | switch (hdr.ipv4->version) { |
| 7947 | case IPVERSION: |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7948 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4; |
| 7949 | common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr; |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7950 | break; |
| 7951 | case 6: |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7952 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6; |
| 7953 | common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^ |
| 7954 | hdr.ipv6->saddr.s6_addr32[1] ^ |
| 7955 | hdr.ipv6->saddr.s6_addr32[2] ^ |
| 7956 | hdr.ipv6->saddr.s6_addr32[3] ^ |
| 7957 | hdr.ipv6->daddr.s6_addr32[0] ^ |
| 7958 | hdr.ipv6->daddr.s6_addr32[1] ^ |
| 7959 | hdr.ipv6->daddr.s6_addr32[2] ^ |
| 7960 | hdr.ipv6->daddr.s6_addr32[3]; |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7961 | break; |
| 7962 | default: |
| 7963 | break; |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7964 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7965 | |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 7966 | if (hdr.network != skb_network_header(skb)) |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7967 | input.formatted.flow_type |= IXGBE_ATR_L4TYPE_TUNNEL_MASK; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7968 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7969 | /* 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] | 7970 | ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw, |
| 7971 | input, common, ring->queue_index); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7972 | } |
| 7973 | |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 7974 | 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] | 7975 | void *accel_priv, select_queue_fallback_t fallback) |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 7976 | { |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 7977 | struct ixgbe_fwd_adapter *fwd_adapter = accel_priv; |
| 7978 | #ifdef IXGBE_FCOE |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 7979 | struct ixgbe_adapter *adapter; |
| 7980 | struct ixgbe_ring_feature *f; |
| 7981 | int txq; |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 7982 | #endif |
| 7983 | |
| 7984 | if (fwd_adapter) |
| 7985 | return skb->queue_mapping + fwd_adapter->tx_base_queue; |
| 7986 | |
| 7987 | #ifdef IXGBE_FCOE |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 7988 | |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 7989 | /* |
| 7990 | * only execute the code below if protocol is FCoE |
| 7991 | * or FIP and we have FCoE enabled on the adapter |
| 7992 | */ |
| 7993 | switch (vlan_get_protocol(skb)) { |
Joe Perches | a1108ff | 2014-03-13 05:19:25 +0000 | [diff] [blame] | 7994 | case htons(ETH_P_FCOE): |
| 7995 | case htons(ETH_P_FIP): |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 7996 | adapter = netdev_priv(dev); |
Alexander Duyck | c087663 | 2012-05-10 00:01:46 +0000 | [diff] [blame] | 7997 | |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 7998 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 7999 | break; |
| 8000 | default: |
Daniel Borkmann | 99932d4 | 2014-02-16 15:55:20 +0100 | [diff] [blame] | 8001 | return fallback(dev, skb); |
Krishna Kumar | fdd3d63 | 2010-02-03 13:13:10 +0000 | [diff] [blame] | 8002 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 8003 | |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 8004 | f = &adapter->ring_feature[RING_F_FCOE]; |
| 8005 | |
| 8006 | txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) : |
| 8007 | smp_processor_id(); |
| 8008 | |
| 8009 | while (txq >= f->indices) |
| 8010 | txq -= f->indices; |
| 8011 | |
| 8012 | return txq + f->offset; |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 8013 | #else |
Daniel Borkmann | 99932d4 | 2014-02-16 15:55:20 +0100 | [diff] [blame] | 8014 | return fallback(dev, skb); |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 8015 | #endif |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 8016 | } |
| 8017 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 8018 | netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb, |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 8019 | struct ixgbe_adapter *adapter, |
| 8020 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8021 | { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8022 | struct ixgbe_tx_buffer *first; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 8023 | int tso; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8024 | u32 tx_flags = 0; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 8025 | unsigned short f; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 8026 | u16 count = TXD_USE_COUNT(skb_headlen(skb)); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8027 | __be16 protocol = skb->protocol; |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 8028 | u8 hdr_len = 0; |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 8029 | |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 8030 | /* |
| 8031 | * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD, |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 8032 | * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD, |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 8033 | * + 2 desc gap to keep tail from touching head, |
| 8034 | * + 1 desc for context descriptor, |
| 8035 | * otherwise try next time |
| 8036 | */ |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 8037 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) |
| 8038 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size); |
Alexander Duyck | 7f66162 | 2013-02-09 01:19:55 +0000 | [diff] [blame] | 8039 | |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 8040 | if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) { |
| 8041 | tx_ring->tx_stats.tx_busy++; |
| 8042 | return NETDEV_TX_BUSY; |
| 8043 | } |
| 8044 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 8045 | /* record the location of the first descriptor for this packet */ |
| 8046 | first = &tx_ring->tx_buffer_info[tx_ring->next_to_use]; |
| 8047 | first->skb = skb; |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 8048 | first->bytecount = skb->len; |
| 8049 | first->gso_segs = 1; |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 8050 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8051 | /* 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] | 8052 | if (skb_vlan_tag_present(skb)) { |
| 8053 | tx_flags |= skb_vlan_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8054 | tx_flags |= IXGBE_TX_FLAGS_HW_VLAN; |
| 8055 | /* 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] | 8056 | } else if (protocol == htons(ETH_P_8021Q)) { |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8057 | struct vlan_hdr *vhdr, _vhdr; |
| 8058 | vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr); |
| 8059 | if (!vhdr) |
| 8060 | goto out_drop; |
| 8061 | |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 8062 | tx_flags |= ntohs(vhdr->h_vlan_TCI) << |
| 8063 | IXGBE_TX_FLAGS_VLAN_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8064 | tx_flags |= IXGBE_TX_FLAGS_SW_VLAN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8065 | } |
Toshiaki Makita | 0213668 | 2015-01-29 20:37:09 +0900 | [diff] [blame] | 8066 | protocol = vlan_get_protocol(skb); |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 8067 | |
Mark Rustad | d523493 | 2014-08-09 07:02:09 +0000 | [diff] [blame] | 8068 | if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && |
| 8069 | adapter->ptp_clock && |
| 8070 | !test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS, |
| 8071 | &adapter->state)) { |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 8072 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; |
| 8073 | tx_flags |= IXGBE_TX_FLAGS_TSTAMP; |
Jacob Keller | 891dc08 | 2012-12-05 07:24:46 +0000 | [diff] [blame] | 8074 | |
| 8075 | /* schedule check for Tx timestamp */ |
| 8076 | adapter->ptp_tx_skb = skb_get(skb); |
| 8077 | adapter->ptp_tx_start = jiffies; |
| 8078 | schedule_work(&adapter->ptp_tx_work); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 8079 | } |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 8080 | |
Jakub Kicinski | ff29a86 | 2014-03-15 14:55:16 +0000 | [diff] [blame] | 8081 | skb_tx_timestamp(skb); |
| 8082 | |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 8083 | #ifdef CONFIG_PCI_IOV |
| 8084 | /* |
| 8085 | * Use the l2switch_enable flag - would be false if the DMA |
| 8086 | * Tx switch had been disabled. |
| 8087 | */ |
| 8088 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 8089 | tx_flags |= IXGBE_TX_FLAGS_CC; |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 8090 | |
| 8091 | #endif |
John Fastabend | 32701dc | 2011-09-27 03:51:56 +0000 | [diff] [blame] | 8092 | /* 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] | 8093 | if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && |
Alexander Duyck | 09dca47 | 2011-07-20 00:09:10 +0000 | [diff] [blame] | 8094 | ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) || |
| 8095 | (skb->priority != TC_PRIO_CONTROL))) { |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8096 | tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK; |
John Fastabend | 32701dc | 2011-09-27 03:51:56 +0000 | [diff] [blame] | 8097 | tx_flags |= (skb->priority & 0x7) << |
| 8098 | IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8099 | if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) { |
| 8100 | struct vlan_ethhdr *vhdr; |
Francois Romieu | 2049e1f | 2014-03-30 03:14:27 +0000 | [diff] [blame] | 8101 | |
| 8102 | if (skb_cow_head(skb, 0)) |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8103 | goto out_drop; |
| 8104 | vhdr = (struct vlan_ethhdr *)skb->data; |
| 8105 | vhdr->h_vlan_TCI = htons(tx_flags >> |
| 8106 | IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 8107 | } else { |
| 8108 | tx_flags |= IXGBE_TX_FLAGS_HW_VLAN; |
| 8109 | } |
| 8110 | } |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 8111 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 8112 | /* record initial flags and protocol */ |
| 8113 | first->tx_flags = tx_flags; |
| 8114 | first->protocol = protocol; |
| 8115 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 8116 | #ifdef IXGBE_FCOE |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8117 | /* setup tx offload for FCoE */ |
Joe Perches | a1108ff | 2014-03-13 05:19:25 +0000 | [diff] [blame] | 8118 | if ((protocol == htons(ETH_P_FCOE)) && |
Alexander Duyck | a58915c | 2012-05-25 06:38:18 +0000 | [diff] [blame] | 8119 | (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) { |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 8120 | tso = ixgbe_fso(tx_ring, first, &hdr_len); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 8121 | if (tso < 0) |
| 8122 | goto out_drop; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8123 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8124 | goto xmit_fcoe; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 8125 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8126 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8127 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 8128 | tso = ixgbe_tso(tx_ring, first, &hdr_len); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8129 | if (tso < 0) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8130 | goto out_drop; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 8131 | else if (!tso) |
| 8132 | ixgbe_tx_csum(tx_ring, first); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8133 | |
| 8134 | /* add the ATR filter if ATR is on */ |
| 8135 | if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state)) |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 8136 | ixgbe_atr(tx_ring, first); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8137 | |
| 8138 | #ifdef IXGBE_FCOE |
| 8139 | xmit_fcoe: |
| 8140 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 8141 | ixgbe_tx_map(tx_ring, first, hdr_len); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8142 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8143 | return NETDEV_TX_OK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 8144 | |
| 8145 | out_drop: |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 8146 | dev_kfree_skb_any(first->skb); |
| 8147 | first->skb = NULL; |
| 8148 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 8149 | return NETDEV_TX_OK; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8150 | } |
| 8151 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8152 | static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb, |
| 8153 | struct net_device *netdev, |
| 8154 | struct ixgbe_ring *ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8155 | { |
| 8156 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 8157 | struct ixgbe_ring *tx_ring; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8158 | |
Alexander Duyck | a50c29d | 2012-02-08 07:50:40 +0000 | [diff] [blame] | 8159 | /* |
| 8160 | * The minimum packet size for olinfo paylen is 17 so pad the skb |
| 8161 | * in order to meet this minimum size requirement. |
| 8162 | */ |
Alexander Duyck | a94d9e2 | 2014-12-03 08:17:39 -0800 | [diff] [blame] | 8163 | if (skb_put_padto(skb, 17)) |
| 8164 | return NETDEV_TX_OK; |
Alexander Duyck | a50c29d | 2012-02-08 07:50:40 +0000 | [diff] [blame] | 8165 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8166 | tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping]; |
| 8167 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8168 | return ixgbe_xmit_frame_ring(skb, adapter, tx_ring); |
| 8169 | } |
| 8170 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8171 | static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, |
| 8172 | struct net_device *netdev) |
| 8173 | { |
| 8174 | return __ixgbe_xmit_frame(skb, netdev, NULL); |
| 8175 | } |
| 8176 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8177 | /** |
| 8178 | * ixgbe_set_mac - Change the Ethernet Address of the NIC |
| 8179 | * @netdev: network interface device structure |
| 8180 | * @p: pointer to an address structure |
| 8181 | * |
| 8182 | * Returns 0 on success, negative on failure |
| 8183 | **/ |
| 8184 | static int ixgbe_set_mac(struct net_device *netdev, void *p) |
| 8185 | { |
| 8186 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8187 | struct ixgbe_hw *hw = &adapter->hw; |
| 8188 | struct sockaddr *addr = p; |
| 8189 | |
| 8190 | if (!is_valid_ether_addr(addr->sa_data)) |
| 8191 | return -EADDRNOTAVAIL; |
| 8192 | |
| 8193 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 8194 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8195 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 8196 | ixgbe_mac_set_default_filter(adapter); |
| 8197 | |
| 8198 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8199 | } |
| 8200 | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 8201 | static int |
| 8202 | ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr) |
| 8203 | { |
| 8204 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8205 | struct ixgbe_hw *hw = &adapter->hw; |
| 8206 | u16 value; |
| 8207 | int rc; |
| 8208 | |
| 8209 | if (prtad != hw->phy.mdio.prtad) |
| 8210 | return -EINVAL; |
| 8211 | rc = hw->phy.ops.read_reg(hw, addr, devad, &value); |
| 8212 | if (!rc) |
| 8213 | rc = value; |
| 8214 | return rc; |
| 8215 | } |
| 8216 | |
| 8217 | static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad, |
| 8218 | u16 addr, u16 value) |
| 8219 | { |
| 8220 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8221 | struct ixgbe_hw *hw = &adapter->hw; |
| 8222 | |
| 8223 | if (prtad != hw->phy.mdio.prtad) |
| 8224 | return -EINVAL; |
| 8225 | return hw->phy.ops.write_reg(hw, addr, devad, value); |
| 8226 | } |
| 8227 | |
| 8228 | static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd) |
| 8229 | { |
| 8230 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8231 | |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 8232 | switch (cmd) { |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 8233 | case SIOCSHWTSTAMP: |
Jacob Keller | 93501d4 | 2014-02-28 15:48:58 -0800 | [diff] [blame] | 8234 | return ixgbe_ptp_set_ts_config(adapter, req); |
| 8235 | case SIOCGHWTSTAMP: |
| 8236 | return ixgbe_ptp_get_ts_config(adapter, req); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 8237 | default: |
| 8238 | return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd); |
| 8239 | } |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 8240 | } |
| 8241 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8242 | /** |
| 8243 | * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 8244 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8245 | * @netdev: network interface device structure |
| 8246 | * |
| 8247 | * Returns non-zero on failure |
| 8248 | **/ |
| 8249 | static int ixgbe_add_sanmac_netdev(struct net_device *dev) |
| 8250 | { |
| 8251 | int err = 0; |
| 8252 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 8253 | struct ixgbe_hw *hw = &adapter->hw; |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8254 | |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 8255 | if (is_valid_ether_addr(hw->mac.san_addr)) { |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8256 | rtnl_lock(); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 8257 | 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] | 8258 | rtnl_unlock(); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 8259 | |
| 8260 | /* update SAN MAC vmdq pool selection */ |
| 8261 | hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0)); |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8262 | } |
| 8263 | return err; |
| 8264 | } |
| 8265 | |
| 8266 | /** |
| 8267 | * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 8268 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8269 | * @netdev: network interface device structure |
| 8270 | * |
| 8271 | * Returns non-zero on failure |
| 8272 | **/ |
| 8273 | static int ixgbe_del_sanmac_netdev(struct net_device *dev) |
| 8274 | { |
| 8275 | int err = 0; |
| 8276 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 8277 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 8278 | |
| 8279 | if (is_valid_ether_addr(mac->san_addr)) { |
| 8280 | rtnl_lock(); |
| 8281 | err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 8282 | rtnl_unlock(); |
| 8283 | } |
| 8284 | return err; |
| 8285 | } |
| 8286 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8287 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 8288 | /* |
| 8289 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 8290 | * without having to re-enable interrupts. It's not called while |
| 8291 | * the interrupt routine is executing. |
| 8292 | */ |
| 8293 | static void ixgbe_netpoll(struct net_device *netdev) |
| 8294 | { |
| 8295 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 8296 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8297 | |
Alexander Duyck | 1a647bd | 2010-01-13 01:49:13 +0000 | [diff] [blame] | 8298 | /* if interface is down do nothing */ |
| 8299 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 8300 | return; |
| 8301 | |
Alexander Duyck | 856f606 | 2015-02-25 17:45:54 +0000 | [diff] [blame] | 8302 | /* loop through and schedule all active queues */ |
| 8303 | for (i = 0; i < adapter->num_q_vectors; i++) |
| 8304 | ixgbe_msix_clean_rings(0, adapter->q_vector[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8305 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8306 | |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 8307 | #endif |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 8308 | |
| 8309 | static void ixgbe_get_stats64(struct net_device *netdev, |
| 8310 | struct rtnl_link_stats64 *stats) |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8311 | { |
| 8312 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8313 | int i; |
| 8314 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8315 | rcu_read_lock(); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8316 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8317 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8318 | u64 bytes, packets; |
| 8319 | unsigned int start; |
| 8320 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8321 | if (ring) { |
| 8322 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 8323 | start = u64_stats_fetch_begin_irq(&ring->syncp); |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8324 | packets = ring->stats.packets; |
| 8325 | bytes = ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 8326 | } while (u64_stats_fetch_retry_irq(&ring->syncp, start)); |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8327 | stats->rx_packets += packets; |
| 8328 | stats->rx_bytes += bytes; |
| 8329 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8330 | } |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 8331 | |
| 8332 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 8333 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]); |
| 8334 | u64 bytes, packets; |
| 8335 | unsigned int start; |
| 8336 | |
| 8337 | if (ring) { |
| 8338 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 8339 | start = u64_stats_fetch_begin_irq(&ring->syncp); |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 8340 | packets = ring->stats.packets; |
| 8341 | bytes = ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 8342 | } while (u64_stats_fetch_retry_irq(&ring->syncp, start)); |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 8343 | stats->tx_packets += packets; |
| 8344 | stats->tx_bytes += bytes; |
| 8345 | } |
| 8346 | } |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8347 | rcu_read_unlock(); |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 8348 | |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8349 | /* following stats updated by ixgbe_watchdog_task() */ |
| 8350 | stats->multicast = netdev->stats.multicast; |
| 8351 | stats->rx_errors = netdev->stats.rx_errors; |
| 8352 | stats->rx_length_errors = netdev->stats.rx_length_errors; |
| 8353 | stats->rx_crc_errors = netdev->stats.rx_crc_errors; |
| 8354 | stats->rx_missed_errors = netdev->stats.rx_missed_errors; |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8355 | } |
| 8356 | |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 8357 | #ifdef CONFIG_IXGBE_DCB |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 8358 | /** |
| 8359 | * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid. |
| 8360 | * @adapter: pointer to ixgbe_adapter |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8361 | * @tc: number of traffic classes currently enabled |
| 8362 | * |
| 8363 | * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm |
| 8364 | * 802.1Q priority maps to a packet buffer that exists. |
| 8365 | */ |
| 8366 | static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc) |
| 8367 | { |
| 8368 | struct ixgbe_hw *hw = &adapter->hw; |
| 8369 | u32 reg, rsave; |
| 8370 | int i; |
| 8371 | |
| 8372 | /* 82598 have a static priority to TC mapping that can not |
| 8373 | * be changed so no validation is needed. |
| 8374 | */ |
| 8375 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 8376 | return; |
| 8377 | |
| 8378 | reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC); |
| 8379 | rsave = reg; |
| 8380 | |
| 8381 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 8382 | u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT); |
| 8383 | |
| 8384 | /* If up2tc is out of bounds default to zero */ |
| 8385 | if (up2tc > tc) |
| 8386 | reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT); |
| 8387 | } |
| 8388 | |
| 8389 | if (reg != rsave) |
| 8390 | IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg); |
| 8391 | |
| 8392 | return; |
| 8393 | } |
| 8394 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 8395 | /** |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 8396 | * ixgbe_set_prio_tc_map - Configure netdev prio tc map |
| 8397 | * @adapter: Pointer to adapter struct |
| 8398 | * |
| 8399 | * Populate the netdev user priority to tc map |
| 8400 | */ |
| 8401 | static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter) |
| 8402 | { |
| 8403 | struct net_device *dev = adapter->netdev; |
| 8404 | struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg; |
| 8405 | struct ieee_ets *ets = adapter->ixgbe_ieee_ets; |
| 8406 | u8 prio; |
| 8407 | |
| 8408 | for (prio = 0; prio < MAX_USER_PRIORITY; prio++) { |
| 8409 | u8 tc = 0; |
| 8410 | |
| 8411 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) |
| 8412 | tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio); |
| 8413 | else if (ets) |
| 8414 | tc = ets->prio_tc[prio]; |
| 8415 | |
| 8416 | netdev_set_prio_tc_map(dev, prio, tc); |
| 8417 | } |
| 8418 | } |
| 8419 | |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 8420 | #endif /* CONFIG_IXGBE_DCB */ |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 8421 | /** |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 8422 | * ixgbe_setup_tc - configure net_device for multiple traffic classes |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8423 | * |
| 8424 | * @netdev: net device to configure |
| 8425 | * @tc: number of traffic classes to enable |
| 8426 | */ |
| 8427 | int ixgbe_setup_tc(struct net_device *dev, u8 tc) |
| 8428 | { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8429 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 8430 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8431 | bool pools; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8432 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8433 | /* Hardware supports up to 8 traffic classes */ |
Emil Tantilov | 7e3f5c8 | 2015-07-09 12:28:59 -0700 | [diff] [blame] | 8434 | if (tc > adapter->dcb_cfg.num_tcs.pg_tcs) |
| 8435 | return -EINVAL; |
| 8436 | |
| 8437 | if (hw->mac.type == ixgbe_mac_82598EB && tc && tc < MAX_TRAFFIC_CLASS) |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8438 | return -EINVAL; |
| 8439 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8440 | pools = (find_first_zero_bit(&adapter->fwd_bitmask, 32) > 1); |
| 8441 | if (tc && pools && adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS) |
| 8442 | return -EBUSY; |
| 8443 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8444 | /* Hardware has to reinitialize queues and interrupts to |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 8445 | * match packet buffer alignment. Unfortunately, the |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8446 | * hardware is not flexible enough to do this dynamically. |
| 8447 | */ |
| 8448 | if (netif_running(dev)) |
| 8449 | ixgbe_close(dev); |
Alexander Duyck | bf4d67d | 2015-10-20 13:28:17 -0700 | [diff] [blame] | 8450 | else |
| 8451 | ixgbe_reset(adapter); |
| 8452 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8453 | ixgbe_clear_interrupt_scheme(adapter); |
| 8454 | |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 8455 | #ifdef CONFIG_IXGBE_DCB |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8456 | if (tc) { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8457 | netdev_set_num_tc(dev, tc); |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 8458 | ixgbe_set_prio_tc_map(adapter); |
| 8459 | |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8460 | adapter->flags |= IXGBE_FLAG_DCB_ENABLED; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8461 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 8462 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 8463 | adapter->last_lfc_mode = adapter->hw.fc.requested_mode; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8464 | adapter->hw.fc.requested_mode = ixgbe_fc_none; |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 8465 | } |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8466 | } else { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8467 | netdev_reset_tc(dev); |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 8468 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 8469 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 8470 | adapter->hw.fc.requested_mode = adapter->last_lfc_mode; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8471 | |
| 8472 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8473 | |
| 8474 | adapter->temp_dcb_cfg.pfc_mode_enable = false; |
| 8475 | adapter->dcb_cfg.pfc_mode_enable = false; |
| 8476 | } |
| 8477 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8478 | ixgbe_validate_rtr(adapter, tc); |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 8479 | |
| 8480 | #endif /* CONFIG_IXGBE_DCB */ |
| 8481 | ixgbe_init_interrupt_scheme(adapter); |
| 8482 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8483 | if (netif_running(dev)) |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 8484 | return ixgbe_open(dev); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8485 | |
| 8486 | return 0; |
| 8487 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8488 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8489 | static int ixgbe_delete_clsu32(struct ixgbe_adapter *adapter, |
| 8490 | struct tc_cls_u32_offload *cls) |
| 8491 | { |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8492 | u32 hdl = cls->knode.handle; |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8493 | u32 uhtid = TC_U32_USERHTID(cls->knode.handle); |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8494 | u32 loc = cls->knode.handle & 0xfffff; |
| 8495 | int err = 0, i, j; |
| 8496 | struct ixgbe_jump_table *jump = NULL; |
| 8497 | |
| 8498 | if (loc > IXGBE_MAX_HW_ENTRIES) |
| 8499 | return -EINVAL; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8500 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8501 | if ((uhtid != 0x800) && (uhtid >= IXGBE_MAX_LINK_HANDLE)) |
| 8502 | return -EINVAL; |
| 8503 | |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8504 | /* Clear this filter in the link data it is associated with */ |
| 8505 | if (uhtid != 0x800) { |
| 8506 | jump = adapter->jump_tables[uhtid]; |
Amritha Nambiar | 12746fd | 2016-05-16 18:33:20 -0700 | [diff] [blame] | 8507 | if (!jump) |
| 8508 | return -EINVAL; |
| 8509 | if (!test_bit(loc - 1, jump->child_loc_map)) |
| 8510 | return -EINVAL; |
| 8511 | clear_bit(loc - 1, jump->child_loc_map); |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8512 | } |
| 8513 | |
| 8514 | /* Check if the filter being deleted is a link */ |
| 8515 | for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) { |
| 8516 | jump = adapter->jump_tables[i]; |
| 8517 | if (jump && jump->link_hdl == hdl) { |
| 8518 | /* Delete filters in the hardware in the child hash |
| 8519 | * table associated with this link |
| 8520 | */ |
| 8521 | for (j = 0; j < IXGBE_MAX_HW_ENTRIES; j++) { |
| 8522 | if (!test_bit(j, jump->child_loc_map)) |
| 8523 | continue; |
| 8524 | spin_lock(&adapter->fdir_perfect_lock); |
| 8525 | err = ixgbe_update_ethtool_fdir_entry(adapter, |
| 8526 | NULL, |
| 8527 | j + 1); |
| 8528 | spin_unlock(&adapter->fdir_perfect_lock); |
| 8529 | clear_bit(j, jump->child_loc_map); |
| 8530 | } |
| 8531 | /* Remove resources for this link */ |
| 8532 | kfree(jump->input); |
| 8533 | kfree(jump->mask); |
| 8534 | kfree(jump); |
| 8535 | adapter->jump_tables[i] = NULL; |
| 8536 | return err; |
| 8537 | } |
| 8538 | } |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8539 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8540 | spin_lock(&adapter->fdir_perfect_lock); |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8541 | err = ixgbe_update_ethtool_fdir_entry(adapter, NULL, loc); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8542 | spin_unlock(&adapter->fdir_perfect_lock); |
| 8543 | return err; |
| 8544 | } |
| 8545 | |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8546 | static int ixgbe_configure_clsu32_add_hnode(struct ixgbe_adapter *adapter, |
| 8547 | __be16 protocol, |
| 8548 | struct tc_cls_u32_offload *cls) |
| 8549 | { |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8550 | u32 uhtid = TC_U32_USERHTID(cls->hnode.handle); |
| 8551 | |
| 8552 | if (uhtid >= IXGBE_MAX_LINK_HANDLE) |
| 8553 | return -EINVAL; |
| 8554 | |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8555 | /* This ixgbe devices do not support hash tables at the moment |
| 8556 | * so abort when given hash tables. |
| 8557 | */ |
| 8558 | if (cls->hnode.divisor > 0) |
| 8559 | return -EINVAL; |
| 8560 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8561 | set_bit(uhtid - 1, &adapter->tables); |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8562 | return 0; |
| 8563 | } |
| 8564 | |
| 8565 | static int ixgbe_configure_clsu32_del_hnode(struct ixgbe_adapter *adapter, |
| 8566 | struct tc_cls_u32_offload *cls) |
| 8567 | { |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8568 | u32 uhtid = TC_U32_USERHTID(cls->hnode.handle); |
| 8569 | |
| 8570 | if (uhtid >= IXGBE_MAX_LINK_HANDLE) |
| 8571 | return -EINVAL; |
| 8572 | |
| 8573 | clear_bit(uhtid - 1, &adapter->tables); |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8574 | return 0; |
| 8575 | } |
| 8576 | |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8577 | #ifdef CONFIG_NET_CLS_ACT |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 8578 | struct upper_walk_data { |
| 8579 | struct ixgbe_adapter *adapter; |
| 8580 | u64 action; |
| 8581 | int ifindex; |
| 8582 | u8 queue; |
| 8583 | }; |
| 8584 | |
| 8585 | static int get_macvlan_queue(struct net_device *upper, void *_data) |
| 8586 | { |
| 8587 | if (netif_is_macvlan(upper)) { |
| 8588 | struct macvlan_dev *dfwd = netdev_priv(upper); |
| 8589 | struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv; |
| 8590 | struct upper_walk_data *data = _data; |
| 8591 | struct ixgbe_adapter *adapter = data->adapter; |
| 8592 | int ifindex = data->ifindex; |
| 8593 | |
| 8594 | if (vadapter && vadapter->netdev->ifindex == ifindex) { |
| 8595 | data->queue = adapter->rx_ring[vadapter->rx_base_queue]->reg_idx; |
| 8596 | data->action = data->queue; |
| 8597 | return 1; |
| 8598 | } |
| 8599 | } |
| 8600 | |
| 8601 | return 0; |
| 8602 | } |
| 8603 | |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8604 | static int handle_redirect_action(struct ixgbe_adapter *adapter, int ifindex, |
| 8605 | u8 *queue, u64 *action) |
| 8606 | { |
| 8607 | unsigned int num_vfs = adapter->num_vfs, vf; |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 8608 | struct upper_walk_data data; |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8609 | struct net_device *upper; |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8610 | |
| 8611 | /* redirect to a SRIOV VF */ |
| 8612 | for (vf = 0; vf < num_vfs; ++vf) { |
| 8613 | upper = pci_get_drvdata(adapter->vfinfo[vf].vfdev); |
| 8614 | if (upper->ifindex == ifindex) { |
| 8615 | if (adapter->num_rx_pools > 1) |
| 8616 | *queue = vf * 2; |
| 8617 | else |
| 8618 | *queue = vf * adapter->num_rx_queues_per_pool; |
| 8619 | |
| 8620 | *action = vf + 1; |
| 8621 | *action <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF; |
| 8622 | return 0; |
| 8623 | } |
| 8624 | } |
| 8625 | |
| 8626 | /* redirect to a offloaded macvlan netdev */ |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 8627 | data.adapter = adapter; |
| 8628 | data.ifindex = ifindex; |
| 8629 | data.action = 0; |
| 8630 | data.queue = 0; |
| 8631 | if (netdev_walk_all_upper_dev_rcu(adapter->netdev, |
| 8632 | get_macvlan_queue, &data)) { |
| 8633 | *action = data.action; |
| 8634 | *queue = data.queue; |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8635 | |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 8636 | return 0; |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8637 | } |
| 8638 | |
| 8639 | return -EINVAL; |
| 8640 | } |
| 8641 | |
| 8642 | static int parse_tc_actions(struct ixgbe_adapter *adapter, |
| 8643 | struct tcf_exts *exts, u64 *action, u8 *queue) |
| 8644 | { |
| 8645 | const struct tc_action *a; |
WANG Cong | 22dc13c | 2016-08-13 22:35:00 -0700 | [diff] [blame] | 8646 | LIST_HEAD(actions); |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8647 | int err; |
| 8648 | |
| 8649 | if (tc_no_actions(exts)) |
| 8650 | return -EINVAL; |
| 8651 | |
WANG Cong | 22dc13c | 2016-08-13 22:35:00 -0700 | [diff] [blame] | 8652 | tcf_exts_to_list(exts, &actions); |
| 8653 | list_for_each_entry(a, &actions, list) { |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8654 | |
| 8655 | /* Drop action */ |
| 8656 | if (is_tcf_gact_shot(a)) { |
| 8657 | *action = IXGBE_FDIR_DROP_QUEUE; |
| 8658 | *queue = IXGBE_FDIR_DROP_QUEUE; |
| 8659 | return 0; |
| 8660 | } |
| 8661 | |
| 8662 | /* Redirect to a VF or a offloaded macvlan */ |
Shmulik Ladkani | 5724b8b | 2016-10-13 09:06:43 +0300 | [diff] [blame] | 8663 | if (is_tcf_mirred_egress_redirect(a)) { |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8664 | int ifindex = tcf_mirred_ifindex(a); |
| 8665 | |
| 8666 | err = handle_redirect_action(adapter, ifindex, queue, |
| 8667 | action); |
| 8668 | if (err == 0) |
| 8669 | return err; |
| 8670 | } |
| 8671 | } |
| 8672 | |
| 8673 | return -EINVAL; |
| 8674 | } |
| 8675 | #else |
| 8676 | static int parse_tc_actions(struct ixgbe_adapter *adapter, |
| 8677 | struct tcf_exts *exts, u64 *action, u8 *queue) |
| 8678 | { |
| 8679 | return -EINVAL; |
| 8680 | } |
| 8681 | #endif /* CONFIG_NET_CLS_ACT */ |
| 8682 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8683 | static int ixgbe_clsu32_build_input(struct ixgbe_fdir_filter *input, |
| 8684 | union ixgbe_atr_input *mask, |
| 8685 | struct tc_cls_u32_offload *cls, |
| 8686 | struct ixgbe_mat_field *field_ptr, |
| 8687 | struct ixgbe_nexthdr *nexthdr) |
| 8688 | { |
| 8689 | int i, j, off; |
| 8690 | __be32 val, m; |
| 8691 | bool found_entry = false, found_jump_field = false; |
| 8692 | |
| 8693 | for (i = 0; i < cls->knode.sel->nkeys; i++) { |
| 8694 | off = cls->knode.sel->keys[i].off; |
| 8695 | val = cls->knode.sel->keys[i].val; |
| 8696 | m = cls->knode.sel->keys[i].mask; |
| 8697 | |
| 8698 | for (j = 0; field_ptr[j].val; j++) { |
| 8699 | if (field_ptr[j].off == off) { |
| 8700 | field_ptr[j].val(input, mask, val, m); |
| 8701 | input->filter.formatted.flow_type |= |
| 8702 | field_ptr[j].type; |
| 8703 | found_entry = true; |
| 8704 | break; |
| 8705 | } |
| 8706 | } |
| 8707 | if (nexthdr) { |
| 8708 | if (nexthdr->off == cls->knode.sel->keys[i].off && |
| 8709 | nexthdr->val == cls->knode.sel->keys[i].val && |
| 8710 | nexthdr->mask == cls->knode.sel->keys[i].mask) |
| 8711 | found_jump_field = true; |
| 8712 | else |
| 8713 | continue; |
| 8714 | } |
| 8715 | } |
| 8716 | |
| 8717 | if (nexthdr && !found_jump_field) |
| 8718 | return -EINVAL; |
| 8719 | |
| 8720 | if (!found_entry) |
| 8721 | return 0; |
| 8722 | |
| 8723 | mask->formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK | |
| 8724 | IXGBE_ATR_L4TYPE_MASK; |
| 8725 | |
| 8726 | if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4) |
| 8727 | mask->formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK; |
| 8728 | |
| 8729 | return 0; |
| 8730 | } |
| 8731 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8732 | static int ixgbe_configure_clsu32(struct ixgbe_adapter *adapter, |
| 8733 | __be16 protocol, |
| 8734 | struct tc_cls_u32_offload *cls) |
| 8735 | { |
| 8736 | u32 loc = cls->knode.handle & 0xfffff; |
| 8737 | struct ixgbe_hw *hw = &adapter->hw; |
| 8738 | struct ixgbe_mat_field *field_ptr; |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8739 | struct ixgbe_fdir_filter *input = NULL; |
| 8740 | union ixgbe_atr_input *mask = NULL; |
| 8741 | struct ixgbe_jump_table *jump = NULL; |
| 8742 | int i, err = -EINVAL; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8743 | u8 queue; |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8744 | u32 uhtid, link_uhtid; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8745 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8746 | uhtid = TC_U32_USERHTID(cls->knode.handle); |
| 8747 | link_uhtid = TC_U32_USERHTID(cls->knode.link_handle); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8748 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8749 | /* At the moment cls_u32 jumps to network layer and skips past |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8750 | * L2 headers. The canonical method to match L2 frames is to use |
| 8751 | * negative values. However this is error prone at best but really |
| 8752 | * 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] | 8753 | * 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] | 8754 | * headers when needed. |
| 8755 | */ |
| 8756 | if (protocol != htons(ETH_P_IP)) |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8757 | return err; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8758 | |
| 8759 | if (loc >= ((1024 << adapter->fdir_pballoc) - 2)) { |
| 8760 | e_err(drv, "Location out of range\n"); |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8761 | return err; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8762 | } |
| 8763 | |
| 8764 | /* cls u32 is a graph starting at root node 0x800. The driver tracks |
| 8765 | * links and also the fields used to advance the parser across each |
| 8766 | * link (e.g. nexthdr/eat parameters from 'tc'). This way we can map |
| 8767 | * the u32 graph onto the hardware parse graph denoted in ixgbe_model.h |
| 8768 | * To add support for new nodes update ixgbe_model.h parse structures |
| 8769 | * this function _should_ be generic try not to hardcode values here. |
| 8770 | */ |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8771 | if (uhtid == 0x800) { |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8772 | field_ptr = (adapter->jump_tables[0])->mat; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8773 | } else { |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8774 | if (uhtid >= IXGBE_MAX_LINK_HANDLE) |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8775 | return err; |
| 8776 | if (!adapter->jump_tables[uhtid]) |
| 8777 | return err; |
| 8778 | field_ptr = (adapter->jump_tables[uhtid])->mat; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8779 | } |
| 8780 | |
| 8781 | if (!field_ptr) |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8782 | return err; |
| 8783 | |
| 8784 | /* At this point we know the field_ptr is valid and need to either |
| 8785 | * build cls_u32 link or attach filter. Because adding a link to |
| 8786 | * a handle that does not exist is invalid and the same for adding |
| 8787 | * rules to handles that don't exist. |
| 8788 | */ |
| 8789 | |
| 8790 | if (link_uhtid) { |
| 8791 | struct ixgbe_nexthdr *nexthdr = ixgbe_ipv4_jumps; |
| 8792 | |
| 8793 | if (link_uhtid >= IXGBE_MAX_LINK_HANDLE) |
| 8794 | return err; |
| 8795 | |
| 8796 | if (!test_bit(link_uhtid - 1, &adapter->tables)) |
| 8797 | return err; |
| 8798 | |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8799 | /* Multiple filters as links to the same hash table are not |
| 8800 | * supported. To add a new filter with the same next header |
| 8801 | * but different match/jump conditions, create a new hash table |
| 8802 | * and link to it. |
| 8803 | */ |
| 8804 | if (adapter->jump_tables[link_uhtid] && |
| 8805 | (adapter->jump_tables[link_uhtid])->link_hdl) { |
| 8806 | e_err(drv, "Link filter exists for link: %x\n", |
| 8807 | link_uhtid); |
| 8808 | return err; |
| 8809 | } |
| 8810 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8811 | for (i = 0; nexthdr[i].jump; i++) { |
| 8812 | if (nexthdr[i].o != cls->knode.sel->offoff || |
| 8813 | nexthdr[i].s != cls->knode.sel->offshift || |
| 8814 | nexthdr[i].m != cls->knode.sel->offmask) |
| 8815 | return err; |
| 8816 | |
| 8817 | jump = kzalloc(sizeof(*jump), GFP_KERNEL); |
| 8818 | if (!jump) |
| 8819 | return -ENOMEM; |
| 8820 | input = kzalloc(sizeof(*input), GFP_KERNEL); |
| 8821 | if (!input) { |
| 8822 | err = -ENOMEM; |
| 8823 | goto free_jump; |
| 8824 | } |
| 8825 | mask = kzalloc(sizeof(*mask), GFP_KERNEL); |
| 8826 | if (!mask) { |
| 8827 | err = -ENOMEM; |
Amritha Nambiar | 12746fd | 2016-05-16 18:33:20 -0700 | [diff] [blame] | 8828 | goto free_input; |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8829 | } |
| 8830 | jump->input = input; |
| 8831 | jump->mask = mask; |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8832 | jump->link_hdl = cls->knode.handle; |
| 8833 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8834 | err = ixgbe_clsu32_build_input(input, mask, cls, |
| 8835 | field_ptr, &nexthdr[i]); |
| 8836 | if (!err) { |
| 8837 | jump->mat = nexthdr[i].jump; |
| 8838 | adapter->jump_tables[link_uhtid] = jump; |
| 8839 | break; |
| 8840 | } |
| 8841 | } |
| 8842 | return 0; |
| 8843 | } |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8844 | |
| 8845 | input = kzalloc(sizeof(*input), GFP_KERNEL); |
| 8846 | if (!input) |
| 8847 | return -ENOMEM; |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8848 | mask = kzalloc(sizeof(*mask), GFP_KERNEL); |
| 8849 | if (!mask) { |
| 8850 | err = -ENOMEM; |
Amritha Nambiar | 12746fd | 2016-05-16 18:33:20 -0700 | [diff] [blame] | 8851 | goto free_input; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8852 | } |
| 8853 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8854 | if ((uhtid != 0x800) && (adapter->jump_tables[uhtid])) { |
| 8855 | if ((adapter->jump_tables[uhtid])->input) |
| 8856 | memcpy(input, (adapter->jump_tables[uhtid])->input, |
| 8857 | sizeof(*input)); |
| 8858 | if ((adapter->jump_tables[uhtid])->mask) |
| 8859 | memcpy(mask, (adapter->jump_tables[uhtid])->mask, |
| 8860 | sizeof(*mask)); |
Amritha Nambiar | 12746fd | 2016-05-16 18:33:20 -0700 | [diff] [blame] | 8861 | |
| 8862 | /* Lookup in all child hash tables if this location is already |
| 8863 | * filled with a filter |
| 8864 | */ |
| 8865 | for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) { |
| 8866 | struct ixgbe_jump_table *link = adapter->jump_tables[i]; |
| 8867 | |
| 8868 | if (link && (test_bit(loc - 1, link->child_loc_map))) { |
| 8869 | e_err(drv, "Filter exists in location: %x\n", |
| 8870 | loc); |
| 8871 | err = -EINVAL; |
| 8872 | goto err_out; |
| 8873 | } |
| 8874 | } |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8875 | } |
| 8876 | err = ixgbe_clsu32_build_input(input, mask, cls, field_ptr, NULL); |
| 8877 | if (err) |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8878 | goto err_out; |
| 8879 | |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8880 | err = parse_tc_actions(adapter, cls->knode.exts, &input->action, |
| 8881 | &queue); |
| 8882 | if (err < 0) |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8883 | goto err_out; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8884 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8885 | input->sw_idx = loc; |
| 8886 | |
| 8887 | spin_lock(&adapter->fdir_perfect_lock); |
| 8888 | |
| 8889 | if (hlist_empty(&adapter->fdir_filter_list)) { |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8890 | memcpy(&adapter->fdir_mask, mask, sizeof(*mask)); |
| 8891 | err = ixgbe_fdir_set_input_mask_82599(hw, mask); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8892 | if (err) |
| 8893 | goto err_out_w_lock; |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8894 | } else if (memcmp(&adapter->fdir_mask, mask, sizeof(*mask))) { |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8895 | err = -EINVAL; |
| 8896 | goto err_out_w_lock; |
| 8897 | } |
| 8898 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8899 | ixgbe_atr_compute_perfect_hash_82599(&input->filter, mask); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8900 | err = ixgbe_fdir_write_perfect_filter_82599(hw, &input->filter, |
| 8901 | input->sw_idx, queue); |
| 8902 | if (!err) |
| 8903 | ixgbe_update_ethtool_fdir_entry(adapter, input, input->sw_idx); |
| 8904 | spin_unlock(&adapter->fdir_perfect_lock); |
| 8905 | |
Amritha Nambiar | 12746fd | 2016-05-16 18:33:20 -0700 | [diff] [blame] | 8906 | if ((uhtid != 0x800) && (adapter->jump_tables[uhtid])) |
| 8907 | set_bit(loc - 1, (adapter->jump_tables[uhtid])->child_loc_map); |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8908 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8909 | kfree(mask); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8910 | return err; |
| 8911 | err_out_w_lock: |
| 8912 | spin_unlock(&adapter->fdir_perfect_lock); |
| 8913 | err_out: |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8914 | kfree(mask); |
Amritha Nambiar | 12746fd | 2016-05-16 18:33:20 -0700 | [diff] [blame] | 8915 | free_input: |
| 8916 | kfree(input); |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 8917 | free_jump: |
| 8918 | kfree(jump); |
| 8919 | return err; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8920 | } |
| 8921 | |
Emil Tantilov | 6e2a60b | 2016-02-17 15:55:06 -0800 | [diff] [blame] | 8922 | static int __ixgbe_setup_tc(struct net_device *dev, u32 handle, __be16 proto, |
| 8923 | struct tc_to_netdev *tc) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 8924 | { |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8925 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 8926 | |
| 8927 | if (TC_H_MAJ(handle) == TC_H_MAJ(TC_H_INGRESS) && |
| 8928 | tc->type == TC_SETUP_CLSU32) { |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8929 | switch (tc->cls_u32->command) { |
| 8930 | case TC_CLSU32_NEW_KNODE: |
| 8931 | case TC_CLSU32_REPLACE_KNODE: |
| 8932 | return ixgbe_configure_clsu32(adapter, |
| 8933 | proto, tc->cls_u32); |
| 8934 | case TC_CLSU32_DELETE_KNODE: |
| 8935 | return ixgbe_delete_clsu32(adapter, tc->cls_u32); |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8936 | case TC_CLSU32_NEW_HNODE: |
| 8937 | case TC_CLSU32_REPLACE_HNODE: |
| 8938 | return ixgbe_configure_clsu32_add_hnode(adapter, proto, |
| 8939 | tc->cls_u32); |
| 8940 | case TC_CLSU32_DELETE_HNODE: |
| 8941 | return ixgbe_configure_clsu32_del_hnode(adapter, |
| 8942 | tc->cls_u32); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8943 | default: |
| 8944 | return -EINVAL; |
| 8945 | } |
| 8946 | } |
| 8947 | |
John Fastabend | 5eb4dce | 2016-02-29 11:26:13 -0800 | [diff] [blame] | 8948 | if (tc->type != TC_SETUP_MQPRIO) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 8949 | return -EINVAL; |
| 8950 | |
Amritha Nambiar | 56f36ac | 2017-03-15 10:39:25 -0700 | [diff] [blame] | 8951 | tc->mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS; |
| 8952 | |
| 8953 | return ixgbe_setup_tc(dev, tc->mqprio->num_tc); |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 8954 | } |
| 8955 | |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 8956 | #ifdef CONFIG_PCI_IOV |
| 8957 | void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter) |
| 8958 | { |
| 8959 | struct net_device *netdev = adapter->netdev; |
| 8960 | |
| 8961 | rtnl_lock(); |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 8962 | ixgbe_setup_tc(netdev, netdev_get_num_tc(netdev)); |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 8963 | rtnl_unlock(); |
| 8964 | } |
| 8965 | |
| 8966 | #endif |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8967 | void ixgbe_do_reset(struct net_device *netdev) |
| 8968 | { |
| 8969 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8970 | |
| 8971 | if (netif_running(netdev)) |
| 8972 | ixgbe_reinit_locked(adapter); |
| 8973 | else |
| 8974 | ixgbe_reset(adapter); |
| 8975 | } |
| 8976 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 8977 | static netdev_features_t ixgbe_fix_features(struct net_device *netdev, |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8978 | netdev_features_t features) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8979 | { |
| 8980 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8981 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8982 | /* If Rx checksum is disabled, then RSC/LRO should also be disabled */ |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8983 | if (!(features & NETIF_F_RXCSUM)) |
| 8984 | features &= ~NETIF_F_LRO; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8985 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8986 | /* Turn off LRO if not RSC capable */ |
| 8987 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) |
| 8988 | features &= ~NETIF_F_LRO; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 8989 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8990 | return features; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8991 | } |
| 8992 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 8993 | static int ixgbe_set_features(struct net_device *netdev, |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8994 | netdev_features_t features) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8995 | { |
| 8996 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8997 | netdev_features_t changed = netdev->features ^ features; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8998 | bool need_reset = false; |
| 8999 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9000 | /* Make sure RSC matches LRO, reset if change */ |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9001 | if (!(features & NETIF_F_LRO)) { |
| 9002 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9003 | need_reset = true; |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9004 | adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED; |
| 9005 | } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) && |
| 9006 | !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) { |
| 9007 | if (adapter->rx_itr_setting == 1 || |
| 9008 | adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) { |
| 9009 | adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED; |
| 9010 | need_reset = true; |
| 9011 | } else if ((changed ^ features) & NETIF_F_LRO) { |
| 9012 | e_info(probe, "rx-usecs set too low, " |
| 9013 | "disabling RSC\n"); |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9014 | } |
| 9015 | } |
| 9016 | |
| 9017 | /* |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9018 | * Check if Flow Director n-tuple support or hw_tc support was |
| 9019 | * enabled or disabled. If the state changed, we need to reset. |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9020 | */ |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9021 | if ((features & NETIF_F_NTUPLE) || (features & NETIF_F_HW_TC)) { |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9022 | /* turn off ATR, enable perfect filters and reset */ |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 9023 | if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) |
| 9024 | need_reset = true; |
| 9025 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9026 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 9027 | adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9028 | } else { |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 9029 | /* turn off perfect filters, enable ATR and reset */ |
| 9030 | if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 9031 | need_reset = true; |
| 9032 | |
| 9033 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 9034 | |
| 9035 | /* We cannot enable ATR if SR-IOV is enabled */ |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9036 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED || |
| 9037 | /* We cannot enable ATR if we have 2 or more tcs */ |
| 9038 | (netdev_get_num_tc(netdev) > 1) || |
| 9039 | /* We cannot enable ATR if RSS is disabled */ |
| 9040 | (adapter->ring_feature[RING_F_RSS].limit <= 1) || |
| 9041 | /* A sample rate of 0 indicates ATR disabled */ |
| 9042 | (!adapter->atr_sample_rate)) |
| 9043 | ; /* do nothing not supported */ |
| 9044 | else /* otherwise supported and set the flag */ |
| 9045 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9046 | } |
| 9047 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 9048 | if (changed & NETIF_F_RXALL) |
| 9049 | need_reset = true; |
| 9050 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9051 | netdev->features = features; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 9052 | |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 9053 | if ((adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) { |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9054 | if (features & NETIF_F_RXCSUM) { |
| 9055 | adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED; |
| 9056 | } else { |
| 9057 | u32 port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK; |
| 9058 | |
| 9059 | ixgbe_clear_udp_tunnel_port(adapter, port_mask); |
| 9060 | } |
| 9061 | } |
| 9062 | |
| 9063 | if ((adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)) { |
| 9064 | if (features & NETIF_F_RXCSUM) { |
| 9065 | adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED; |
| 9066 | } else { |
| 9067 | u32 port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK; |
| 9068 | |
| 9069 | ixgbe_clear_udp_tunnel_port(adapter, port_mask); |
| 9070 | } |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 9071 | } |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 9072 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9073 | if (need_reset) |
| 9074 | ixgbe_do_reset(netdev); |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 9075 | else if (changed & (NETIF_F_HW_VLAN_CTAG_RX | |
| 9076 | NETIF_F_HW_VLAN_CTAG_FILTER)) |
| 9077 | ixgbe_set_rx_mode(netdev); |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9078 | |
| 9079 | return 0; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9080 | } |
| 9081 | |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9082 | /** |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9083 | * ixgbe_add_udp_tunnel_port - Get notifications about adding UDP tunnel ports |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9084 | * @dev: The port's netdev |
Sabrina Dubroca | e5de25d | 2016-07-11 13:12:28 +0200 | [diff] [blame] | 9085 | * @ti: Tunnel endpoint information |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9086 | **/ |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9087 | static void ixgbe_add_udp_tunnel_port(struct net_device *dev, |
| 9088 | struct udp_tunnel_info *ti) |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9089 | { |
| 9090 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 9091 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 9092 | __be16 port = ti->port; |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9093 | u32 port_shift = 0; |
| 9094 | u32 reg; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 9095 | |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 9096 | if (ti->sa_family != AF_INET) |
| 9097 | return; |
| 9098 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9099 | switch (ti->type) { |
| 9100 | case UDP_TUNNEL_TYPE_VXLAN: |
| 9101 | if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) |
| 9102 | return; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9103 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9104 | if (adapter->vxlan_port == port) |
| 9105 | return; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9106 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9107 | if (adapter->vxlan_port) { |
| 9108 | netdev_info(dev, |
| 9109 | "VXLAN port %d set, not adding port %d\n", |
| 9110 | ntohs(adapter->vxlan_port), |
| 9111 | ntohs(port)); |
| 9112 | return; |
| 9113 | } |
| 9114 | |
| 9115 | adapter->vxlan_port = port; |
| 9116 | break; |
| 9117 | case UDP_TUNNEL_TYPE_GENEVE: |
| 9118 | if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)) |
| 9119 | return; |
| 9120 | |
| 9121 | if (adapter->geneve_port == port) |
| 9122 | return; |
| 9123 | |
| 9124 | if (adapter->geneve_port) { |
| 9125 | netdev_info(dev, |
| 9126 | "GENEVE port %d set, not adding port %d\n", |
| 9127 | ntohs(adapter->geneve_port), |
| 9128 | ntohs(port)); |
| 9129 | return; |
| 9130 | } |
| 9131 | |
| 9132 | port_shift = IXGBE_VXLANCTRL_GENEVE_UDPPORT_SHIFT; |
| 9133 | adapter->geneve_port = port; |
| 9134 | break; |
| 9135 | default: |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9136 | return; |
| 9137 | } |
| 9138 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9139 | reg = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) | ntohs(port) << port_shift; |
| 9140 | IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, reg); |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9141 | } |
| 9142 | |
| 9143 | /** |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9144 | * ixgbe_del_udp_tunnel_port - Get notifications about removing UDP tunnel ports |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9145 | * @dev: The port's netdev |
Sabrina Dubroca | e5de25d | 2016-07-11 13:12:28 +0200 | [diff] [blame] | 9146 | * @ti: Tunnel endpoint information |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9147 | **/ |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9148 | static void ixgbe_del_udp_tunnel_port(struct net_device *dev, |
| 9149 | struct udp_tunnel_info *ti) |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9150 | { |
| 9151 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9152 | u32 port_mask; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9153 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9154 | if (ti->type != UDP_TUNNEL_TYPE_VXLAN && |
| 9155 | ti->type != UDP_TUNNEL_TYPE_GENEVE) |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 9156 | return; |
| 9157 | |
| 9158 | if (ti->sa_family != AF_INET) |
| 9159 | return; |
| 9160 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9161 | switch (ti->type) { |
| 9162 | case UDP_TUNNEL_TYPE_VXLAN: |
| 9163 | if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) |
| 9164 | return; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 9165 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9166 | if (adapter->vxlan_port != ti->port) { |
| 9167 | netdev_info(dev, "VXLAN port %d not found\n", |
| 9168 | ntohs(ti->port)); |
| 9169 | return; |
| 9170 | } |
| 9171 | |
| 9172 | port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK; |
| 9173 | break; |
| 9174 | case UDP_TUNNEL_TYPE_GENEVE: |
| 9175 | if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)) |
| 9176 | return; |
| 9177 | |
| 9178 | if (adapter->geneve_port != ti->port) { |
| 9179 | netdev_info(dev, "GENEVE port %d not found\n", |
| 9180 | ntohs(ti->port)); |
| 9181 | return; |
| 9182 | } |
| 9183 | |
| 9184 | port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK; |
| 9185 | break; |
| 9186 | default: |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9187 | return; |
| 9188 | } |
| 9189 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9190 | ixgbe_clear_udp_tunnel_port(adapter, port_mask); |
| 9191 | adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9192 | } |
| 9193 | |
stephen hemminger | edc7d57 | 2012-10-01 12:32:33 +0000 | [diff] [blame] | 9194 | static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 9195 | struct net_device *dev, |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 9196 | const unsigned char *addr, u16 vid, |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 9197 | u16 flags) |
| 9198 | { |
Alexander Duyck | bcfd343 | 2014-07-17 02:11:22 +0000 | [diff] [blame] | 9199 | /* guarantee we can provide a unique filter for the unicast address */ |
Ben Hutchings | 46acc46 | 2012-11-01 09:11:11 +0000 | [diff] [blame] | 9200 | if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) { |
Alexander Duyck | 2f9be16 | 2015-10-22 16:26:42 -0700 | [diff] [blame] | 9201 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 9202 | u16 pool = VMDQ_P(0); |
| 9203 | |
| 9204 | if (netdev_uc_count(dev) >= ixgbe_available_rars(adapter, pool)) |
Alexander Duyck | bcfd343 | 2014-07-17 02:11:22 +0000 | [diff] [blame] | 9205 | return -ENOMEM; |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 9206 | } |
| 9207 | |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 9208 | return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags); |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 9209 | } |
| 9210 | |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9211 | /** |
| 9212 | * ixgbe_configure_bridge_mode - set various bridge modes |
| 9213 | * @adapter - the private structure |
| 9214 | * @mode - requested bridge mode |
| 9215 | * |
| 9216 | * Configure some settings require for various bridge modes. |
| 9217 | **/ |
| 9218 | static int ixgbe_configure_bridge_mode(struct ixgbe_adapter *adapter, |
| 9219 | __u16 mode) |
| 9220 | { |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 9221 | struct ixgbe_hw *hw = &adapter->hw; |
| 9222 | unsigned int p, num_pools; |
| 9223 | u32 vmdctl; |
| 9224 | |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9225 | switch (mode) { |
| 9226 | case BRIDGE_MODE_VEPA: |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 9227 | /* disable Tx loopback, rely on switch hairpin mode */ |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9228 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, 0); |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 9229 | |
| 9230 | /* must enable Rx switching replication to allow multicast |
| 9231 | * packet reception on all VFs, and to enable source address |
| 9232 | * pruning. |
| 9233 | */ |
| 9234 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL); |
| 9235 | vmdctl |= IXGBE_VT_CTL_REPLEN; |
| 9236 | IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl); |
| 9237 | |
| 9238 | /* enable Rx source address pruning. Note, this requires |
| 9239 | * replication to be enabled or else it does nothing. |
| 9240 | */ |
| 9241 | num_pools = adapter->num_vfs + adapter->num_rx_pools; |
| 9242 | for (p = 0; p < num_pools; p++) { |
| 9243 | if (hw->mac.ops.set_source_address_pruning) |
| 9244 | hw->mac.ops.set_source_address_pruning(hw, |
| 9245 | true, |
| 9246 | p); |
| 9247 | } |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9248 | break; |
| 9249 | case BRIDGE_MODE_VEB: |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 9250 | /* enable Tx loopback for internal VF/PF communication */ |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9251 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, |
| 9252 | IXGBE_PFDTXGSWC_VT_LBEN); |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 9253 | |
| 9254 | /* disable Rx switching replication unless we have SR-IOV |
| 9255 | * virtual functions |
| 9256 | */ |
| 9257 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL); |
| 9258 | if (!adapter->num_vfs) |
| 9259 | vmdctl &= ~IXGBE_VT_CTL_REPLEN; |
| 9260 | IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl); |
| 9261 | |
| 9262 | /* disable Rx source address pruning, since we don't expect to |
| 9263 | * be receiving external loopback of our transmitted frames. |
| 9264 | */ |
| 9265 | num_pools = adapter->num_vfs + adapter->num_rx_pools; |
| 9266 | for (p = 0; p < num_pools; p++) { |
| 9267 | if (hw->mac.ops.set_source_address_pruning) |
| 9268 | hw->mac.ops.set_source_address_pruning(hw, |
| 9269 | false, |
| 9270 | p); |
| 9271 | } |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9272 | break; |
| 9273 | default: |
| 9274 | return -EINVAL; |
| 9275 | } |
| 9276 | |
| 9277 | adapter->bridge_mode = mode; |
| 9278 | |
| 9279 | e_info(drv, "enabling bridge mode: %s\n", |
| 9280 | mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
| 9281 | |
| 9282 | return 0; |
| 9283 | } |
| 9284 | |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9285 | static int ixgbe_ndo_bridge_setlink(struct net_device *dev, |
Roopa Prabhu | add511b | 2015-01-29 22:40:12 -0800 | [diff] [blame] | 9286 | struct nlmsghdr *nlh, u16 flags) |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9287 | { |
| 9288 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 9289 | struct nlattr *attr, *br_spec; |
| 9290 | int rem; |
| 9291 | |
| 9292 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 9293 | return -EOPNOTSUPP; |
| 9294 | |
| 9295 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
Thomas Graf | 4ea85e8 | 2014-11-26 13:42:18 +0100 | [diff] [blame] | 9296 | if (!br_spec) |
| 9297 | return -EINVAL; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9298 | |
| 9299 | nla_for_each_nested(attr, br_spec, rem) { |
Mark Rustad | a1e869d | 2015-04-10 10:36:36 -0700 | [diff] [blame] | 9300 | int status; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9301 | __u16 mode; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9302 | |
| 9303 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 9304 | continue; |
| 9305 | |
Thomas Graf | b7c1a31 | 2014-11-26 13:42:17 +0100 | [diff] [blame] | 9306 | if (nla_len(attr) < sizeof(mode)) |
| 9307 | return -EINVAL; |
| 9308 | |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9309 | mode = nla_get_u16(attr); |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9310 | status = ixgbe_configure_bridge_mode(adapter, mode); |
| 9311 | if (status) |
| 9312 | return status; |
Don Skidmore | aa2bacb | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9313 | |
| 9314 | break; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9315 | } |
| 9316 | |
| 9317 | return 0; |
| 9318 | } |
| 9319 | |
| 9320 | 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] | 9321 | struct net_device *dev, |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 9322 | u32 filter_mask, int nlflags) |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9323 | { |
| 9324 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9325 | |
| 9326 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 9327 | return 0; |
| 9328 | |
Don Skidmore | aa2bacb | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9329 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, |
Scott Feldman | 7d4f8d8 | 2015-06-22 00:27:17 -0700 | [diff] [blame] | 9330 | adapter->bridge_mode, 0, 0, nlflags, |
| 9331 | filter_mask, NULL); |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9332 | } |
| 9333 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9334 | static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev) |
| 9335 | { |
| 9336 | struct ixgbe_fwd_adapter *fwd_adapter = NULL; |
| 9337 | struct ixgbe_adapter *adapter = netdev_priv(pdev); |
Jacob Keller | aac2f1b | 2014-08-21 06:17:59 +0000 | [diff] [blame] | 9338 | int used_pools = adapter->num_vfs + adapter->num_rx_pools; |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 9339 | unsigned int limit; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9340 | int pool, err; |
| 9341 | |
Jacob Keller | aac2f1b | 2014-08-21 06:17:59 +0000 | [diff] [blame] | 9342 | /* Hardware has a limited number of available pools. Each VF, and the |
| 9343 | * PF require a pool. Check to ensure we don't attempt to use more |
| 9344 | * then the available number of pools. |
| 9345 | */ |
| 9346 | if (used_pools >= IXGBE_MAX_VF_FUNCTIONS) |
| 9347 | return ERR_PTR(-EINVAL); |
| 9348 | |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 9349 | #ifdef CONFIG_RPS |
| 9350 | if (vdev->num_rx_queues != vdev->num_tx_queues) { |
| 9351 | netdev_info(pdev, "%s: Only supports a single queue count for TX and RX\n", |
| 9352 | vdev->name); |
| 9353 | return ERR_PTR(-EINVAL); |
| 9354 | } |
| 9355 | #endif |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9356 | /* Check for hardware restriction on number of rx/tx queues */ |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 9357 | if (vdev->num_tx_queues > IXGBE_MAX_L2A_QUEUES || |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9358 | vdev->num_tx_queues == IXGBE_BAD_L2A_QUEUE) { |
| 9359 | netdev_info(pdev, |
| 9360 | "%s: Supports RX/TX Queue counts 1,2, and 4\n", |
| 9361 | pdev->name); |
| 9362 | return ERR_PTR(-EINVAL); |
| 9363 | } |
| 9364 | |
| 9365 | if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && |
| 9366 | adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS - 1) || |
| 9367 | (adapter->num_rx_pools > IXGBE_MAX_MACVLANS)) |
| 9368 | return ERR_PTR(-EBUSY); |
| 9369 | |
Maninder Singh | bc52f95 | 2015-06-19 09:37:55 +0530 | [diff] [blame] | 9370 | fwd_adapter = kzalloc(sizeof(*fwd_adapter), GFP_KERNEL); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9371 | if (!fwd_adapter) |
| 9372 | return ERR_PTR(-ENOMEM); |
| 9373 | |
| 9374 | pool = find_first_zero_bit(&adapter->fwd_bitmask, 32); |
| 9375 | adapter->num_rx_pools++; |
| 9376 | set_bit(pool, &adapter->fwd_bitmask); |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 9377 | limit = find_last_bit(&adapter->fwd_bitmask, 32); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9378 | |
| 9379 | /* Enable VMDq flag so device will be set in VM mode */ |
| 9380 | adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED | IXGBE_FLAG_SRIOV_ENABLED; |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 9381 | adapter->ring_feature[RING_F_VMDQ].limit = limit + 1; |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 9382 | adapter->ring_feature[RING_F_RSS].limit = vdev->num_tx_queues; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9383 | |
| 9384 | /* Force reinit of ring allocation with VMDQ enabled */ |
| 9385 | err = ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev)); |
| 9386 | if (err) |
| 9387 | goto fwd_add_err; |
| 9388 | fwd_adapter->pool = pool; |
| 9389 | fwd_adapter->real_adapter = adapter; |
Emil Tantilov | a3b8cb1 | 2016-09-22 15:06:52 -0700 | [diff] [blame] | 9390 | |
| 9391 | if (netif_running(pdev)) { |
| 9392 | err = ixgbe_fwd_ring_up(vdev, fwd_adapter); |
| 9393 | if (err) |
| 9394 | goto fwd_add_err; |
| 9395 | netif_tx_start_all_queues(vdev); |
| 9396 | } |
| 9397 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9398 | return fwd_adapter; |
| 9399 | fwd_add_err: |
| 9400 | /* unwind counter and free adapter struct */ |
| 9401 | netdev_info(pdev, |
| 9402 | "%s: dfwd hardware acceleration failed\n", vdev->name); |
| 9403 | clear_bit(pool, &adapter->fwd_bitmask); |
| 9404 | adapter->num_rx_pools--; |
| 9405 | kfree(fwd_adapter); |
| 9406 | return ERR_PTR(err); |
| 9407 | } |
| 9408 | |
| 9409 | static void ixgbe_fwd_del(struct net_device *pdev, void *priv) |
| 9410 | { |
| 9411 | struct ixgbe_fwd_adapter *fwd_adapter = priv; |
| 9412 | struct ixgbe_adapter *adapter = fwd_adapter->real_adapter; |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 9413 | unsigned int limit; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9414 | |
| 9415 | clear_bit(fwd_adapter->pool, &adapter->fwd_bitmask); |
| 9416 | adapter->num_rx_pools--; |
| 9417 | |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 9418 | limit = find_last_bit(&adapter->fwd_bitmask, 32); |
| 9419 | adapter->ring_feature[RING_F_VMDQ].limit = limit + 1; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9420 | ixgbe_fwd_ring_down(fwd_adapter->netdev, fwd_adapter); |
| 9421 | ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev)); |
| 9422 | netdev_dbg(pdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n", |
| 9423 | fwd_adapter->pool, adapter->num_rx_pools, |
| 9424 | fwd_adapter->rx_base_queue, |
| 9425 | fwd_adapter->rx_base_queue + adapter->num_rx_queues_per_pool, |
| 9426 | adapter->fwd_bitmask); |
| 9427 | kfree(fwd_adapter); |
| 9428 | } |
| 9429 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9430 | #define IXGBE_MAX_MAC_HDR_LEN 127 |
| 9431 | #define IXGBE_MAX_NETWORK_HDR_LEN 511 |
| 9432 | |
Mark Rustad | f467bc0 | 2015-06-15 11:33:20 -0700 | [diff] [blame] | 9433 | static netdev_features_t |
| 9434 | ixgbe_features_check(struct sk_buff *skb, struct net_device *dev, |
| 9435 | netdev_features_t features) |
| 9436 | { |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9437 | unsigned int network_hdr_len, mac_hdr_len; |
Mark Rustad | f467bc0 | 2015-06-15 11:33:20 -0700 | [diff] [blame] | 9438 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9439 | /* Make certain the headers can be described by a context descriptor */ |
| 9440 | mac_hdr_len = skb_network_header(skb) - skb->data; |
| 9441 | if (unlikely(mac_hdr_len > IXGBE_MAX_MAC_HDR_LEN)) |
| 9442 | return features & ~(NETIF_F_HW_CSUM | |
| 9443 | NETIF_F_SCTP_CRC | |
| 9444 | NETIF_F_HW_VLAN_CTAG_TX | |
| 9445 | NETIF_F_TSO | |
| 9446 | NETIF_F_TSO6); |
| 9447 | |
| 9448 | network_hdr_len = skb_checksum_start(skb) - skb_network_header(skb); |
| 9449 | if (unlikely(network_hdr_len > IXGBE_MAX_NETWORK_HDR_LEN)) |
| 9450 | return features & ~(NETIF_F_HW_CSUM | |
| 9451 | NETIF_F_SCTP_CRC | |
| 9452 | NETIF_F_TSO | |
| 9453 | NETIF_F_TSO6); |
| 9454 | |
| 9455 | /* We can only support IPV4 TSO in tunnels if we can mangle the |
| 9456 | * inner IP ID field, so strip TSO if MANGLEID is not supported. |
| 9457 | */ |
| 9458 | if (skb->encapsulation && !(features & NETIF_F_TSO_MANGLEID)) |
| 9459 | features &= ~NETIF_F_TSO; |
Mark Rustad | f467bc0 | 2015-06-15 11:33:20 -0700 | [diff] [blame] | 9460 | |
| 9461 | return features; |
| 9462 | } |
| 9463 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 9464 | static const struct net_device_ops ixgbe_netdev_ops = { |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 9465 | .ndo_open = ixgbe_open, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 9466 | .ndo_stop = ixgbe_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 9467 | .ndo_start_xmit = ixgbe_xmit_frame, |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 9468 | .ndo_select_queue = ixgbe_select_queue, |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 9469 | .ndo_set_rx_mode = ixgbe_set_rx_mode, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 9470 | .ndo_validate_addr = eth_validate_addr, |
| 9471 | .ndo_set_mac_address = ixgbe_set_mac, |
| 9472 | .ndo_change_mtu = ixgbe_change_mtu, |
| 9473 | .ndo_tx_timeout = ixgbe_tx_timeout, |
Rostislav Pehlivanov | c04f90e | 2016-01-27 18:33:30 +0000 | [diff] [blame] | 9474 | .ndo_set_tx_maxrate = ixgbe_tx_maxrate, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 9475 | .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid, |
| 9476 | .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid, |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 9477 | .ndo_do_ioctl = ixgbe_ioctl, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 9478 | .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac, |
| 9479 | .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan, |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 9480 | .ndo_set_vf_rate = ixgbe_ndo_set_vf_bw, |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 9481 | .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk, |
Vlad Zolotarov | e65ce0d | 2015-03-30 21:35:24 +0300 | [diff] [blame] | 9482 | .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] | 9483 | .ndo_set_vf_trust = ixgbe_ndo_set_vf_trust, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 9484 | .ndo_get_vf_config = ixgbe_ndo_get_vf_config, |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 9485 | .ndo_get_stats64 = ixgbe_get_stats64, |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 9486 | .ndo_setup_tc = __ixgbe_setup_tc, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 9487 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 9488 | .ndo_poll_controller = ixgbe_netpoll, |
| 9489 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 9490 | #ifdef IXGBE_FCOE |
| 9491 | .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get, |
Yi Zou | 68a683c | 2011-02-01 07:22:16 +0000 | [diff] [blame] | 9492 | .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 9493 | .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put, |
Yi Zou | 8450ff8 | 2009-08-31 12:32:14 +0000 | [diff] [blame] | 9494 | .ndo_fcoe_enable = ixgbe_fcoe_enable, |
| 9495 | .ndo_fcoe_disable = ixgbe_fcoe_disable, |
Yi Zou | 61a1fa1 | 2009-10-28 18:24:56 +0000 | [diff] [blame] | 9496 | .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn, |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 9497 | .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 9498 | #endif /* IXGBE_FCOE */ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9499 | .ndo_set_features = ixgbe_set_features, |
| 9500 | .ndo_fix_features = ixgbe_fix_features, |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 9501 | .ndo_fdb_add = ixgbe_ndo_fdb_add, |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9502 | .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink, |
| 9503 | .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink, |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9504 | .ndo_dfwd_add_station = ixgbe_fwd_add, |
| 9505 | .ndo_dfwd_del_station = ixgbe_fwd_del, |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9506 | .ndo_udp_tunnel_add = ixgbe_add_udp_tunnel_port, |
| 9507 | .ndo_udp_tunnel_del = ixgbe_del_udp_tunnel_port, |
Mark Rustad | f467bc0 | 2015-06-15 11:33:20 -0700 | [diff] [blame] | 9508 | .ndo_features_check = ixgbe_features_check, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 9509 | }; |
| 9510 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9511 | /** |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 9512 | * ixgbe_enumerate_functions - Get the number of ports this device has |
| 9513 | * @adapter: adapter structure |
| 9514 | * |
| 9515 | * This function enumerates the phsyical functions co-located on a single slot, |
| 9516 | * in order to determine how many ports a device has. This is most useful in |
| 9517 | * determining the required GT/s of PCIe bandwidth necessary for optimal |
| 9518 | * performance. |
| 9519 | **/ |
| 9520 | static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter) |
| 9521 | { |
Jacob Keller | caafb95 | 2014-07-19 07:17:17 +0000 | [diff] [blame] | 9522 | struct pci_dev *entry, *pdev = adapter->pdev; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 9523 | int physfns = 0; |
| 9524 | |
Jacob Keller | f1f9657 | 2013-08-31 02:45:38 +0000 | [diff] [blame] | 9525 | /* Some cards can not use the generic count PCIe functions method, |
| 9526 | * because they are behind a parent switch, so we hardcode these with |
| 9527 | * the correct number of functions. |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 9528 | */ |
Jacob Keller | 8818970 | 2014-07-19 07:17:16 +0000 | [diff] [blame] | 9529 | if (ixgbe_pcie_from_parent(&adapter->hw)) |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 9530 | physfns = 4; |
Jacob Keller | 8818970 | 2014-07-19 07:17:16 +0000 | [diff] [blame] | 9531 | |
| 9532 | list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) { |
| 9533 | /* don't count virtual functions */ |
Jacob Keller | caafb95 | 2014-07-19 07:17:17 +0000 | [diff] [blame] | 9534 | if (entry->is_virtfn) |
| 9535 | continue; |
| 9536 | |
| 9537 | /* When the devices on the bus don't all match our device ID, |
| 9538 | * we can't reliably determine the correct number of |
| 9539 | * functions. This can occur if a function has been direct |
| 9540 | * attached to a virtual machine using VT-d, for example. In |
| 9541 | * this case, simply return -1 to indicate this. |
| 9542 | */ |
| 9543 | if ((entry->vendor != pdev->vendor) || |
| 9544 | (entry->device != pdev->device)) |
| 9545 | return -1; |
| 9546 | |
| 9547 | physfns++; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 9548 | } |
| 9549 | |
| 9550 | return physfns; |
| 9551 | } |
| 9552 | |
| 9553 | /** |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9554 | * ixgbe_wol_supported - Check whether device supports WoL |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 9555 | * @adapter: the adapter private structure |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9556 | * @device_id: the device ID |
| 9557 | * @subdev_id: the subsystem device ID |
| 9558 | * |
| 9559 | * This function is used by probe and ethtool to determine |
| 9560 | * which devices have WoL support |
| 9561 | * |
| 9562 | **/ |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 9563 | bool ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id, |
| 9564 | u16 subdevice_id) |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9565 | { |
| 9566 | struct ixgbe_hw *hw = &adapter->hw; |
| 9567 | u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9568 | |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 9569 | /* WOL not supported on 82598 */ |
| 9570 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 9571 | return false; |
| 9572 | |
| 9573 | /* check eeprom to see if WOL is enabled for X540 and newer */ |
| 9574 | if (hw->mac.type >= ixgbe_mac_X540) { |
| 9575 | if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) || |
| 9576 | ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) && |
| 9577 | (hw->bus.func == 0))) |
| 9578 | return true; |
| 9579 | } |
| 9580 | |
| 9581 | /* WOL is determined based on device IDs for 82599 MACs */ |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9582 | switch (device_id) { |
| 9583 | case IXGBE_DEV_ID_82599_SFP: |
| 9584 | /* Only these subdevices could supports WOL */ |
| 9585 | switch (subdevice_id) { |
| 9586 | case IXGBE_SUBDEV_ID_82599_560FLR: |
Emil Tantilov | 00103a6c | 2016-04-21 11:37:06 -0700 | [diff] [blame] | 9587 | case IXGBE_SUBDEV_ID_82599_LOM_SNAP6: |
| 9588 | case IXGBE_SUBDEV_ID_82599_SFP_WOL0: |
| 9589 | case IXGBE_SUBDEV_ID_82599_SFP_2OCP: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9590 | /* only support first port */ |
| 9591 | if (hw->bus.func != 0) |
| 9592 | break; |
Emil Tantilov | 5700ff2 | 2013-04-18 08:18:55 +0000 | [diff] [blame] | 9593 | case IXGBE_SUBDEV_ID_82599_SP_560FLR: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9594 | case IXGBE_SUBDEV_ID_82599_SFP: |
Don Skidmore | b6dfd93 | 2012-07-11 07:17:42 +0000 | [diff] [blame] | 9595 | case IXGBE_SUBDEV_ID_82599_RNDC: |
Emil Tantilov | f8a06c2 | 2012-08-16 08:13:07 +0000 | [diff] [blame] | 9596 | case IXGBE_SUBDEV_ID_82599_ECNA_DP: |
Emil Tantilov | 00103a6c | 2016-04-21 11:37:06 -0700 | [diff] [blame] | 9597 | case IXGBE_SUBDEV_ID_82599_SFP_1OCP: |
| 9598 | case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM1: |
| 9599 | case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM2: |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 9600 | return true; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9601 | } |
| 9602 | break; |
Don Skidmore | 5daebbb | 2013-04-05 05:49:34 +0000 | [diff] [blame] | 9603 | case IXGBE_DEV_ID_82599EN_SFP: |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 9604 | /* Only these subdevices support WOL */ |
Don Skidmore | 5daebbb | 2013-04-05 05:49:34 +0000 | [diff] [blame] | 9605 | switch (subdevice_id) { |
| 9606 | case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1: |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 9607 | return true; |
Don Skidmore | 5daebbb | 2013-04-05 05:49:34 +0000 | [diff] [blame] | 9608 | } |
| 9609 | break; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9610 | case IXGBE_DEV_ID_82599_COMBO_BACKPLANE: |
| 9611 | /* All except this subdevice support WOL */ |
| 9612 | if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ) |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 9613 | return true; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9614 | break; |
| 9615 | case IXGBE_DEV_ID_82599_KX4: |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 9616 | return true; |
| 9617 | default: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9618 | break; |
| 9619 | } |
| 9620 | |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 9621 | return false; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9622 | } |
| 9623 | |
| 9624 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9625 | * ixgbe_probe - Device Initialization Routine |
| 9626 | * @pdev: PCI device information struct |
| 9627 | * @ent: entry in ixgbe_pci_tbl |
| 9628 | * |
| 9629 | * Returns 0 on success, negative on failure |
| 9630 | * |
| 9631 | * ixgbe_probe initializes an adapter identified by a pci_dev structure. |
| 9632 | * The OS initialization, configuring of the adapter private structure, |
| 9633 | * and a hardware reset occur. |
| 9634 | **/ |
Greg Kroah-Hartman | 1dd06ae | 2012-12-06 14:30:56 +0000 | [diff] [blame] | 9635 | 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] | 9636 | { |
| 9637 | struct net_device *netdev; |
| 9638 | struct ixgbe_adapter *adapter = NULL; |
| 9639 | struct ixgbe_hw *hw; |
| 9640 | const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data]; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 9641 | int i, err, pci_using_dac, expected_gts; |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 9642 | unsigned int indices = MAX_TX_QUEUES; |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 9643 | u8 part_str[IXGBE_PBANUM_LENGTH]; |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 9644 | bool disable_dev = false; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 9645 | #ifdef IXGBE_FCOE |
| 9646 | u16 device_caps; |
| 9647 | #endif |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 9648 | u32 eec; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9649 | |
Andy Gospodarek | bded64a | 2010-07-21 06:40:31 +0000 | [diff] [blame] | 9650 | /* Catch broken hardware that put the wrong VF device ID in |
| 9651 | * the PCIe SR-IOV capability. |
| 9652 | */ |
| 9653 | if (pdev->is_virtfn) { |
| 9654 | WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n", |
| 9655 | pci_name(pdev), pdev->vendor, pdev->device); |
| 9656 | return -EINVAL; |
| 9657 | } |
| 9658 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 9659 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9660 | if (err) |
| 9661 | return err; |
| 9662 | |
Russell King | f5f2eda | 2013-06-10 12:47:42 +0100 | [diff] [blame] | 9663 | if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9664 | pci_using_dac = 1; |
| 9665 | } else { |
Russell King | f5f2eda | 2013-06-10 12:47:42 +0100 | [diff] [blame] | 9666 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9667 | if (err) { |
Russell King | f5f2eda | 2013-06-10 12:47:42 +0100 | [diff] [blame] | 9668 | dev_err(&pdev->dev, |
| 9669 | "No usable DMA configuration, aborting\n"); |
| 9670 | goto err_dma; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9671 | } |
| 9672 | pci_using_dac = 0; |
| 9673 | } |
| 9674 | |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 9675 | err = pci_request_mem_regions(pdev, ixgbe_driver_name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9676 | if (err) { |
Dan Carpenter | b8bc042 | 2010-07-27 00:05:56 +0000 | [diff] [blame] | 9677 | dev_err(&pdev->dev, |
| 9678 | "pci_request_selected_regions failed 0x%x\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9679 | goto err_pci_reg; |
| 9680 | } |
| 9681 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 9682 | pci_enable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9683 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9684 | pci_set_master(pdev); |
Wendy Xiong | fb3b27b | 2008-04-23 11:09:24 -0700 | [diff] [blame] | 9685 | pci_save_state(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9686 | |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 9687 | if (ii->mac == ixgbe_mac_82598EB) { |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 9688 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 9689 | /* 8 TC w/ 4 queues per TC */ |
| 9690 | indices = 4 * MAX_TRAFFIC_CLASS; |
| 9691 | #else |
| 9692 | indices = IXGBE_MAX_RSS_INDICES; |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 9693 | #endif |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 9694 | } |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 9695 | |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 9696 | netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9697 | if (!netdev) { |
| 9698 | err = -ENOMEM; |
| 9699 | goto err_alloc_etherdev; |
| 9700 | } |
| 9701 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9702 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 9703 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9704 | adapter = netdev_priv(netdev); |
| 9705 | |
| 9706 | adapter->netdev = netdev; |
| 9707 | adapter->pdev = pdev; |
| 9708 | hw = &adapter->hw; |
| 9709 | hw->back = adapter; |
stephen hemminger | b3f4d59 | 2012-03-13 06:04:20 +0000 | [diff] [blame] | 9710 | adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9711 | |
Jeff Kirsher | 0585798 | 2008-09-11 19:57:00 -0700 | [diff] [blame] | 9712 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 9713 | pci_resource_len(pdev, 0)); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 9714 | adapter->io_addr = hw->hw_addr; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9715 | if (!hw->hw_addr) { |
| 9716 | err = -EIO; |
| 9717 | goto err_ioremap; |
| 9718 | } |
| 9719 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 9720 | netdev->netdev_ops = &ixgbe_netdev_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9721 | ixgbe_set_ethtool_ops(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9722 | netdev->watchdog_timeo = 5 * HZ; |
Mark Rustad | 339de30 | 2014-06-06 01:57:06 +0000 | [diff] [blame] | 9723 | strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9724 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9725 | /* Setup hw api */ |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 9726 | hw->mac.ops = *ii->mac_ops; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 9727 | hw->mac.type = ii->mac; |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 9728 | hw->mvals = ii->mvals; |
Emil Tantilov | b71f6c4 | 2016-10-10 14:54:03 -0700 | [diff] [blame] | 9729 | if (ii->link_ops) |
| 9730 | hw->link.ops = *ii->link_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9731 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9732 | /* EEPROM */ |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 9733 | hw->eeprom.ops = *ii->eeprom_ops; |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 9734 | eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw)); |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 9735 | if (ixgbe_removed(hw->hw_addr)) { |
| 9736 | err = -EIO; |
| 9737 | goto err_ioremap; |
| 9738 | } |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9739 | /* 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] | 9740 | if (!(eec & BIT(8))) |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9741 | hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic; |
| 9742 | |
| 9743 | /* PHY */ |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 9744 | hw->phy.ops = *ii->phy_ops; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 9745 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 9746 | /* ixgbe_identify_phy_generic will set prtad and mmds properly */ |
| 9747 | hw->phy.mdio.prtad = MDIO_PRTAD_NONE; |
| 9748 | hw->phy.mdio.mmds = 0; |
| 9749 | hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 9750 | hw->phy.mdio.dev = netdev; |
| 9751 | hw->phy.mdio.mdio_read = ixgbe_mdio_read; |
| 9752 | hw->phy.mdio.mdio_write = ixgbe_mdio_write; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 9753 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9754 | /* setup the private structure */ |
Emil Tantilov | 55570b6 | 2016-10-12 12:34:25 -0700 | [diff] [blame] | 9755 | err = ixgbe_sw_init(adapter, ii); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9756 | if (err) |
| 9757 | goto err_sw_init; |
| 9758 | |
Don Skidmore | dbd15b8 | 2016-03-09 16:45:00 -0500 | [diff] [blame] | 9759 | /* Make sure the SWFW semaphore is in a valid state */ |
| 9760 | if (hw->mac.ops.init_swfw_sync) |
| 9761 | hw->mac.ops.init_swfw_sync(hw); |
| 9762 | |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 9763 | /* Make it possible the adapter to be woken up via WOL */ |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 9764 | switch (adapter->hw.mac.type) { |
| 9765 | case ixgbe_mac_82599EB: |
| 9766 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 9767 | case ixgbe_mac_X550: |
| 9768 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 9769 | case ixgbe_mac_x550em_a: |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 9770 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 9771 | break; |
| 9772 | default: |
| 9773 | break; |
| 9774 | } |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 9775 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 9776 | /* |
| 9777 | * If there is a fan on this device and it has failed log the |
| 9778 | * failure. |
| 9779 | */ |
| 9780 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 9781 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 9782 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 9783 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 9784 | } |
| 9785 | |
Peter P Waskiewicz Jr | 8ef78ad | 2012-02-01 09:19:21 +0000 | [diff] [blame] | 9786 | if (allow_unsupported_sfp) |
| 9787 | hw->allow_unsupported_sfp = allow_unsupported_sfp; |
| 9788 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9789 | /* reset_hw fills in the perm_addr as well */ |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 9790 | hw->phy.reset_if_overtemp = true; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9791 | err = hw->mac.ops.reset_hw(hw); |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 9792 | hw->phy.reset_if_overtemp = false; |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 9793 | ixgbe_set_eee_capable(adapter); |
Mark Rustad | 29a8dca | 2015-08-08 16:17:46 -0700 | [diff] [blame] | 9794 | if (err == IXGBE_ERR_SFP_NOT_PRESENT) { |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 9795 | err = 0; |
| 9796 | } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 1b1bf31 | 2013-07-31 05:27:04 +0000 | [diff] [blame] | 9797 | e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n"); |
| 9798 | e_dev_err("Reload the driver after installing a supported module.\n"); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 9799 | goto err_sw_init; |
| 9800 | } else if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 9801 | e_dev_err("HW Init failed: %d\n", err); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9802 | goto err_sw_init; |
| 9803 | } |
| 9804 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 9805 | #ifdef CONFIG_PCI_IOV |
Greg Rose | 60a1a68 | 2012-12-11 08:26:33 +0000 | [diff] [blame] | 9806 | /* SR-IOV not supported on the 82598 */ |
| 9807 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 9808 | goto skip_sriov; |
| 9809 | /* Mailbox */ |
| 9810 | ixgbe_init_mbx_params_pf(hw); |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 9811 | hw->mbx.ops = ii->mbx_ops; |
ethan.zhao | dcc23e3 | 2014-01-16 19:41:04 -0800 | [diff] [blame] | 9812 | pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT); |
ethan.zhao | 31ac910 | 2014-01-16 19:41:05 -0800 | [diff] [blame] | 9813 | ixgbe_enable_sriov(adapter); |
Greg Rose | 60a1a68 | 2012-12-11 08:26:33 +0000 | [diff] [blame] | 9814 | skip_sriov: |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 9815 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 9816 | #endif |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 9817 | netdev->features = NETIF_F_SG | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9818 | NETIF_F_TSO | |
| 9819 | NETIF_F_TSO6 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9820 | NETIF_F_RXHASH | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 9821 | NETIF_F_RXCSUM | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9822 | NETIF_F_HW_CSUM; |
| 9823 | |
| 9824 | #define IXGBE_GSO_PARTIAL_FEATURES (NETIF_F_GSO_GRE | \ |
| 9825 | NETIF_F_GSO_GRE_CSUM | \ |
Tom Herbert | 7e13318 | 2016-05-18 09:06:10 -0700 | [diff] [blame] | 9826 | NETIF_F_GSO_IPXIP4 | \ |
Alexander Duyck | bf2d1df | 2016-05-18 10:44:53 -0700 | [diff] [blame] | 9827 | NETIF_F_GSO_IPXIP6 | \ |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9828 | NETIF_F_GSO_UDP_TUNNEL | \ |
| 9829 | NETIF_F_GSO_UDP_TUNNEL_CSUM) |
| 9830 | |
| 9831 | netdev->gso_partial_features = IXGBE_GSO_PARTIAL_FEATURES; |
| 9832 | netdev->features |= NETIF_F_GSO_PARTIAL | |
| 9833 | IXGBE_GSO_PARTIAL_FEATURES; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9834 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 9835 | if (hw->mac.type >= ixgbe_mac_82599EB) |
Tom Herbert | 53692b1 | 2015-12-14 11:19:41 -0800 | [diff] [blame] | 9836 | netdev->features |= NETIF_F_SCTP_CRC; |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 9837 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 9838 | /* copy netdev features into list of user selectable features */ |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9839 | netdev->hw_features |= netdev->features | |
Alexander Duyck | 3d95182 | 2016-08-12 09:53:39 -0700 | [diff] [blame] | 9840 | NETIF_F_HW_VLAN_CTAG_FILTER | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9841 | NETIF_F_HW_VLAN_CTAG_RX | |
| 9842 | NETIF_F_HW_VLAN_CTAG_TX | |
| 9843 | NETIF_F_RXALL | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 9844 | NETIF_F_HW_L2FW_DOFFLOAD; |
| 9845 | |
| 9846 | if (hw->mac.type >= ixgbe_mac_82599EB) |
| 9847 | netdev->hw_features |= NETIF_F_NTUPLE | |
| 9848 | NETIF_F_HW_TC; |
| 9849 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9850 | if (pci_using_dac) |
| 9851 | netdev->features |= NETIF_F_HIGHDMA; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 9852 | |
Alexander Duyck | 5eee87c | 2016-05-11 13:23:34 -0700 | [diff] [blame] | 9853 | netdev->vlan_features |= netdev->features | NETIF_F_TSO_MANGLEID; |
| 9854 | netdev->hw_enc_features |= netdev->vlan_features; |
| 9855 | netdev->mpls_features |= NETIF_F_HW_CSUM; |
| 9856 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9857 | /* set this bit last since it cannot be part of vlan_features */ |
| 9858 | netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER | |
| 9859 | NETIF_F_HW_VLAN_CTAG_RX | |
| 9860 | NETIF_F_HW_VLAN_CTAG_TX; |
| 9861 | |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 9862 | netdev->priv_flags |= IFF_UNICAST_FLT; |
Ben Greear | f43f313 | 2012-03-06 09:42:04 +0000 | [diff] [blame] | 9863 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 9864 | |
Jarod Wilson | 91c527a | 2016-10-17 15:54:05 -0400 | [diff] [blame] | 9865 | /* MTU range: 68 - 9710 */ |
| 9866 | netdev->min_mtu = ETH_MIN_MTU; |
| 9867 | netdev->max_mtu = IXGBE_MAX_JUMBO_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN); |
| 9868 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 9869 | #ifdef CONFIG_IXGBE_DCB |
Usha Ketineni | 8829009 | 2016-04-26 05:00:26 -0700 | [diff] [blame] | 9870 | if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE) |
Stephen Hemminger | 3f40c74 | 2016-11-21 09:52:40 -0800 | [diff] [blame] | 9871 | netdev->dcbnl_ops = &ixgbe_dcbnl_ops; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 9872 | #endif |
| 9873 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 9874 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 9875 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 9876 | unsigned int fcoe_l; |
| 9877 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 9878 | if (hw->mac.ops.get_device_caps) { |
| 9879 | hw->mac.ops.get_device_caps(hw, &device_caps); |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 9880 | if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS) |
| 9881 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 9882 | } |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 9883 | |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 9884 | |
| 9885 | fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus()); |
| 9886 | adapter->ring_feature[RING_F_FCOE].limit = fcoe_l; |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 9887 | |
Alexander Duyck | a58915c | 2012-05-25 06:38:18 +0000 | [diff] [blame] | 9888 | netdev->features |= NETIF_F_FSO | |
| 9889 | NETIF_F_FCOE_CRC; |
| 9890 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 9891 | netdev->vlan_features |= NETIF_F_FSO | |
| 9892 | NETIF_F_FCOE_CRC | |
| 9893 | NETIF_F_FCOE_MTU; |
Yi Zou | 5e09d7f | 2010-07-19 13:59:52 +0000 | [diff] [blame] | 9894 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 9895 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9896 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9897 | if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) |
| 9898 | netdev->hw_features |= NETIF_F_LRO; |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 9899 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 9900 | netdev->features |= NETIF_F_LRO; |
| 9901 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9902 | /* make sure the EEPROM is good */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9903 | if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 9904 | e_dev_err("The EEPROM Checksum Is Not Valid\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9905 | err = -EIO; |
Alexander Duyck | 35937c0 | 2012-02-08 07:51:37 +0000 | [diff] [blame] | 9906 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9907 | } |
| 9908 | |
Sowmini Varadhan | c7374b5 | 2016-01-12 19:32:30 -0800 | [diff] [blame] | 9909 | eth_platform_get_mac_address(&adapter->pdev->dev, |
| 9910 | adapter->hw.mac.perm_addr); |
Martin K Petersen | c762dff | 2014-11-15 14:24:51 +0000 | [diff] [blame] | 9911 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9912 | memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9913 | |
Jiri Pirko | aaeb6cd | 2013-01-08 01:38:26 +0000 | [diff] [blame] | 9914 | if (!is_valid_ether_addr(netdev->dev_addr)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 9915 | e_dev_err("invalid MAC address\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9916 | err = -EIO; |
Alexander Duyck | 35937c0 | 2012-02-08 07:51:37 +0000 | [diff] [blame] | 9917 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9918 | } |
| 9919 | |
Tushar Dave | 5676804 | 2016-01-07 14:17:03 -0800 | [diff] [blame] | 9920 | /* Set hw->mac.addr to permanent MAC address */ |
| 9921 | ether_addr_copy(hw->mac.addr, hw->mac.perm_addr); |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 9922 | ixgbe_mac_set_default_filter(adapter); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 9923 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 9924 | setup_timer(&adapter->service_timer, &ixgbe_service_timer, |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 9925 | (unsigned long) adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9926 | |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 9927 | if (ixgbe_removed(hw->hw_addr)) { |
| 9928 | err = -EIO; |
| 9929 | goto err_sw_init; |
| 9930 | } |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 9931 | INIT_WORK(&adapter->service_task, ixgbe_service_task); |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 9932 | set_bit(__IXGBE_SERVICE_INITED, &adapter->state); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 9933 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9934 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 9935 | err = ixgbe_init_interrupt_scheme(adapter); |
| 9936 | if (err) |
| 9937 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9938 | |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9939 | /* WOL not supported for all devices */ |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 9940 | adapter->wol = 0; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9941 | hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap); |
Jacob Keller | 6b92b0b | 2013-04-13 05:40:37 +0000 | [diff] [blame] | 9942 | hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device, |
Don Skidmore | b8f8363 | 2013-02-28 08:08:44 +0000 | [diff] [blame] | 9943 | pdev->subsystem_device); |
Jacob Keller | 6b92b0b | 2013-04-13 05:40:37 +0000 | [diff] [blame] | 9944 | if (hw->wol_enabled) |
Andy Gospodarek | 9417c46 | 2011-07-16 07:31:33 +0000 | [diff] [blame] | 9945 | adapter->wol = IXGBE_WUFC_MAG; |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 9946 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 9947 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 9948 | |
Emil Tantilov | 15e5209 | 2011-09-29 05:01:29 +0000 | [diff] [blame] | 9949 | /* save off EEPROM version number */ |
| 9950 | hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh); |
| 9951 | hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl); |
| 9952 | |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 9953 | /* pick up the PCI bus settings for reporting later */ |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 9954 | if (ixgbe_pcie_from_parent(hw)) |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 9955 | ixgbe_get_parent_bus_info(adapter); |
Don Skidmore | f9328bc | 2015-06-18 13:24:06 -0400 | [diff] [blame] | 9956 | else |
| 9957 | hw->mac.ops.get_bus_info(hw); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 9958 | |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 9959 | /* calculate the expected PCIe bandwidth required for optimal |
| 9960 | * performance. Note that some older parts will never have enough |
| 9961 | * bandwidth due to being older generation PCIe parts. We clamp these |
| 9962 | * parts to ensure no warning is displayed if it can't be fixed. |
| 9963 | */ |
| 9964 | switch (hw->mac.type) { |
| 9965 | case ixgbe_mac_82598EB: |
| 9966 | expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16); |
| 9967 | break; |
| 9968 | default: |
| 9969 | expected_gts = ixgbe_enumerate_functions(adapter) * 10; |
| 9970 | break; |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 9971 | } |
Jacob Keller | caafb95 | 2014-07-19 07:17:17 +0000 | [diff] [blame] | 9972 | |
| 9973 | /* don't check link if we failed to enumerate functions */ |
| 9974 | if (expected_gts > 0) |
| 9975 | ixgbe_check_minimum_link(adapter, expected_gts); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 9976 | |
Mark Rustad | 339de30 | 2014-06-06 01:57:06 +0000 | [diff] [blame] | 9977 | err = ixgbe_read_pba_string_generic(hw, part_str, sizeof(part_str)); |
Jacob Keller | 6a2aae5 | 2013-10-18 05:09:24 +0000 | [diff] [blame] | 9978 | if (err) |
Mark Rustad | 339de30 | 2014-06-06 01:57:06 +0000 | [diff] [blame] | 9979 | strlcpy(part_str, "Unknown", sizeof(part_str)); |
Jacob Keller | 6a2aae5 | 2013-10-18 05:09:24 +0000 | [diff] [blame] | 9980 | if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present) |
| 9981 | e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n", |
| 9982 | hw->mac.type, hw->phy.type, hw->phy.sfp_type, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 9983 | part_str); |
Jacob Keller | 6a2aae5 | 2013-10-18 05:09:24 +0000 | [diff] [blame] | 9984 | else |
| 9985 | e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n", |
| 9986 | hw->mac.type, hw->phy.type, part_str); |
| 9987 | |
| 9988 | e_dev_info("%pM\n", netdev->dev_addr); |
| 9989 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9990 | /* reset the hardware with the new settings */ |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 9991 | err = hw->mac.ops.start_hw(hw); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 9992 | if (err == IXGBE_ERR_EEPROM_VERSION) { |
| 9993 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 9994 | e_dev_warn("This device is a pre-production adapter/LOM. " |
| 9995 | "Please be aware there may be issues associated " |
| 9996 | "with your hardware. If you are experiencing " |
| 9997 | "problems please contact your Intel or hardware " |
| 9998 | "representative who provided you with this " |
| 9999 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 10000 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10001 | strcpy(netdev->name, "eth%d"); |
| 10002 | err = register_netdev(netdev); |
| 10003 | if (err) |
| 10004 | goto err_register; |
| 10005 | |
Emil Tantilov | 0fb6a55 | 2014-12-04 03:03:38 +0000 | [diff] [blame] | 10006 | pci_set_drvdata(pdev, adapter); |
| 10007 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 10008 | /* power down the optics for 82599 SFP+ fiber */ |
| 10009 | if (hw->mac.ops.disable_tx_laser) |
Emil Tantilov | 93d3ce8 | 2011-10-19 07:59:55 +0000 | [diff] [blame] | 10010 | hw->mac.ops.disable_tx_laser(hw); |
| 10011 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 10012 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 10013 | netif_carrier_off(netdev); |
| 10014 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 10015 | #ifdef CONFIG_IXGBE_DCA |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 10016 | if (dca_add_requester(&pdev->dev) == 0) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10017 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10018 | ixgbe_setup_dca(adapter); |
| 10019 | } |
| 10020 | #endif |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 10021 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 10022 | 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] | 10023 | for (i = 0; i < adapter->num_vfs; i++) |
| 10024 | ixgbe_vf_configuration(pdev, (i | 0x10000000)); |
| 10025 | } |
| 10026 | |
Jacob Keller | 2466dd9 | 2011-09-08 03:50:54 +0000 | [diff] [blame] | 10027 | /* firmware requires driver version to be 0xFFFFFFFF |
| 10028 | * since os does not support feature |
| 10029 | */ |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 10030 | if (hw->mac.ops.set_fw_drv_ver) |
Tony Nguyen | cb8e051 | 2016-10-26 16:25:18 -0700 | [diff] [blame] | 10031 | hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, 0xFF, |
| 10032 | sizeof(ixgbe_driver_version) - 1, |
| 10033 | ixgbe_driver_version); |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 10034 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 10035 | /* add san mac addr to netdev */ |
| 10036 | ixgbe_add_sanmac_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10037 | |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 10038 | e_dev_info("%s\n", ixgbe_default_device_descr); |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 10039 | |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 10040 | #ifdef CONFIG_IXGBE_HWMON |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 10041 | if (ixgbe_sysfs_init(adapter)) |
| 10042 | e_err(probe, "failed to allocate sysfs resources\n"); |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 10043 | #endif /* CONFIG_IXGBE_HWMON */ |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 10044 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 10045 | ixgbe_dbg_adapter_init(adapter); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 10046 | |
Emil Tantilov | d1a35ee | 2014-05-13 08:24:00 +0000 | [diff] [blame] | 10047 | /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */ |
| 10048 | 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] | 10049 | hw->mac.ops.setup_link(hw, |
| 10050 | IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL, |
| 10051 | true); |
| 10052 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10053 | return 0; |
| 10054 | |
| 10055 | err_register: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 10056 | ixgbe_release_hw_control(adapter); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 10057 | ixgbe_clear_interrupt_scheme(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10058 | err_sw_init: |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 10059 | ixgbe_disable_sriov(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 10060 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 10061 | iounmap(adapter->io_addr); |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 10062 | kfree(adapter->jump_tables[0]); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 10063 | kfree(adapter->mac_table); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10064 | err_ioremap: |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 10065 | disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10066 | free_netdev(netdev); |
| 10067 | err_alloc_etherdev: |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 10068 | pci_release_mem_regions(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10069 | err_pci_reg: |
| 10070 | err_dma: |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 10071 | if (!adapter || disable_dev) |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10072 | pci_disable_device(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10073 | return err; |
| 10074 | } |
| 10075 | |
| 10076 | /** |
| 10077 | * ixgbe_remove - Device Removal Routine |
| 10078 | * @pdev: PCI device information struct |
| 10079 | * |
| 10080 | * ixgbe_remove is called by the PCI subsystem to alert the driver |
| 10081 | * that it should release a PCI device. The could be caused by a |
| 10082 | * Hot-Plug event, or because the driver is going to be removed from |
| 10083 | * memory. |
| 10084 | **/ |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 10085 | static void ixgbe_remove(struct pci_dev *pdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10086 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 10087 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
Emil Tantilov | 0fb6a55 | 2014-12-04 03:03:38 +0000 | [diff] [blame] | 10088 | struct net_device *netdev; |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 10089 | bool disable_dev; |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 10090 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10091 | |
Emil Tantilov | 0fb6a55 | 2014-12-04 03:03:38 +0000 | [diff] [blame] | 10092 | /* if !adapter then we already cleaned up in probe */ |
| 10093 | if (!adapter) |
| 10094 | return; |
| 10095 | |
| 10096 | netdev = adapter->netdev; |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 10097 | ixgbe_dbg_adapter_exit(adapter); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 10098 | |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 10099 | set_bit(__IXGBE_REMOVING, &adapter->state); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 10100 | cancel_work_sync(&adapter->service_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10101 | |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 10102 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 10103 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10104 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 10105 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 10106 | dca_remove_requester(&pdev->dev); |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 10107 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 10108 | IXGBE_DCA_CTRL_DCA_DISABLE); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10109 | } |
| 10110 | |
| 10111 | #endif |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 10112 | #ifdef CONFIG_IXGBE_HWMON |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 10113 | ixgbe_sysfs_exit(adapter); |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 10114 | #endif /* CONFIG_IXGBE_HWMON */ |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 10115 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 10116 | /* remove the added san mac */ |
| 10117 | ixgbe_del_sanmac_netdev(netdev); |
| 10118 | |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 10119 | #ifdef CONFIG_PCI_IOV |
Alex Williamson | 7837e28 | 2015-07-10 15:31:34 -0600 | [diff] [blame] | 10120 | ixgbe_disable_sriov(adapter); |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 10121 | #endif |
Alex Williamson | 6b010e9 | 2015-07-29 14:38:21 -0600 | [diff] [blame] | 10122 | if (netdev->reg_state == NETREG_REGISTERED) |
| 10123 | unregister_netdev(netdev); |
| 10124 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 10125 | ixgbe_clear_interrupt_scheme(adapter); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 10126 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 10127 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10128 | |
Alexander Duyck | 2b1588c | 2012-03-17 02:39:16 +0000 | [diff] [blame] | 10129 | #ifdef CONFIG_DCB |
| 10130 | kfree(adapter->ixgbe_ieee_pfc); |
| 10131 | kfree(adapter->ixgbe_ieee_ets); |
| 10132 | |
| 10133 | #endif |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 10134 | iounmap(adapter->io_addr); |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 10135 | pci_release_mem_regions(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10136 | |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 10137 | e_dev_info("complete\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 10138 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 10139 | for (i = 0; i < IXGBE_MAX_LINK_HANDLE; i++) { |
| 10140 | if (adapter->jump_tables[i]) { |
| 10141 | kfree(adapter->jump_tables[i]->input); |
| 10142 | kfree(adapter->jump_tables[i]->mask); |
| 10143 | } |
| 10144 | kfree(adapter->jump_tables[i]); |
| 10145 | } |
| 10146 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 10147 | kfree(adapter->mac_table); |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 10148 | disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10149 | free_netdev(netdev); |
| 10150 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 10151 | pci_disable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10152 | |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 10153 | if (disable_dev) |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10154 | pci_disable_device(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10155 | } |
| 10156 | |
| 10157 | /** |
| 10158 | * ixgbe_io_error_detected - called when PCI error is detected |
| 10159 | * @pdev: Pointer to PCI device |
| 10160 | * @state: The current pci connection state |
| 10161 | * |
| 10162 | * This function is called after a PCI bus error affecting |
| 10163 | * this device has been detected. |
| 10164 | */ |
| 10165 | 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] | 10166 | pci_channel_state_t state) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10167 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 10168 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 10169 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10170 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10171 | #ifdef CONFIG_PCI_IOV |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 10172 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10173 | struct pci_dev *bdev, *vfdev; |
| 10174 | u32 dw0, dw1, dw2, dw3; |
| 10175 | int vf, pos; |
| 10176 | u16 req_id, pf_func; |
| 10177 | |
| 10178 | if (adapter->hw.mac.type == ixgbe_mac_82598EB || |
| 10179 | adapter->num_vfs == 0) |
| 10180 | goto skip_bad_vf_detection; |
| 10181 | |
| 10182 | bdev = pdev->bus->self; |
Yijing Wang | 62f87c0 | 2012-07-24 17:20:03 +0800 | [diff] [blame] | 10183 | while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT)) |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10184 | bdev = bdev->bus->self; |
| 10185 | |
| 10186 | if (!bdev) |
| 10187 | goto skip_bad_vf_detection; |
| 10188 | |
| 10189 | pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR); |
| 10190 | if (!pos) |
| 10191 | goto skip_bad_vf_detection; |
| 10192 | |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 10193 | dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG); |
| 10194 | dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4); |
| 10195 | dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8); |
| 10196 | dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12); |
| 10197 | if (ixgbe_removed(hw->hw_addr)) |
| 10198 | goto skip_bad_vf_detection; |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10199 | |
| 10200 | req_id = dw1 >> 16; |
| 10201 | /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */ |
| 10202 | if (!(req_id & 0x0080)) |
| 10203 | goto skip_bad_vf_detection; |
| 10204 | |
| 10205 | pf_func = req_id & 0x01; |
| 10206 | if ((pf_func & 1) == (pdev->devfn & 1)) { |
| 10207 | unsigned int device_id; |
| 10208 | |
| 10209 | vf = (req_id & 0x7F) >> 1; |
| 10210 | e_dev_err("VF %d has caused a PCIe error\n", vf); |
| 10211 | e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: " |
| 10212 | "%8.8x\tdw3: %8.8x\n", |
| 10213 | dw0, dw1, dw2, dw3); |
| 10214 | switch (adapter->hw.mac.type) { |
| 10215 | case ixgbe_mac_82599EB: |
| 10216 | device_id = IXGBE_82599_VF_DEVICE_ID; |
| 10217 | break; |
| 10218 | case ixgbe_mac_X540: |
| 10219 | device_id = IXGBE_X540_VF_DEVICE_ID; |
| 10220 | break; |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 10221 | case ixgbe_mac_X550: |
| 10222 | device_id = IXGBE_DEV_ID_X550_VF; |
| 10223 | break; |
| 10224 | case ixgbe_mac_X550EM_x: |
| 10225 | device_id = IXGBE_DEV_ID_X550EM_X_VF; |
| 10226 | break; |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 10227 | case ixgbe_mac_x550em_a: |
| 10228 | device_id = IXGBE_DEV_ID_X550EM_A_VF; |
| 10229 | break; |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10230 | default: |
| 10231 | device_id = 0; |
| 10232 | break; |
| 10233 | } |
| 10234 | |
| 10235 | /* Find the pci device of the offending VF */ |
Jon Mason | 36e9031 | 2012-07-19 21:02:09 +0000 | [diff] [blame] | 10236 | vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL); |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10237 | while (vfdev) { |
| 10238 | if (vfdev->devfn == (req_id & 0xFF)) |
| 10239 | break; |
Jon Mason | 36e9031 | 2012-07-19 21:02:09 +0000 | [diff] [blame] | 10240 | vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10241 | device_id, vfdev); |
| 10242 | } |
| 10243 | /* |
| 10244 | * There's a slim chance the VF could have been hot plugged, |
| 10245 | * so if it is no longer present we don't need to issue the |
| 10246 | * VFLR. Just clean up the AER in that case. |
| 10247 | */ |
| 10248 | if (vfdev) { |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 10249 | ixgbe_issue_vf_flr(adapter, vfdev); |
Greg Rose | b4fafbe | 2012-12-13 01:14:06 +0000 | [diff] [blame] | 10250 | /* Free device reference count */ |
| 10251 | pci_dev_put(vfdev); |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10252 | } |
| 10253 | |
| 10254 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 10255 | } |
| 10256 | |
| 10257 | /* |
| 10258 | * Even though the error may have occurred on the other port |
| 10259 | * we still need to increment the vf error reference count for |
| 10260 | * both ports because the I/O resume function will be called |
| 10261 | * for both of them. |
| 10262 | */ |
| 10263 | adapter->vferr_refcount++; |
| 10264 | |
| 10265 | return PCI_ERS_RESULT_RECOVERED; |
| 10266 | |
| 10267 | skip_bad_vf_detection: |
| 10268 | #endif /* CONFIG_PCI_IOV */ |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 10269 | if (!test_bit(__IXGBE_SERVICE_INITED, &adapter->state)) |
| 10270 | return PCI_ERS_RESULT_DISCONNECT; |
| 10271 | |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10272 | rtnl_lock(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10273 | netif_device_detach(netdev); |
| 10274 | |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10275 | if (state == pci_channel_io_perm_failure) { |
| 10276 | rtnl_unlock(); |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 10277 | return PCI_ERS_RESULT_DISCONNECT; |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10278 | } |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 10279 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10280 | if (netif_running(netdev)) |
Emil Tantilov | 126db13 | 2016-11-16 09:48:02 -0800 | [diff] [blame] | 10281 | ixgbe_close_suspend(adapter); |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10282 | |
| 10283 | if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state)) |
| 10284 | pci_disable_device(pdev); |
| 10285 | rtnl_unlock(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10286 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 10287 | /* Request a slot reset. */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10288 | return PCI_ERS_RESULT_NEED_RESET; |
| 10289 | } |
| 10290 | |
| 10291 | /** |
| 10292 | * ixgbe_io_slot_reset - called after the pci bus has been reset. |
| 10293 | * @pdev: Pointer to PCI device |
| 10294 | * |
| 10295 | * Restart the card from scratch, as if from a cold-boot. |
| 10296 | */ |
| 10297 | static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev) |
| 10298 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 10299 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10300 | pci_ers_result_t result; |
| 10301 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10302 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 10303 | if (pci_enable_device_mem(pdev)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 10304 | 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] | 10305 | result = PCI_ERS_RESULT_DISCONNECT; |
| 10306 | } else { |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 10307 | smp_mb__before_atomic(); |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10308 | clear_bit(__IXGBE_DISABLED, &adapter->state); |
Mark Rustad | 0391bbe | 2014-02-28 15:48:55 -0800 | [diff] [blame] | 10309 | adapter->hw.hw_addr = adapter->io_addr; |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10310 | pci_set_master(pdev); |
| 10311 | pci_restore_state(pdev); |
Breno Leitao | c0e1f68 | 2009-11-10 08:37:47 +0000 | [diff] [blame] | 10312 | pci_save_state(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10313 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 10314 | pci_wake_from_d3(pdev, false); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10315 | |
| 10316 | ixgbe_reset(adapter); |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 10317 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10318 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10319 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10320 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10321 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 10322 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 10323 | e_dev_err("pci_cleanup_aer_uncorrect_error_status " |
| 10324 | "failed 0x%0x\n", err); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10325 | /* non-fatal, continue */ |
| 10326 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10327 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10328 | return result; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10329 | } |
| 10330 | |
| 10331 | /** |
| 10332 | * ixgbe_io_resume - called when traffic can start flowing again. |
| 10333 | * @pdev: Pointer to PCI device |
| 10334 | * |
| 10335 | * This callback is called when the error recovery driver tells us that |
| 10336 | * its OK to resume normal operation. |
| 10337 | */ |
| 10338 | static void ixgbe_io_resume(struct pci_dev *pdev) |
| 10339 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 10340 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 10341 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10342 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10343 | #ifdef CONFIG_PCI_IOV |
| 10344 | if (adapter->vferr_refcount) { |
| 10345 | e_info(drv, "Resuming after VF err\n"); |
| 10346 | adapter->vferr_refcount--; |
| 10347 | return; |
| 10348 | } |
| 10349 | |
| 10350 | #endif |
Emil Tantilov | 126db13 | 2016-11-16 09:48:02 -0800 | [diff] [blame] | 10351 | rtnl_lock(); |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 10352 | if (netif_running(netdev)) |
Emil Tantilov | 126db13 | 2016-11-16 09:48:02 -0800 | [diff] [blame] | 10353 | ixgbe_open(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10354 | |
| 10355 | netif_device_attach(netdev); |
Emil Tantilov | 126db13 | 2016-11-16 09:48:02 -0800 | [diff] [blame] | 10356 | rtnl_unlock(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10357 | } |
| 10358 | |
Stephen Hemminger | 3646f0e | 2012-09-07 09:33:15 -0700 | [diff] [blame] | 10359 | static const struct pci_error_handlers ixgbe_err_handler = { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10360 | .error_detected = ixgbe_io_error_detected, |
| 10361 | .slot_reset = ixgbe_io_slot_reset, |
| 10362 | .resume = ixgbe_io_resume, |
| 10363 | }; |
| 10364 | |
| 10365 | static struct pci_driver ixgbe_driver = { |
| 10366 | .name = ixgbe_driver_name, |
| 10367 | .id_table = ixgbe_pci_tbl, |
| 10368 | .probe = ixgbe_probe, |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 10369 | .remove = ixgbe_remove, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10370 | #ifdef CONFIG_PM |
| 10371 | .suspend = ixgbe_suspend, |
| 10372 | .resume = ixgbe_resume, |
| 10373 | #endif |
| 10374 | .shutdown = ixgbe_shutdown, |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 10375 | .sriov_configure = ixgbe_pci_sriov_configure, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10376 | .err_handler = &ixgbe_err_handler |
| 10377 | }; |
| 10378 | |
| 10379 | /** |
| 10380 | * ixgbe_init_module - Driver Registration Routine |
| 10381 | * |
| 10382 | * ixgbe_init_module is the first routine called when the driver is |
| 10383 | * loaded. All it does is register with the PCI subsystem. |
| 10384 | **/ |
| 10385 | static int __init ixgbe_init_module(void) |
| 10386 | { |
| 10387 | int ret; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 10388 | pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version); |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 10389 | pr_info("%s\n", ixgbe_copyright); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10390 | |
Mark Rustad | 780484d | 2015-10-21 17:21:10 -0700 | [diff] [blame] | 10391 | ixgbe_wq = create_singlethread_workqueue(ixgbe_driver_name); |
| 10392 | if (!ixgbe_wq) { |
| 10393 | pr_err("%s: Failed to create workqueue\n", ixgbe_driver_name); |
| 10394 | return -ENOMEM; |
| 10395 | } |
| 10396 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 10397 | ixgbe_dbg_init(); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 10398 | |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 10399 | ret = pci_register_driver(&ixgbe_driver); |
| 10400 | if (ret) { |
Wei Yongjun | 6b83687 | 2016-07-12 15:17:02 +0000 | [diff] [blame] | 10401 | destroy_workqueue(ixgbe_wq); |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 10402 | ixgbe_dbg_exit(); |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 10403 | return ret; |
| 10404 | } |
| 10405 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 10406 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10407 | dca_register_notify(&dca_notifier); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10408 | #endif |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 10409 | |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 10410 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10411 | } |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 10412 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10413 | module_init(ixgbe_init_module); |
| 10414 | |
| 10415 | /** |
| 10416 | * ixgbe_exit_module - Driver Exit Cleanup Routine |
| 10417 | * |
| 10418 | * ixgbe_exit_module is called just before the driver is removed |
| 10419 | * from memory. |
| 10420 | **/ |
| 10421 | static void __exit ixgbe_exit_module(void) |
| 10422 | { |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 10423 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10424 | dca_unregister_notify(&dca_notifier); |
| 10425 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10426 | pci_unregister_driver(&ixgbe_driver); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 10427 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 10428 | ixgbe_dbg_exit(); |
Mark Rustad | 780484d | 2015-10-21 17:21:10 -0700 | [diff] [blame] | 10429 | if (ixgbe_wq) { |
| 10430 | destroy_workqueue(ixgbe_wq); |
| 10431 | ixgbe_wq = NULL; |
| 10432 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10433 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10434 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 10435 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10436 | static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 10437 | void *p) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10438 | { |
| 10439 | int ret_val; |
| 10440 | |
| 10441 | ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 10442 | __ixgbe_notify_dca); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10443 | |
| 10444 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; |
| 10445 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10446 | |
Alexander Duyck | b453368 | 2009-03-31 21:32:42 +0000 | [diff] [blame] | 10447 | #endif /* CONFIG_IXGBE_DCA */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 10448 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10449 | module_exit(ixgbe_exit_module); |
| 10450 | |
| 10451 | /* ixgbe_main.c */ |