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> |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 52 | #include <linux/bpf.h> |
| 53 | #include <linux/bpf_trace.h> |
| 54 | #include <linux/atomic.h> |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 55 | #include <scsi/fc/fc_fcoe.h> |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 56 | #include <net/udp_tunnel.h> |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 57 | #include <net/pkt_cls.h> |
| 58 | #include <net/tc_act/tc_gact.h> |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 59 | #include <net/tc_act/tc_mirred.h> |
Sowmini Varadhan | 9f3c750 | 2016-10-24 15:36:39 -0700 | [diff] [blame] | 60 | #include <net/vxlan.h> |
Scott Peterson | 2a20525 | 2016-11-18 11:25:42 -0800 | [diff] [blame] | 61 | #include <net/mpls.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 62 | |
| 63 | #include "ixgbe.h" |
| 64 | #include "ixgbe_common.h" |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 65 | #include "ixgbe_dcb_82599.h" |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 66 | #include "ixgbe_sriov.h" |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 67 | #include "ixgbe_model.h" |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 68 | |
| 69 | char ixgbe_driver_name[] = "ixgbe"; |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 70 | static const char ixgbe_driver_string[] = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 71 | "Intel(R) 10 Gigabit PCI Express Network Driver"; |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 72 | #ifdef IXGBE_FCOE |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 73 | char ixgbe_default_device_descr[] = |
| 74 | "Intel(R) 10 Gigabit Network Connection"; |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 75 | #else |
| 76 | static char ixgbe_default_device_descr[] = |
| 77 | "Intel(R) 10 Gigabit Network Connection"; |
| 78 | #endif |
Tony Nguyen | 01ec552 | 2017-05-18 14:55:07 -0700 | [diff] [blame] | 79 | #define DRV_VERSION "5.1.0-k" |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 80 | const char ixgbe_driver_version[] = DRV_VERSION; |
Don Skidmore | a52055e | 2011-02-23 09:58:39 +0000 | [diff] [blame] | 81 | static const char ixgbe_copyright[] = |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 82 | "Copyright (c) 1999-2016 Intel Corporation."; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 83 | |
Don Skidmore | f44e751 | 2015-06-09 16:36:23 -0700 | [diff] [blame] | 84 | static const char ixgbe_overheat_msg[] = "Network adapter has been stopped because it has over heated. Restart the computer. If the problem persists, power off the system and replace the adapter"; |
| 85 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 86 | static const struct ixgbe_info *ixgbe_info_tbl[] = { |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 87 | [board_82598] = &ixgbe_82598_info, |
| 88 | [board_82599] = &ixgbe_82599_info, |
| 89 | [board_X540] = &ixgbe_X540_info, |
| 90 | [board_X550] = &ixgbe_X550_info, |
| 91 | [board_X550EM_x] = &ixgbe_X550EM_x_info, |
Paul Greenwalt | 8dc963e | 2017-04-13 08:07:07 -0400 | [diff] [blame] | 92 | [board_x550em_x_fw] = &ixgbe_x550em_x_fw_info, |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 93 | [board_x550em_a] = &ixgbe_x550em_a_info, |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 94 | [board_x550em_a_fw] = &ixgbe_x550em_a_fw_info, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | /* ixgbe_pci_tbl - PCI Device ID Table |
| 98 | * |
| 99 | * Wildcard entries (PCI_ANY_ID) should come last |
| 100 | * Last entry must be all 0s |
| 101 | * |
| 102 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 103 | * Class, Class Mask, private data (not used) } |
| 104 | */ |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 105 | static const struct pci_device_id ixgbe_pci_tbl[] = { |
Alexander Duyck | 54239c6 | 2011-07-15 03:06:06 +0000 | [diff] [blame] | 106 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 }, |
| 107 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 }, |
| 108 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 }, |
| 109 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 }, |
| 110 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 }, |
| 111 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 }, |
| 112 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 }, |
| 113 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 }, |
| 114 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 }, |
| 115 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 }, |
| 116 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 }, |
| 117 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 }, |
| 118 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 }, |
| 119 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 }, |
| 120 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 }, |
| 121 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 }, |
| 122 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 }, |
| 123 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 }, |
| 124 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 }, |
| 125 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 }, |
| 126 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 }, |
| 127 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 }, |
| 128 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 }, |
| 129 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 }, |
| 130 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 }, |
| 131 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 }, |
Don Skidmore | 8f58332 | 2013-07-27 06:25:38 +0000 | [diff] [blame] | 132 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_QSFP_SF_QP), board_82599 }, |
Emil Tantilov | 7d14528 | 2011-09-08 08:30:14 +0000 | [diff] [blame] | 133 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 }, |
Emil Tantilov | 9e791e4 | 2011-11-04 06:43:29 +0000 | [diff] [blame] | 134 | {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] | 135 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 }, |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 136 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T), board_X550}, |
Mark Rustad | a711ad8 | 2016-03-21 11:21:31 -0700 | [diff] [blame] | 137 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T1), board_X550}, |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 138 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KX4), board_X550EM_x}, |
Don Skidmore | 18e01ee | 2016-12-30 21:07:58 -0500 | [diff] [blame] | 139 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_XFI), board_X550EM_x}, |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 140 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KR), board_X550EM_x}, |
Don Skidmore | deda562 | 2015-06-09 17:39:46 -0700 | [diff] [blame] | 141 | {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] | 142 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_SFP), board_X550EM_x}, |
Paul Greenwalt | 8dc963e | 2017-04-13 08:07:07 -0400 | [diff] [blame] | 143 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_1G_T), board_x550em_x_fw}, |
Mark Rustad | f572b2c | 2016-04-01 12:18:46 -0700 | [diff] [blame] | 144 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR), board_x550em_a }, |
| 145 | {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] | 146 | {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] | 147 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII), board_x550em_a }, |
| 148 | {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] | 149 | {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] | 150 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP), board_x550em_a }, |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 151 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_1G_T), board_x550em_a_fw }, |
| 152 | {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] | 153 | /* required last entry */ |
| 154 | {0, } |
| 155 | }; |
| 156 | MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl); |
| 157 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 158 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 159 | static int ixgbe_notify_dca(struct notifier_block *, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 160 | void *p); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 161 | static struct notifier_block dca_notifier = { |
| 162 | .notifier_call = ixgbe_notify_dca, |
| 163 | .next = NULL, |
| 164 | .priority = 0 |
| 165 | }; |
| 166 | #endif |
| 167 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 168 | #ifdef CONFIG_PCI_IOV |
| 169 | static unsigned int max_vfs; |
| 170 | module_param(max_vfs, uint, 0); |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 171 | MODULE_PARM_DESC(max_vfs, |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 172 | "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] | 173 | #endif /* CONFIG_PCI_IOV */ |
| 174 | |
Peter P Waskiewicz Jr | 8ef78ad | 2012-02-01 09:19:21 +0000 | [diff] [blame] | 175 | static unsigned int allow_unsupported_sfp; |
| 176 | module_param(allow_unsupported_sfp, uint, 0); |
| 177 | MODULE_PARM_DESC(allow_unsupported_sfp, |
| 178 | "Allow unsupported and untested SFP+ modules on 82599-based adapters"); |
| 179 | |
stephen hemminger | b3f4d59 | 2012-03-13 06:04:20 +0000 | [diff] [blame] | 180 | #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK) |
| 181 | static int debug = -1; |
| 182 | module_param(debug, int, 0); |
| 183 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 184 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 185 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 186 | MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver"); |
| 187 | MODULE_LICENSE("GPL"); |
| 188 | MODULE_VERSION(DRV_VERSION); |
| 189 | |
Mark Rustad | 780484d | 2015-10-21 17:21:10 -0700 | [diff] [blame] | 190 | static struct workqueue_struct *ixgbe_wq; |
| 191 | |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 192 | 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] | 193 | static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *); |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 194 | |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 195 | static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter *adapter, |
| 196 | u32 reg, u16 *value) |
| 197 | { |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 198 | struct pci_dev *parent_dev; |
| 199 | struct pci_bus *parent_bus; |
| 200 | |
| 201 | parent_bus = adapter->pdev->bus->parent; |
| 202 | if (!parent_bus) |
| 203 | return -1; |
| 204 | |
| 205 | parent_dev = parent_bus->self; |
| 206 | if (!parent_dev) |
| 207 | return -1; |
| 208 | |
Yijing Wang | c0798ed | 2013-09-04 17:30:08 +0000 | [diff] [blame] | 209 | if (!pci_is_pcie(parent_dev)) |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 210 | return -1; |
| 211 | |
Yijing Wang | c0798ed | 2013-09-04 17:30:08 +0000 | [diff] [blame] | 212 | pcie_capability_read_word(parent_dev, reg, value); |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 213 | if (*value == IXGBE_FAILED_READ_CFG_WORD && |
| 214 | ixgbe_check_cfg_remove(&adapter->hw, parent_dev)) |
| 215 | return -1; |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | static s32 ixgbe_get_parent_bus_info(struct ixgbe_adapter *adapter) |
| 220 | { |
| 221 | struct ixgbe_hw *hw = &adapter->hw; |
| 222 | u16 link_status = 0; |
| 223 | int err; |
| 224 | |
| 225 | hw->bus.type = ixgbe_bus_type_pci_express; |
| 226 | |
| 227 | /* Get the negotiated link width and speed from PCI config space of the |
| 228 | * parent, as this device is behind a switch |
| 229 | */ |
| 230 | err = ixgbe_read_pci_cfg_word_parent(adapter, 18, &link_status); |
| 231 | |
| 232 | /* assume caller will handle error case */ |
| 233 | if (err) |
| 234 | return err; |
| 235 | |
| 236 | hw->bus.width = ixgbe_convert_bus_width(link_status); |
| 237 | hw->bus.speed = ixgbe_convert_bus_speed(link_status); |
| 238 | |
| 239 | return 0; |
| 240 | } |
| 241 | |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 242 | /** |
| 243 | * ixgbe_check_from_parent - Determine whether PCIe info should come from parent |
| 244 | * @hw: hw specific details |
| 245 | * |
| 246 | * This function is used by probe to determine whether a device's PCI-Express |
| 247 | * bandwidth details should be gathered from the parent bus instead of from the |
| 248 | * device. Used to ensure that various locations all have the correct device ID |
| 249 | * checks. |
| 250 | */ |
| 251 | static inline bool ixgbe_pcie_from_parent(struct ixgbe_hw *hw) |
| 252 | { |
| 253 | switch (hw->device_id) { |
| 254 | case IXGBE_DEV_ID_82599_SFP_SF_QP: |
Don Skidmore | 8f58332 | 2013-07-27 06:25:38 +0000 | [diff] [blame] | 255 | case IXGBE_DEV_ID_82599_QSFP_SF_QP: |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 256 | return true; |
| 257 | default: |
| 258 | return false; |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | static void ixgbe_check_minimum_link(struct ixgbe_adapter *adapter, |
| 263 | int expected_gts) |
| 264 | { |
Don Skidmore | f9328bc | 2015-06-18 13:24:06 -0400 | [diff] [blame] | 265 | struct ixgbe_hw *hw = &adapter->hw; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 266 | int max_gts = 0; |
| 267 | enum pci_bus_speed speed = PCI_SPEED_UNKNOWN; |
| 268 | enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN; |
| 269 | struct pci_dev *pdev; |
| 270 | |
Don Skidmore | f9328bc | 2015-06-18 13:24:06 -0400 | [diff] [blame] | 271 | /* Some devices are not connected over PCIe and thus do not negotiate |
| 272 | * speed. These devices do not have valid bus info, and thus any report |
| 273 | * we generate may not be correct. |
| 274 | */ |
| 275 | if (hw->bus.type == ixgbe_bus_type_internal) |
| 276 | return; |
| 277 | |
Jacob Keller | 56d1392 | 2015-06-10 11:44:45 -0700 | [diff] [blame] | 278 | /* determine whether to use the parent device */ |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 279 | if (ixgbe_pcie_from_parent(&adapter->hw)) |
| 280 | pdev = adapter->pdev->bus->parent->self; |
| 281 | else |
| 282 | pdev = adapter->pdev; |
| 283 | |
| 284 | if (pcie_get_minimum_link(pdev, &speed, &width) || |
| 285 | speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) { |
| 286 | e_dev_warn("Unable to determine PCI Express bandwidth.\n"); |
| 287 | return; |
| 288 | } |
| 289 | |
| 290 | switch (speed) { |
| 291 | case PCIE_SPEED_2_5GT: |
| 292 | /* 8b/10b encoding reduces max throughput by 20% */ |
| 293 | max_gts = 2 * width; |
| 294 | break; |
| 295 | case PCIE_SPEED_5_0GT: |
| 296 | /* 8b/10b encoding reduces max throughput by 20% */ |
| 297 | max_gts = 4 * width; |
| 298 | break; |
| 299 | case PCIE_SPEED_8_0GT: |
Jacob Keller | 9f0a433 | 2013-10-18 05:09:19 +0000 | [diff] [blame] | 300 | /* 128b/130b encoding reduces throughput by less than 2% */ |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 301 | max_gts = 8 * width; |
| 302 | break; |
| 303 | default: |
| 304 | e_dev_warn("Unable to determine PCI Express bandwidth.\n"); |
| 305 | return; |
| 306 | } |
| 307 | |
| 308 | e_dev_info("PCI Express bandwidth of %dGT/s available\n", |
| 309 | max_gts); |
| 310 | e_dev_info("(Speed:%s, Width: x%d, Encoding Loss:%s)\n", |
| 311 | (speed == PCIE_SPEED_8_0GT ? "8.0GT/s" : |
| 312 | speed == PCIE_SPEED_5_0GT ? "5.0GT/s" : |
| 313 | speed == PCIE_SPEED_2_5GT ? "2.5GT/s" : |
| 314 | "Unknown"), |
| 315 | width, |
| 316 | (speed == PCIE_SPEED_2_5GT ? "20%" : |
| 317 | speed == PCIE_SPEED_5_0GT ? "20%" : |
Jacob Keller | 9f0a433 | 2013-10-18 05:09:19 +0000 | [diff] [blame] | 318 | speed == PCIE_SPEED_8_0GT ? "<2%" : |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 319 | "Unknown")); |
| 320 | |
| 321 | if (max_gts < expected_gts) { |
| 322 | e_dev_warn("This is not sufficient for optimal performance of this card.\n"); |
| 323 | e_dev_warn("For optimal performance, at least %dGT/s of bandwidth is required.\n", |
| 324 | expected_gts); |
| 325 | e_dev_warn("A slot with more lanes and/or higher speed is suggested.\n"); |
| 326 | } |
| 327 | } |
| 328 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 329 | static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter) |
| 330 | { |
| 331 | if (!test_bit(__IXGBE_DOWN, &adapter->state) && |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 332 | !test_bit(__IXGBE_REMOVING, &adapter->state) && |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 333 | !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state)) |
Mark Rustad | 780484d | 2015-10-21 17:21:10 -0700 | [diff] [blame] | 334 | queue_work(ixgbe_wq, &adapter->service_task); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 335 | } |
| 336 | |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 337 | static void ixgbe_remove_adapter(struct ixgbe_hw *hw) |
| 338 | { |
| 339 | struct ixgbe_adapter *adapter = hw->back; |
| 340 | |
| 341 | if (!hw->hw_addr) |
| 342 | return; |
| 343 | hw->hw_addr = NULL; |
| 344 | e_dev_err("Adapter removed\n"); |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 345 | if (test_bit(__IXGBE_SERVICE_INITED, &adapter->state)) |
| 346 | ixgbe_service_event_schedule(adapter); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 347 | } |
| 348 | |
Mark Rustad | f8e2472 | 2014-03-18 07:03:40 +0000 | [diff] [blame] | 349 | static void ixgbe_check_remove(struct ixgbe_hw *hw, u32 reg) |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 350 | { |
| 351 | u32 value; |
| 352 | |
| 353 | /* The following check not only optimizes a bit by not |
| 354 | * performing a read on the status register when the |
| 355 | * register just read was a status register read that |
| 356 | * returned IXGBE_FAILED_READ_REG. It also blocks any |
| 357 | * potential recursion. |
| 358 | */ |
| 359 | if (reg == IXGBE_STATUS) { |
| 360 | ixgbe_remove_adapter(hw); |
| 361 | return; |
| 362 | } |
| 363 | value = ixgbe_read_reg(hw, IXGBE_STATUS); |
| 364 | if (value == IXGBE_FAILED_READ_REG) |
| 365 | ixgbe_remove_adapter(hw); |
| 366 | } |
| 367 | |
Mark Rustad | f8e2472 | 2014-03-18 07:03:40 +0000 | [diff] [blame] | 368 | /** |
| 369 | * ixgbe_read_reg - Read from device register |
| 370 | * @hw: hw specific details |
| 371 | * @reg: offset of register to read |
| 372 | * |
| 373 | * Returns : value read or IXGBE_FAILED_READ_REG if removed |
| 374 | * |
| 375 | * This function is used to read device registers. It checks for device |
| 376 | * removal by confirming any read that returns all ones by checking the |
| 377 | * status register value for all ones. This function avoids reading from |
| 378 | * the hardware if a removal was previously detected in which case it |
| 379 | * returns IXGBE_FAILED_READ_REG (all ones). |
| 380 | */ |
| 381 | u32 ixgbe_read_reg(struct ixgbe_hw *hw, u32 reg) |
| 382 | { |
Mark Rutland | 6aa7de0 | 2017-10-23 14:07:29 -0700 | [diff] [blame] | 383 | u8 __iomem *reg_addr = READ_ONCE(hw->hw_addr); |
Mark Rustad | f8e2472 | 2014-03-18 07:03:40 +0000 | [diff] [blame] | 384 | u32 value; |
| 385 | |
| 386 | if (ixgbe_removed(reg_addr)) |
| 387 | return IXGBE_FAILED_READ_REG; |
Mark Rustad | 2f2219b | 2016-04-07 10:43:50 -0700 | [diff] [blame] | 388 | if (unlikely(hw->phy.nw_mng_if_sel & |
Tony Nguyen | 48301cf | 2017-06-07 14:36:19 -0700 | [diff] [blame] | 389 | IXGBE_NW_MNG_IF_SEL_SGMII_ENABLE)) { |
Mark Rustad | 2f2219b | 2016-04-07 10:43:50 -0700 | [diff] [blame] | 390 | struct ixgbe_adapter *adapter; |
| 391 | int i; |
| 392 | |
| 393 | for (i = 0; i < 200; ++i) { |
| 394 | value = readl(reg_addr + IXGBE_MAC_SGMII_BUSY); |
| 395 | if (likely(!value)) |
| 396 | goto writes_completed; |
| 397 | if (value == IXGBE_FAILED_READ_REG) { |
| 398 | ixgbe_remove_adapter(hw); |
| 399 | return IXGBE_FAILED_READ_REG; |
| 400 | } |
| 401 | udelay(5); |
| 402 | } |
| 403 | |
| 404 | adapter = hw->back; |
| 405 | e_warn(hw, "register writes incomplete %08x\n", value); |
| 406 | } |
| 407 | |
| 408 | writes_completed: |
Mark Rustad | f8e2472 | 2014-03-18 07:03:40 +0000 | [diff] [blame] | 409 | value = readl(reg_addr + reg); |
| 410 | if (unlikely(value == IXGBE_FAILED_READ_REG)) |
| 411 | ixgbe_check_remove(hw, reg); |
| 412 | return value; |
| 413 | } |
| 414 | |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 415 | static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev) |
| 416 | { |
| 417 | u16 value; |
| 418 | |
| 419 | pci_read_config_word(pdev, PCI_VENDOR_ID, &value); |
| 420 | if (value == IXGBE_FAILED_READ_CFG_WORD) { |
| 421 | ixgbe_remove_adapter(hw); |
| 422 | return true; |
| 423 | } |
| 424 | return false; |
| 425 | } |
| 426 | |
| 427 | u16 ixgbe_read_pci_cfg_word(struct ixgbe_hw *hw, u32 reg) |
| 428 | { |
| 429 | struct ixgbe_adapter *adapter = hw->back; |
| 430 | u16 value; |
| 431 | |
| 432 | if (ixgbe_removed(hw->hw_addr)) |
| 433 | return IXGBE_FAILED_READ_CFG_WORD; |
| 434 | pci_read_config_word(adapter->pdev, reg, &value); |
| 435 | if (value == IXGBE_FAILED_READ_CFG_WORD && |
| 436 | ixgbe_check_cfg_remove(hw, adapter->pdev)) |
| 437 | return IXGBE_FAILED_READ_CFG_WORD; |
| 438 | return value; |
| 439 | } |
| 440 | |
| 441 | #ifdef CONFIG_PCI_IOV |
| 442 | static u32 ixgbe_read_pci_cfg_dword(struct ixgbe_hw *hw, u32 reg) |
| 443 | { |
| 444 | struct ixgbe_adapter *adapter = hw->back; |
| 445 | u32 value; |
| 446 | |
| 447 | if (ixgbe_removed(hw->hw_addr)) |
| 448 | return IXGBE_FAILED_READ_CFG_DWORD; |
| 449 | pci_read_config_dword(adapter->pdev, reg, &value); |
| 450 | if (value == IXGBE_FAILED_READ_CFG_DWORD && |
| 451 | ixgbe_check_cfg_remove(hw, adapter->pdev)) |
| 452 | return IXGBE_FAILED_READ_CFG_DWORD; |
| 453 | return value; |
| 454 | } |
| 455 | #endif /* CONFIG_PCI_IOV */ |
| 456 | |
Jacob Keller | ed19231 | 2014-02-22 01:23:53 +0000 | [diff] [blame] | 457 | void ixgbe_write_pci_cfg_word(struct ixgbe_hw *hw, u32 reg, u16 value) |
| 458 | { |
| 459 | struct ixgbe_adapter *adapter = hw->back; |
| 460 | |
| 461 | if (ixgbe_removed(hw->hw_addr)) |
| 462 | return; |
| 463 | pci_write_config_word(adapter->pdev, reg, value); |
| 464 | } |
| 465 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 466 | static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter) |
| 467 | { |
| 468 | BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state)); |
| 469 | |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 470 | /* flush memory to make sure state is correct before next watchdog */ |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 471 | smp_mb__before_atomic(); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 472 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
| 473 | } |
| 474 | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 475 | struct ixgbe_reg_info { |
| 476 | u32 ofs; |
| 477 | char *name; |
| 478 | }; |
| 479 | |
| 480 | static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = { |
| 481 | |
| 482 | /* General Registers */ |
| 483 | {IXGBE_CTRL, "CTRL"}, |
| 484 | {IXGBE_STATUS, "STATUS"}, |
| 485 | {IXGBE_CTRL_EXT, "CTRL_EXT"}, |
| 486 | |
| 487 | /* Interrupt Registers */ |
| 488 | {IXGBE_EICR, "EICR"}, |
| 489 | |
| 490 | /* RX Registers */ |
| 491 | {IXGBE_SRRCTL(0), "SRRCTL"}, |
| 492 | {IXGBE_DCA_RXCTRL(0), "DRXCTL"}, |
| 493 | {IXGBE_RDLEN(0), "RDLEN"}, |
| 494 | {IXGBE_RDH(0), "RDH"}, |
| 495 | {IXGBE_RDT(0), "RDT"}, |
| 496 | {IXGBE_RXDCTL(0), "RXDCTL"}, |
| 497 | {IXGBE_RDBAL(0), "RDBAL"}, |
| 498 | {IXGBE_RDBAH(0), "RDBAH"}, |
| 499 | |
| 500 | /* TX Registers */ |
| 501 | {IXGBE_TDBAL(0), "TDBAL"}, |
| 502 | {IXGBE_TDBAH(0), "TDBAH"}, |
| 503 | {IXGBE_TDLEN(0), "TDLEN"}, |
| 504 | {IXGBE_TDH(0), "TDH"}, |
| 505 | {IXGBE_TDT(0), "TDT"}, |
| 506 | {IXGBE_TXDCTL(0), "TXDCTL"}, |
| 507 | |
| 508 | /* List Terminator */ |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 509 | { .name = NULL } |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 510 | }; |
| 511 | |
| 512 | |
| 513 | /* |
| 514 | * ixgbe_regdump - register printout routine |
| 515 | */ |
| 516 | static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo) |
| 517 | { |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 518 | int i; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 519 | char rname[16]; |
| 520 | u32 regs[64]; |
| 521 | |
| 522 | switch (reginfo->ofs) { |
| 523 | case IXGBE_SRRCTL(0): |
| 524 | for (i = 0; i < 64; i++) |
| 525 | regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i)); |
| 526 | break; |
| 527 | case IXGBE_DCA_RXCTRL(0): |
| 528 | for (i = 0; i < 64; i++) |
| 529 | regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i)); |
| 530 | break; |
| 531 | case IXGBE_RDLEN(0): |
| 532 | for (i = 0; i < 64; i++) |
| 533 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i)); |
| 534 | break; |
| 535 | case IXGBE_RDH(0): |
| 536 | for (i = 0; i < 64; i++) |
| 537 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i)); |
| 538 | break; |
| 539 | case IXGBE_RDT(0): |
| 540 | for (i = 0; i < 64; i++) |
| 541 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i)); |
| 542 | break; |
| 543 | case IXGBE_RXDCTL(0): |
| 544 | for (i = 0; i < 64; i++) |
| 545 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i)); |
| 546 | break; |
| 547 | case IXGBE_RDBAL(0): |
| 548 | for (i = 0; i < 64; i++) |
| 549 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i)); |
| 550 | break; |
| 551 | case IXGBE_RDBAH(0): |
| 552 | for (i = 0; i < 64; i++) |
| 553 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i)); |
| 554 | break; |
| 555 | case IXGBE_TDBAL(0): |
| 556 | for (i = 0; i < 64; i++) |
| 557 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i)); |
| 558 | break; |
| 559 | case IXGBE_TDBAH(0): |
| 560 | for (i = 0; i < 64; i++) |
| 561 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i)); |
| 562 | break; |
| 563 | case IXGBE_TDLEN(0): |
| 564 | for (i = 0; i < 64; i++) |
| 565 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i)); |
| 566 | break; |
| 567 | case IXGBE_TDH(0): |
| 568 | for (i = 0; i < 64; i++) |
| 569 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i)); |
| 570 | break; |
| 571 | case IXGBE_TDT(0): |
| 572 | for (i = 0; i < 64; i++) |
| 573 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i)); |
| 574 | break; |
| 575 | case IXGBE_TXDCTL(0): |
| 576 | for (i = 0; i < 64; i++) |
| 577 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i)); |
| 578 | break; |
| 579 | default: |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 580 | pr_info("%-15s %08x\n", |
| 581 | reginfo->name, IXGBE_READ_REG(hw, reginfo->ofs)); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 582 | return; |
| 583 | } |
| 584 | |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 585 | i = 0; |
| 586 | while (i < 64) { |
| 587 | int j; |
| 588 | char buf[9 * 8 + 1]; |
| 589 | char *p = buf; |
| 590 | |
| 591 | snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i, i + 7); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 592 | for (j = 0; j < 8; j++) |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 593 | p += sprintf(p, " %08x", regs[i++]); |
| 594 | pr_err("%-15s%s\n", rname, buf); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | } |
| 598 | |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 599 | static void ixgbe_print_buffer(struct ixgbe_ring *ring, int n) |
| 600 | { |
| 601 | struct ixgbe_tx_buffer *tx_buffer; |
| 602 | |
| 603 | tx_buffer = &ring->tx_buffer_info[ring->next_to_clean]; |
| 604 | pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n", |
| 605 | n, ring->next_to_use, ring->next_to_clean, |
| 606 | (u64)dma_unmap_addr(tx_buffer, dma), |
| 607 | dma_unmap_len(tx_buffer, len), |
| 608 | tx_buffer->next_to_watch, |
| 609 | (u64)tx_buffer->time_stamp); |
| 610 | } |
| 611 | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 612 | /* |
| 613 | * ixgbe_dump - Print registers, tx-rings and rx-rings |
| 614 | */ |
| 615 | static void ixgbe_dump(struct ixgbe_adapter *adapter) |
| 616 | { |
| 617 | struct net_device *netdev = adapter->netdev; |
| 618 | struct ixgbe_hw *hw = &adapter->hw; |
| 619 | struct ixgbe_reg_info *reginfo; |
| 620 | int n = 0; |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 621 | struct ixgbe_ring *ring; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 622 | struct ixgbe_tx_buffer *tx_buffer; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 623 | union ixgbe_adv_tx_desc *tx_desc; |
| 624 | struct my_u0 { u64 a; u64 b; } *u0; |
| 625 | struct ixgbe_ring *rx_ring; |
| 626 | union ixgbe_adv_rx_desc *rx_desc; |
| 627 | struct ixgbe_rx_buffer *rx_buffer_info; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 628 | int i = 0; |
| 629 | |
| 630 | if (!netif_msg_hw(adapter)) |
| 631 | return; |
| 632 | |
| 633 | /* Print netdevice Info */ |
| 634 | if (netdev) { |
| 635 | dev_info(&adapter->pdev->dev, "Net device Info\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 636 | pr_info("Device Name state " |
Tobias Klauser | 4a7c972 | 2017-01-18 17:45:01 +0100 | [diff] [blame] | 637 | "trans_start\n"); |
| 638 | pr_info("%-15s %016lX %016lX\n", |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 639 | netdev->name, |
| 640 | netdev->state, |
Tobias Klauser | 4a7c972 | 2017-01-18 17:45:01 +0100 | [diff] [blame] | 641 | dev_trans_start(netdev)); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | /* Print Registers */ |
| 645 | dev_info(&adapter->pdev->dev, "Register Dump\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 646 | pr_info(" Register Name Value\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 647 | for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl; |
| 648 | reginfo->name; reginfo++) { |
| 649 | ixgbe_regdump(hw, reginfo); |
| 650 | } |
| 651 | |
| 652 | /* Print TX Ring Summary */ |
| 653 | if (!netdev || !netif_running(netdev)) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 654 | return; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 655 | |
| 656 | dev_info(&adapter->pdev->dev, "TX Rings Summary\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 657 | pr_info(" %s %s %s %s\n", |
| 658 | "Queue [NTU] [NTC] [bi(ntc)->dma ]", |
| 659 | "leng", "ntw", "timestamp"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 660 | for (n = 0; n < adapter->num_tx_queues; n++) { |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 661 | ring = adapter->tx_ring[n]; |
| 662 | ixgbe_print_buffer(ring, n); |
| 663 | } |
| 664 | |
| 665 | for (n = 0; n < adapter->num_xdp_queues; n++) { |
| 666 | ring = adapter->xdp_ring[n]; |
| 667 | ixgbe_print_buffer(ring, n); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | /* Print TX Rings */ |
| 671 | if (!netif_msg_tx_done(adapter)) |
| 672 | goto rx_ring_summary; |
| 673 | |
| 674 | dev_info(&adapter->pdev->dev, "TX Rings Dump\n"); |
| 675 | |
| 676 | /* Transmit Descriptor Formats |
| 677 | * |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 678 | * 82598 Advanced Transmit Descriptor |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 679 | * +--------------------------------------------------------------+ |
| 680 | * 0 | Buffer Address [63:0] | |
| 681 | * +--------------------------------------------------------------+ |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 682 | * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 683 | * +--------------------------------------------------------------+ |
| 684 | * 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] | 685 | * |
| 686 | * 82598 Advanced Transmit Descriptor (Write-Back Format) |
| 687 | * +--------------------------------------------------------------+ |
| 688 | * 0 | RSV [63:0] | |
| 689 | * +--------------------------------------------------------------+ |
| 690 | * 8 | RSV | STA | NXTSEQ | |
| 691 | * +--------------------------------------------------------------+ |
| 692 | * 63 36 35 32 31 0 |
| 693 | * |
| 694 | * 82599+ Advanced Transmit Descriptor |
| 695 | * +--------------------------------------------------------------+ |
| 696 | * 0 | Buffer Address [63:0] | |
| 697 | * +--------------------------------------------------------------+ |
| 698 | * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN | |
| 699 | * +--------------------------------------------------------------+ |
| 700 | * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0 |
| 701 | * |
| 702 | * 82599+ Advanced Transmit Descriptor (Write-Back Format) |
| 703 | * +--------------------------------------------------------------+ |
| 704 | * 0 | RSV [63:0] | |
| 705 | * +--------------------------------------------------------------+ |
| 706 | * 8 | RSV | STA | RSV | |
| 707 | * +--------------------------------------------------------------+ |
| 708 | * 63 36 35 32 31 0 |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 709 | */ |
| 710 | |
| 711 | for (n = 0; n < adapter->num_tx_queues; n++) { |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 712 | ring = adapter->tx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 713 | pr_info("------------------------------------\n"); |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 714 | pr_info("TX QUEUE INDEX = %d\n", ring->queue_index); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 715 | pr_info("------------------------------------\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 716 | pr_info("%s%s %s %s %s %s\n", |
| 717 | "T [desc] [address 63:0 ] ", |
| 718 | "[PlPOIdStDDt Ln] [bi->dma ] ", |
| 719 | "leng", "ntw", "timestamp", "bi->skb"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 720 | |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 721 | for (i = 0; ring->desc && (i < ring->count); i++) { |
| 722 | tx_desc = IXGBE_TX_DESC(ring, i); |
| 723 | tx_buffer = &ring->tx_buffer_info[i]; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 724 | u0 = (struct my_u0 *)tx_desc; |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 725 | if (dma_unmap_len(tx_buffer, len) > 0) { |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 726 | const char *ring_desc; |
| 727 | |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 728 | if (i == ring->next_to_use && |
| 729 | i == ring->next_to_clean) |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 730 | ring_desc = " NTC/U"; |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 731 | else if (i == ring->next_to_use) |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 732 | ring_desc = " NTU"; |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 733 | else if (i == ring->next_to_clean) |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 734 | ring_desc = " NTC"; |
| 735 | else |
| 736 | ring_desc = ""; |
| 737 | pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p%s", |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 738 | i, |
| 739 | le64_to_cpu(u0->a), |
| 740 | le64_to_cpu(u0->b), |
| 741 | (u64)dma_unmap_addr(tx_buffer, dma), |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 742 | dma_unmap_len(tx_buffer, len), |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 743 | tx_buffer->next_to_watch, |
| 744 | (u64)tx_buffer->time_stamp, |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 745 | tx_buffer->skb, |
| 746 | ring_desc); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 747 | |
| 748 | if (netif_msg_pktdata(adapter) && |
| 749 | tx_buffer->skb) |
| 750 | print_hex_dump(KERN_INFO, "", |
| 751 | DUMP_PREFIX_ADDRESS, 16, 1, |
| 752 | tx_buffer->skb->data, |
| 753 | dma_unmap_len(tx_buffer, len), |
| 754 | true); |
| 755 | } |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 756 | } |
| 757 | } |
| 758 | |
| 759 | /* Print RX Rings Summary */ |
| 760 | rx_ring_summary: |
| 761 | dev_info(&adapter->pdev->dev, "RX Rings Summary\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 762 | pr_info("Queue [NTU] [NTC]\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 763 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 764 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 765 | pr_info("%5d %5X %5X\n", |
| 766 | n, rx_ring->next_to_use, rx_ring->next_to_clean); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | /* Print RX Rings */ |
| 770 | if (!netif_msg_rx_status(adapter)) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 771 | return; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 772 | |
| 773 | dev_info(&adapter->pdev->dev, "RX Rings Dump\n"); |
| 774 | |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 775 | /* Receive Descriptor Formats |
| 776 | * |
| 777 | * 82598 Advanced Receive Descriptor (Read) Format |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 778 | * 63 1 0 |
| 779 | * +-----------------------------------------------------+ |
| 780 | * 0 | Packet Buffer Address [63:1] |A0/NSE| |
| 781 | * +----------------------------------------------+------+ |
| 782 | * 8 | Header Buffer Address [63:1] | DD | |
| 783 | * +-----------------------------------------------------+ |
| 784 | * |
| 785 | * |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 786 | * 82598 Advanced Receive Descriptor (Write-Back) Format |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 787 | * |
| 788 | * 63 48 47 32 31 30 21 20 16 15 4 3 0 |
| 789 | * +------------------------------------------------------+ |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 790 | * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS | |
| 791 | * | Packet | IP | | | | Type | Type | |
| 792 | * | Checksum | Ident | | | | | | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 793 | * +------------------------------------------------------+ |
| 794 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | |
| 795 | * +------------------------------------------------------+ |
| 796 | * 63 48 47 32 31 20 19 0 |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 797 | * |
| 798 | * 82599+ Advanced Receive Descriptor (Read) Format |
| 799 | * 63 1 0 |
| 800 | * +-----------------------------------------------------+ |
| 801 | * 0 | Packet Buffer Address [63:1] |A0/NSE| |
| 802 | * +----------------------------------------------+------+ |
| 803 | * 8 | Header Buffer Address [63:1] | DD | |
| 804 | * +-----------------------------------------------------+ |
| 805 | * |
| 806 | * |
| 807 | * 82599+ Advanced Receive Descriptor (Write-Back) Format |
| 808 | * |
| 809 | * 63 48 47 32 31 30 21 20 17 16 4 3 0 |
| 810 | * +------------------------------------------------------+ |
| 811 | * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS | |
| 812 | * |/ RTT / PCoE_PARAM | | | CNT | Type | Type | |
| 813 | * |/ Flow Dir Flt ID | | | | | | |
| 814 | * +------------------------------------------------------+ |
| 815 | * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP | |
| 816 | * +------------------------------------------------------+ |
| 817 | * 63 48 47 32 31 20 19 0 |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 818 | */ |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 819 | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 820 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 821 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 822 | pr_info("------------------------------------\n"); |
| 823 | pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index); |
| 824 | pr_info("------------------------------------\n"); |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 825 | pr_info("%s%s%s\n", |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 826 | "R [desc] [ PktBuf A0] ", |
| 827 | "[ HeadBuf DD] [bi->dma ] [bi->skb ] ", |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 828 | "<-- Adv Rx Read format"); |
| 829 | pr_info("%s%s%s\n", |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 830 | "RWB[desc] [PcsmIpSHl PtRs] ", |
| 831 | "[vl er S cks ln] ---------------- [bi->skb ] ", |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 832 | "<-- Adv Rx Write-Back format"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 833 | |
| 834 | for (i = 0; i < rx_ring->count; i++) { |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 835 | const char *ring_desc; |
| 836 | |
| 837 | if (i == rx_ring->next_to_use) |
| 838 | ring_desc = " NTU"; |
| 839 | else if (i == rx_ring->next_to_clean) |
| 840 | ring_desc = " NTC"; |
| 841 | else |
| 842 | ring_desc = ""; |
| 843 | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 844 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 845 | rx_desc = IXGBE_RX_DESC(rx_ring, i); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 846 | u0 = (struct my_u0 *)rx_desc; |
Alexander Duyck | 18a8cc9 | 2017-03-02 15:01:36 -0800 | [diff] [blame] | 847 | if (rx_desc->wb.upper.length) { |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 848 | /* Descriptor Done */ |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 849 | pr_info("RWB[0x%03X] %016llX %016llX ---------------- %p%s\n", |
| 850 | i, |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 851 | le64_to_cpu(u0->a), |
| 852 | le64_to_cpu(u0->b), |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 853 | rx_buffer_info->skb, |
| 854 | ring_desc); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 855 | } else { |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 856 | pr_info("R [0x%03X] %016llX %016llX %016llX %p%s\n", |
| 857 | i, |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 858 | le64_to_cpu(u0->a), |
| 859 | le64_to_cpu(u0->b), |
| 860 | (u64)rx_buffer_info->dma, |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 861 | rx_buffer_info->skb, |
| 862 | ring_desc); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 863 | |
Emil Tantilov | 9c50c03 | 2012-07-26 01:21:24 +0000 | [diff] [blame] | 864 | if (netif_msg_pktdata(adapter) && |
| 865 | rx_buffer_info->dma) { |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 866 | print_hex_dump(KERN_INFO, "", |
| 867 | DUMP_PREFIX_ADDRESS, 16, 1, |
Emil Tantilov | 9c50c03 | 2012-07-26 01:21:24 +0000 | [diff] [blame] | 868 | page_address(rx_buffer_info->page) + |
| 869 | rx_buffer_info->page_offset, |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 870 | ixgbe_rx_bufsz(rx_ring), true); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 871 | } |
| 872 | } |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 873 | } |
| 874 | } |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 875 | } |
| 876 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 877 | static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter) |
| 878 | { |
| 879 | u32 ctrl_ext; |
| 880 | |
| 881 | /* Let firmware take over control of h/w */ |
| 882 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 883 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 884 | ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter) |
| 888 | { |
| 889 | u32 ctrl_ext; |
| 890 | |
| 891 | /* Let firmware know the driver has taken over */ |
| 892 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 893 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 894 | ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 895 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 896 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 897 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 898 | * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors |
| 899 | * @adapter: pointer to adapter struct |
| 900 | * @direction: 0 for Rx, 1 for Tx, -1 for other causes |
| 901 | * @queue: queue to map the corresponding interrupt to |
| 902 | * @msix_vector: the vector to map to the corresponding queue |
| 903 | * |
| 904 | */ |
| 905 | static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 906 | u8 queue, u8 msix_vector) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 907 | { |
| 908 | u32 ivar, index; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 909 | struct ixgbe_hw *hw = &adapter->hw; |
| 910 | switch (hw->mac.type) { |
| 911 | case ixgbe_mac_82598EB: |
| 912 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 913 | if (direction == -1) |
| 914 | direction = 0; |
| 915 | index = (((direction * 64) + queue) >> 2) & 0x1F; |
| 916 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index)); |
| 917 | ivar &= ~(0xFF << (8 * (queue & 0x3))); |
| 918 | ivar |= (msix_vector << (8 * (queue & 0x3))); |
| 919 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar); |
| 920 | break; |
| 921 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 922 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 923 | case ixgbe_mac_X550: |
| 924 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 925 | case ixgbe_mac_x550em_a: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 926 | if (direction == -1) { |
| 927 | /* other causes */ |
| 928 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 929 | index = ((queue & 1) * 8); |
| 930 | ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC); |
| 931 | ivar &= ~(0xFF << index); |
| 932 | ivar |= (msix_vector << index); |
| 933 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar); |
| 934 | break; |
| 935 | } else { |
| 936 | /* tx or rx causes */ |
| 937 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 938 | index = ((16 * (queue & 1)) + (8 * direction)); |
| 939 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1)); |
| 940 | ivar &= ~(0xFF << index); |
| 941 | ivar |= (msix_vector << index); |
| 942 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar); |
| 943 | break; |
| 944 | } |
| 945 | default: |
| 946 | break; |
| 947 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 948 | } |
| 949 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 950 | static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 951 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 952 | { |
| 953 | u32 mask; |
| 954 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 955 | switch (adapter->hw.mac.type) { |
| 956 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 957 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 958 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 959 | break; |
| 960 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 961 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 962 | case ixgbe_mac_X550: |
| 963 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 964 | case ixgbe_mac_x550em_a: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 965 | mask = (qmask & 0xFFFFFFFF); |
| 966 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask); |
| 967 | mask = (qmask >> 32); |
| 968 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 969 | break; |
| 970 | default: |
| 971 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 972 | } |
| 973 | } |
| 974 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 975 | static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter) |
| 976 | { |
| 977 | struct ixgbe_hw *hw = &adapter->hw; |
| 978 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
| 979 | int i; |
| 980 | u32 data; |
| 981 | |
| 982 | if ((hw->fc.current_mode != ixgbe_fc_full) && |
| 983 | (hw->fc.current_mode != ixgbe_fc_rx_pause)) |
| 984 | return; |
| 985 | |
| 986 | switch (hw->mac.type) { |
| 987 | case ixgbe_mac_82598EB: |
| 988 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); |
| 989 | break; |
| 990 | default: |
| 991 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); |
| 992 | } |
| 993 | hwstats->lxoffrxc += data; |
| 994 | |
| 995 | /* refill credits (no tx hang) if we received xoff */ |
| 996 | if (!data) |
| 997 | return; |
| 998 | |
| 999 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 1000 | clear_bit(__IXGBE_HANG_CHECK_ARMED, |
| 1001 | &adapter->tx_ring[i]->state); |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 1002 | |
| 1003 | for (i = 0; i < adapter->num_xdp_queues; i++) |
| 1004 | clear_bit(__IXGBE_HANG_CHECK_ARMED, |
| 1005 | &adapter->xdp_ring[i]->state); |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1008 | static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1009 | { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1010 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1011 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1012 | u32 xoff[8] = {0}; |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 1013 | u8 tc; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1014 | int i; |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 1015 | bool pfc_en = adapter->dcb_cfg.pfc_mode_enable; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1016 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 1017 | if (adapter->ixgbe_ieee_pfc) |
| 1018 | pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1019 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 1020 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) { |
| 1021 | ixgbe_update_xoff_rx_lfc(adapter); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1022 | return; |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 1023 | } |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1024 | |
| 1025 | /* update stats for each tc, only valid with PFC enabled */ |
| 1026 | for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) { |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 1027 | u32 pxoffrxc; |
| 1028 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1029 | switch (hw->mac.type) { |
| 1030 | case ixgbe_mac_82598EB: |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 1031 | pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i)); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1032 | break; |
| 1033 | default: |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 1034 | pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i)); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1035 | } |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 1036 | hwstats->pxoffrxc[i] += pxoffrxc; |
| 1037 | /* Get the TC for given UP */ |
| 1038 | tc = netdev_get_prio_tc_map(adapter->netdev, i); |
| 1039 | xoff[tc] += pxoffrxc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1040 | } |
| 1041 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1042 | /* disarm tx queues that have received xoff frames */ |
| 1043 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 1044 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1045 | |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 1046 | tc = tx_ring->dcb_tc; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1047 | if (xoff[tc]) |
| 1048 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
| 1049 | } |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 1050 | |
| 1051 | for (i = 0; i < adapter->num_xdp_queues; i++) { |
| 1052 | struct ixgbe_ring *xdp_ring = adapter->xdp_ring[i]; |
| 1053 | |
| 1054 | tc = xdp_ring->dcb_tc; |
| 1055 | if (xoff[tc]) |
| 1056 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &xdp_ring->state); |
| 1057 | } |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring) |
| 1061 | { |
Alexander Duyck | 7d7ce68 | 2012-02-08 07:50:51 +0000 | [diff] [blame] | 1062 | return ring->stats.packets; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring) |
| 1066 | { |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 1067 | struct ixgbe_adapter *adapter; |
| 1068 | struct ixgbe_hw *hw; |
| 1069 | u32 head, tail; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1070 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 1071 | if (ring->l2_accel_priv) |
| 1072 | adapter = ring->l2_accel_priv->real_adapter; |
| 1073 | else |
| 1074 | adapter = netdev_priv(ring->netdev); |
| 1075 | |
| 1076 | hw = &adapter->hw; |
| 1077 | head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx)); |
| 1078 | tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx)); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1079 | |
| 1080 | if (head != tail) |
| 1081 | return (head < tail) ? |
| 1082 | tail - head : (tail + ring->count - head); |
| 1083 | |
| 1084 | return 0; |
| 1085 | } |
| 1086 | |
| 1087 | static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring) |
| 1088 | { |
| 1089 | u32 tx_done = ixgbe_get_tx_completed(tx_ring); |
| 1090 | u32 tx_done_old = tx_ring->tx_stats.tx_done_old; |
| 1091 | u32 tx_pending = ixgbe_get_tx_pending(tx_ring); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1092 | |
| 1093 | clear_check_for_tx_hang(tx_ring); |
| 1094 | |
| 1095 | /* |
| 1096 | * Check for a hung queue, but be thorough. This verifies |
| 1097 | * that a transmit has been completed since the previous |
| 1098 | * check AND there is at least one packet pending. The |
| 1099 | * ARMED bit is set to indicate a potential hang. The |
| 1100 | * bit is cleared if a pause frame is received to remove |
| 1101 | * false hang detection due to PFC or 802.3x frames. By |
| 1102 | * requiring this to fail twice we avoid races with |
| 1103 | * pfc clearing the ARMED bit and conditions where we |
| 1104 | * run the check_tx_hang logic with a transmit completion |
| 1105 | * pending but without time to complete it yet. |
| 1106 | */ |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 1107 | if (tx_done_old == tx_done && tx_pending) |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1108 | /* make sure it is true for two checks in a row */ |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 1109 | return test_and_set_bit(__IXGBE_HANG_CHECK_ARMED, |
| 1110 | &tx_ring->state); |
| 1111 | /* update completed stats and continue */ |
| 1112 | tx_ring->tx_stats.tx_done_old = tx_done; |
| 1113 | /* reset the countdown */ |
| 1114 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1115 | |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 1116 | return false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1117 | } |
| 1118 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 1119 | /** |
| 1120 | * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout |
| 1121 | * @adapter: driver private struct |
| 1122 | **/ |
| 1123 | static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter) |
| 1124 | { |
| 1125 | |
| 1126 | /* Do the reset outside of interrupt context */ |
| 1127 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
Emil Tantilov | 57ca2a4 | 2016-07-29 14:46:31 -0700 | [diff] [blame] | 1128 | set_bit(__IXGBE_RESET_REQUESTED, &adapter->state); |
Jacob Keller | 12ff3f3 | 2012-12-01 07:57:17 +0000 | [diff] [blame] | 1129 | e_warn(drv, "initiating reset due to tx timeout\n"); |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 1130 | ixgbe_service_event_schedule(adapter); |
| 1131 | } |
| 1132 | } |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1133 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1134 | /** |
Rostislav Pehlivanov | c04f90e | 2016-01-27 18:33:30 +0000 | [diff] [blame] | 1135 | * ixgbe_tx_maxrate - callback to set the maximum per-queue bitrate |
| 1136 | **/ |
| 1137 | static int ixgbe_tx_maxrate(struct net_device *netdev, |
| 1138 | int queue_index, u32 maxrate) |
| 1139 | { |
| 1140 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1141 | struct ixgbe_hw *hw = &adapter->hw; |
| 1142 | u32 bcnrc_val = ixgbe_link_mbps(adapter); |
| 1143 | |
| 1144 | if (!maxrate) |
| 1145 | return 0; |
| 1146 | |
| 1147 | /* Calculate the rate factor values to set */ |
| 1148 | bcnrc_val <<= IXGBE_RTTBCNRC_RF_INT_SHIFT; |
| 1149 | bcnrc_val /= maxrate; |
| 1150 | |
| 1151 | /* clear everything but the rate factor */ |
| 1152 | bcnrc_val &= IXGBE_RTTBCNRC_RF_INT_MASK | |
| 1153 | IXGBE_RTTBCNRC_RF_DEC_MASK; |
| 1154 | |
| 1155 | /* enable the rate scheduler */ |
| 1156 | bcnrc_val |= IXGBE_RTTBCNRC_RS_ENA; |
| 1157 | |
| 1158 | IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, queue_index); |
| 1159 | IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val); |
| 1160 | |
| 1161 | return 0; |
| 1162 | } |
| 1163 | |
| 1164 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1165 | * ixgbe_clean_tx_irq - Reclaim resources after transmit completes |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1166 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1167 | * @tx_ring: tx ring to clean |
Alexander Duyck | 8220bbc | 2016-03-07 09:30:09 -0800 | [diff] [blame] | 1168 | * @napi_budget: Used to determine if we are in netpoll |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1169 | **/ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1170 | 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] | 1171 | struct ixgbe_ring *tx_ring, int napi_budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1172 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1173 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1174 | struct ixgbe_tx_buffer *tx_buffer; |
| 1175 | union ixgbe_adv_tx_desc *tx_desc; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1176 | unsigned int total_bytes = 0, total_packets = 0; |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 1177 | unsigned int budget = q_vector->tx.work_limit; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1178 | unsigned int i = tx_ring->next_to_clean; |
| 1179 | |
| 1180 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1181 | return true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1182 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1183 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1184 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1185 | i -= tx_ring->count; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 1186 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1187 | do { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1188 | union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1189 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1190 | /* if next_to_watch is not set then there is no work pending */ |
| 1191 | if (!eop_desc) |
| 1192 | break; |
| 1193 | |
Alexander Duyck | 7f83a9e | 2012-02-08 07:49:23 +0000 | [diff] [blame] | 1194 | /* prevent any other reads prior to eop_desc */ |
Brian King | 0a9a17e | 2017-11-17 11:05:43 -0600 | [diff] [blame] | 1195 | smp_rmb(); |
Alexander Duyck | 7f83a9e | 2012-02-08 07:49:23 +0000 | [diff] [blame] | 1196 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1197 | /* if DD is not set pending work has not been completed */ |
| 1198 | if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD))) |
| 1199 | break; |
| 1200 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1201 | /* clear next_to_watch to prevent false hangs */ |
| 1202 | tx_buffer->next_to_watch = NULL; |
| 1203 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 1204 | /* update the statistics for this packet */ |
| 1205 | total_bytes += tx_buffer->bytecount; |
| 1206 | total_packets += tx_buffer->gso_segs; |
| 1207 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1208 | /* free the skb */ |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 1209 | if (ring_is_xdp(tx_ring)) |
| 1210 | page_frag_free(tx_buffer->data); |
| 1211 | else |
| 1212 | napi_consume_skb(tx_buffer->skb, napi_budget); |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1213 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1214 | /* unmap skb header data */ |
| 1215 | dma_unmap_single(tx_ring->dev, |
| 1216 | dma_unmap_addr(tx_buffer, dma), |
| 1217 | dma_unmap_len(tx_buffer, len), |
| 1218 | DMA_TO_DEVICE); |
| 1219 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1220 | /* clear tx_buffer data */ |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1221 | dma_unmap_len_set(tx_buffer, len, 0); |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1222 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1223 | /* unmap remaining buffers */ |
| 1224 | while (tx_desc != eop_desc) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1225 | tx_buffer++; |
| 1226 | tx_desc++; |
| 1227 | i++; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1228 | if (unlikely(!i)) { |
| 1229 | i -= tx_ring->count; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1230 | tx_buffer = tx_ring->tx_buffer_info; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1231 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1232 | } |
| 1233 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1234 | /* unmap any remaining paged data */ |
| 1235 | if (dma_unmap_len(tx_buffer, len)) { |
| 1236 | dma_unmap_page(tx_ring->dev, |
| 1237 | dma_unmap_addr(tx_buffer, dma), |
| 1238 | dma_unmap_len(tx_buffer, len), |
| 1239 | DMA_TO_DEVICE); |
| 1240 | dma_unmap_len_set(tx_buffer, len, 0); |
| 1241 | } |
| 1242 | } |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 1243 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1244 | /* move us one more past the eop_desc for start of next pkt */ |
| 1245 | tx_buffer++; |
| 1246 | tx_desc++; |
| 1247 | i++; |
| 1248 | if (unlikely(!i)) { |
| 1249 | i -= tx_ring->count; |
| 1250 | tx_buffer = tx_ring->tx_buffer_info; |
| 1251 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
| 1252 | } |
| 1253 | |
| 1254 | /* issue prefetch for next Tx descriptor */ |
| 1255 | prefetch(tx_desc); |
| 1256 | |
| 1257 | /* update budget accounting */ |
| 1258 | budget--; |
| 1259 | } while (likely(budget)); |
| 1260 | |
| 1261 | i += tx_ring->count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1262 | tx_ring->next_to_clean = i; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1263 | u64_stats_update_begin(&tx_ring->syncp); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1264 | tx_ring->stats.bytes += total_bytes; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1265 | tx_ring->stats.packets += total_packets; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1266 | u64_stats_update_end(&tx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1267 | q_vector->tx.total_bytes += total_bytes; |
| 1268 | q_vector->tx.total_packets += total_packets; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1269 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1270 | 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] | 1271 | /* schedule immediate reset if we believe we hung */ |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1272 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 1273 | e_err(drv, "Detected Tx Unit Hang %s\n" |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1274 | " Tx Queue <%d>\n" |
| 1275 | " TDH, TDT <%x>, <%x>\n" |
| 1276 | " next_to_use <%x>\n" |
| 1277 | " next_to_clean <%x>\n" |
| 1278 | "tx_buffer_info[next_to_clean]\n" |
| 1279 | " time_stamp <%lx>\n" |
| 1280 | " jiffies <%lx>\n", |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 1281 | ring_is_xdp(tx_ring) ? "(XDP)" : "", |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1282 | tx_ring->queue_index, |
| 1283 | IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)), |
| 1284 | IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)), |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1285 | tx_ring->next_to_use, i, |
| 1286 | tx_ring->tx_buffer_info[i].time_stamp, jiffies); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1287 | |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 1288 | if (!ring_is_xdp(tx_ring)) |
| 1289 | netif_stop_subqueue(tx_ring->netdev, |
| 1290 | tx_ring->queue_index); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1291 | |
| 1292 | e_info(probe, |
| 1293 | "tx hang %d detected on queue %d, resetting adapter\n", |
| 1294 | adapter->tx_timeout_count + 1, tx_ring->queue_index); |
| 1295 | |
| 1296 | /* schedule immediate reset if we believe we hung */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 1297 | ixgbe_tx_timeout_reset(adapter); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1298 | |
| 1299 | /* the adapter is about to reset, no point in enabling stuff */ |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 1300 | return true; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1301 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1302 | |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 1303 | if (ring_is_xdp(tx_ring)) |
| 1304 | return !!budget; |
| 1305 | |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 1306 | netdev_tx_completed_queue(txring_txq(tx_ring), |
| 1307 | total_packets, total_bytes); |
| 1308 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 1309 | #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) |
Alexander Duyck | 30065e6 | 2011-07-15 03:05:14 +0000 | [diff] [blame] | 1310 | if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) && |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 1311 | (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 1312 | /* Make sure that anybody stopping the queue after this |
| 1313 | * sees the new next_to_clean. |
| 1314 | */ |
| 1315 | smp_mb(); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1316 | if (__netif_subqueue_stopped(tx_ring->netdev, |
| 1317 | tx_ring->queue_index) |
| 1318 | && !test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1319 | netif_wake_subqueue(tx_ring->netdev, |
| 1320 | tx_ring->queue_index); |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 1321 | ++tx_ring->tx_stats.restart_queue; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 1322 | } |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 1323 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1324 | |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 1325 | return !!budget; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1326 | } |
| 1327 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1328 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1329 | static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter, |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1330 | struct ixgbe_ring *tx_ring, |
| 1331 | int cpu) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1332 | { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 1333 | struct ixgbe_hw *hw = &adapter->hw; |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1334 | u32 txctrl = 0; |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1335 | u16 reg_offset; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1336 | |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1337 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1338 | txctrl = dca3_get_tag(tx_ring->dev, cpu); |
| 1339 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1340 | switch (hw->mac.type) { |
| 1341 | case ixgbe_mac_82598EB: |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1342 | reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1343 | break; |
| 1344 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1345 | case ixgbe_mac_X540: |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1346 | reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx); |
| 1347 | txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599; |
| 1348 | break; |
| 1349 | default: |
| 1350 | /* for unknown hardware do not write register */ |
| 1351 | return; |
| 1352 | } |
| 1353 | |
| 1354 | /* |
| 1355 | * We can enable relaxed ordering for reads, but not writes when |
| 1356 | * DCA is enabled. This is due to a known issue in some chipsets |
| 1357 | * which will cause the DCA tag to be cleared. |
| 1358 | */ |
| 1359 | txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN | |
| 1360 | IXGBE_DCA_TXCTRL_DATA_RRO_EN | |
| 1361 | IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
| 1362 | |
| 1363 | IXGBE_WRITE_REG(hw, reg_offset, txctrl); |
| 1364 | } |
| 1365 | |
| 1366 | static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter, |
| 1367 | struct ixgbe_ring *rx_ring, |
| 1368 | int cpu) |
| 1369 | { |
| 1370 | struct ixgbe_hw *hw = &adapter->hw; |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1371 | u32 rxctrl = 0; |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1372 | u8 reg_idx = rx_ring->reg_idx; |
| 1373 | |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1374 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1375 | rxctrl = dca3_get_tag(rx_ring->dev, cpu); |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1376 | |
| 1377 | switch (hw->mac.type) { |
| 1378 | case ixgbe_mac_82599EB: |
| 1379 | case ixgbe_mac_X540: |
| 1380 | rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1381 | break; |
| 1382 | default: |
| 1383 | break; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1384 | } |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1385 | |
| 1386 | /* |
| 1387 | * We can enable relaxed ordering for reads, but not writes when |
| 1388 | * DCA is enabled. This is due to a known issue in some chipsets |
| 1389 | * which will cause the DCA tag to be cleared. |
| 1390 | */ |
| 1391 | rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN | |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1392 | IXGBE_DCA_RXCTRL_DATA_DCA_EN | |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1393 | IXGBE_DCA_RXCTRL_DESC_DCA_EN; |
| 1394 | |
| 1395 | IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1396 | } |
| 1397 | |
| 1398 | static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector) |
| 1399 | { |
| 1400 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1401 | struct ixgbe_ring *ring; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1402 | int cpu = get_cpu(); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1403 | |
| 1404 | if (q_vector->cpu == cpu) |
| 1405 | goto out_no_update; |
| 1406 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 1407 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1408 | ixgbe_update_tx_dca(adapter, ring, cpu); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1409 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 1410 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1411 | ixgbe_update_rx_dca(adapter, ring, cpu); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1412 | |
| 1413 | q_vector->cpu = cpu; |
| 1414 | out_no_update: |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1415 | put_cpu(); |
| 1416 | } |
| 1417 | |
| 1418 | static void ixgbe_setup_dca(struct ixgbe_adapter *adapter) |
| 1419 | { |
| 1420 | int i; |
| 1421 | |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 1422 | /* always use CB2 mode, difference is masked in the CB driver */ |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1423 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1424 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 1425 | IXGBE_DCA_CTRL_DCA_MODE_CB2); |
| 1426 | else |
| 1427 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 1428 | IXGBE_DCA_CTRL_DCA_DISABLE); |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 1429 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 1430 | for (i = 0; i < adapter->num_q_vectors; i++) { |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1431 | adapter->q_vector[i]->cpu = -1; |
| 1432 | ixgbe_update_dca(adapter->q_vector[i]); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1433 | } |
| 1434 | } |
| 1435 | |
| 1436 | static int __ixgbe_notify_dca(struct device *dev, void *data) |
| 1437 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 1438 | struct ixgbe_adapter *adapter = dev_get_drvdata(dev); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1439 | unsigned long event = *(unsigned long *)data; |
| 1440 | |
Don Skidmore | 2a72c31 | 2011-07-20 02:27:05 +0000 | [diff] [blame] | 1441 | if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE)) |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1442 | return 0; |
| 1443 | |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1444 | switch (event) { |
| 1445 | case DCA_PROVIDER_ADD: |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 1446 | /* if we're already enabled, don't do it again */ |
| 1447 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1448 | break; |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 1449 | if (dca_add_requester(dev) == 0) { |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 1450 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1451 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 1452 | IXGBE_DCA_CTRL_DCA_MODE_CB2); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1453 | break; |
| 1454 | } |
Tony Nguyen | 93df946 | 2017-05-31 04:43:47 -0700 | [diff] [blame] | 1455 | /* fall through - DCA is disabled. */ |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1456 | case DCA_PROVIDER_REMOVE: |
| 1457 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 1458 | dca_remove_requester(dev); |
| 1459 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1460 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 1461 | IXGBE_DCA_CTRL_DCA_DISABLE); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1462 | } |
| 1463 | break; |
| 1464 | } |
| 1465 | |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 1466 | return 0; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1467 | } |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1468 | |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1469 | #endif /* CONFIG_IXGBE_DCA */ |
Fan Du | 7edda4b8 | 2015-04-29 10:57:39 +0800 | [diff] [blame] | 1470 | |
| 1471 | #define IXGBE_RSS_L4_TYPES_MASK \ |
| 1472 | ((1ul << IXGBE_RXDADV_RSSTYPE_IPV4_TCP) | \ |
| 1473 | (1ul << IXGBE_RXDADV_RSSTYPE_IPV4_UDP) | \ |
| 1474 | (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_TCP) | \ |
| 1475 | (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_UDP)) |
| 1476 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1477 | static inline void ixgbe_rx_hash(struct ixgbe_ring *ring, |
| 1478 | union ixgbe_adv_rx_desc *rx_desc, |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1479 | struct sk_buff *skb) |
| 1480 | { |
Fan Du | 7edda4b8 | 2015-04-29 10:57:39 +0800 | [diff] [blame] | 1481 | u16 rss_type; |
| 1482 | |
| 1483 | if (!(ring->netdev->features & NETIF_F_RXHASH)) |
| 1484 | return; |
| 1485 | |
| 1486 | rss_type = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) & |
| 1487 | IXGBE_RXDADV_RSSTYPE_MASK; |
| 1488 | |
| 1489 | if (!rss_type) |
| 1490 | return; |
| 1491 | |
| 1492 | skb_set_hash(skb, le32_to_cpu(rx_desc->wb.lower.hi_dword.rss), |
| 1493 | (IXGBE_RSS_L4_TYPES_MASK & (1ul << rss_type)) ? |
| 1494 | PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3); |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1495 | } |
| 1496 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1497 | #ifdef IXGBE_FCOE |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1498 | /** |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1499 | * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1500 | * @ring: structure containing ring specific data |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1501 | * @rx_desc: advanced rx descriptor |
| 1502 | * |
| 1503 | * Returns : true if it is FCoE pkt |
| 1504 | */ |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1505 | static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring, |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1506 | union ixgbe_adv_rx_desc *rx_desc) |
| 1507 | { |
| 1508 | __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 1509 | |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1510 | return test_bit(__IXGBE_RX_FCOE, &ring->state) && |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1511 | ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) == |
| 1512 | (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE << |
| 1513 | IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT))); |
| 1514 | } |
| 1515 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1516 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1517 | /** |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1518 | * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1519 | * @ring: structure containing ring specific data |
| 1520 | * @rx_desc: current Rx descriptor being processed |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1521 | * @skb: skb currently being received and modified |
| 1522 | **/ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1523 | static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring, |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1524 | union ixgbe_adv_rx_desc *rx_desc, |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1525 | struct sk_buff *skb) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1526 | { |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1527 | __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] | 1528 | bool encap_pkt = false; |
| 1529 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1530 | skb_checksum_none_assert(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1531 | |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 1532 | /* Rx csum disabled */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1533 | if (!(ring->netdev->features & NETIF_F_RXCSUM)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1534 | return; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1535 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 1536 | /* check for VXLAN and Geneve packets */ |
| 1537 | if (pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_VXLAN)) { |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1538 | encap_pkt = true; |
| 1539 | skb->encapsulation = 1; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1540 | } |
| 1541 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1542 | /* if IP and error */ |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1543 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) && |
| 1544 | ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1545 | ring->rx_stats.csum_err++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1546 | return; |
| 1547 | } |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1548 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1549 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS)) |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1550 | return; |
| 1551 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1552 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) { |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1553 | /* |
| 1554 | * 82599 errata, UDP frames with a 0 checksum can be marked as |
| 1555 | * checksum errors. |
| 1556 | */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1557 | if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) && |
| 1558 | test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state)) |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1559 | return; |
| 1560 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1561 | ring->rx_stats.csum_err++; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1562 | return; |
| 1563 | } |
| 1564 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1565 | /* It must be a TCP or UDP packet with a valid checksum */ |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1566 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1567 | if (encap_pkt) { |
| 1568 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_OUTERIPCS)) |
| 1569 | return; |
| 1570 | |
| 1571 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_OUTERIPER)) { |
Mark Rustad | d469251 | 2015-12-04 11:26:43 -0800 | [diff] [blame] | 1572 | skb->ip_summed = CHECKSUM_NONE; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1573 | return; |
| 1574 | } |
| 1575 | /* If we checked the outer header let the stack know */ |
| 1576 | skb->csum_level = 1; |
| 1577 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1578 | } |
| 1579 | |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 1580 | static inline unsigned int ixgbe_rx_offset(struct ixgbe_ring *rx_ring) |
| 1581 | { |
| 1582 | return ring_uses_build_skb(rx_ring) ? IXGBE_SKB_PAD : 0; |
| 1583 | } |
| 1584 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1585 | static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring, |
| 1586 | struct ixgbe_rx_buffer *bi) |
| 1587 | { |
| 1588 | struct page *page = bi->page; |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1589 | dma_addr_t dma; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1590 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1591 | /* since we are recycling buffers we should seldom need to alloc */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1592 | if (likely(page)) |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1593 | return true; |
| 1594 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1595 | /* alloc new page for storage */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1596 | page = dev_alloc_pages(ixgbe_rx_pg_order(rx_ring)); |
| 1597 | if (unlikely(!page)) { |
| 1598 | rx_ring->rx_stats.alloc_rx_page_failed++; |
| 1599 | return false; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1600 | } |
| 1601 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1602 | /* map page for use */ |
Alexander Duyck | f3213d9 | 2017-01-17 08:35:54 -0800 | [diff] [blame] | 1603 | dma = dma_map_page_attrs(rx_ring->dev, page, 0, |
| 1604 | ixgbe_rx_pg_size(rx_ring), |
| 1605 | DMA_FROM_DEVICE, |
| 1606 | IXGBE_RX_DMA_ATTR); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1607 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1608 | /* |
| 1609 | * if mapping failed free memory back to system since |
| 1610 | * there isn't much point in holding memory we can't use |
| 1611 | */ |
| 1612 | if (dma_mapping_error(rx_ring->dev, dma)) { |
Alexander Duyck | dd411ec | 2012-04-06 04:24:50 +0000 | [diff] [blame] | 1613 | __free_pages(page, ixgbe_rx_pg_order(rx_ring)); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1614 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1615 | rx_ring->rx_stats.alloc_rx_page_failed++; |
| 1616 | return false; |
| 1617 | } |
| 1618 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1619 | bi->dma = dma; |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1620 | bi->page = page; |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 1621 | bi->page_offset = ixgbe_rx_offset(rx_ring); |
Alexander Duyck | 1b56cf4 | 2017-01-17 08:36:03 -0800 | [diff] [blame] | 1622 | bi->pagecnt_bias = 1; |
Jesper Dangaard Brouer | 86e2349 | 2017-09-04 20:40:22 +0200 | [diff] [blame] | 1623 | rx_ring->rx_stats.alloc_rx_page++; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1624 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1625 | return true; |
| 1626 | } |
| 1627 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1628 | /** |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1629 | * ixgbe_alloc_rx_buffers - Replace used receive buffers |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1630 | * @rx_ring: ring to place buffers on |
| 1631 | * @cleaned_count: number of buffers to replace |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1632 | **/ |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1633 | 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] | 1634 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1635 | union ixgbe_adv_rx_desc *rx_desc; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1636 | struct ixgbe_rx_buffer *bi; |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1637 | u16 i = rx_ring->next_to_use; |
Alexander Duyck | 4f4542b | 2017-01-17 08:36:14 -0800 | [diff] [blame] | 1638 | u16 bufsz; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1639 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1640 | /* nothing to do */ |
| 1641 | if (!cleaned_count) |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1642 | return; |
| 1643 | |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1644 | rx_desc = IXGBE_RX_DESC(rx_ring, i); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1645 | bi = &rx_ring->rx_buffer_info[i]; |
| 1646 | i -= rx_ring->count; |
| 1647 | |
Alexander Duyck | 4f4542b | 2017-01-17 08:36:14 -0800 | [diff] [blame] | 1648 | bufsz = ixgbe_rx_bufsz(rx_ring); |
| 1649 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1650 | do { |
| 1651 | if (!ixgbe_alloc_mapped_page(rx_ring, bi)) |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1652 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1653 | |
Alexander Duyck | f3213d9 | 2017-01-17 08:35:54 -0800 | [diff] [blame] | 1654 | /* sync the buffer for use by the device */ |
| 1655 | dma_sync_single_range_for_device(rx_ring->dev, bi->dma, |
Alexander Duyck | 4f4542b | 2017-01-17 08:36:14 -0800 | [diff] [blame] | 1656 | bi->page_offset, bufsz, |
Alexander Duyck | f3213d9 | 2017-01-17 08:35:54 -0800 | [diff] [blame] | 1657 | DMA_FROM_DEVICE); |
| 1658 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1659 | /* |
| 1660 | * Refresh the desc even if buffer_addrs didn't change |
| 1661 | * because each write-back erases this info. |
| 1662 | */ |
| 1663 | 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] | 1664 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1665 | rx_desc++; |
| 1666 | bi++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1667 | i++; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1668 | if (unlikely(!i)) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1669 | rx_desc = IXGBE_RX_DESC(rx_ring, 0); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1670 | bi = rx_ring->rx_buffer_info; |
| 1671 | i -= rx_ring->count; |
| 1672 | } |
| 1673 | |
Alexander Duyck | c3630cc | 2017-01-17 08:36:28 -0800 | [diff] [blame] | 1674 | /* clear the length for the next_to_use descriptor */ |
| 1675 | rx_desc->wb.upper.length = 0; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1676 | |
| 1677 | cleaned_count--; |
| 1678 | } while (cleaned_count); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1679 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1680 | i += rx_ring->count; |
| 1681 | |
Alexander Duyck | ad435ec | 2014-11-14 00:56:35 +0000 | [diff] [blame] | 1682 | if (rx_ring->next_to_use != i) { |
| 1683 | rx_ring->next_to_use = i; |
| 1684 | |
| 1685 | /* update next to alloc since we have filled the ring */ |
| 1686 | rx_ring->next_to_alloc = i; |
| 1687 | |
| 1688 | /* Force memory writes to complete before letting h/w |
| 1689 | * know there are new descriptors to fetch. (Only |
| 1690 | * applicable for weak-ordered memory model archs, |
| 1691 | * such as IA-64). |
| 1692 | */ |
| 1693 | wmb(); |
| 1694 | writel(i, rx_ring->tail); |
| 1695 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1696 | } |
| 1697 | |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1698 | static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring, |
| 1699 | struct sk_buff *skb) |
| 1700 | { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1701 | u16 hdr_len = skb_headlen(skb); |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1702 | |
| 1703 | /* set gso_size to avoid messing up TCP MSS */ |
| 1704 | skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len), |
| 1705 | IXGBE_CB(skb)->append_cnt); |
Alexander Duyck | 96be80a | 2013-02-12 09:45:44 +0000 | [diff] [blame] | 1706 | skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4; |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1707 | } |
| 1708 | |
| 1709 | static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring, |
| 1710 | struct sk_buff *skb) |
| 1711 | { |
| 1712 | /* if append_cnt is 0 then frame is not RSC */ |
| 1713 | if (!IXGBE_CB(skb)->append_cnt) |
| 1714 | return; |
| 1715 | |
| 1716 | rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt; |
| 1717 | rx_ring->rx_stats.rsc_flush++; |
| 1718 | |
| 1719 | ixgbe_set_rsc_gso_size(rx_ring, skb); |
| 1720 | |
| 1721 | /* gso_size is computed using append_cnt so always clear it last */ |
| 1722 | IXGBE_CB(skb)->append_cnt = 0; |
| 1723 | } |
| 1724 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1725 | /** |
| 1726 | * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor |
| 1727 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1728 | * @rx_desc: pointer to the EOP Rx descriptor |
| 1729 | * @skb: pointer to current skb being populated |
| 1730 | * |
| 1731 | * This function checks the ring, descriptor, and packet information in |
| 1732 | * order to populate the hash, checksum, VLAN, timestamp, protocol, and |
| 1733 | * other fields within the skb. |
| 1734 | **/ |
| 1735 | static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring, |
| 1736 | union ixgbe_adv_rx_desc *rx_desc, |
| 1737 | struct sk_buff *skb) |
| 1738 | { |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1739 | struct net_device *dev = rx_ring->netdev; |
Mark Rustad | a9763f3 | 2015-10-27 09:58:07 -0700 | [diff] [blame] | 1740 | u32 flags = rx_ring->q_vector->adapter->flags; |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1741 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1742 | ixgbe_update_rsc_stats(rx_ring, skb); |
| 1743 | |
| 1744 | ixgbe_rx_hash(rx_ring, rx_desc, skb); |
| 1745 | |
| 1746 | ixgbe_rx_checksum(rx_ring, rx_desc, skb); |
| 1747 | |
Mark Rustad | a9763f3 | 2015-10-27 09:58:07 -0700 | [diff] [blame] | 1748 | if (unlikely(flags & IXGBE_FLAG_RX_HWTSTAMP_ENABLED)) |
| 1749 | ixgbe_ptp_rx_hwtstamp(rx_ring, rx_desc, skb); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 1750 | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 1751 | if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) && |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1752 | ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1753 | u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan); |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 1754 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid); |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | skb_record_rx_queue(skb, rx_ring->queue_index); |
| 1758 | |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1759 | skb->protocol = eth_type_trans(skb, dev); |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1760 | } |
| 1761 | |
| 1762 | static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector, |
| 1763 | struct sk_buff *skb) |
| 1764 | { |
Eric Dumazet | 3ffc1af | 2017-02-02 16:26:39 -0800 | [diff] [blame] | 1765 | napi_gro_receive(&q_vector->napi, skb); |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1766 | } |
Mallikarjuna R Chilakala | 43634e8 | 2010-02-25 23:14:37 +0000 | [diff] [blame] | 1767 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1768 | /** |
| 1769 | * ixgbe_is_non_eop - process handling of non-EOP buffers |
| 1770 | * @rx_ring: Rx ring being processed |
| 1771 | * @rx_desc: Rx descriptor for current buffer |
| 1772 | * @skb: Current socket buffer containing buffer in progress |
| 1773 | * |
| 1774 | * This function updates next to clean. If the buffer is an EOP buffer |
| 1775 | * this function exits returning false, otherwise it will place the |
| 1776 | * sk_buff in the next buffer to be chained and return true indicating |
| 1777 | * that this is in fact a non-EOP buffer. |
| 1778 | **/ |
| 1779 | static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring, |
| 1780 | union ixgbe_adv_rx_desc *rx_desc, |
| 1781 | struct sk_buff *skb) |
| 1782 | { |
| 1783 | u32 ntc = rx_ring->next_to_clean + 1; |
| 1784 | |
| 1785 | /* fetch, update, and store next to clean */ |
| 1786 | ntc = (ntc < rx_ring->count) ? ntc : 0; |
| 1787 | rx_ring->next_to_clean = ntc; |
| 1788 | |
| 1789 | prefetch(IXGBE_RX_DESC(rx_ring, ntc)); |
| 1790 | |
Alexander Duyck | 5a02cbd | 2012-07-20 08:08:51 +0000 | [diff] [blame] | 1791 | /* update RSC append count if present */ |
| 1792 | if (ring_is_rsc_enabled(rx_ring)) { |
| 1793 | __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data & |
| 1794 | cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK); |
| 1795 | |
| 1796 | if (unlikely(rsc_enabled)) { |
| 1797 | u32 rsc_cnt = le32_to_cpu(rsc_enabled); |
| 1798 | |
| 1799 | rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT; |
| 1800 | IXGBE_CB(skb)->append_cnt += rsc_cnt - 1; |
| 1801 | |
| 1802 | /* update ntc based on RSC value */ |
| 1803 | ntc = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 1804 | ntc &= IXGBE_RXDADV_NEXTP_MASK; |
| 1805 | ntc >>= IXGBE_RXDADV_NEXTP_SHIFT; |
| 1806 | } |
| 1807 | } |
| 1808 | |
| 1809 | /* 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] | 1810 | if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))) |
| 1811 | return false; |
| 1812 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1813 | /* place skb in next buffer to be received */ |
| 1814 | rx_ring->rx_buffer_info[ntc].skb = skb; |
| 1815 | rx_ring->rx_stats.non_eop_descs++; |
| 1816 | |
| 1817 | return true; |
| 1818 | } |
| 1819 | |
| 1820 | /** |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1821 | * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail |
| 1822 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1823 | * @skb: pointer to current skb being adjusted |
| 1824 | * |
| 1825 | * This function is an ixgbe specific version of __pskb_pull_tail. The |
| 1826 | * main difference between this version and the original function is that |
| 1827 | * this function can make several assumptions about the state of things |
| 1828 | * that allow for significant optimizations versus the standard function. |
| 1829 | * As a result we can do things like drop a frag and maintain an accurate |
| 1830 | * truesize for the skb. |
| 1831 | */ |
| 1832 | static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring, |
| 1833 | struct sk_buff *skb) |
| 1834 | { |
| 1835 | struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0]; |
| 1836 | unsigned char *va; |
| 1837 | unsigned int pull_len; |
| 1838 | |
| 1839 | /* |
| 1840 | * it is valid to use page_address instead of kmap since we are |
| 1841 | * working with pages allocated out of the lomem pool per |
| 1842 | * alloc_page(GFP_ATOMIC) |
| 1843 | */ |
| 1844 | va = skb_frag_address(frag); |
| 1845 | |
| 1846 | /* |
| 1847 | * we need the header to contain the greater of either ETH_HLEN or |
| 1848 | * 60 bytes if the skb->len is less than 60 for skb_pad. |
| 1849 | */ |
Alexander Duyck | 8496e338 | 2014-09-05 19:22:18 -0400 | [diff] [blame] | 1850 | pull_len = eth_get_headlen(va, IXGBE_RX_HDR_SIZE); |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1851 | |
| 1852 | /* align pull length to size of long to optimize memcpy performance */ |
| 1853 | skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long))); |
| 1854 | |
| 1855 | /* update all of the pointers */ |
| 1856 | skb_frag_size_sub(frag, pull_len); |
| 1857 | frag->page_offset += pull_len; |
| 1858 | skb->data_len -= pull_len; |
| 1859 | skb->tail += pull_len; |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1860 | } |
| 1861 | |
| 1862 | /** |
Alexander Duyck | 42073d9 | 2012-07-20 08:08:28 +0000 | [diff] [blame] | 1863 | * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB |
| 1864 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1865 | * @skb: pointer to current skb being updated |
| 1866 | * |
| 1867 | * This function provides a basic DMA sync up for the first fragment of an |
| 1868 | * skb. The reason for doing this is that the first fragment cannot be |
| 1869 | * unmapped until we have reached the end of packet descriptor for a buffer |
| 1870 | * chain. |
| 1871 | */ |
| 1872 | static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring, |
| 1873 | struct sk_buff *skb) |
| 1874 | { |
| 1875 | /* if the page was released unmap it, else just sync our portion */ |
| 1876 | if (unlikely(IXGBE_CB(skb)->page_released)) { |
Alexander Duyck | f3213d9 | 2017-01-17 08:35:54 -0800 | [diff] [blame] | 1877 | dma_unmap_page_attrs(rx_ring->dev, IXGBE_CB(skb)->dma, |
| 1878 | ixgbe_rx_pg_size(rx_ring), |
| 1879 | DMA_FROM_DEVICE, |
| 1880 | IXGBE_RX_DMA_ATTR); |
Alexander Duyck | 42073d9 | 2012-07-20 08:08:28 +0000 | [diff] [blame] | 1881 | } else { |
| 1882 | struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0]; |
| 1883 | |
| 1884 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 1885 | IXGBE_CB(skb)->dma, |
| 1886 | frag->page_offset, |
Alexander Duyck | f215af8 | 2017-01-17 08:35:44 -0800 | [diff] [blame] | 1887 | skb_frag_size(frag), |
Alexander Duyck | 42073d9 | 2012-07-20 08:08:28 +0000 | [diff] [blame] | 1888 | DMA_FROM_DEVICE); |
| 1889 | } |
Alexander Duyck | 42073d9 | 2012-07-20 08:08:28 +0000 | [diff] [blame] | 1890 | } |
| 1891 | |
| 1892 | /** |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1893 | * ixgbe_cleanup_headers - Correct corrupted or empty headers |
| 1894 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1895 | * @rx_desc: pointer to the EOP Rx descriptor |
| 1896 | * @skb: pointer to current skb being fixed |
| 1897 | * |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 1898 | * Check if the skb is valid in the XDP case it will be an error pointer. |
| 1899 | * Return true in this case to abort processing and advance to next |
| 1900 | * descriptor. |
| 1901 | * |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1902 | * Check for corrupted packet headers caused by senders on the local L2 |
| 1903 | * embedded NIC switch not setting up their Tx Descriptors right. These |
| 1904 | * should be very rare. |
| 1905 | * |
| 1906 | * Also address the case where we are pulling data in on pages only |
| 1907 | * and as such no data is present in the skb header. |
| 1908 | * |
| 1909 | * In addition if skb is not at least 60 bytes we need to pad it so that |
| 1910 | * it is large enough to qualify as a valid Ethernet frame. |
| 1911 | * |
| 1912 | * Returns true if an error was encountered and skb was freed. |
| 1913 | **/ |
| 1914 | static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring, |
| 1915 | union ixgbe_adv_rx_desc *rx_desc, |
| 1916 | struct sk_buff *skb) |
| 1917 | { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1918 | struct net_device *netdev = rx_ring->netdev; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1919 | |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 1920 | /* XDP packets use error pointer so abort at this point */ |
| 1921 | if (IS_ERR(skb)) |
| 1922 | return true; |
| 1923 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1924 | /* verify that the packet does not have any known errors */ |
| 1925 | if (unlikely(ixgbe_test_staterr(rx_desc, |
| 1926 | IXGBE_RXDADV_ERR_FRAME_ERR_MASK) && |
| 1927 | !(netdev->features & NETIF_F_RXALL))) { |
| 1928 | dev_kfree_skb_any(skb); |
| 1929 | return true; |
| 1930 | } |
| 1931 | |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1932 | /* place header in linear portion of buffer */ |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 1933 | if (!skb_headlen(skb)) |
Alexander Duyck | cf3fe7a | 2012-07-20 08:08:39 +0000 | [diff] [blame] | 1934 | ixgbe_pull_tail(rx_ring, skb); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1935 | |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1936 | #ifdef IXGBE_FCOE |
| 1937 | /* do not attempt to pad FCoE Frames as this will disrupt DDP */ |
| 1938 | if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) |
| 1939 | return false; |
| 1940 | |
| 1941 | #endif |
Alexander Duyck | a94d9e2 | 2014-12-03 08:17:39 -0800 | [diff] [blame] | 1942 | /* if eth_skb_pad returns an error the skb was freed */ |
| 1943 | if (eth_skb_pad(skb)) |
| 1944 | return true; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1945 | |
| 1946 | return false; |
| 1947 | } |
| 1948 | |
| 1949 | /** |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1950 | * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring |
| 1951 | * @rx_ring: rx descriptor ring to store buffers on |
| 1952 | * @old_buff: donor buffer to have page reused |
| 1953 | * |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1954 | * Synchronizes page for reuse by the adapter |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1955 | **/ |
| 1956 | static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring, |
| 1957 | struct ixgbe_rx_buffer *old_buff) |
| 1958 | { |
| 1959 | struct ixgbe_rx_buffer *new_buff; |
| 1960 | u16 nta = rx_ring->next_to_alloc; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1961 | |
| 1962 | new_buff = &rx_ring->rx_buffer_info[nta]; |
| 1963 | |
| 1964 | /* update, and store next to alloc */ |
| 1965 | nta++; |
| 1966 | rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0; |
| 1967 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 1968 | /* Transfer page from old buffer to new buffer. |
| 1969 | * Move each member individually to avoid possible store |
| 1970 | * forwarding stalls and unnecessary copy of skb. |
| 1971 | */ |
| 1972 | new_buff->dma = old_buff->dma; |
| 1973 | new_buff->page = old_buff->page; |
| 1974 | new_buff->page_offset = old_buff->page_offset; |
| 1975 | new_buff->pagecnt_bias = old_buff->pagecnt_bias; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1976 | } |
| 1977 | |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1978 | static inline bool ixgbe_page_is_reserved(struct page *page) |
| 1979 | { |
Michal Hocko | 2f064f3 | 2015-08-21 14:11:51 -0700 | [diff] [blame] | 1980 | return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page); |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1981 | } |
| 1982 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 1983 | 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] | 1984 | { |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 1985 | unsigned int pagecnt_bias = rx_buffer->pagecnt_bias; |
| 1986 | struct page *page = rx_buffer->page; |
Alexander Duyck | 1b56cf4 | 2017-01-17 08:36:03 -0800 | [diff] [blame] | 1987 | |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1988 | /* avoid re-using remote pages */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1989 | if (unlikely(ixgbe_page_is_reserved(page))) |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1990 | return false; |
| 1991 | |
| 1992 | #if (PAGE_SIZE < 8192) |
| 1993 | /* if we are only owner of page we can reuse it */ |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 1994 | if (unlikely((page_ref_count(page) - pagecnt_bias) > 1)) |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1995 | return false; |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1996 | #else |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 1997 | /* The last offset is a bit aggressive in that we assume the |
| 1998 | * worst case of FCoE being enabled and using a 3K buffer. |
| 1999 | * However this should have minimal impact as the 1K extra is |
| 2000 | * still less than one buffer in size. |
| 2001 | */ |
| 2002 | #define IXGBE_LAST_OFFSET \ |
| 2003 | (SKB_WITH_OVERHEAD(PAGE_SIZE) - IXGBE_RXBUFFER_3K) |
| 2004 | if (rx_buffer->page_offset > IXGBE_LAST_OFFSET) |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 2005 | return false; |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 2006 | #endif |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 2007 | |
Alexander Duyck | 1b56cf4 | 2017-01-17 08:36:03 -0800 | [diff] [blame] | 2008 | /* If we have drained the page fragment pool we need to update |
| 2009 | * the pagecnt_bias and page count so that we fully restock the |
| 2010 | * number of references the driver holds. |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 2011 | */ |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2012 | if (unlikely(!pagecnt_bias)) { |
Alexander Duyck | 1b56cf4 | 2017-01-17 08:36:03 -0800 | [diff] [blame] | 2013 | page_ref_add(page, USHRT_MAX); |
| 2014 | rx_buffer->pagecnt_bias = USHRT_MAX; |
| 2015 | } |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 2016 | |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 2017 | return true; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2018 | } |
| 2019 | |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 2020 | /** |
| 2021 | * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff |
| 2022 | * @rx_ring: rx descriptor ring to transact packets on |
| 2023 | * @rx_buffer: buffer containing page to add |
| 2024 | * @rx_desc: descriptor containing length of buffer written by hardware |
| 2025 | * @skb: sk_buff to place the data into |
| 2026 | * |
| 2027 | * This function will add the data contained in rx_buffer->page to the skb. |
| 2028 | * This is done either through a direct copy if the data in the buffer is |
| 2029 | * less than the skb header size, otherwise it will just attach the page as |
| 2030 | * a frag to the skb. |
| 2031 | * |
| 2032 | * The function will then update the page offset if necessary and return |
| 2033 | * true if the buffer can be reused by the adapter. |
| 2034 | **/ |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2035 | static void ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring, |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 2036 | struct ixgbe_rx_buffer *rx_buffer, |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2037 | struct sk_buff *skb, |
| 2038 | unsigned int size) |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 2039 | { |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 2040 | #if (PAGE_SIZE < 8192) |
Alexander Duyck | 4f4542b | 2017-01-17 08:36:14 -0800 | [diff] [blame] | 2041 | unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2; |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 2042 | #else |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 2043 | unsigned int truesize = ring_uses_build_skb(rx_ring) ? |
| 2044 | SKB_DATA_ALIGN(IXGBE_SKB_PAD + size) : |
| 2045 | SKB_DATA_ALIGN(size); |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 2046 | #endif |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2047 | 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] | 2048 | rx_buffer->page_offset, size, truesize); |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2049 | #if (PAGE_SIZE < 8192) |
| 2050 | rx_buffer->page_offset ^= truesize; |
| 2051 | #else |
| 2052 | rx_buffer->page_offset += truesize; |
| 2053 | #endif |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 2054 | } |
| 2055 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2056 | static struct ixgbe_rx_buffer *ixgbe_get_rx_buffer(struct ixgbe_ring *rx_ring, |
| 2057 | union ixgbe_adv_rx_desc *rx_desc, |
| 2058 | struct sk_buff **skb, |
| 2059 | const unsigned int size) |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2060 | { |
| 2061 | struct ixgbe_rx_buffer *rx_buffer; |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2062 | |
| 2063 | rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean]; |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2064 | prefetchw(rx_buffer->page); |
| 2065 | *skb = rx_buffer->skb; |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2066 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2067 | /* Delay unmapping of the first packet. It carries the header |
| 2068 | * information, HW may still access the header after the writeback. |
| 2069 | * Only unmap it when EOP is reached |
| 2070 | */ |
| 2071 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)) { |
| 2072 | if (!*skb) |
| 2073 | goto skip_sync; |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2074 | } else { |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2075 | if (*skb) |
| 2076 | ixgbe_dma_sync_frag(rx_ring, *skb); |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2077 | } |
| 2078 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2079 | /* we are reusing so sync this buffer for CPU use */ |
| 2080 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 2081 | rx_buffer->dma, |
| 2082 | rx_buffer->page_offset, |
| 2083 | size, |
| 2084 | DMA_FROM_DEVICE); |
| 2085 | skip_sync: |
| 2086 | rx_buffer->pagecnt_bias--; |
| 2087 | |
| 2088 | return rx_buffer; |
| 2089 | } |
| 2090 | |
| 2091 | static void ixgbe_put_rx_buffer(struct ixgbe_ring *rx_ring, |
| 2092 | struct ixgbe_rx_buffer *rx_buffer, |
| 2093 | struct sk_buff *skb) |
| 2094 | { |
| 2095 | if (ixgbe_can_reuse_rx_page(rx_buffer)) { |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2096 | /* hand second half of page back to the ring */ |
| 2097 | ixgbe_reuse_rx_page(rx_ring, rx_buffer); |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2098 | } else { |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2099 | if (!IS_ERR(skb) && IXGBE_CB(skb)->dma == rx_buffer->dma) { |
Alexander Duyck | 1b56cf4 | 2017-01-17 08:36:03 -0800 | [diff] [blame] | 2100 | /* the page has been released from the ring */ |
| 2101 | IXGBE_CB(skb)->page_released = true; |
| 2102 | } else { |
| 2103 | /* we are not reusing the buffer so unmap it */ |
| 2104 | dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma, |
| 2105 | ixgbe_rx_pg_size(rx_ring), |
| 2106 | DMA_FROM_DEVICE, |
| 2107 | IXGBE_RX_DMA_ATTR); |
| 2108 | } |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2109 | __page_frag_cache_drain(rx_buffer->page, |
Alexander Duyck | 1b56cf4 | 2017-01-17 08:36:03 -0800 | [diff] [blame] | 2110 | rx_buffer->pagecnt_bias); |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2111 | } |
| 2112 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2113 | /* clear contents of rx_buffer */ |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2114 | rx_buffer->page = NULL; |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2115 | rx_buffer->skb = NULL; |
| 2116 | } |
| 2117 | |
| 2118 | static struct sk_buff *ixgbe_construct_skb(struct ixgbe_ring *rx_ring, |
| 2119 | struct ixgbe_rx_buffer *rx_buffer, |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2120 | struct xdp_buff *xdp, |
| 2121 | union ixgbe_adv_rx_desc *rx_desc) |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2122 | { |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2123 | unsigned int size = xdp->data_end - xdp->data; |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2124 | #if (PAGE_SIZE < 8192) |
| 2125 | unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2; |
| 2126 | #else |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2127 | unsigned int truesize = SKB_DATA_ALIGN(xdp->data_end - |
| 2128 | xdp->data_hard_start); |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2129 | #endif |
| 2130 | struct sk_buff *skb; |
| 2131 | |
| 2132 | /* prefetch first cache line of first page */ |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2133 | prefetch(xdp->data); |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2134 | #if L1_CACHE_BYTES < 128 |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2135 | prefetch(xdp->data + L1_CACHE_BYTES); |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2136 | #endif |
Daniel Borkmann | 366a88f | 2017-09-25 02:25:55 +0200 | [diff] [blame] | 2137 | /* Note, we get here by enabling legacy-rx via: |
| 2138 | * |
| 2139 | * ethtool --set-priv-flags <dev> legacy-rx on |
| 2140 | * |
| 2141 | * In this mode, we currently get 0 extra XDP headroom as |
| 2142 | * opposed to having legacy-rx off, where we process XDP |
| 2143 | * packets going to stack via ixgbe_build_skb(). The latter |
| 2144 | * provides us currently with 192 bytes of headroom. |
| 2145 | * |
| 2146 | * For ixgbe_construct_skb() mode it means that the |
| 2147 | * xdp->data_meta will always point to xdp->data, since |
| 2148 | * the helper cannot expand the head. Should this ever |
| 2149 | * change in future for legacy-rx mode on, then lets also |
| 2150 | * add xdp->data_meta handling here. |
| 2151 | */ |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2152 | |
| 2153 | /* allocate a skb to store the frags */ |
| 2154 | skb = napi_alloc_skb(&rx_ring->q_vector->napi, IXGBE_RX_HDR_SIZE); |
| 2155 | if (unlikely(!skb)) |
| 2156 | return NULL; |
| 2157 | |
| 2158 | if (size > IXGBE_RX_HDR_SIZE) { |
| 2159 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)) |
| 2160 | IXGBE_CB(skb)->dma = rx_buffer->dma; |
| 2161 | |
| 2162 | skb_add_rx_frag(skb, 0, rx_buffer->page, |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2163 | xdp->data - page_address(rx_buffer->page), |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2164 | size, truesize); |
| 2165 | #if (PAGE_SIZE < 8192) |
| 2166 | rx_buffer->page_offset ^= truesize; |
| 2167 | #else |
| 2168 | rx_buffer->page_offset += truesize; |
| 2169 | #endif |
| 2170 | } else { |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2171 | memcpy(__skb_put(skb, size), |
| 2172 | xdp->data, ALIGN(size, sizeof(long))); |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2173 | rx_buffer->pagecnt_bias++; |
| 2174 | } |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2175 | |
| 2176 | return skb; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2177 | } |
| 2178 | |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 2179 | static struct sk_buff *ixgbe_build_skb(struct ixgbe_ring *rx_ring, |
| 2180 | struct ixgbe_rx_buffer *rx_buffer, |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2181 | struct xdp_buff *xdp, |
| 2182 | union ixgbe_adv_rx_desc *rx_desc) |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 2183 | { |
Daniel Borkmann | 366a88f | 2017-09-25 02:25:55 +0200 | [diff] [blame] | 2184 | unsigned int metasize = xdp->data - xdp->data_meta; |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 2185 | #if (PAGE_SIZE < 8192) |
| 2186 | unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2; |
| 2187 | #else |
| 2188 | unsigned int truesize = SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) + |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2189 | SKB_DATA_ALIGN(xdp->data_end - |
| 2190 | xdp->data_hard_start); |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 2191 | #endif |
| 2192 | struct sk_buff *skb; |
| 2193 | |
Daniel Borkmann | 366a88f | 2017-09-25 02:25:55 +0200 | [diff] [blame] | 2194 | /* Prefetch first cache line of first page. If xdp->data_meta |
| 2195 | * is unused, this points extactly as xdp->data, otherwise we |
| 2196 | * likely have a consumer accessing first few bytes of meta |
| 2197 | * data, and then actual data. |
| 2198 | */ |
| 2199 | prefetch(xdp->data_meta); |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 2200 | #if L1_CACHE_BYTES < 128 |
Daniel Borkmann | 366a88f | 2017-09-25 02:25:55 +0200 | [diff] [blame] | 2201 | prefetch(xdp->data_meta + L1_CACHE_BYTES); |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 2202 | #endif |
| 2203 | |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2204 | /* build an skb to around the page buffer */ |
| 2205 | skb = build_skb(xdp->data_hard_start, truesize); |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 2206 | if (unlikely(!skb)) |
| 2207 | return NULL; |
| 2208 | |
| 2209 | /* update pointers within the skb to store the data */ |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2210 | skb_reserve(skb, xdp->data - xdp->data_hard_start); |
| 2211 | __skb_put(skb, xdp->data_end - xdp->data); |
Daniel Borkmann | 366a88f | 2017-09-25 02:25:55 +0200 | [diff] [blame] | 2212 | if (metasize) |
| 2213 | skb_metadata_set(skb, metasize); |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 2214 | |
| 2215 | /* record DMA address if this is the start of a chain of buffers */ |
| 2216 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)) |
| 2217 | IXGBE_CB(skb)->dma = rx_buffer->dma; |
| 2218 | |
| 2219 | /* update buffer offset */ |
| 2220 | #if (PAGE_SIZE < 8192) |
| 2221 | rx_buffer->page_offset ^= truesize; |
| 2222 | #else |
| 2223 | rx_buffer->page_offset += truesize; |
| 2224 | #endif |
| 2225 | |
| 2226 | return skb; |
| 2227 | } |
| 2228 | |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2229 | #define IXGBE_XDP_PASS 0 |
| 2230 | #define IXGBE_XDP_CONSUMED 1 |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 2231 | #define IXGBE_XDP_TX 2 |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2232 | |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 2233 | static int ixgbe_xmit_xdp_ring(struct ixgbe_adapter *adapter, |
| 2234 | struct xdp_buff *xdp); |
| 2235 | |
| 2236 | static struct sk_buff *ixgbe_run_xdp(struct ixgbe_adapter *adapter, |
| 2237 | struct ixgbe_ring *rx_ring, |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2238 | struct xdp_buff *xdp) |
| 2239 | { |
John Fastabend | 6453073 | 2017-07-17 09:28:12 -0700 | [diff] [blame] | 2240 | int err, result = IXGBE_XDP_PASS; |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2241 | struct bpf_prog *xdp_prog; |
| 2242 | u32 act; |
| 2243 | |
| 2244 | rcu_read_lock(); |
| 2245 | xdp_prog = READ_ONCE(rx_ring->xdp_prog); |
| 2246 | |
| 2247 | if (!xdp_prog) |
| 2248 | goto xdp_out; |
| 2249 | |
| 2250 | act = bpf_prog_run_xdp(xdp_prog, xdp); |
| 2251 | switch (act) { |
| 2252 | case XDP_PASS: |
| 2253 | break; |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 2254 | case XDP_TX: |
| 2255 | result = ixgbe_xmit_xdp_ring(adapter, xdp); |
| 2256 | break; |
John Fastabend | 6453073 | 2017-07-17 09:28:12 -0700 | [diff] [blame] | 2257 | case XDP_REDIRECT: |
John Fastabend | 5acaee0 | 2017-07-17 09:28:35 -0700 | [diff] [blame] | 2258 | err = xdp_do_redirect(adapter->netdev, xdp, xdp_prog); |
John Fastabend | 6453073 | 2017-07-17 09:28:12 -0700 | [diff] [blame] | 2259 | if (!err) |
| 2260 | result = IXGBE_XDP_TX; |
| 2261 | else |
| 2262 | result = IXGBE_XDP_CONSUMED; |
| 2263 | break; |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2264 | default: |
| 2265 | bpf_warn_invalid_xdp_action(act); |
Tony Nguyen | 93df946 | 2017-05-31 04:43:47 -0700 | [diff] [blame] | 2266 | /* fallthrough */ |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2267 | case XDP_ABORTED: |
| 2268 | trace_xdp_exception(rx_ring->netdev, xdp_prog, act); |
| 2269 | /* fallthrough -- handle aborts by dropping packet */ |
| 2270 | case XDP_DROP: |
| 2271 | result = IXGBE_XDP_CONSUMED; |
| 2272 | break; |
| 2273 | } |
| 2274 | xdp_out: |
| 2275 | rcu_read_unlock(); |
| 2276 | return ERR_PTR(-result); |
| 2277 | } |
| 2278 | |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 2279 | static void ixgbe_rx_buffer_flip(struct ixgbe_ring *rx_ring, |
| 2280 | struct ixgbe_rx_buffer *rx_buffer, |
| 2281 | unsigned int size) |
| 2282 | { |
| 2283 | #if (PAGE_SIZE < 8192) |
| 2284 | unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2; |
| 2285 | |
| 2286 | rx_buffer->page_offset ^= truesize; |
| 2287 | #else |
| 2288 | unsigned int truesize = ring_uses_build_skb(rx_ring) ? |
| 2289 | SKB_DATA_ALIGN(IXGBE_SKB_PAD + size) : |
| 2290 | SKB_DATA_ALIGN(size); |
| 2291 | |
| 2292 | rx_buffer->page_offset += truesize; |
| 2293 | #endif |
| 2294 | } |
| 2295 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2296 | /** |
| 2297 | * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf |
| 2298 | * @q_vector: structure containing interrupt and ring information |
| 2299 | * @rx_ring: rx descriptor ring to transact packets on |
| 2300 | * @budget: Total limit on number of packets to process |
| 2301 | * |
| 2302 | * This function provides a "bounce buffer" approach to Rx interrupt |
| 2303 | * processing. The advantage to this is that on systems that have |
| 2304 | * expensive overhead for IOMMU access this provides a means of avoiding |
| 2305 | * it by maintaining the mapping of the page to the syste. |
| 2306 | * |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2307 | * Returns amount of work completed |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2308 | **/ |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2309 | static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2310 | struct ixgbe_ring *rx_ring, |
Alexander Duyck | f4de00e | 2012-09-25 00:29:37 +0000 | [diff] [blame] | 2311 | const int budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2312 | { |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 2313 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2314 | struct ixgbe_adapter *adapter = q_vector->adapter; |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 2315 | #ifdef IXGBE_FCOE |
Mark Rustad | 4ffdf91 | 2012-07-18 06:05:50 +0000 | [diff] [blame] | 2316 | int ddp_bytes; |
| 2317 | unsigned int mss = 0; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 2318 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2319 | u16 cleaned_count = ixgbe_desc_unused(rx_ring); |
John Fastabend | 7379f97 | 2017-03-28 09:47:03 -0700 | [diff] [blame] | 2320 | bool xdp_xmit = false; |
Jesper Dangaard Brouer | 99ffc5a | 2018-01-03 11:25:29 +0100 | [diff] [blame] | 2321 | struct xdp_buff xdp; |
| 2322 | |
| 2323 | xdp.rxq = &rx_ring->xdp_rxq; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2324 | |
Eric W. Biederman | fdabfc8a | 2014-03-14 18:00:41 -0700 | [diff] [blame] | 2325 | while (likely(total_rx_packets < budget)) { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2326 | union ixgbe_adv_rx_desc *rx_desc; |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2327 | struct ixgbe_rx_buffer *rx_buffer; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2328 | struct sk_buff *skb; |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2329 | unsigned int size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2330 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2331 | /* return some buffers to hardware, one at a time is too slow */ |
| 2332 | if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) { |
| 2333 | ixgbe_alloc_rx_buffers(rx_ring, cleaned_count); |
| 2334 | cleaned_count = 0; |
| 2335 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2336 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2337 | rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean); |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2338 | size = le16_to_cpu(rx_desc->wb.upper.length); |
| 2339 | if (!size) |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2340 | break; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 2341 | |
Alexander Duyck | 124b74c | 2014-12-11 15:02:28 -0800 | [diff] [blame] | 2342 | /* This memory barrier is needed to keep us from reading |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2343 | * any other fields out of the rx_desc until we know the |
Alexander Duyck | 124b74c | 2014-12-11 15:02:28 -0800 | [diff] [blame] | 2344 | * descriptor has been written back |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2345 | */ |
Alexander Duyck | 124b74c | 2014-12-11 15:02:28 -0800 | [diff] [blame] | 2346 | dma_rmb(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2347 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2348 | rx_buffer = ixgbe_get_rx_buffer(rx_ring, rx_desc, &skb, size); |
| 2349 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2350 | /* retrieve a buffer from the ring */ |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2351 | if (!skb) { |
| 2352 | xdp.data = page_address(rx_buffer->page) + |
| 2353 | rx_buffer->page_offset; |
Daniel Borkmann | 366a88f | 2017-09-25 02:25:55 +0200 | [diff] [blame] | 2354 | xdp.data_meta = xdp.data; |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2355 | xdp.data_hard_start = xdp.data - |
| 2356 | ixgbe_rx_offset(rx_ring); |
| 2357 | xdp.data_end = xdp.data + size; |
| 2358 | |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 2359 | skb = ixgbe_run_xdp(adapter, rx_ring, &xdp); |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2360 | } |
| 2361 | |
| 2362 | if (IS_ERR(skb)) { |
John Fastabend | 7379f97 | 2017-03-28 09:47:03 -0700 | [diff] [blame] | 2363 | if (PTR_ERR(skb) == -IXGBE_XDP_TX) { |
| 2364 | xdp_xmit = true; |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 2365 | ixgbe_rx_buffer_flip(rx_ring, rx_buffer, size); |
John Fastabend | 7379f97 | 2017-03-28 09:47:03 -0700 | [diff] [blame] | 2366 | } else { |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 2367 | rx_buffer->pagecnt_bias++; |
John Fastabend | 7379f97 | 2017-03-28 09:47:03 -0700 | [diff] [blame] | 2368 | } |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2369 | total_rx_packets++; |
| 2370 | total_rx_bytes += size; |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2371 | } else if (skb) { |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2372 | ixgbe_add_rx_frag(rx_ring, rx_buffer, skb, size); |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2373 | } else if (ring_uses_build_skb(rx_ring)) { |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 2374 | skb = ixgbe_build_skb(rx_ring, rx_buffer, |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2375 | &xdp, rx_desc); |
| 2376 | } else { |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2377 | skb = ixgbe_construct_skb(rx_ring, rx_buffer, |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2378 | &xdp, rx_desc); |
| 2379 | } |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2380 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2381 | /* exit if we failed to retrieve a buffer */ |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2382 | if (!skb) { |
| 2383 | rx_ring->rx_stats.alloc_rx_buff_failed++; |
| 2384 | rx_buffer->pagecnt_bias++; |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2385 | break; |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2386 | } |
Alexander Duyck | 4c1975d | 2012-01-31 02:59:23 +0000 | [diff] [blame] | 2387 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2388 | ixgbe_put_rx_buffer(rx_ring, rx_buffer, skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2389 | cleaned_count++; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2390 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2391 | /* place incomplete frames back on ring for completion */ |
| 2392 | if (ixgbe_is_non_eop(rx_ring, rx_desc, skb)) |
| 2393 | continue; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2394 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2395 | /* verify the packet layout is correct */ |
| 2396 | if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb)) |
| 2397 | continue; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 2398 | |
| 2399 | /* probably a little skewed due to removing CRC */ |
| 2400 | total_rx_bytes += skb->len; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 2401 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 2402 | /* populate checksum, timestamp, VLAN, and protocol */ |
| 2403 | ixgbe_process_skb_fields(rx_ring, rx_desc, skb); |
| 2404 | |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 2405 | #ifdef IXGBE_FCOE |
| 2406 | /* if ddp, not passing to ULD unless for FCP_RSP or error */ |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 2407 | if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) { |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 2408 | ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb); |
Mark Rustad | 4ffdf91 | 2012-07-18 06:05:50 +0000 | [diff] [blame] | 2409 | /* include DDPed FCoE data */ |
| 2410 | if (ddp_bytes > 0) { |
| 2411 | if (!mss) { |
| 2412 | mss = rx_ring->netdev->mtu - |
| 2413 | sizeof(struct fcoe_hdr) - |
| 2414 | sizeof(struct fc_frame_header) - |
| 2415 | sizeof(struct fcoe_crc_eof); |
| 2416 | if (mss > 512) |
| 2417 | mss &= ~511; |
| 2418 | } |
| 2419 | total_rx_bytes += ddp_bytes; |
| 2420 | total_rx_packets += DIV_ROUND_UP(ddp_bytes, |
| 2421 | mss); |
| 2422 | } |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 2423 | if (!ddp_bytes) { |
| 2424 | dev_kfree_skb_any(skb); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2425 | continue; |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 2426 | } |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 2427 | } |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2428 | |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 2429 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 2430 | ixgbe_rx_skb(q_vector, skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2431 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2432 | /* update budget accounting */ |
Alexander Duyck | f4de00e | 2012-09-25 00:29:37 +0000 | [diff] [blame] | 2433 | total_rx_packets++; |
Eric W. Biederman | fdabfc8a | 2014-03-14 18:00:41 -0700 | [diff] [blame] | 2434 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2435 | |
John Fastabend | 7379f97 | 2017-03-28 09:47:03 -0700 | [diff] [blame] | 2436 | if (xdp_xmit) { |
| 2437 | struct ixgbe_ring *ring = adapter->xdp_ring[smp_processor_id()]; |
| 2438 | |
| 2439 | /* Force memory writes to complete before letting h/w |
| 2440 | * know there are new descriptors to fetch. |
| 2441 | */ |
| 2442 | wmb(); |
| 2443 | writel(ring->next_to_use, ring->tail); |
John Fastabend | 11393cc | 2017-07-17 09:29:40 -0700 | [diff] [blame] | 2444 | |
| 2445 | xdp_do_flush_map(); |
John Fastabend | 7379f97 | 2017-03-28 09:47:03 -0700 | [diff] [blame] | 2446 | } |
| 2447 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 2448 | u64_stats_update_begin(&rx_ring->syncp); |
| 2449 | rx_ring->stats.packets += total_rx_packets; |
| 2450 | rx_ring->stats.bytes += total_rx_bytes; |
| 2451 | u64_stats_update_end(&rx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2452 | q_vector->rx.total_packets += total_rx_packets; |
| 2453 | q_vector->rx.total_bytes += total_rx_bytes; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2454 | |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2455 | return total_rx_packets; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2456 | } |
| 2457 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2458 | /** |
| 2459 | * ixgbe_configure_msix - Configure MSI-X hardware |
| 2460 | * @adapter: board private structure |
| 2461 | * |
| 2462 | * ixgbe_configure_msix sets up the hardware to properly generate MSI-X |
| 2463 | * interrupts. |
| 2464 | **/ |
| 2465 | static void ixgbe_configure_msix(struct ixgbe_adapter *adapter) |
| 2466 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2467 | struct ixgbe_q_vector *q_vector; |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2468 | int v_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2469 | u32 mask; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2470 | |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 2471 | /* Populate MSIX to EITR Select */ |
| 2472 | if (adapter->num_vfs > 32) { |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 2473 | u32 eitrsel = BIT(adapter->num_vfs - 32) - 1; |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 2474 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel); |
| 2475 | } |
| 2476 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 2477 | /* |
| 2478 | * Populate the IVAR table and set the ITR values to the |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2479 | * corresponding register. |
| 2480 | */ |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2481 | for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) { |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2482 | struct ixgbe_ring *ring; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2483 | q_vector = adapter->q_vector[v_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2484 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 2485 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2486 | ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2487 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 2488 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2489 | ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2490 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2491 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2492 | } |
| 2493 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2494 | switch (adapter->hw.mac.type) { |
| 2495 | case ixgbe_mac_82598EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2496 | ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2497 | v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2498 | break; |
| 2499 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2500 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2501 | case ixgbe_mac_X550: |
| 2502 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2503 | case ixgbe_mac_x550em_a: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2504 | ixgbe_set_ivar(adapter, -1, 1, v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2505 | break; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2506 | default: |
| 2507 | break; |
| 2508 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2509 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2510 | |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 2511 | /* set up to autoclear timer, and the vectors */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2512 | mask = IXGBE_EIMS_ENABLE_MASK; |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2513 | mask &= ~(IXGBE_EIMS_OTHER | |
| 2514 | IXGBE_EIMS_MAILBOX | |
| 2515 | IXGBE_EIMS_LSC); |
| 2516 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2517 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2518 | } |
| 2519 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2520 | /** |
| 2521 | * ixgbe_update_itr - update the dynamic ITR value based on statistics |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2522 | * @q_vector: structure containing interrupt and ring information |
| 2523 | * @ring_container: structure containing ring performance data |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2524 | * |
| 2525 | * Stores a new ITR value based on packets and byte |
| 2526 | * counts during the last interrupt. The advantage of per interrupt |
| 2527 | * computation is faster updates and more accurate ITR for the current |
| 2528 | * traffic pattern. Constants in this function were computed |
| 2529 | * based on theoretical maximum wire speed and thresholds were set based |
| 2530 | * on testing data as well as attempting to minimize response time |
| 2531 | * while increasing bulk throughput. |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2532 | **/ |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2533 | static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector, |
| 2534 | struct ixgbe_ring_container *ring_container) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2535 | { |
Alexander Duyck | b4ded83 | 2017-09-25 14:55:36 -0700 | [diff] [blame] | 2536 | unsigned int itr = IXGBE_ITR_ADAPTIVE_MIN_USECS | |
| 2537 | IXGBE_ITR_ADAPTIVE_LATENCY; |
| 2538 | unsigned int avg_wire_size, packets, bytes; |
| 2539 | unsigned long next_update = jiffies; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2540 | |
Alexander Duyck | b4ded83 | 2017-09-25 14:55:36 -0700 | [diff] [blame] | 2541 | /* If we don't have any rings just leave ourselves set for maximum |
| 2542 | * possible latency so we take ourselves out of the equation. |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2543 | */ |
Alexander Duyck | b4ded83 | 2017-09-25 14:55:36 -0700 | [diff] [blame] | 2544 | if (!ring_container->ring) |
Don Skidmore | bdbeefe | 2013-03-02 07:17:37 +0000 | [diff] [blame] | 2545 | return; |
| 2546 | |
Alexander Duyck | b4ded83 | 2017-09-25 14:55:36 -0700 | [diff] [blame] | 2547 | /* If we didn't update within up to 1 - 2 jiffies we can assume |
| 2548 | * that either packets are coming in so slow there hasn't been |
| 2549 | * any work, or that there is so much work that NAPI is dealing |
| 2550 | * with interrupt moderation and we don't need to do anything. |
| 2551 | */ |
| 2552 | if (time_after(next_update, ring_container->next_update)) |
| 2553 | goto clear_counts; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2554 | |
Alexander Duyck | b4ded83 | 2017-09-25 14:55:36 -0700 | [diff] [blame] | 2555 | packets = ring_container->total_packets; |
| 2556 | |
| 2557 | /* We have no packets to actually measure against. This means |
| 2558 | * either one of the other queues on this vector is active or |
| 2559 | * we are a Tx queue doing TSO with too high of an interrupt rate. |
| 2560 | * |
| 2561 | * When this occurs just tick up our delay by the minimum value |
| 2562 | * and hope that this extra delay will prevent us from being called |
| 2563 | * without any work on our queue. |
| 2564 | */ |
| 2565 | if (!packets) { |
| 2566 | itr = (q_vector->itr >> 2) + IXGBE_ITR_ADAPTIVE_MIN_INC; |
| 2567 | if (itr > IXGBE_ITR_ADAPTIVE_MAX_USECS) |
| 2568 | itr = IXGBE_ITR_ADAPTIVE_MAX_USECS; |
| 2569 | itr += ring_container->itr & IXGBE_ITR_ADAPTIVE_LATENCY; |
| 2570 | goto clear_counts; |
| 2571 | } |
| 2572 | |
| 2573 | bytes = ring_container->total_bytes; |
| 2574 | |
| 2575 | /* If packets are less than 4 or bytes are less than 9000 assume |
| 2576 | * insufficient data to use bulk rate limiting approach. We are |
| 2577 | * likely latency driven. |
| 2578 | */ |
| 2579 | if (packets < 4 && bytes < 9000) { |
| 2580 | itr = IXGBE_ITR_ADAPTIVE_LATENCY; |
| 2581 | goto adjust_by_size; |
| 2582 | } |
| 2583 | |
| 2584 | /* Between 4 and 48 we can assume that our current interrupt delay |
| 2585 | * is only slightly too low. As such we should increase it by a small |
| 2586 | * fixed amount. |
| 2587 | */ |
| 2588 | if (packets < 48) { |
| 2589 | itr = (q_vector->itr >> 2) + IXGBE_ITR_ADAPTIVE_MIN_INC; |
| 2590 | if (itr > IXGBE_ITR_ADAPTIVE_MAX_USECS) |
| 2591 | itr = IXGBE_ITR_ADAPTIVE_MAX_USECS; |
| 2592 | goto clear_counts; |
| 2593 | } |
| 2594 | |
| 2595 | /* Between 48 and 96 is our "goldilocks" zone where we are working |
| 2596 | * out "just right". Just report that our current ITR is good for us. |
| 2597 | */ |
| 2598 | if (packets < 96) { |
| 2599 | itr = q_vector->itr >> 2; |
| 2600 | goto clear_counts; |
| 2601 | } |
| 2602 | |
| 2603 | /* If packet count is 96 or greater we are likely looking at a slight |
| 2604 | * overrun of the delay we want. Try halving our delay to see if that |
| 2605 | * will cut the number of packets in half per interrupt. |
| 2606 | */ |
| 2607 | if (packets < 256) { |
| 2608 | itr = q_vector->itr >> 3; |
| 2609 | if (itr < IXGBE_ITR_ADAPTIVE_MIN_USECS) |
| 2610 | itr = IXGBE_ITR_ADAPTIVE_MIN_USECS; |
| 2611 | goto clear_counts; |
| 2612 | } |
| 2613 | |
| 2614 | /* The paths below assume we are dealing with a bulk ITR since number |
| 2615 | * of packets is 256 or greater. We are just going to have to compute |
| 2616 | * a value and try to bring the count under control, though for smaller |
| 2617 | * packet sizes there isn't much we can do as NAPI polling will likely |
| 2618 | * be kicking in sooner rather than later. |
| 2619 | */ |
| 2620 | itr = IXGBE_ITR_ADAPTIVE_BULK; |
| 2621 | |
| 2622 | adjust_by_size: |
| 2623 | /* If packet counts are 256 or greater we can assume we have a gross |
| 2624 | * overestimation of what the rate should be. Instead of trying to fine |
| 2625 | * tune it just use the formula below to try and dial in an exact value |
| 2626 | * give the current packet size of the frame. |
| 2627 | */ |
| 2628 | avg_wire_size = bytes / packets; |
| 2629 | |
| 2630 | /* The following is a crude approximation of: |
| 2631 | * wmem_default / (size + overhead) = desired_pkts_per_int |
| 2632 | * rate / bits_per_byte / (size + ethernet overhead) = pkt_rate |
| 2633 | * (desired_pkt_rate / pkt_rate) * usecs_per_sec = ITR value |
| 2634 | * |
| 2635 | * Assuming wmem_default is 212992 and overhead is 640 bytes per |
| 2636 | * packet, (256 skb, 64 headroom, 320 shared info), we can reduce the |
| 2637 | * formula down to |
| 2638 | * |
| 2639 | * (170 * (size + 24)) / (size + 640) = ITR |
| 2640 | * |
| 2641 | * We first do some math on the packet size and then finally bitshift |
| 2642 | * by 8 after rounding up. We also have to account for PCIe link speed |
| 2643 | * difference as ITR scales based on this. |
| 2644 | */ |
| 2645 | if (avg_wire_size <= 60) { |
| 2646 | /* Start at 50k ints/sec */ |
| 2647 | avg_wire_size = 5120; |
| 2648 | } else if (avg_wire_size <= 316) { |
| 2649 | /* 50K ints/sec to 16K ints/sec */ |
| 2650 | avg_wire_size *= 40; |
| 2651 | avg_wire_size += 2720; |
| 2652 | } else if (avg_wire_size <= 1084) { |
| 2653 | /* 16K ints/sec to 9.2K ints/sec */ |
| 2654 | avg_wire_size *= 15; |
| 2655 | avg_wire_size += 11452; |
| 2656 | } else if (avg_wire_size <= 1980) { |
| 2657 | /* 9.2K ints/sec to 8K ints/sec */ |
| 2658 | avg_wire_size *= 5; |
| 2659 | avg_wire_size += 22420; |
| 2660 | } else { |
| 2661 | /* plateau at a limit of 8K ints/sec */ |
| 2662 | avg_wire_size = 32256; |
| 2663 | } |
| 2664 | |
| 2665 | /* If we are in low latency mode half our delay which doubles the rate |
| 2666 | * to somewhere between 100K to 16K ints/sec |
| 2667 | */ |
| 2668 | if (itr & IXGBE_ITR_ADAPTIVE_LATENCY) |
| 2669 | avg_wire_size >>= 1; |
| 2670 | |
| 2671 | /* Resultant value is 256 times larger than it needs to be. This |
| 2672 | * gives us room to adjust the value as needed to either increase |
| 2673 | * or decrease the value based on link speeds of 10G, 2.5G, 1G, etc. |
| 2674 | * |
| 2675 | * Use addition as we have already recorded the new latency flag |
| 2676 | * for the ITR value. |
| 2677 | */ |
| 2678 | switch (q_vector->adapter->link_speed) { |
| 2679 | case IXGBE_LINK_SPEED_10GB_FULL: |
| 2680 | case IXGBE_LINK_SPEED_100_FULL: |
| 2681 | default: |
| 2682 | itr += DIV_ROUND_UP(avg_wire_size, |
| 2683 | IXGBE_ITR_ADAPTIVE_MIN_INC * 256) * |
| 2684 | IXGBE_ITR_ADAPTIVE_MIN_INC; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2685 | break; |
Alexander Duyck | b4ded83 | 2017-09-25 14:55:36 -0700 | [diff] [blame] | 2686 | case IXGBE_LINK_SPEED_2_5GB_FULL: |
| 2687 | case IXGBE_LINK_SPEED_1GB_FULL: |
| 2688 | case IXGBE_LINK_SPEED_10_FULL: |
| 2689 | itr += DIV_ROUND_UP(avg_wire_size, |
| 2690 | IXGBE_ITR_ADAPTIVE_MIN_INC * 64) * |
| 2691 | IXGBE_ITR_ADAPTIVE_MIN_INC; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2692 | break; |
| 2693 | } |
| 2694 | |
Alexander Duyck | b4ded83 | 2017-09-25 14:55:36 -0700 | [diff] [blame] | 2695 | clear_counts: |
| 2696 | /* write back value */ |
| 2697 | ring_container->itr = itr; |
| 2698 | |
| 2699 | /* next update should occur within next jiffy */ |
| 2700 | ring_container->next_update = next_update + 1; |
| 2701 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2702 | ring_container->total_bytes = 0; |
| 2703 | ring_container->total_packets = 0; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2704 | } |
| 2705 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2706 | /** |
| 2707 | * ixgbe_write_eitr - write EITR register in hardware specific way |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2708 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2709 | * |
| 2710 | * This function is made to be called by ethtool and by the driver |
| 2711 | * when it needs to update EITR registers at runtime. Hardware |
| 2712 | * specific quirks/differences are taken care of here. |
| 2713 | */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2714 | void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector) |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2715 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2716 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2717 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2718 | int v_idx = q_vector->v_idx; |
Alexander Duyck | 5d967eb | 2012-02-08 07:49:43 +0000 | [diff] [blame] | 2719 | u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2720 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2721 | switch (adapter->hw.mac.type) { |
| 2722 | case ixgbe_mac_82598EB: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2723 | /* must write high and low 16 bits to reset counter */ |
| 2724 | itr_reg |= (itr_reg << 16); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2725 | break; |
| 2726 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2727 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2728 | case ixgbe_mac_X550: |
| 2729 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2730 | case ixgbe_mac_x550em_a: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2731 | /* |
| 2732 | * set the WDIS bit to not clear the timer bits and cause an |
| 2733 | * immediate assertion of the interrupt |
| 2734 | */ |
| 2735 | itr_reg |= IXGBE_EITR_CNT_WDIS; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2736 | break; |
| 2737 | default: |
| 2738 | break; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2739 | } |
| 2740 | IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg); |
| 2741 | } |
| 2742 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2743 | static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2744 | { |
Alexander Duyck | b4ded83 | 2017-09-25 14:55:36 -0700 | [diff] [blame] | 2745 | u32 new_itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2746 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2747 | ixgbe_update_itr(q_vector, &q_vector->tx); |
| 2748 | ixgbe_update_itr(q_vector, &q_vector->rx); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2749 | |
Alexander Duyck | b4ded83 | 2017-09-25 14:55:36 -0700 | [diff] [blame] | 2750 | /* use the smallest value of new ITR delay calculations */ |
| 2751 | new_itr = min(q_vector->rx.itr, q_vector->tx.itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2752 | |
Alexander Duyck | b4ded83 | 2017-09-25 14:55:36 -0700 | [diff] [blame] | 2753 | /* Clear latency flag if set, shift into correct position */ |
| 2754 | new_itr &= ~IXGBE_ITR_ADAPTIVE_LATENCY; |
| 2755 | new_itr <<= 2; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2756 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2757 | if (new_itr != q_vector->itr) { |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2758 | /* save the algorithm value here */ |
Alexander Duyck | 5d967eb | 2012-02-08 07:49:43 +0000 | [diff] [blame] | 2759 | q_vector->itr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2760 | |
| 2761 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2762 | } |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2763 | } |
| 2764 | |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2765 | /** |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2766 | * ixgbe_check_overtemp_subtask - check for over temperature |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2767 | * @adapter: pointer to adapter |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2768 | **/ |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2769 | static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter) |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2770 | { |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2771 | struct ixgbe_hw *hw = &adapter->hw; |
| 2772 | u32 eicr = adapter->interrupt_event; |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 2773 | s32 rc; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2774 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2775 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2776 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2777 | |
Mark Rustad | 22cb4ff | 2017-04-25 13:55:25 -0700 | [diff] [blame] | 2778 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT)) |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2779 | return; |
| 2780 | |
| 2781 | adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2782 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2783 | switch (hw->device_id) { |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2784 | case IXGBE_DEV_ID_82599_T3_LOM: |
| 2785 | /* |
| 2786 | * Since the warning interrupt is for both ports |
| 2787 | * we don't have to check if: |
| 2788 | * - This interrupt wasn't for our port. |
| 2789 | * - We may have missed the interrupt so always have to |
| 2790 | * check if we got a LSC |
| 2791 | */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2792 | if (!(eicr & IXGBE_EICR_GPI_SDP0_8259X) && |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2793 | !(eicr & IXGBE_EICR_LSC)) |
| 2794 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2795 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2796 | if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) { |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 2797 | u32 speed; |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2798 | bool link_up = false; |
| 2799 | |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 2800 | hw->mac.ops.check_link(hw, &speed, &link_up, false); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2801 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2802 | if (link_up) |
| 2803 | return; |
| 2804 | } |
| 2805 | |
| 2806 | /* Check if this is not due to overtemp */ |
| 2807 | if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP) |
| 2808 | return; |
| 2809 | |
| 2810 | break; |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 2811 | case IXGBE_DEV_ID_X550EM_A_1G_T: |
| 2812 | case IXGBE_DEV_ID_X550EM_A_1G_T_L: |
| 2813 | rc = hw->phy.ops.check_overtemp(hw); |
| 2814 | if (rc != IXGBE_ERR_OVERTEMP) |
| 2815 | return; |
| 2816 | break; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2817 | default: |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 2818 | if (adapter->hw.mac.type >= ixgbe_mac_X540) |
| 2819 | return; |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2820 | if (!(eicr & IXGBE_EICR_GPI_SDP0(hw))) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2821 | return; |
| 2822 | break; |
| 2823 | } |
Don Skidmore | f44e751 | 2015-06-09 16:36:23 -0700 | [diff] [blame] | 2824 | e_crit(drv, "%s\n", ixgbe_overheat_msg); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2825 | |
| 2826 | adapter->interrupt_event = 0; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2827 | } |
| 2828 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2829 | static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr) |
| 2830 | { |
| 2831 | struct ixgbe_hw *hw = &adapter->hw; |
| 2832 | |
| 2833 | if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) && |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2834 | (eicr & IXGBE_EICR_GPI_SDP1(hw))) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2835 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2836 | /* write to clear the interrupt */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2837 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw)); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2838 | } |
| 2839 | } |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2840 | |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2841 | static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 2842 | { |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2843 | struct ixgbe_hw *hw = &adapter->hw; |
| 2844 | |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2845 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)) |
| 2846 | return; |
| 2847 | |
| 2848 | switch (adapter->hw.mac.type) { |
| 2849 | case ixgbe_mac_82599EB: |
| 2850 | /* |
| 2851 | * Need to check link state so complete overtemp check |
| 2852 | * on service task |
| 2853 | */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2854 | if (((eicr & IXGBE_EICR_GPI_SDP0(hw)) || |
| 2855 | (eicr & IXGBE_EICR_LSC)) && |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2856 | (!test_bit(__IXGBE_DOWN, &adapter->state))) { |
| 2857 | adapter->interrupt_event = eicr; |
| 2858 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2859 | ixgbe_service_event_schedule(adapter); |
| 2860 | return; |
| 2861 | } |
| 2862 | return; |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 2863 | case ixgbe_mac_x550em_a: |
| 2864 | if (eicr & IXGBE_EICR_GPI_SDP0_X550EM_a) { |
| 2865 | adapter->interrupt_event = eicr; |
| 2866 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2867 | ixgbe_service_event_schedule(adapter); |
| 2868 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, |
| 2869 | IXGBE_EICR_GPI_SDP0_X550EM_a); |
| 2870 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICR, |
| 2871 | IXGBE_EICR_GPI_SDP0_X550EM_a); |
| 2872 | } |
| 2873 | return; |
| 2874 | case ixgbe_mac_X550: |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2875 | case ixgbe_mac_X540: |
| 2876 | if (!(eicr & IXGBE_EICR_TS)) |
| 2877 | return; |
| 2878 | break; |
| 2879 | default: |
| 2880 | return; |
| 2881 | } |
| 2882 | |
Don Skidmore | f44e751 | 2015-06-09 16:36:23 -0700 | [diff] [blame] | 2883 | e_crit(drv, "%s\n", ixgbe_overheat_msg); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2884 | } |
| 2885 | |
Don Skidmore | 45788d2 | 2015-06-09 16:59:04 -0700 | [diff] [blame] | 2886 | static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw) |
| 2887 | { |
| 2888 | switch (hw->mac.type) { |
| 2889 | case ixgbe_mac_82598EB: |
| 2890 | if (hw->phy.type == ixgbe_phy_nl) |
| 2891 | return true; |
| 2892 | return false; |
| 2893 | case ixgbe_mac_82599EB: |
| 2894 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2895 | case ixgbe_mac_x550em_a: |
Don Skidmore | 45788d2 | 2015-06-09 16:59:04 -0700 | [diff] [blame] | 2896 | switch (hw->mac.ops.get_media_type(hw)) { |
| 2897 | case ixgbe_media_type_fiber: |
| 2898 | case ixgbe_media_type_fiber_qsfp: |
| 2899 | return true; |
| 2900 | default: |
| 2901 | return false; |
| 2902 | } |
| 2903 | default: |
| 2904 | return false; |
| 2905 | } |
| 2906 | } |
| 2907 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2908 | static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 2909 | { |
| 2910 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 4ccc650 | 2015-09-02 13:47:54 -0700 | [diff] [blame] | 2911 | u32 eicr_mask = IXGBE_EICR_GPI_SDP2(hw); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2912 | |
Don Skidmore | 4ccc650 | 2015-09-02 13:47:54 -0700 | [diff] [blame] | 2913 | if (!ixgbe_is_sfp(hw)) |
| 2914 | return; |
| 2915 | |
| 2916 | /* Later MAC's use different SDP */ |
| 2917 | if (hw->mac.type >= ixgbe_mac_X540) |
| 2918 | eicr_mask = IXGBE_EICR_GPI_SDP0_X540; |
| 2919 | |
| 2920 | if (eicr & eicr_mask) { |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2921 | /* Clear the interrupt */ |
Don Skidmore | 4ccc650 | 2015-09-02 13:47:54 -0700 | [diff] [blame] | 2922 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr_mask); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2923 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2924 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
Mark Rustad | 58e7cd2 | 2015-08-08 16:18:48 -0700 | [diff] [blame] | 2925 | adapter->sfp_poll_time = 0; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2926 | ixgbe_service_event_schedule(adapter); |
| 2927 | } |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2928 | } |
| 2929 | |
Don Skidmore | 4ccc650 | 2015-09-02 13:47:54 -0700 | [diff] [blame] | 2930 | if (adapter->hw.mac.type == ixgbe_mac_82599EB && |
| 2931 | (eicr & IXGBE_EICR_GPI_SDP1(hw))) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2932 | /* Clear the interrupt */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2933 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw)); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2934 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2935 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 2936 | ixgbe_service_event_schedule(adapter); |
| 2937 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2938 | } |
| 2939 | } |
| 2940 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2941 | static void ixgbe_check_lsc(struct ixgbe_adapter *adapter) |
| 2942 | { |
| 2943 | struct ixgbe_hw *hw = &adapter->hw; |
| 2944 | |
| 2945 | adapter->lsc_int++; |
| 2946 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 2947 | adapter->link_check_timeout = jiffies; |
| 2948 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2949 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC); |
Nelson, Shannon | 8a0717f | 2009-11-12 18:47:11 +0000 | [diff] [blame] | 2950 | IXGBE_WRITE_FLUSH(hw); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 2951 | ixgbe_service_event_schedule(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2952 | } |
| 2953 | } |
| 2954 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2955 | static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter, |
| 2956 | u64 qmask) |
| 2957 | { |
| 2958 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2959 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2960 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2961 | switch (hw->mac.type) { |
| 2962 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2963 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2964 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask); |
| 2965 | break; |
| 2966 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2967 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2968 | case ixgbe_mac_X550: |
| 2969 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2970 | case ixgbe_mac_x550em_a: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2971 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2972 | if (mask) |
| 2973 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2974 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2975 | if (mask) |
| 2976 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask); |
| 2977 | break; |
| 2978 | default: |
| 2979 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2980 | } |
| 2981 | /* skip the flush */ |
| 2982 | } |
| 2983 | |
| 2984 | static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2985 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2986 | { |
| 2987 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2988 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2989 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2990 | switch (hw->mac.type) { |
| 2991 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2992 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2993 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask); |
| 2994 | break; |
| 2995 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2996 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2997 | case ixgbe_mac_X550: |
| 2998 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2999 | case ixgbe_mac_x550em_a: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 3000 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3001 | if (mask) |
| 3002 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 3003 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3004 | if (mask) |
| 3005 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask); |
| 3006 | break; |
| 3007 | default: |
| 3008 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 3009 | } |
| 3010 | /* skip the flush */ |
| 3011 | } |
| 3012 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3013 | /** |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3014 | * ixgbe_irq_enable - Enable default interrupt generation settings |
| 3015 | * @adapter: board private structure |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3016 | **/ |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3017 | static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues, |
| 3018 | bool flush) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3019 | { |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 3020 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3021 | u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE); |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 3022 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3023 | /* don't reenable LSC while waiting for link */ |
| 3024 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 3025 | mask &= ~IXGBE_EIMS_LSC; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3026 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3027 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 3028 | switch (adapter->hw.mac.type) { |
| 3029 | case ixgbe_mac_82599EB: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 3030 | mask |= IXGBE_EIMS_GPI_SDP0(hw); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 3031 | break; |
| 3032 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 3033 | case ixgbe_mac_X550: |
| 3034 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 3035 | case ixgbe_mac_x550em_a: |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 3036 | mask |= IXGBE_EIMS_TS; |
| 3037 | break; |
| 3038 | default: |
| 3039 | break; |
| 3040 | } |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3041 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 3042 | mask |= IXGBE_EIMS_GPI_SDP1(hw); |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3043 | switch (adapter->hw.mac.type) { |
| 3044 | case ixgbe_mac_82599EB: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 3045 | mask |= IXGBE_EIMS_GPI_SDP1(hw); |
| 3046 | mask |= IXGBE_EIMS_GPI_SDP2(hw); |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 3047 | /* fall through */ |
Don Skidmore | 858bc08 | 2011-08-04 09:28:30 +0000 | [diff] [blame] | 3048 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 3049 | case ixgbe_mac_X550: |
| 3050 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 3051 | case ixgbe_mac_x550em_a: |
| 3052 | if (adapter->hw.device_id == IXGBE_DEV_ID_X550EM_X_SFP || |
Mark Rustad | 2d40cd1 | 2016-04-01 12:18:35 -0700 | [diff] [blame] | 3053 | adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP || |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 3054 | adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP_N) |
Mark Rustad | cbd45ec | 2015-08-08 16:17:51 -0700 | [diff] [blame] | 3055 | mask |= IXGBE_EIMS_GPI_SDP0(&adapter->hw); |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 3056 | if (adapter->hw.phy.type == ixgbe_phy_x550em_ext_t) |
| 3057 | mask |= IXGBE_EICR_GPI_SDP0_X540; |
Don Skidmore | 858bc08 | 2011-08-04 09:28:30 +0000 | [diff] [blame] | 3058 | mask |= IXGBE_EIMS_ECC; |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3059 | mask |= IXGBE_EIMS_MAILBOX; |
| 3060 | break; |
| 3061 | default: |
| 3062 | break; |
| 3063 | } |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 3064 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3065 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) && |
| 3066 | !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 3067 | mask |= IXGBE_EIMS_FLOW_DIR; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3068 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3069 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
| 3070 | if (queues) |
| 3071 | ixgbe_irq_enable_queues(adapter, ~0); |
| 3072 | if (flush) |
| 3073 | IXGBE_WRITE_FLUSH(&adapter->hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3074 | } |
| 3075 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3076 | static irqreturn_t ixgbe_msix_other(int irq, void *data) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3077 | { |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3078 | struct ixgbe_adapter *adapter = data; |
| 3079 | struct ixgbe_hw *hw = &adapter->hw; |
| 3080 | u32 eicr; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3081 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3082 | /* |
| 3083 | * Workaround for Silicon errata. Use clear-by-write instead |
| 3084 | * of clear-by-read. Reading with EICS will return the |
| 3085 | * interrupt causes without clearing, which later be done |
| 3086 | * with the write to EICR. |
| 3087 | */ |
| 3088 | eicr = IXGBE_READ_REG(hw, IXGBE_EICS); |
Jacob Keller | d87d830 | 2013-03-02 07:51:42 +0000 | [diff] [blame] | 3089 | |
| 3090 | /* The lower 16bits of the EICR register are for the queue interrupts |
Joe Perches | dbedd44 | 2015-03-06 20:49:12 -0800 | [diff] [blame] | 3091 | * 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] | 3092 | * the bits are high when ixgbe_msix_other is called. There is a race |
| 3093 | * condition otherwise which results in possible performance loss |
| 3094 | * especially if the ixgbe_msix_other interrupt is triggering |
| 3095 | * consistently (as it would when PPS is turned on for the X540 device) |
| 3096 | */ |
| 3097 | eicr &= 0xFFFF0000; |
| 3098 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3099 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3100 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3101 | if (eicr & IXGBE_EICR_LSC) |
| 3102 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3103 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3104 | if (eicr & IXGBE_EICR_MAILBOX) |
| 3105 | ixgbe_msg_task(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3106 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3107 | switch (hw->mac.type) { |
| 3108 | case ixgbe_mac_82599EB: |
| 3109 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 3110 | case ixgbe_mac_X550: |
| 3111 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 3112 | case ixgbe_mac_x550em_a: |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 3113 | if (hw->phy.type == ixgbe_phy_x550em_ext_t && |
| 3114 | (eicr & IXGBE_EICR_GPI_SDP0_X540)) { |
| 3115 | adapter->flags2 |= IXGBE_FLAG2_PHY_INTERRUPT; |
| 3116 | ixgbe_service_event_schedule(adapter); |
| 3117 | IXGBE_WRITE_REG(hw, IXGBE_EICR, |
| 3118 | IXGBE_EICR_GPI_SDP0_X540); |
| 3119 | } |
Don Skidmore | d773ce2 | 2014-02-25 17:58:53 -0800 | [diff] [blame] | 3120 | if (eicr & IXGBE_EICR_ECC) { |
| 3121 | e_info(link, "Received ECC Err, initiating reset\n"); |
Emil Tantilov | 57ca2a4 | 2016-07-29 14:46:31 -0700 | [diff] [blame] | 3122 | set_bit(__IXGBE_RESET_REQUESTED, &adapter->state); |
Don Skidmore | d773ce2 | 2014-02-25 17:58:53 -0800 | [diff] [blame] | 3123 | ixgbe_service_event_schedule(adapter); |
| 3124 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC); |
| 3125 | } |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3126 | /* Handle Flow Director Full threshold interrupt */ |
| 3127 | if (eicr & IXGBE_EICR_FLOW_DIR) { |
| 3128 | int reinit_count = 0; |
| 3129 | int i; |
| 3130 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 3131 | struct ixgbe_ring *ring = adapter->tx_ring[i]; |
| 3132 | if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE, |
| 3133 | &ring->state)) |
| 3134 | reinit_count++; |
| 3135 | } |
| 3136 | if (reinit_count) { |
| 3137 | /* no more flow director interrupts until after init */ |
| 3138 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR); |
| 3139 | adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 3140 | ixgbe_service_event_schedule(adapter); |
| 3141 | } |
| 3142 | } |
| 3143 | ixgbe_check_sfp_event(adapter, eicr); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 3144 | ixgbe_check_overtemp_event(adapter, eicr); |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3145 | break; |
| 3146 | default: |
| 3147 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3148 | } |
| 3149 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3150 | ixgbe_check_fan_failure(adapter, eicr); |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 3151 | |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 3152 | if (unlikely(eicr & IXGBE_EICR_TIMESYNC)) |
Mark Rustad | a9763f3 | 2015-10-27 09:58:07 -0700 | [diff] [blame] | 3153 | ixgbe_ptp_check_pps_event(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3154 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3155 | /* re-enable the original interrupt state, no lsc, no queues */ |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 3156 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3157 | ixgbe_irq_enable(adapter, false, false); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3158 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3159 | return IRQ_HANDLED; |
| 3160 | } |
| 3161 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 3162 | static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3163 | { |
| 3164 | struct ixgbe_q_vector *q_vector = data; |
| 3165 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3166 | /* EIAM disabled interrupts (on this vector) for us */ |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 3167 | |
| 3168 | if (q_vector->rx.ring || q_vector->tx.ring) |
Alexander Duyck | ef2662b | 2015-09-29 15:19:43 -0700 | [diff] [blame] | 3169 | napi_schedule_irqoff(&q_vector->napi); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3170 | |
| 3171 | return IRQ_HANDLED; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3172 | } |
| 3173 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3174 | /** |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 3175 | * ixgbe_poll - NAPI Rx polling callback |
| 3176 | * @napi: structure for representing this polling device |
| 3177 | * @budget: how many packets driver is allowed to clean |
| 3178 | * |
| 3179 | * This function is used for legacy and MSI, NAPI mode |
| 3180 | **/ |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 3181 | int ixgbe_poll(struct napi_struct *napi, int budget) |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 3182 | { |
| 3183 | struct ixgbe_q_vector *q_vector = |
| 3184 | container_of(napi, struct ixgbe_q_vector, napi); |
| 3185 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 3186 | struct ixgbe_ring *ring; |
Jesse Brandeburg | 32b3e08 | 2015-09-24 16:35:47 -0700 | [diff] [blame] | 3187 | int per_ring_budget, work_done = 0; |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 3188 | bool clean_complete = true; |
| 3189 | |
| 3190 | #ifdef CONFIG_IXGBE_DCA |
| 3191 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 3192 | ixgbe_update_dca(q_vector); |
| 3193 | #endif |
| 3194 | |
Alexander Duyck | 8220bbc | 2016-03-07 09:30:09 -0800 | [diff] [blame] | 3195 | ixgbe_for_each_ring(ring, q_vector->tx) { |
| 3196 | if (!ixgbe_clean_tx_irq(q_vector, ring, budget)) |
| 3197 | clean_complete = false; |
| 3198 | } |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 3199 | |
Eric Dumazet | 3ffc1af | 2017-02-02 16:26:39 -0800 | [diff] [blame] | 3200 | /* Exit if we are called by netpoll */ |
| 3201 | if (budget <= 0) |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 3202 | return budget; |
| 3203 | |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 3204 | /* attempt to distribute budget to each queue fairly, but don't allow |
| 3205 | * the budget to go below 1 because we'll exit polling */ |
| 3206 | if (q_vector->rx.count > 1) |
| 3207 | per_ring_budget = max(budget/q_vector->rx.count, 1); |
| 3208 | else |
| 3209 | per_ring_budget = budget; |
| 3210 | |
Jesse Brandeburg | 32b3e08 | 2015-09-24 16:35:47 -0700 | [diff] [blame] | 3211 | ixgbe_for_each_ring(ring, q_vector->rx) { |
| 3212 | int cleaned = ixgbe_clean_rx_irq(q_vector, ring, |
| 3213 | per_ring_budget); |
| 3214 | |
| 3215 | work_done += cleaned; |
Alexander Duyck | 8220bbc | 2016-03-07 09:30:09 -0800 | [diff] [blame] | 3216 | if (cleaned >= per_ring_budget) |
| 3217 | clean_complete = false; |
Jesse Brandeburg | 32b3e08 | 2015-09-24 16:35:47 -0700 | [diff] [blame] | 3218 | } |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 3219 | |
| 3220 | /* If all work not completed, return budget and keep polling */ |
| 3221 | if (!clean_complete) |
| 3222 | return budget; |
| 3223 | |
| 3224 | /* all work done, exit the polling mode */ |
Jesse Brandeburg | 32b3e08 | 2015-09-24 16:35:47 -0700 | [diff] [blame] | 3225 | napi_complete_done(napi, work_done); |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 3226 | if (adapter->rx_itr_setting & 1) |
| 3227 | ixgbe_set_itr(q_vector); |
| 3228 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 3229 | ixgbe_irq_enable_queues(adapter, BIT_ULL(q_vector->v_idx)); |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 3230 | |
Paolo Abeni | 4b732cd | 2016-06-15 15:37:59 +0200 | [diff] [blame] | 3231 | return min(work_done, budget - 1); |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 3232 | } |
| 3233 | |
| 3234 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3235 | * ixgbe_request_msix_irqs - Initialize MSI-X interrupts |
| 3236 | * @adapter: board private structure |
| 3237 | * |
| 3238 | * ixgbe_request_msix_irqs allocates MSI-X vectors and requests |
| 3239 | * interrupts from the kernel. |
| 3240 | **/ |
| 3241 | static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter) |
| 3242 | { |
| 3243 | struct net_device *netdev = adapter->netdev; |
Tony Nguyen | e61e4c8 | 2017-05-12 11:38:07 -0700 | [diff] [blame] | 3244 | unsigned int ri = 0, ti = 0; |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 3245 | int vector, err; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3246 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3247 | for (vector = 0; vector < adapter->num_q_vectors; vector++) { |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 3248 | struct ixgbe_q_vector *q_vector = adapter->q_vector[vector]; |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 3249 | struct msix_entry *entry = &adapter->msix_entries[vector]; |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 3250 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 3251 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Tony Nguyen | e61e4c8 | 2017-05-12 11:38:07 -0700 | [diff] [blame] | 3252 | snprintf(q_vector->name, sizeof(q_vector->name), |
| 3253 | "%s-TxRx-%u", netdev->name, ri++); |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 3254 | ti++; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 3255 | } else if (q_vector->rx.ring) { |
Tony Nguyen | e61e4c8 | 2017-05-12 11:38:07 -0700 | [diff] [blame] | 3256 | snprintf(q_vector->name, sizeof(q_vector->name), |
| 3257 | "%s-rx-%u", netdev->name, ri++); |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 3258 | } else if (q_vector->tx.ring) { |
Tony Nguyen | e61e4c8 | 2017-05-12 11:38:07 -0700 | [diff] [blame] | 3259 | snprintf(q_vector->name, sizeof(q_vector->name), |
| 3260 | "%s-tx-%u", netdev->name, ti++); |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 3261 | } else { |
| 3262 | /* skip this unused q_vector */ |
| 3263 | continue; |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 3264 | } |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 3265 | err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0, |
| 3266 | q_vector->name, q_vector); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3267 | if (err) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 3268 | e_err(probe, "request_irq failed for MSIX interrupt " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 3269 | "Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3270 | goto free_queue_irqs; |
| 3271 | } |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 3272 | /* If Flow Director is enabled, set interrupt affinity */ |
| 3273 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 3274 | /* assign the mask for this irq */ |
| 3275 | irq_set_affinity_hint(entry->vector, |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 3276 | &q_vector->affinity_mask); |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 3277 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3278 | } |
| 3279 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3280 | err = request_irq(adapter->msix_entries[vector].vector, |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3281 | ixgbe_msix_other, 0, netdev->name, adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3282 | if (err) { |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 3283 | e_err(probe, "request_irq for msix_other failed: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3284 | goto free_queue_irqs; |
| 3285 | } |
| 3286 | |
| 3287 | return 0; |
| 3288 | |
| 3289 | free_queue_irqs: |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 3290 | while (vector) { |
| 3291 | vector--; |
| 3292 | irq_set_affinity_hint(adapter->msix_entries[vector].vector, |
| 3293 | NULL); |
| 3294 | free_irq(adapter->msix_entries[vector].vector, |
| 3295 | adapter->q_vector[vector]); |
| 3296 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3297 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 3298 | pci_disable_msix(adapter->pdev); |
| 3299 | kfree(adapter->msix_entries); |
| 3300 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3301 | return err; |
| 3302 | } |
| 3303 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 3304 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3305 | * ixgbe_intr - legacy mode Interrupt Handler |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3306 | * @irq: interrupt number |
| 3307 | * @data: pointer to a network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3308 | **/ |
| 3309 | static irqreturn_t ixgbe_intr(int irq, void *data) |
| 3310 | { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 3311 | struct ixgbe_adapter *adapter = data; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3312 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3313 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3314 | u32 eicr; |
| 3315 | |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 3316 | /* |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 3317 | * Workaround for silicon errata #26 on 82598. Mask the interrupt |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 3318 | * before the read of EICR. |
| 3319 | */ |
| 3320 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); |
| 3321 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3322 | /* 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] | 3323 | * therefore no explicit interrupt disable is necessary */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3324 | eicr = IXGBE_READ_REG(hw, IXGBE_EICR); |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 3325 | if (!eicr) { |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 3326 | /* |
| 3327 | * shared interrupt alert! |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 3328 | * make sure interrupts are enabled because the read will |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 3329 | * have disabled interrupts due to EIAM |
| 3330 | * finish the workaround of silicon errata on 82598. Unmask |
| 3331 | * the interrupt that we masked before the EICR read. |
| 3332 | */ |
| 3333 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 3334 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3335 | return IRQ_NONE; /* Not our interrupt */ |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 3336 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3337 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 3338 | if (eicr & IXGBE_EICR_LSC) |
| 3339 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3340 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3341 | switch (hw->mac.type) { |
| 3342 | case ixgbe_mac_82599EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3343 | ixgbe_check_sfp_event(adapter, eicr); |
Don Skidmore | 0ccb974 | 2011-08-04 02:07:48 +0000 | [diff] [blame] | 3344 | /* Fall through */ |
| 3345 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 3346 | case ixgbe_mac_X550: |
| 3347 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 3348 | case ixgbe_mac_x550em_a: |
Don Skidmore | d773ce2 | 2014-02-25 17:58:53 -0800 | [diff] [blame] | 3349 | if (eicr & IXGBE_EICR_ECC) { |
| 3350 | e_info(link, "Received ECC Err, initiating reset\n"); |
Emil Tantilov | 57ca2a4 | 2016-07-29 14:46:31 -0700 | [diff] [blame] | 3351 | set_bit(__IXGBE_RESET_REQUESTED, &adapter->state); |
Don Skidmore | d773ce2 | 2014-02-25 17:58:53 -0800 | [diff] [blame] | 3352 | ixgbe_service_event_schedule(adapter); |
| 3353 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC); |
| 3354 | } |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 3355 | ixgbe_check_overtemp_event(adapter, eicr); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3356 | break; |
| 3357 | default: |
| 3358 | break; |
| 3359 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3360 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 3361 | ixgbe_check_fan_failure(adapter, eicr); |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 3362 | if (unlikely(eicr & IXGBE_EICR_TIMESYNC)) |
Mark Rustad | a9763f3 | 2015-10-27 09:58:07 -0700 | [diff] [blame] | 3363 | ixgbe_ptp_check_pps_event(adapter); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 3364 | |
Alexander Duyck | b9f6ed2 | 2012-02-08 07:49:54 +0000 | [diff] [blame] | 3365 | /* would disable interrupts here but EIAM disabled it */ |
Alexander Duyck | ef2662b | 2015-09-29 15:19:43 -0700 | [diff] [blame] | 3366 | napi_schedule_irqoff(&q_vector->napi); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3367 | |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 3368 | /* |
| 3369 | * re-enable link(maybe) and non-queue interrupts, no flush. |
| 3370 | * ixgbe_poll will re-enable the queue interrupts |
| 3371 | */ |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 3372 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 3373 | ixgbe_irq_enable(adapter, false, false); |
| 3374 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3375 | return IRQ_HANDLED; |
| 3376 | } |
| 3377 | |
| 3378 | /** |
| 3379 | * ixgbe_request_irq - initialize interrupts |
| 3380 | * @adapter: board private structure |
| 3381 | * |
| 3382 | * Attempts to configure interrupts using the best available |
| 3383 | * capabilities of the hardware and kernel. |
| 3384 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3385 | static int ixgbe_request_irq(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3386 | { |
| 3387 | struct net_device *netdev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3388 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3389 | |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 3390 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3391 | err = ixgbe_request_msix_irqs(adapter); |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 3392 | else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 3393 | err = request_irq(adapter->pdev->irq, ixgbe_intr, 0, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 3394 | netdev->name, adapter); |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 3395 | else |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 3396 | err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 3397 | netdev->name, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3398 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 3399 | if (err) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 3400 | e_err(probe, "request_irq failed, Error %d\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3401 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3402 | return err; |
| 3403 | } |
| 3404 | |
| 3405 | static void ixgbe_free_irq(struct ixgbe_adapter *adapter) |
| 3406 | { |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3407 | int vector; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3408 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3409 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 3410 | free_irq(adapter->pdev->irq, adapter); |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3411 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3412 | } |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3413 | |
Mark Rustad | 1fa7125 | 2016-09-28 15:36:38 -0700 | [diff] [blame] | 3414 | if (!adapter->msix_entries) |
| 3415 | return; |
| 3416 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3417 | for (vector = 0; vector < adapter->num_q_vectors; vector++) { |
| 3418 | struct ixgbe_q_vector *q_vector = adapter->q_vector[vector]; |
| 3419 | struct msix_entry *entry = &adapter->msix_entries[vector]; |
| 3420 | |
| 3421 | /* free only the irqs that were actually requested */ |
| 3422 | if (!q_vector->rx.ring && !q_vector->tx.ring) |
| 3423 | continue; |
| 3424 | |
| 3425 | /* clear the affinity_mask in the IRQ descriptor */ |
| 3426 | irq_set_affinity_hint(entry->vector, NULL); |
| 3427 | |
| 3428 | free_irq(entry->vector, q_vector); |
| 3429 | } |
| 3430 | |
Babu Moger | 90c6f87 | 2016-06-18 17:40:47 -0700 | [diff] [blame] | 3431 | free_irq(adapter->msix_entries[vector].vector, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3432 | } |
| 3433 | |
| 3434 | /** |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3435 | * ixgbe_irq_disable - Mask off interrupt generation on the NIC |
| 3436 | * @adapter: board private structure |
| 3437 | **/ |
| 3438 | static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter) |
| 3439 | { |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3440 | switch (adapter->hw.mac.type) { |
| 3441 | case ixgbe_mac_82598EB: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 3442 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3443 | break; |
| 3444 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3445 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 3446 | case ixgbe_mac_X550: |
| 3447 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 3448 | case ixgbe_mac_x550em_a: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 3449 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000); |
| 3450 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3451 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3452 | break; |
| 3453 | default: |
| 3454 | break; |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3455 | } |
| 3456 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 3457 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3458 | int vector; |
| 3459 | |
| 3460 | for (vector = 0; vector < adapter->num_q_vectors; vector++) |
| 3461 | synchronize_irq(adapter->msix_entries[vector].vector); |
| 3462 | |
| 3463 | synchronize_irq(adapter->msix_entries[vector++].vector); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3464 | } else { |
| 3465 | synchronize_irq(adapter->pdev->irq); |
| 3466 | } |
| 3467 | } |
| 3468 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3469 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3470 | * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts |
| 3471 | * |
| 3472 | **/ |
| 3473 | static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter) |
| 3474 | { |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 3475 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3476 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 3477 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3478 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3479 | ixgbe_set_ivar(adapter, 0, 0, 0); |
| 3480 | ixgbe_set_ivar(adapter, 1, 0, 0); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3481 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 3482 | e_info(hw, "Legacy interrupt IVAR setup done\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3483 | } |
| 3484 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3485 | /** |
| 3486 | * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset |
| 3487 | * @adapter: board private structure |
| 3488 | * @ring: structure containing ring specific data |
| 3489 | * |
| 3490 | * Configure the Tx descriptor ring after a reset. |
| 3491 | **/ |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 3492 | void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter, |
| 3493 | struct ixgbe_ring *ring) |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3494 | { |
| 3495 | struct ixgbe_hw *hw = &adapter->hw; |
| 3496 | u64 tdba = ring->dma; |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3497 | int wait_loop = 10; |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3498 | u32 txdctl = IXGBE_TXDCTL_ENABLE; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3499 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3500 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3501 | /* disable queue to avoid issues while updating state */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3502 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3503 | IXGBE_WRITE_FLUSH(hw); |
| 3504 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3505 | IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3506 | (tdba & DMA_BIT_MASK(32))); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3507 | IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32)); |
| 3508 | IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx), |
| 3509 | ring->count * sizeof(union ixgbe_adv_tx_desc)); |
| 3510 | IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0); |
| 3511 | IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 3512 | ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3513 | |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3514 | /* |
| 3515 | * set WTHRESH to encourage burst writeback, it should not be set |
Emil Tantilov | 67da097 | 2013-01-25 06:19:20 +0000 | [diff] [blame] | 3516 | * higher than 1 when: |
| 3517 | * - ITR is 0 as it could cause false TX hangs |
| 3518 | * - ITR is set to > 100k int/sec and BQL is enabled |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3519 | * |
| 3520 | * In order to avoid issues WTHRESH + PTHRESH should always be equal |
| 3521 | * to or less than the number of on chip descriptors, which is |
| 3522 | * currently 40. |
| 3523 | */ |
Emil Tantilov | 67da097 | 2013-01-25 06:19:20 +0000 | [diff] [blame] | 3524 | if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR)) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 3525 | txdctl |= 1u << 16; /* WTHRESH = 1 */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3526 | else |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 3527 | txdctl |= 8u << 16; /* WTHRESH = 8 */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3528 | |
Alexander Duyck | e954b37 | 2012-02-08 07:49:38 +0000 | [diff] [blame] | 3529 | /* |
| 3530 | * Setting PTHRESH to 32 both improves performance |
| 3531 | * and avoids a TX hang with DFP enabled |
| 3532 | */ |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 3533 | txdctl |= (1u << 8) | /* HTHRESH = 1 */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3534 | 32; /* PTHRESH = 32 */ |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3535 | |
| 3536 | /* reinitialize flowdirector state */ |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 3537 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 3538 | ring->atr_sample_rate = adapter->atr_sample_rate; |
| 3539 | ring->atr_count = 0; |
| 3540 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state); |
| 3541 | } else { |
| 3542 | ring->atr_sample_rate = 0; |
| 3543 | } |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3544 | |
Alexander Duyck | fd786b7 | 2013-01-12 06:33:31 +0000 | [diff] [blame] | 3545 | /* initialize XPS */ |
| 3546 | if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) { |
| 3547 | struct ixgbe_q_vector *q_vector = ring->q_vector; |
| 3548 | |
| 3549 | if (q_vector) |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 3550 | netif_set_xps_queue(ring->netdev, |
Alexander Duyck | fd786b7 | 2013-01-12 06:33:31 +0000 | [diff] [blame] | 3551 | &q_vector->affinity_mask, |
| 3552 | ring->queue_index); |
| 3553 | } |
| 3554 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 3555 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state); |
| 3556 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 3557 | /* reinitialize tx_buffer_info */ |
| 3558 | memset(ring->tx_buffer_info, 0, |
| 3559 | sizeof(struct ixgbe_tx_buffer) * ring->count); |
| 3560 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3561 | /* enable queue */ |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3562 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl); |
| 3563 | |
| 3564 | /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 3565 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 3566 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 3567 | return; |
| 3568 | |
| 3569 | /* poll to verify queue is enabled */ |
| 3570 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 3571 | usleep_range(1000, 2000); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3572 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx)); |
| 3573 | } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE)); |
| 3574 | if (!wait_loop) |
Emil Tantilov | a55defd | 2016-07-29 10:30:06 -0700 | [diff] [blame] | 3575 | hw_dbg(hw, "Could not enable Tx Queue %d\n", reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3576 | } |
| 3577 | |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 3578 | static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter) |
| 3579 | { |
| 3580 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3581 | u32 rttdcs, mtqc; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3582 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 3583 | |
| 3584 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3585 | return; |
| 3586 | |
| 3587 | /* disable the arbiter while setting MTQC */ |
| 3588 | rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS); |
| 3589 | rttdcs |= IXGBE_RTTDCS_ARBDIS; |
| 3590 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 3591 | |
| 3592 | /* set transmit pool layout */ |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3593 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 3594 | mtqc = IXGBE_MTQC_VT_ENA; |
| 3595 | if (tcs > 4) |
| 3596 | mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ; |
| 3597 | else if (tcs > 1) |
| 3598 | mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ; |
Alexander Duyck | e24fcf2 | 2016-09-07 20:28:24 -0700 | [diff] [blame] | 3599 | else if (adapter->ring_feature[RING_F_VMDQ].mask == |
| 3600 | IXGBE_82599_VMDQ_4Q_MASK) |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3601 | mtqc |= IXGBE_MTQC_32VF; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3602 | else |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3603 | mtqc |= IXGBE_MTQC_64VF; |
| 3604 | } else { |
| 3605 | if (tcs > 4) |
| 3606 | mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ; |
| 3607 | else if (tcs > 1) |
| 3608 | mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ; |
| 3609 | else |
| 3610 | mtqc = IXGBE_MTQC_64Q_1PB; |
| 3611 | } |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3612 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3613 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3614 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3615 | /* Enable Security TX Buffer IFG for multiple pb */ |
| 3616 | if (tcs) { |
| 3617 | u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG); |
| 3618 | sectx |= IXGBE_SECTX_DCB; |
| 3619 | IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx); |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 3620 | } |
| 3621 | |
| 3622 | /* re-enable the arbiter */ |
| 3623 | rttdcs &= ~IXGBE_RTTDCS_ARBDIS; |
| 3624 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 3625 | } |
| 3626 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3627 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3628 | * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3629 | * @adapter: board private structure |
| 3630 | * |
| 3631 | * Configure the Tx unit of the MAC after a reset. |
| 3632 | **/ |
| 3633 | static void ixgbe_configure_tx(struct ixgbe_adapter *adapter) |
| 3634 | { |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3635 | struct ixgbe_hw *hw = &adapter->hw; |
| 3636 | u32 dmatxctl; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3637 | u32 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3638 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3639 | ixgbe_setup_mtqc(adapter); |
| 3640 | |
| 3641 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 3642 | /* DMATXCTL.EN must be before Tx queues are enabled */ |
| 3643 | dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); |
| 3644 | dmatxctl |= IXGBE_DMATXCTL_TE; |
| 3645 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl); |
| 3646 | } |
| 3647 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3648 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3649 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 3650 | ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]); |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 3651 | for (i = 0; i < adapter->num_xdp_queues; i++) |
| 3652 | ixgbe_configure_tx_ring(adapter, adapter->xdp_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3653 | } |
| 3654 | |
Alexander Duyck | 3ebe8fd | 2012-04-25 04:36:38 +0000 | [diff] [blame] | 3655 | static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter, |
| 3656 | struct ixgbe_ring *ring) |
| 3657 | { |
| 3658 | struct ixgbe_hw *hw = &adapter->hw; |
| 3659 | u8 reg_idx = ring->reg_idx; |
| 3660 | u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx)); |
| 3661 | |
| 3662 | srrctl |= IXGBE_SRRCTL_DROP_EN; |
| 3663 | |
| 3664 | IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl); |
| 3665 | } |
| 3666 | |
| 3667 | static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter, |
| 3668 | struct ixgbe_ring *ring) |
| 3669 | { |
| 3670 | struct ixgbe_hw *hw = &adapter->hw; |
| 3671 | u8 reg_idx = ring->reg_idx; |
| 3672 | u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx)); |
| 3673 | |
| 3674 | srrctl &= ~IXGBE_SRRCTL_DROP_EN; |
| 3675 | |
| 3676 | IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl); |
| 3677 | } |
| 3678 | |
| 3679 | #ifdef CONFIG_IXGBE_DCB |
| 3680 | void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter) |
| 3681 | #else |
| 3682 | static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter) |
| 3683 | #endif |
| 3684 | { |
| 3685 | int i; |
| 3686 | bool pfc_en = adapter->dcb_cfg.pfc_mode_enable; |
| 3687 | |
| 3688 | if (adapter->ixgbe_ieee_pfc) |
| 3689 | pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en); |
| 3690 | |
| 3691 | /* |
| 3692 | * We should set the drop enable bit if: |
| 3693 | * SR-IOV is enabled |
| 3694 | * or |
| 3695 | * Number of Rx queues > 1 and flow control is disabled |
| 3696 | * |
| 3697 | * This allows us to avoid head of line blocking for security |
| 3698 | * and performance reasons. |
| 3699 | */ |
| 3700 | if (adapter->num_vfs || (adapter->num_rx_queues > 1 && |
| 3701 | !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) { |
| 3702 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3703 | ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]); |
| 3704 | } else { |
| 3705 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3706 | ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]); |
| 3707 | } |
| 3708 | } |
| 3709 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3710 | #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3711 | |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 3712 | static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3713 | struct ixgbe_ring *rx_ring) |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3714 | { |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3715 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3716 | u32 srrctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3717 | u8 reg_idx = rx_ring->reg_idx; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3718 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3719 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 3720 | u16 mask = adapter->ring_feature[RING_F_RSS].mask; |
| 3721 | |
| 3722 | /* |
| 3723 | * if VMDq is not active we must program one srrctl register |
| 3724 | * per RSS queue since we have enabled RDRXCTL.MVMEN |
| 3725 | */ |
| 3726 | reg_idx &= mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3727 | } |
| 3728 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3729 | /* configure header buffer length, needed for RSC */ |
| 3730 | srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3731 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3732 | /* configure the packet buffer length */ |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 3733 | if (test_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state)) |
| 3734 | srrctl |= IXGBE_RXBUFFER_3K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 3735 | else |
| 3736 | srrctl |= IXGBE_RXBUFFER_2K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3737 | |
| 3738 | /* configure descriptor type */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 3739 | srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3740 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3741 | IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3742 | } |
| 3743 | |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3744 | /** |
Jean Sacren | a897a2a | 2015-09-19 05:08:44 -0600 | [diff] [blame] | 3745 | * ixgbe_rss_indir_tbl_entries - Return RSS indirection table entries |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3746 | * @adapter: device handle |
| 3747 | * |
| 3748 | * - 82598/82599/X540: 128 |
| 3749 | * - X550(non-SRIOV mode): 512 |
| 3750 | * - X550(SRIOV mode): 64 |
| 3751 | */ |
Vlad Zolotarov | 7f276ef | 2015-03-30 21:18:58 +0300 | [diff] [blame] | 3752 | u32 ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3753 | { |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3754 | if (adapter->hw.mac.type < ixgbe_mac_X550) |
| 3755 | return 128; |
| 3756 | else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 3757 | return 64; |
| 3758 | else |
| 3759 | return 512; |
| 3760 | } |
| 3761 | |
| 3762 | /** |
Paolo Abeni | d3aa9c9 | 2016-12-15 15:20:34 +0100 | [diff] [blame] | 3763 | * ixgbe_store_key - Write the RSS key to HW |
| 3764 | * @adapter: device handle |
| 3765 | * |
| 3766 | * Write the RSS key stored in adapter.rss_key to HW. |
| 3767 | */ |
| 3768 | void ixgbe_store_key(struct ixgbe_adapter *adapter) |
| 3769 | { |
| 3770 | struct ixgbe_hw *hw = &adapter->hw; |
| 3771 | int i; |
| 3772 | |
| 3773 | for (i = 0; i < 10; i++) |
| 3774 | IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), adapter->rss_key[i]); |
| 3775 | } |
| 3776 | |
| 3777 | /** |
Tony Nguyen | 3dfbfc7 | 2017-04-13 07:26:05 -0700 | [diff] [blame] | 3778 | * ixgbe_init_rss_key - Initialize adapter RSS key |
| 3779 | * @adapter: device handle |
| 3780 | * |
| 3781 | * Allocates and initializes the RSS key if it is not allocated. |
| 3782 | **/ |
| 3783 | static inline int ixgbe_init_rss_key(struct ixgbe_adapter *adapter) |
| 3784 | { |
| 3785 | u32 *rss_key; |
| 3786 | |
| 3787 | if (!adapter->rss_key) { |
| 3788 | rss_key = kzalloc(IXGBE_RSS_KEY_SIZE, GFP_KERNEL); |
| 3789 | if (unlikely(!rss_key)) |
| 3790 | return -ENOMEM; |
| 3791 | |
| 3792 | netdev_rss_key_fill(rss_key, IXGBE_RSS_KEY_SIZE); |
| 3793 | adapter->rss_key = rss_key; |
| 3794 | } |
| 3795 | |
| 3796 | return 0; |
| 3797 | } |
| 3798 | |
| 3799 | /** |
Jean Sacren | a897a2a | 2015-09-19 05:08:44 -0600 | [diff] [blame] | 3800 | * ixgbe_store_reta - Write the RETA table to HW |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3801 | * @adapter: device handle |
| 3802 | * |
| 3803 | * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW. |
| 3804 | */ |
Tom Barbette | 1c7cf07 | 2015-06-26 15:40:18 +0200 | [diff] [blame] | 3805 | void ixgbe_store_reta(struct ixgbe_adapter *adapter) |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3806 | { |
| 3807 | u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter); |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3808 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3809 | u32 reta = 0; |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3810 | u32 indices_multi; |
| 3811 | u8 *indir_tbl = adapter->rss_indir_tbl; |
John Fastabend | 86b4db3 | 2011-04-26 07:26:19 +0000 | [diff] [blame] | 3812 | |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3813 | /* Fill out the redirection table as follows: |
| 3814 | * - 82598: 8 bit wide entries containing pair of 4 bit RSS |
| 3815 | * indices. |
| 3816 | * - 82599/X540: 8 bit wide entries containing 4 bit RSS index |
| 3817 | * - X550: 8 bit wide entries containing 6 bit RSS index |
| 3818 | */ |
| 3819 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 3820 | indices_multi = 0x11; |
| 3821 | else |
| 3822 | indices_multi = 0x1; |
| 3823 | |
| 3824 | /* Write redirection table to HW */ |
| 3825 | for (i = 0; i < reta_entries; i++) { |
| 3826 | reta |= indices_multi * indir_tbl[i] << (i & 0x3) * 8; |
| 3827 | if ((i & 3) == 3) { |
| 3828 | if (i < 128) |
| 3829 | IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); |
| 3830 | else |
| 3831 | IXGBE_WRITE_REG(hw, IXGBE_ERETA((i >> 2) - 32), |
| 3832 | reta); |
| 3833 | reta = 0; |
| 3834 | } |
| 3835 | } |
| 3836 | } |
| 3837 | |
| 3838 | /** |
Jean Sacren | a897a2a | 2015-09-19 05:08:44 -0600 | [diff] [blame] | 3839 | * 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] | 3840 | * @adapter: device handle |
| 3841 | * |
| 3842 | * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW. |
| 3843 | */ |
| 3844 | static void ixgbe_store_vfreta(struct ixgbe_adapter *adapter) |
| 3845 | { |
| 3846 | u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter); |
| 3847 | struct ixgbe_hw *hw = &adapter->hw; |
| 3848 | u32 vfreta = 0; |
| 3849 | unsigned int pf_pool = adapter->num_vfs; |
| 3850 | |
| 3851 | /* Write redirection table to HW */ |
| 3852 | for (i = 0; i < reta_entries; i++) { |
| 3853 | vfreta |= (u32)adapter->rss_indir_tbl[i] << (i & 0x3) * 8; |
| 3854 | if ((i & 3) == 3) { |
| 3855 | IXGBE_WRITE_REG(hw, IXGBE_PFVFRETA(i >> 2, pf_pool), |
| 3856 | vfreta); |
| 3857 | vfreta = 0; |
| 3858 | } |
| 3859 | } |
| 3860 | } |
| 3861 | |
| 3862 | static void ixgbe_setup_reta(struct ixgbe_adapter *adapter) |
| 3863 | { |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3864 | u32 i, j; |
| 3865 | u32 reta_entries = ixgbe_rss_indir_tbl_entries(adapter); |
| 3866 | u16 rss_i = adapter->ring_feature[RING_F_RSS].indices; |
| 3867 | |
Alexander Duyck | e24fcf2 | 2016-09-07 20:28:24 -0700 | [diff] [blame] | 3868 | /* 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] | 3869 | * make full use of any rings they may have. We will use the |
| 3870 | * PSRTYPE register to control how many rings we use within the PF. |
| 3871 | */ |
Alexander Duyck | e24fcf2 | 2016-09-07 20:28:24 -0700 | [diff] [blame] | 3872 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 4)) |
| 3873 | rss_i = 4; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3874 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3875 | /* Fill out hash function seeds */ |
Paolo Abeni | d3aa9c9 | 2016-12-15 15:20:34 +0100 | [diff] [blame] | 3876 | ixgbe_store_key(adapter); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3877 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3878 | /* Fill out redirection table */ |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3879 | memset(adapter->rss_indir_tbl, 0, sizeof(adapter->rss_indir_tbl)); |
| 3880 | |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3881 | for (i = 0, j = 0; i < reta_entries; i++, j++) { |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3882 | if (j == rss_i) |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3883 | j = 0; |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3884 | |
| 3885 | adapter->rss_indir_tbl[i] = j; |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3886 | } |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3887 | |
| 3888 | ixgbe_store_reta(adapter); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3889 | } |
| 3890 | |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3891 | static void ixgbe_setup_vfreta(struct ixgbe_adapter *adapter) |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3892 | { |
| 3893 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3894 | u16 rss_i = adapter->ring_feature[RING_F_RSS].indices; |
| 3895 | unsigned int pf_pool = adapter->num_vfs; |
| 3896 | int i, j; |
| 3897 | |
| 3898 | /* Fill out hash function seeds */ |
| 3899 | for (i = 0; i < 10; i++) |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3900 | IXGBE_WRITE_REG(hw, IXGBE_PFVFRSSRK(i, pf_pool), |
Tony Nguyen | 3dfbfc7 | 2017-04-13 07:26:05 -0700 | [diff] [blame] | 3901 | *(adapter->rss_key + i)); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3902 | |
| 3903 | /* Fill out the redirection table */ |
| 3904 | for (i = 0, j = 0; i < 64; i++, j++) { |
| 3905 | if (j == rss_i) |
| 3906 | j = 0; |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3907 | |
| 3908 | adapter->rss_indir_tbl[i] = j; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3909 | } |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3910 | |
| 3911 | ixgbe_store_vfreta(adapter); |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3912 | } |
| 3913 | |
| 3914 | static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter) |
| 3915 | { |
| 3916 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3917 | u32 mrqc = 0, rss_field = 0, vfmrqc = 0; |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3918 | u32 rxcsum; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3919 | |
| 3920 | /* Disable indicating checksum in descriptor, enables RSS hash */ |
| 3921 | rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); |
| 3922 | rxcsum |= IXGBE_RXCSUM_PCSD; |
| 3923 | IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); |
| 3924 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3925 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 3926 | if (adapter->ring_feature[RING_F_RSS].mask) |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3927 | mrqc = IXGBE_MRQC_RSSEN; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3928 | } else { |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3929 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3930 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3931 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 3932 | if (tcs > 4) |
| 3933 | mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */ |
| 3934 | else if (tcs > 1) |
| 3935 | mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */ |
Alexander Duyck | e24fcf2 | 2016-09-07 20:28:24 -0700 | [diff] [blame] | 3936 | else if (adapter->ring_feature[RING_F_VMDQ].mask == |
| 3937 | IXGBE_82599_VMDQ_4Q_MASK) |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3938 | mrqc = IXGBE_MRQC_VMDQRSS32EN; |
| 3939 | else |
| 3940 | mrqc = IXGBE_MRQC_VMDQRSS64EN; |
Emil Tantilov | e6b41c8 | 2017-04-25 11:31:06 -0700 | [diff] [blame] | 3941 | |
| 3942 | /* Enable L3/L4 for Tx Switched packets */ |
| 3943 | mrqc |= IXGBE_MRQC_L3L4TXSWEN; |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3944 | } else { |
| 3945 | if (tcs > 4) |
| 3946 | mrqc = IXGBE_MRQC_RTRSS8TCEN; |
| 3947 | else if (tcs > 1) |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3948 | mrqc = IXGBE_MRQC_RTRSS4TCEN; |
| 3949 | else |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3950 | mrqc = IXGBE_MRQC_RSSEN; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3951 | } |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3952 | } |
| 3953 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3954 | /* Perform hash on these packet types */ |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3955 | rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4 | |
| 3956 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP | |
| 3957 | IXGBE_MRQC_RSS_FIELD_IPV6 | |
| 3958 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3959 | |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 3960 | if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP) |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3961 | rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP; |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 3962 | if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP) |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3963 | rss_field |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP; |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 3964 | |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3965 | if ((hw->mac.type >= ixgbe_mac_X550) && |
| 3966 | (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) { |
| 3967 | unsigned int pf_pool = adapter->num_vfs; |
| 3968 | |
| 3969 | /* Enable VF RSS mode */ |
| 3970 | mrqc |= IXGBE_MRQC_MULTIPLE_RSS; |
| 3971 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
| 3972 | |
| 3973 | /* Setup RSS through the VF registers */ |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3974 | ixgbe_setup_vfreta(adapter); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3975 | vfmrqc = IXGBE_MRQC_RSSEN; |
| 3976 | vfmrqc |= rss_field; |
| 3977 | IXGBE_WRITE_REG(hw, IXGBE_PFVFMRQC(pf_pool), vfmrqc); |
| 3978 | } else { |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3979 | ixgbe_setup_reta(adapter); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3980 | mrqc |= rss_field; |
| 3981 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
| 3982 | } |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3983 | } |
| 3984 | |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3985 | /** |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3986 | * ixgbe_configure_rscctl - enable RSC for the indicated ring |
| 3987 | * @adapter: address of board private structure |
| 3988 | * @index: index of ring to set |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3989 | **/ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 3990 | static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3991 | struct ixgbe_ring *ring) |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3992 | { |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3993 | struct ixgbe_hw *hw = &adapter->hw; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3994 | u32 rscctrl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3995 | u8 reg_idx = ring->reg_idx; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3996 | |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3997 | if (!ring_is_rsc_enabled(ring)) |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3998 | return; |
| 3999 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 4000 | rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx)); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 4001 | rscctrl |= IXGBE_RSCCTL_RSCEN; |
| 4002 | /* |
| 4003 | * we must limit the number of descriptors so that the |
| 4004 | * total size of max desc * buf_len is not greater |
Alexander Duyck | 642c680 | 2011-11-10 09:09:17 +0000 | [diff] [blame] | 4005 | * than 65536 |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 4006 | */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 4007 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 4008 | IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 4009 | } |
| 4010 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4011 | #define IXGBE_MAX_RX_DESC_POLL 10 |
| 4012 | static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter, |
| 4013 | struct ixgbe_ring *ring) |
| 4014 | { |
| 4015 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4016 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 4017 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4018 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4019 | |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 4020 | if (ixgbe_removed(hw->hw_addr)) |
| 4021 | return; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4022 | /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 4023 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 4024 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 4025 | return; |
| 4026 | |
| 4027 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 4028 | usleep_range(1000, 2000); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4029 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 4030 | } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 4031 | |
| 4032 | if (!wait_loop) { |
| 4033 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within " |
| 4034 | "the polling period\n", reg_idx); |
| 4035 | } |
| 4036 | } |
| 4037 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 4038 | void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter, |
| 4039 | struct ixgbe_ring *ring) |
| 4040 | { |
| 4041 | struct ixgbe_hw *hw = &adapter->hw; |
| 4042 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 4043 | u32 rxdctl; |
| 4044 | u8 reg_idx = ring->reg_idx; |
| 4045 | |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 4046 | if (ixgbe_removed(hw->hw_addr)) |
| 4047 | return; |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 4048 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 4049 | rxdctl &= ~IXGBE_RXDCTL_ENABLE; |
| 4050 | |
| 4051 | /* write value back with RXDCTL.ENABLE bit cleared */ |
| 4052 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 4053 | |
| 4054 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 4055 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 4056 | return; |
| 4057 | |
| 4058 | /* the hardware may take up to 100us to really disable the rx queue */ |
| 4059 | do { |
| 4060 | udelay(10); |
| 4061 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 4062 | } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 4063 | |
| 4064 | if (!wait_loop) { |
| 4065 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within " |
| 4066 | "the polling period\n", reg_idx); |
| 4067 | } |
| 4068 | } |
| 4069 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 4070 | void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter, |
| 4071 | struct ixgbe_ring *ring) |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 4072 | { |
| 4073 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | c3630cc | 2017-01-17 08:36:28 -0800 | [diff] [blame] | 4074 | union ixgbe_adv_rx_desc *rx_desc; |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 4075 | u64 rdba = ring->dma; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4076 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4077 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 4078 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4079 | /* disable queue to avoid issues while updating state */ |
| 4080 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 4081 | ixgbe_disable_rx_queue(adapter, ring); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4082 | |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 4083 | IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32))); |
| 4084 | IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32)); |
| 4085 | IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx), |
| 4086 | ring->count * sizeof(union ixgbe_adv_rx_desc)); |
Neerav Parikh | 8b75451 | 2015-12-08 22:13:58 -0800 | [diff] [blame] | 4087 | /* Force flushing of IXGBE_RDLEN to prevent MDD */ |
| 4088 | IXGBE_WRITE_FLUSH(hw); |
| 4089 | |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 4090 | IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0); |
| 4091 | IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 4092 | ring->tail = adapter->io_addr + IXGBE_RDT(reg_idx); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4093 | |
| 4094 | ixgbe_configure_srrctl(adapter, ring); |
| 4095 | ixgbe_configure_rscctl(adapter, ring); |
| 4096 | |
| 4097 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 4098 | /* |
| 4099 | * enable cache line friendly hardware writes: |
| 4100 | * PTHRESH=32 descriptors (half the internal cache), |
| 4101 | * this also removes ugly rx_no_buffer_count increment |
| 4102 | * HTHRESH=4 descriptors (to minimize latency on fetch) |
| 4103 | * WTHRESH=8 burst writeback up to two cache lines |
| 4104 | */ |
| 4105 | rxdctl &= ~0x3FFFFF; |
| 4106 | rxdctl |= 0x080420; |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 4107 | #if (PAGE_SIZE < 8192) |
| 4108 | } else { |
| 4109 | rxdctl &= ~(IXGBE_RXDCTL_RLPMLMASK | |
| 4110 | IXGBE_RXDCTL_RLPML_EN); |
| 4111 | |
| 4112 | /* Limit the maximum frame size so we don't overrun the skb */ |
| 4113 | if (ring_uses_build_skb(ring) && |
| 4114 | !test_bit(__IXGBE_RX_3K_BUFFER, &ring->state)) |
Alexander Duyck | 541ea69 | 2017-03-02 15:01:05 -0800 | [diff] [blame] | 4115 | rxdctl |= IXGBE_MAX_2K_FRAME_BUILD_SKB | |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 4116 | IXGBE_RXDCTL_RLPML_EN; |
| 4117 | #endif |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4118 | } |
| 4119 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 4120 | /* initialize rx_buffer_info */ |
| 4121 | memset(ring->rx_buffer_info, 0, |
| 4122 | sizeof(struct ixgbe_rx_buffer) * ring->count); |
| 4123 | |
Alexander Duyck | c3630cc | 2017-01-17 08:36:28 -0800 | [diff] [blame] | 4124 | /* initialize Rx descriptor 0 */ |
| 4125 | rx_desc = IXGBE_RX_DESC(ring, 0); |
| 4126 | rx_desc->wb.upper.length = 0; |
| 4127 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4128 | /* enable receive descriptor ring */ |
| 4129 | rxdctl |= IXGBE_RXDCTL_ENABLE; |
| 4130 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 4131 | |
| 4132 | ixgbe_rx_desc_queue_enable(adapter, ring); |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 4133 | ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring)); |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 4134 | } |
| 4135 | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 4136 | static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter) |
| 4137 | { |
| 4138 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 4139 | int rss_i = adapter->ring_feature[RING_F_RSS].indices; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4140 | u16 pool; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 4141 | |
| 4142 | /* PSRTYPE must be initialized in non 82598 adapters */ |
| 4143 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4144 | IXGBE_PSRTYPE_UDPHDR | |
| 4145 | IXGBE_PSRTYPE_IPV4HDR | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 4146 | IXGBE_PSRTYPE_L2HDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4147 | IXGBE_PSRTYPE_IPV6HDR; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 4148 | |
| 4149 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4150 | return; |
| 4151 | |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 4152 | if (rss_i > 3) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 4153 | psrtype |= 2u << 29; |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 4154 | else if (rss_i > 1) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 4155 | psrtype |= 1u << 29; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 4156 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4157 | for_each_set_bit(pool, &adapter->fwd_bitmask, 32) |
| 4158 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype); |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 4159 | } |
| 4160 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 4161 | static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter) |
| 4162 | { |
| 4163 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 4164 | u32 reg_offset, vf_shift; |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 4165 | u32 gcr_ext, vmdctl; |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 4166 | int i; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 4167 | |
| 4168 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 4169 | return; |
| 4170 | |
| 4171 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL); |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 4172 | vmdctl |= IXGBE_VMD_CTL_VMDQ_EN; |
| 4173 | vmdctl &= ~IXGBE_VT_CTL_POOL_MASK; |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 4174 | vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT; |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 4175 | vmdctl |= IXGBE_VT_CTL_REPLEN; |
| 4176 | IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 4177 | |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 4178 | vf_shift = VMDQ_P(0) % 32; |
| 4179 | reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 4180 | |
| 4181 | /* Enable only the PF's pool for Tx/Rx */ |
Emil Tantilov | 11f2b49 | 2016-05-04 15:01:27 -0700 | [diff] [blame] | 4182 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), GENMASK(31, vf_shift)); |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 4183 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1); |
Emil Tantilov | 11f2b49 | 2016-05-04 15:01:27 -0700 | [diff] [blame] | 4184 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), GENMASK(31, vf_shift)); |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 4185 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1); |
Don Skidmore | aa2bacb | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 4186 | if (adapter->bridge_mode == BRIDGE_MODE_VEB) |
Greg Rose | 9b73598 | 2012-11-08 02:41:35 +0000 | [diff] [blame] | 4187 | IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 4188 | |
| 4189 | /* 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] | 4190 | hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0)); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 4191 | |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4192 | /* clear VLAN promisc flag so VFTA will be updated if necessary */ |
| 4193 | adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC; |
| 4194 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 4195 | /* |
| 4196 | * Set up VF register offsets for selected VT Mode, |
| 4197 | * i.e. 32 or 64 VFs for SR-IOV |
| 4198 | */ |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 4199 | switch (adapter->ring_feature[RING_F_VMDQ].mask) { |
| 4200 | case IXGBE_82599_VMDQ_8Q_MASK: |
| 4201 | gcr_ext = IXGBE_GCR_EXT_VT_MODE_16; |
| 4202 | break; |
| 4203 | case IXGBE_82599_VMDQ_4Q_MASK: |
| 4204 | gcr_ext = IXGBE_GCR_EXT_VT_MODE_32; |
| 4205 | break; |
| 4206 | default: |
| 4207 | gcr_ext = IXGBE_GCR_EXT_VT_MODE_64; |
| 4208 | break; |
| 4209 | } |
| 4210 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 4211 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext); |
| 4212 | |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 4213 | for (i = 0; i < adapter->num_vfs; i++) { |
Emil Tantilov | 77f192a | 2016-03-18 16:11:14 -0700 | [diff] [blame] | 4214 | /* configure spoof checking */ |
| 4215 | ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, |
| 4216 | adapter->vfinfo[i].spoofchk_enabled); |
Vlad Zolotarov | e65ce0d | 2015-03-30 21:35:24 +0300 | [diff] [blame] | 4217 | |
| 4218 | /* Enable/Disable RSS query feature */ |
| 4219 | ixgbe_ndo_set_vf_rss_query_en(adapter->netdev, i, |
| 4220 | adapter->vfinfo[i].rss_query_enabled); |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 4221 | } |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 4222 | } |
| 4223 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4224 | static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4225 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4226 | struct ixgbe_hw *hw = &adapter->hw; |
| 4227 | struct net_device *netdev = adapter->netdev; |
| 4228 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4229 | struct ixgbe_ring *rx_ring; |
| 4230 | int i; |
| 4231 | u32 mhadd, hlreg0; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 4232 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4233 | #ifdef IXGBE_FCOE |
| 4234 | /* adjust max frame to be able to do baby jumbo for FCoE */ |
| 4235 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 4236 | (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE)) |
| 4237 | max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 4238 | |
| 4239 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 4240 | |
| 4241 | /* adjust max frame to be at least the size of a standard frame */ |
| 4242 | if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN)) |
| 4243 | max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN); |
| 4244 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4245 | mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD); |
| 4246 | if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) { |
| 4247 | mhadd &= ~IXGBE_MHADD_MFS_MASK; |
| 4248 | mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT; |
| 4249 | |
| 4250 | IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4251 | } |
| 4252 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4253 | hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4254 | /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */ |
| 4255 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4256 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0); |
| 4257 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 4258 | /* |
| 4259 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 4260 | * the Base and Length of the Rx Descriptor Ring |
| 4261 | */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4262 | for (i = 0; i < adapter->num_rx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4263 | rx_ring = adapter->rx_ring[i]; |
Alexander Duyck | 4f4542b | 2017-01-17 08:36:14 -0800 | [diff] [blame] | 4264 | |
| 4265 | clear_ring_rsc_enabled(rx_ring); |
| 4266 | clear_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state); |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 4267 | clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state); |
Alexander Duyck | 4f4542b | 2017-01-17 08:36:14 -0800 | [diff] [blame] | 4268 | |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 4269 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
| 4270 | set_ring_rsc_enabled(rx_ring); |
Alexander Duyck | 4f4542b | 2017-01-17 08:36:14 -0800 | [diff] [blame] | 4271 | |
| 4272 | if (test_bit(__IXGBE_RX_FCOE, &rx_ring->state)) |
| 4273 | set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state); |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 4274 | |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 4275 | clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state); |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 4276 | if (adapter->flags2 & IXGBE_FLAG2_RX_LEGACY) |
| 4277 | continue; |
| 4278 | |
| 4279 | set_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state); |
| 4280 | |
| 4281 | #if (PAGE_SIZE < 8192) |
| 4282 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
| 4283 | set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state); |
| 4284 | |
Alexander Duyck | 541ea69 | 2017-03-02 15:01:05 -0800 | [diff] [blame] | 4285 | if (IXGBE_2K_TOO_SMALL_WITH_PADDING || |
| 4286 | (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN))) |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 4287 | set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state); |
| 4288 | #endif |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4289 | } |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4290 | } |
| 4291 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 4292 | static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter) |
| 4293 | { |
| 4294 | struct ixgbe_hw *hw = &adapter->hw; |
| 4295 | u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 4296 | |
| 4297 | switch (hw->mac.type) { |
| 4298 | case ixgbe_mac_82598EB: |
| 4299 | /* |
| 4300 | * For VMDq support of different descriptor types or |
| 4301 | * buffer sizes through the use of multiple SRRCTL |
| 4302 | * registers, RDRXCTL.MVMEN must be set to 1 |
| 4303 | * |
| 4304 | * also, the manual doesn't mention it clearly but DCA hints |
| 4305 | * will only use queue 0's tags unless this bit is set. Side |
| 4306 | * effects of setting this bit are only that SRRCTL must be |
| 4307 | * fully programmed [0..15] |
| 4308 | */ |
| 4309 | rdrxctl |= IXGBE_RDRXCTL_MVMEN; |
| 4310 | break; |
Mark Rustad | 052a1a7 | 2015-08-08 16:19:04 -0700 | [diff] [blame] | 4311 | case ixgbe_mac_X550: |
| 4312 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 4313 | case ixgbe_mac_x550em_a: |
Mark Rustad | f961dda | 2015-08-08 16:19:09 -0700 | [diff] [blame] | 4314 | if (adapter->num_vfs) |
| 4315 | rdrxctl |= IXGBE_RDRXCTL_PSP; |
Tony Nguyen | 93df946 | 2017-05-31 04:43:47 -0700 | [diff] [blame] | 4316 | /* fall through */ |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 4317 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4318 | case ixgbe_mac_X540: |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 4319 | /* Disable RSC for ACK packets */ |
| 4320 | IXGBE_WRITE_REG(hw, IXGBE_RSCDBU, |
| 4321 | (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU))); |
| 4322 | rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE; |
| 4323 | /* hardware requires some bits to be set by default */ |
| 4324 | rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX); |
| 4325 | rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP; |
| 4326 | break; |
| 4327 | default: |
| 4328 | /* We should do nothing since we don't know this hardware */ |
| 4329 | return; |
| 4330 | } |
| 4331 | |
| 4332 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
| 4333 | } |
| 4334 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4335 | /** |
| 4336 | * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset |
| 4337 | * @adapter: board private structure |
| 4338 | * |
| 4339 | * Configure the Rx unit of the MAC after a reset. |
| 4340 | **/ |
| 4341 | static void ixgbe_configure_rx(struct ixgbe_adapter *adapter) |
| 4342 | { |
| 4343 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4344 | int i; |
Jacob Keller | 6dcc28b | 2013-07-17 02:53:23 +0000 | [diff] [blame] | 4345 | u32 rxctrl, rfctl; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4346 | |
| 4347 | /* disable receives while setting up the descriptors */ |
Don Skidmore | 1f9ac57 | 2015-03-13 13:54:30 -0700 | [diff] [blame] | 4348 | hw->mac.ops.disable_rx(hw); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4349 | |
| 4350 | ixgbe_setup_psrtype(adapter); |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 4351 | ixgbe_setup_rdrxctl(adapter); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4352 | |
Jacob Keller | 6dcc28b | 2013-07-17 02:53:23 +0000 | [diff] [blame] | 4353 | /* RSC Setup */ |
| 4354 | rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL); |
| 4355 | rfctl &= ~IXGBE_RFCTL_RSC_DIS; |
| 4356 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) |
| 4357 | rfctl |= IXGBE_RFCTL_RSC_DIS; |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 4358 | |
| 4359 | /* disable NFS filtering */ |
| 4360 | rfctl |= (IXGBE_RFCTL_NFSW_DIS | IXGBE_RFCTL_NFSR_DIS); |
Jacob Keller | 6dcc28b | 2013-07-17 02:53:23 +0000 | [diff] [blame] | 4361 | IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl); |
| 4362 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4363 | /* Program registers for the distribution of queues */ |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 4364 | ixgbe_setup_mrqc(adapter); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 4365 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4366 | /* set_rx_buffer_len must be called before ring initialization */ |
| 4367 | ixgbe_set_rx_buffer_len(adapter); |
| 4368 | |
| 4369 | /* |
| 4370 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 4371 | * the Base and Length of the Rx Descriptor Ring |
| 4372 | */ |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4373 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 4374 | ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 4375 | |
Don Skidmore | 1f9ac57 | 2015-03-13 13:54:30 -0700 | [diff] [blame] | 4376 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4377 | /* disable drop enable for 82598 parts */ |
| 4378 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4379 | rxctrl |= IXGBE_RXCTRL_DMBYPS; |
| 4380 | |
| 4381 | /* enable all receives */ |
| 4382 | rxctrl |= IXGBE_RXCTRL_RXEN; |
| 4383 | hw->mac.ops.enable_rx_dma(hw, rxctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4384 | } |
| 4385 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 4386 | static int ixgbe_vlan_rx_add_vid(struct net_device *netdev, |
| 4387 | __be16 proto, u16 vid) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4388 | { |
| 4389 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4390 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4391 | |
| 4392 | /* add VID to filter table */ |
Alexander Duyck | 18be4fc | 2016-01-06 22:48:44 -0800 | [diff] [blame] | 4393 | if (!vid || !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)) |
| 4394 | hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true, !!vid); |
| 4395 | |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4396 | set_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 4397 | |
| 4398 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4399 | } |
| 4400 | |
Alexander Duyck | e1d0a2a | 2015-11-02 17:10:19 -0800 | [diff] [blame] | 4401 | static int ixgbe_find_vlvf_entry(struct ixgbe_hw *hw, u32 vlan) |
| 4402 | { |
| 4403 | u32 vlvf; |
| 4404 | int idx; |
| 4405 | |
| 4406 | /* short cut the special case */ |
| 4407 | if (vlan == 0) |
| 4408 | return 0; |
| 4409 | |
| 4410 | /* Search for the vlan id in the VLVF entries */ |
| 4411 | for (idx = IXGBE_VLVF_ENTRIES; --idx;) { |
| 4412 | vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(idx)); |
| 4413 | if ((vlvf & VLAN_VID_MASK) == vlan) |
| 4414 | break; |
| 4415 | } |
| 4416 | |
| 4417 | return idx; |
| 4418 | } |
| 4419 | |
| 4420 | void ixgbe_update_pf_promisc_vlvf(struct ixgbe_adapter *adapter, u32 vid) |
| 4421 | { |
| 4422 | struct ixgbe_hw *hw = &adapter->hw; |
| 4423 | u32 bits, word; |
| 4424 | int idx; |
| 4425 | |
| 4426 | idx = ixgbe_find_vlvf_entry(hw, vid); |
| 4427 | if (!idx) |
| 4428 | return; |
| 4429 | |
| 4430 | /* See if any other pools are set for this VLAN filter |
| 4431 | * entry other than the PF. |
| 4432 | */ |
| 4433 | word = idx * 2 + (VMDQ_P(0) / 32); |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 4434 | bits = ~BIT(VMDQ_P(0) % 32); |
Alexander Duyck | e1d0a2a | 2015-11-02 17:10:19 -0800 | [diff] [blame] | 4435 | bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word)); |
| 4436 | |
| 4437 | /* Disable the filter so this falls into the default pool. */ |
| 4438 | if (!bits && !IXGBE_READ_REG(hw, IXGBE_VLVFB(word ^ 1))) { |
| 4439 | if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)) |
| 4440 | IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), 0); |
| 4441 | IXGBE_WRITE_REG(hw, IXGBE_VLVF(idx), 0); |
| 4442 | } |
| 4443 | } |
| 4444 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 4445 | static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev, |
| 4446 | __be16 proto, u16 vid) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4447 | { |
| 4448 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4449 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4450 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4451 | /* remove VID from filter table */ |
Alexander Duyck | 18be4fc | 2016-01-06 22:48:44 -0800 | [diff] [blame] | 4452 | if (vid && !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)) |
Alexander Duyck | e1d0a2a | 2015-11-02 17:10:19 -0800 | [diff] [blame] | 4453 | hw->mac.ops.set_vfta(hw, vid, VMDQ_P(0), false, true); |
| 4454 | |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4455 | clear_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 4456 | |
| 4457 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4458 | } |
| 4459 | |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4460 | /** |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4461 | * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping |
| 4462 | * @adapter: driver data |
| 4463 | */ |
| 4464 | static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter) |
| 4465 | { |
| 4466 | struct ixgbe_hw *hw = &adapter->hw; |
| 4467 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4468 | int i, j; |
| 4469 | |
| 4470 | switch (hw->mac.type) { |
| 4471 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4472 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 4473 | vlnctrl &= ~IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4474 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4475 | break; |
| 4476 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4477 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 4478 | case ixgbe_mac_X550: |
| 4479 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 4480 | case ixgbe_mac_x550em_a: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4481 | for (i = 0; i < adapter->num_rx_queues; i++) { |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4482 | struct ixgbe_ring *ring = adapter->rx_ring[i]; |
| 4483 | |
| 4484 | if (ring->l2_accel_priv) |
| 4485 | continue; |
| 4486 | j = ring->reg_idx; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4487 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 4488 | vlnctrl &= ~IXGBE_RXDCTL_VME; |
| 4489 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 4490 | } |
| 4491 | break; |
| 4492 | default: |
| 4493 | break; |
| 4494 | } |
| 4495 | } |
| 4496 | |
| 4497 | /** |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4498 | * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4499 | * @adapter: driver data |
| 4500 | */ |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4501 | static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4502 | { |
| 4503 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4504 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4505 | int i, j; |
| 4506 | |
| 4507 | switch (hw->mac.type) { |
| 4508 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4509 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 4510 | vlnctrl |= IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4511 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4512 | break; |
| 4513 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4514 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 4515 | case ixgbe_mac_X550: |
| 4516 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 4517 | case ixgbe_mac_x550em_a: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4518 | for (i = 0; i < adapter->num_rx_queues; i++) { |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4519 | struct ixgbe_ring *ring = adapter->rx_ring[i]; |
| 4520 | |
| 4521 | if (ring->l2_accel_priv) |
| 4522 | continue; |
| 4523 | j = ring->reg_idx; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4524 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 4525 | vlnctrl |= IXGBE_RXDCTL_VME; |
| 4526 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 4527 | } |
| 4528 | break; |
| 4529 | default: |
| 4530 | break; |
| 4531 | } |
| 4532 | } |
| 4533 | |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4534 | static void ixgbe_vlan_promisc_enable(struct ixgbe_adapter *adapter) |
| 4535 | { |
| 4536 | struct ixgbe_hw *hw = &adapter->hw; |
| 4537 | u32 vlnctrl, i; |
| 4538 | |
Alexander Duyck | f60439b | 2016-08-11 14:51:56 -0700 | [diff] [blame] | 4539 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 4540 | |
Emil Tantilov | 691e412 | 2016-08-22 16:17:46 -0700 | [diff] [blame] | 4541 | if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) { |
| 4542 | /* For VMDq and SR-IOV we must leave VLAN filtering enabled */ |
| 4543 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
| 4544 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4545 | } else { |
Alexander Duyck | f60439b | 2016-08-11 14:51:56 -0700 | [diff] [blame] | 4546 | vlnctrl &= ~IXGBE_VLNCTRL_VFE; |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4547 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4548 | return; |
| 4549 | } |
| 4550 | |
Emil Tantilov | 691e412 | 2016-08-22 16:17:46 -0700 | [diff] [blame] | 4551 | /* Nothing to do for 82598 */ |
| 4552 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4553 | return; |
| 4554 | |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4555 | /* We are already in VLAN promisc, nothing to do */ |
| 4556 | if (adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC) |
| 4557 | return; |
| 4558 | |
| 4559 | /* Set flag so we don't redo unnecessary work */ |
| 4560 | adapter->flags2 |= IXGBE_FLAG2_VLAN_PROMISC; |
| 4561 | |
| 4562 | /* Add PF to all active pools */ |
| 4563 | for (i = IXGBE_VLVF_ENTRIES; --i;) { |
| 4564 | u32 reg_offset = IXGBE_VLVFB(i * 2 + VMDQ_P(0) / 32); |
| 4565 | u32 vlvfb = IXGBE_READ_REG(hw, reg_offset); |
| 4566 | |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 4567 | vlvfb |= BIT(VMDQ_P(0) % 32); |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4568 | IXGBE_WRITE_REG(hw, reg_offset, vlvfb); |
| 4569 | } |
| 4570 | |
| 4571 | /* Set all bits in the VLAN filter table array */ |
| 4572 | for (i = hw->mac.vft_size; i--;) |
| 4573 | IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), ~0U); |
| 4574 | } |
| 4575 | |
| 4576 | #define VFTA_BLOCK_SIZE 8 |
| 4577 | static void ixgbe_scrub_vfta(struct ixgbe_adapter *adapter, u32 vfta_offset) |
| 4578 | { |
| 4579 | struct ixgbe_hw *hw = &adapter->hw; |
| 4580 | u32 vfta[VFTA_BLOCK_SIZE] = { 0 }; |
| 4581 | u32 vid_start = vfta_offset * 32; |
| 4582 | u32 vid_end = vid_start + (VFTA_BLOCK_SIZE * 32); |
| 4583 | u32 i, vid, word, bits; |
| 4584 | |
| 4585 | for (i = IXGBE_VLVF_ENTRIES; --i;) { |
| 4586 | u32 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(i)); |
| 4587 | |
| 4588 | /* pull VLAN ID from VLVF */ |
| 4589 | vid = vlvf & VLAN_VID_MASK; |
| 4590 | |
| 4591 | /* only concern outselves with a certain range */ |
| 4592 | if (vid < vid_start || vid >= vid_end) |
| 4593 | continue; |
| 4594 | |
| 4595 | if (vlvf) { |
| 4596 | /* record VLAN ID in VFTA */ |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 4597 | vfta[(vid - vid_start) / 32] |= BIT(vid % 32); |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4598 | |
| 4599 | /* if PF is part of this then continue */ |
| 4600 | if (test_bit(vid, adapter->active_vlans)) |
| 4601 | continue; |
| 4602 | } |
| 4603 | |
| 4604 | /* remove PF from the pool */ |
| 4605 | word = i * 2 + VMDQ_P(0) / 32; |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 4606 | bits = ~BIT(VMDQ_P(0) % 32); |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4607 | bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word)); |
| 4608 | IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), bits); |
| 4609 | } |
| 4610 | |
| 4611 | /* extract values from active_vlans and write back to VFTA */ |
| 4612 | for (i = VFTA_BLOCK_SIZE; i--;) { |
| 4613 | vid = (vfta_offset + i) * 32; |
| 4614 | word = vid / BITS_PER_LONG; |
| 4615 | bits = vid % BITS_PER_LONG; |
| 4616 | |
| 4617 | vfta[i] |= adapter->active_vlans[word] >> bits; |
| 4618 | |
| 4619 | IXGBE_WRITE_REG(hw, IXGBE_VFTA(vfta_offset + i), vfta[i]); |
| 4620 | } |
| 4621 | } |
| 4622 | |
| 4623 | static void ixgbe_vlan_promisc_disable(struct ixgbe_adapter *adapter) |
| 4624 | { |
| 4625 | struct ixgbe_hw *hw = &adapter->hw; |
| 4626 | u32 vlnctrl, i; |
| 4627 | |
Alexander Duyck | f60439b | 2016-08-11 14:51:56 -0700 | [diff] [blame] | 4628 | /* Set VLAN filtering to enabled */ |
| 4629 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 4630 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
| 4631 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4632 | |
Emil Tantilov | 691e412 | 2016-08-22 16:17:46 -0700 | [diff] [blame] | 4633 | if (!(adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) || |
| 4634 | hw->mac.type == ixgbe_mac_82598EB) |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4635 | return; |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4636 | |
| 4637 | /* We are not in VLAN promisc, nothing to do */ |
| 4638 | if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)) |
| 4639 | return; |
| 4640 | |
| 4641 | /* Set flag so we don't redo unnecessary work */ |
| 4642 | adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC; |
| 4643 | |
| 4644 | for (i = 0; i < hw->mac.vft_size; i += VFTA_BLOCK_SIZE) |
| 4645 | ixgbe_scrub_vfta(adapter, i); |
| 4646 | } |
| 4647 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4648 | static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter) |
| 4649 | { |
Alexander Duyck | 06bb1c3 | 2016-01-06 22:48:50 -0800 | [diff] [blame] | 4650 | u16 vid = 1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4651 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 4652 | ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4653 | |
Alexander Duyck | 06bb1c3 | 2016-01-06 22:48:50 -0800 | [diff] [blame] | 4654 | for_each_set_bit_from(vid, adapter->active_vlans, VLAN_N_VID) |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 4655 | ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4656 | } |
| 4657 | |
| 4658 | /** |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4659 | * ixgbe_write_mc_addr_list - write multicast addresses to MTA |
| 4660 | * @netdev: network interface device structure |
| 4661 | * |
| 4662 | * Writes multicast address list to the MTA hash table. |
| 4663 | * Returns: -ENOMEM on failure |
| 4664 | * 0 on no addresses written |
| 4665 | * X on writing X addresses to MTA |
| 4666 | **/ |
| 4667 | static int ixgbe_write_mc_addr_list(struct net_device *netdev) |
| 4668 | { |
| 4669 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4670 | struct ixgbe_hw *hw = &adapter->hw; |
| 4671 | |
| 4672 | if (!netif_running(netdev)) |
| 4673 | return 0; |
| 4674 | |
| 4675 | if (hw->mac.ops.update_mc_addr_list) |
| 4676 | hw->mac.ops.update_mc_addr_list(hw, netdev); |
| 4677 | else |
| 4678 | return -ENOMEM; |
| 4679 | |
| 4680 | #ifdef CONFIG_PCI_IOV |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4681 | ixgbe_restore_vf_multicasts(adapter); |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4682 | #endif |
| 4683 | |
| 4684 | return netdev_mc_count(netdev); |
| 4685 | } |
| 4686 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4687 | #ifdef CONFIG_PCI_IOV |
| 4688 | void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter) |
| 4689 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4690 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4691 | struct ixgbe_hw *hw = &adapter->hw; |
| 4692 | int i; |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4693 | |
| 4694 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4695 | mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED; |
| 4696 | |
| 4697 | if (mac_table->state & IXGBE_MAC_STATE_IN_USE) |
| 4698 | hw->mac.ops.set_rar(hw, i, |
| 4699 | mac_table->addr, |
| 4700 | mac_table->pool, |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4701 | IXGBE_RAH_AV); |
| 4702 | else |
| 4703 | hw->mac.ops.clear_rar(hw, i); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4704 | } |
| 4705 | } |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4706 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4707 | #endif |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4708 | static void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter) |
| 4709 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4710 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4711 | struct ixgbe_hw *hw = &adapter->hw; |
| 4712 | int i; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4713 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4714 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4715 | if (!(mac_table->state & IXGBE_MAC_STATE_MODIFIED)) |
| 4716 | continue; |
| 4717 | |
| 4718 | mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED; |
| 4719 | |
| 4720 | if (mac_table->state & IXGBE_MAC_STATE_IN_USE) |
| 4721 | hw->mac.ops.set_rar(hw, i, |
| 4722 | mac_table->addr, |
| 4723 | mac_table->pool, |
| 4724 | IXGBE_RAH_AV); |
| 4725 | else |
| 4726 | hw->mac.ops.clear_rar(hw, i); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4727 | } |
| 4728 | } |
| 4729 | |
| 4730 | static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter) |
| 4731 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4732 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4733 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4734 | int i; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4735 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4736 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4737 | mac_table->state |= IXGBE_MAC_STATE_MODIFIED; |
| 4738 | mac_table->state &= ~IXGBE_MAC_STATE_IN_USE; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4739 | } |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4740 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4741 | ixgbe_sync_mac_table(adapter); |
| 4742 | } |
| 4743 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4744 | static int ixgbe_available_rars(struct ixgbe_adapter *adapter, u16 pool) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4745 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4746 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4747 | struct ixgbe_hw *hw = &adapter->hw; |
| 4748 | int i, count = 0; |
| 4749 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4750 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4751 | /* do not count default RAR as available */ |
| 4752 | if (mac_table->state & IXGBE_MAC_STATE_DEFAULT) |
| 4753 | continue; |
| 4754 | |
| 4755 | /* only count unused and addresses that belong to us */ |
| 4756 | if (mac_table->state & IXGBE_MAC_STATE_IN_USE) { |
| 4757 | if (mac_table->pool != pool) |
| 4758 | continue; |
| 4759 | } |
| 4760 | |
| 4761 | count++; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4762 | } |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4763 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4764 | return count; |
| 4765 | } |
| 4766 | |
| 4767 | /* this function destroys the first RAR entry */ |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4768 | static void ixgbe_mac_set_default_filter(struct ixgbe_adapter *adapter) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4769 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4770 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4771 | struct ixgbe_hw *hw = &adapter->hw; |
| 4772 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4773 | memcpy(&mac_table->addr, hw->mac.addr, ETH_ALEN); |
| 4774 | mac_table->pool = VMDQ_P(0); |
| 4775 | |
| 4776 | mac_table->state = IXGBE_MAC_STATE_DEFAULT | IXGBE_MAC_STATE_IN_USE; |
| 4777 | |
| 4778 | 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] | 4779 | IXGBE_RAH_AV); |
| 4780 | } |
| 4781 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4782 | int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter, |
| 4783 | const u8 *addr, u16 pool) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4784 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4785 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4786 | struct ixgbe_hw *hw = &adapter->hw; |
| 4787 | int i; |
| 4788 | |
| 4789 | if (is_zero_ether_addr(addr)) |
| 4790 | return -EINVAL; |
| 4791 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4792 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4793 | if (mac_table->state & IXGBE_MAC_STATE_IN_USE) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4794 | continue; |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4795 | |
| 4796 | ether_addr_copy(mac_table->addr, addr); |
| 4797 | mac_table->pool = pool; |
| 4798 | |
| 4799 | mac_table->state |= IXGBE_MAC_STATE_MODIFIED | |
| 4800 | IXGBE_MAC_STATE_IN_USE; |
| 4801 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4802 | ixgbe_sync_mac_table(adapter); |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4803 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4804 | return i; |
| 4805 | } |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4806 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4807 | return -ENOMEM; |
| 4808 | } |
| 4809 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4810 | int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter, |
| 4811 | const u8 *addr, u16 pool) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4812 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4813 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4814 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4815 | int i; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4816 | |
| 4817 | if (is_zero_ether_addr(addr)) |
| 4818 | return -EINVAL; |
| 4819 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4820 | /* search table for addr, if found clear IN_USE flag and sync */ |
| 4821 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4822 | /* we can only delete an entry if it is in use */ |
| 4823 | if (!(mac_table->state & IXGBE_MAC_STATE_IN_USE)) |
| 4824 | continue; |
| 4825 | /* we only care about entries that belong to the given pool */ |
| 4826 | if (mac_table->pool != pool) |
| 4827 | continue; |
| 4828 | /* we only care about a specific MAC address */ |
| 4829 | if (!ether_addr_equal(addr, mac_table->addr)) |
| 4830 | continue; |
| 4831 | |
| 4832 | mac_table->state |= IXGBE_MAC_STATE_MODIFIED; |
| 4833 | mac_table->state &= ~IXGBE_MAC_STATE_IN_USE; |
| 4834 | |
| 4835 | ixgbe_sync_mac_table(adapter); |
| 4836 | |
| 4837 | return 0; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4838 | } |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4839 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4840 | return -ENOMEM; |
| 4841 | } |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4842 | /** |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4843 | * ixgbe_write_uc_addr_list - write unicast addresses to RAR table |
| 4844 | * @netdev: network interface device structure |
| 4845 | * |
| 4846 | * Writes unicast address list to the RAR table. |
| 4847 | * Returns: -ENOMEM on failure/insufficient address space |
| 4848 | * 0 on no addresses written |
| 4849 | * X on writing X addresses to the RAR table |
| 4850 | **/ |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4851 | 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] | 4852 | { |
| 4853 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4854 | int count = 0; |
| 4855 | |
| 4856 | /* return ENOMEM indicating insufficient memory for addresses */ |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4857 | if (netdev_uc_count(netdev) > ixgbe_available_rars(adapter, vfn)) |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4858 | return -ENOMEM; |
| 4859 | |
John Fastabend | 9544746 | 2012-05-31 12:42:26 +0000 | [diff] [blame] | 4860 | if (!netdev_uc_empty(netdev)) { |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4861 | struct netdev_hw_addr *ha; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4862 | netdev_for_each_uc_addr(ha, netdev) { |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4863 | ixgbe_del_mac_filter(adapter, ha->addr, vfn); |
| 4864 | ixgbe_add_mac_filter(adapter, ha->addr, vfn); |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4865 | count++; |
| 4866 | } |
| 4867 | } |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4868 | return count; |
| 4869 | } |
| 4870 | |
Alexander Duyck | 0f079d2 | 2015-10-22 16:26:36 -0700 | [diff] [blame] | 4871 | static int ixgbe_uc_sync(struct net_device *netdev, const unsigned char *addr) |
| 4872 | { |
| 4873 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4874 | int ret; |
| 4875 | |
| 4876 | ret = ixgbe_add_mac_filter(adapter, addr, VMDQ_P(0)); |
| 4877 | |
| 4878 | return min_t(int, ret, 0); |
| 4879 | } |
| 4880 | |
| 4881 | static int ixgbe_uc_unsync(struct net_device *netdev, const unsigned char *addr) |
| 4882 | { |
| 4883 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4884 | |
| 4885 | ixgbe_del_mac_filter(adapter, addr, VMDQ_P(0)); |
| 4886 | |
| 4887 | return 0; |
| 4888 | } |
| 4889 | |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4890 | /** |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 4891 | * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4892 | * @netdev: network interface device structure |
| 4893 | * |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 4894 | * The set_rx_method entry point is called whenever the unicast/multicast |
| 4895 | * address list or the network interface flags are updated. This routine is |
| 4896 | * responsible for configuring the hardware for proper unicast, multicast and |
| 4897 | * promiscuous mode. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4898 | **/ |
Greg Rose | 7f87047 | 2010-01-09 02:25:29 +0000 | [diff] [blame] | 4899 | void ixgbe_set_rx_mode(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4900 | { |
| 4901 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4902 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4903 | u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE; |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 4904 | netdev_features_t features = netdev->features; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4905 | int count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4906 | |
| 4907 | /* Check for Promiscuous and All Multicast modes */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4908 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 4909 | |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 4910 | /* set all bits that we expect to always be set */ |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 4911 | fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */ |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 4912 | fctrl |= IXGBE_FCTRL_BAM; |
| 4913 | fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */ |
| 4914 | fctrl |= IXGBE_FCTRL_PMCF; |
| 4915 | |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4916 | /* clear the bits we are changing the status of */ |
| 4917 | fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4918 | if (netdev->flags & IFF_PROMISC) { |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 4919 | hw->addr_ctrl.user_set_promisc = true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4920 | fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4921 | vmolr |= IXGBE_VMOLR_MPE; |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 4922 | features &= ~NETIF_F_HW_VLAN_CTAG_FILTER; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4923 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 4924 | if (netdev->flags & IFF_ALLMULTI) { |
| 4925 | fctrl |= IXGBE_FCTRL_MPE; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4926 | vmolr |= IXGBE_VMOLR_MPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 4927 | } |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 4928 | hw->addr_ctrl.user_set_promisc = false; |
John Fastabend | 9dcb373 | 2012-04-15 06:44:25 +0000 | [diff] [blame] | 4929 | } |
| 4930 | |
| 4931 | /* |
| 4932 | * Write addresses to available RAR registers, if there is not |
| 4933 | * sufficient space to store all the addresses then enable |
| 4934 | * unicast promiscuous mode |
| 4935 | */ |
Alexander Duyck | 0f079d2 | 2015-10-22 16:26:36 -0700 | [diff] [blame] | 4936 | if (__dev_uc_sync(netdev, ixgbe_uc_sync, ixgbe_uc_unsync)) { |
John Fastabend | 9dcb373 | 2012-04-15 06:44:25 +0000 | [diff] [blame] | 4937 | fctrl |= IXGBE_FCTRL_UPE; |
| 4938 | vmolr |= IXGBE_VMOLR_ROPE; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4939 | } |
| 4940 | |
Emil Tantilov | cf78959 | 2013-10-26 08:13:20 +0000 | [diff] [blame] | 4941 | /* Write addresses to the MTA, if the attempt fails |
| 4942 | * then we should just turn on promiscuous mode so |
| 4943 | * that we can at least receive multicast traffic |
| 4944 | */ |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4945 | count = ixgbe_write_mc_addr_list(netdev); |
| 4946 | if (count < 0) { |
| 4947 | fctrl |= IXGBE_FCTRL_MPE; |
| 4948 | vmolr |= IXGBE_VMOLR_MPE; |
| 4949 | } else if (count) { |
| 4950 | vmolr |= IXGBE_VMOLR_ROMPE; |
| 4951 | } |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 4952 | |
| 4953 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 4954 | vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) & |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4955 | ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE | |
| 4956 | IXGBE_VMOLR_ROPE); |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 4957 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4958 | } |
| 4959 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 4960 | /* This is useful for sniffing bad packets. */ |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 4961 | if (features & NETIF_F_RXALL) { |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 4962 | /* UPE and MPE will be handled by normal PROMISC logic |
| 4963 | * in e1000e_set_rx_mode */ |
| 4964 | fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */ |
| 4965 | IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */ |
| 4966 | IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */ |
| 4967 | |
| 4968 | fctrl &= ~(IXGBE_FCTRL_DPF); |
| 4969 | /* NOTE: VLAN filtering is disabled by setting PROMISC */ |
| 4970 | } |
| 4971 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4972 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4973 | |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 4974 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4975 | ixgbe_vlan_strip_enable(adapter); |
| 4976 | else |
| 4977 | ixgbe_vlan_strip_disable(adapter); |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 4978 | |
| 4979 | if (features & NETIF_F_HW_VLAN_CTAG_FILTER) |
| 4980 | ixgbe_vlan_promisc_disable(adapter); |
| 4981 | else |
| 4982 | ixgbe_vlan_promisc_enable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4983 | } |
| 4984 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4985 | static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter) |
| 4986 | { |
| 4987 | int q_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4988 | |
Eric Dumazet | 3ffc1af | 2017-02-02 16:26:39 -0800 | [diff] [blame] | 4989 | for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 4990 | napi_enable(&adapter->q_vector[q_idx]->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4991 | } |
| 4992 | |
| 4993 | static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter) |
| 4994 | { |
| 4995 | int q_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4996 | |
Eric Dumazet | 3ffc1af | 2017-02-02 16:26:39 -0800 | [diff] [blame] | 4997 | for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 4998 | napi_disable(&adapter->q_vector[q_idx]->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4999 | } |
| 5000 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 5001 | 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] | 5002 | { |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 5003 | struct ixgbe_hw *hw = &adapter->hw; |
| 5004 | u32 vxlanctrl; |
| 5005 | |
| 5006 | if (!(adapter->flags & (IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE | |
| 5007 | IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))) |
| 5008 | return; |
| 5009 | |
Sabrina Dubroca | a39221c | 2017-07-03 13:02:55 +0200 | [diff] [blame] | 5010 | vxlanctrl = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) & ~mask; |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 5011 | IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, vxlanctrl); |
| 5012 | |
| 5013 | if (mask & IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK) |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 5014 | adapter->vxlan_port = 0; |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 5015 | |
| 5016 | if (mask & IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK) |
| 5017 | adapter->geneve_port = 0; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 5018 | } |
| 5019 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5020 | #ifdef CONFIG_IXGBE_DCB |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 5021 | /** |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5022 | * ixgbe_configure_dcb - Configure DCB hardware |
| 5023 | * @adapter: ixgbe adapter struct |
| 5024 | * |
| 5025 | * This is called by the driver on open to configure the DCB hardware. |
| 5026 | * This is also called by the gennetlink interface when reconfiguring |
| 5027 | * the DCB state. |
| 5028 | */ |
| 5029 | static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter) |
| 5030 | { |
| 5031 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 9806307a | 2010-10-28 00:59:57 +0000 | [diff] [blame] | 5032 | int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5033 | |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 5034 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) { |
| 5035 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 5036 | netif_set_gso_max_size(adapter->netdev, 65536); |
| 5037 | return; |
| 5038 | } |
| 5039 | |
| 5040 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 5041 | netif_set_gso_max_size(adapter->netdev, 32768); |
| 5042 | |
John Fastabend | b120818 | 2011-10-15 05:00:10 +0000 | [diff] [blame] | 5043 | #ifdef IXGBE_FCOE |
| 5044 | if (adapter->netdev->features & NETIF_F_FCOE_MTU) |
| 5045 | max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE); |
| 5046 | #endif |
| 5047 | |
Alexander Duyck | 01fa7d9 | 2010-11-16 19:26:53 -0800 | [diff] [blame] | 5048 | /* reconfigure the hardware */ |
John Fastabend | 6f70f6a | 2011-04-26 07:26:25 +0000 | [diff] [blame] | 5049 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) { |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 5050 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 5051 | DCB_TX_CONFIG); |
| 5052 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 5053 | DCB_RX_CONFIG); |
| 5054 | ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg); |
John Fastabend | b120818 | 2011-10-15 05:00:10 +0000 | [diff] [blame] | 5055 | } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) { |
| 5056 | ixgbe_dcb_hw_ets(&adapter->hw, |
| 5057 | adapter->ixgbe_ieee_ets, |
| 5058 | max_frame); |
| 5059 | ixgbe_dcb_hw_pfc_config(&adapter->hw, |
| 5060 | adapter->ixgbe_ieee_pfc->pfc_en, |
| 5061 | adapter->ixgbe_ieee_ets->prio_tc); |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 5062 | } |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 5063 | |
| 5064 | /* Enable RSS Hash per TC */ |
| 5065 | if (hw->mac.type != ixgbe_mac_82598EB) { |
Alexander Duyck | 4ae6373 | 2012-06-22 06:46:33 +0000 | [diff] [blame] | 5066 | u32 msb = 0; |
| 5067 | u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1; |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 5068 | |
Alexander Duyck | d411a93 | 2012-06-30 00:14:01 +0000 | [diff] [blame] | 5069 | while (rss_i) { |
| 5070 | msb++; |
| 5071 | rss_i >>= 1; |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 5072 | } |
Alexander Duyck | d411a93 | 2012-06-30 00:14:01 +0000 | [diff] [blame] | 5073 | |
Alexander Duyck | 4ae6373 | 2012-06-22 06:46:33 +0000 | [diff] [blame] | 5074 | /* write msb to all 8 TCs in one write */ |
| 5075 | IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111); |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 5076 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5077 | } |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5078 | #endif |
| 5079 | |
| 5080 | /* Additional bittime to account for IXGBE framing */ |
| 5081 | #define IXGBE_ETH_FRAMING 20 |
| 5082 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 5083 | /** |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5084 | * ixgbe_hpbthresh - calculate high water mark for flow control |
| 5085 | * |
| 5086 | * @adapter: board private structure to calculate for |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 5087 | * @pb: packet buffer to calculate |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5088 | */ |
| 5089 | static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb) |
| 5090 | { |
| 5091 | struct ixgbe_hw *hw = &adapter->hw; |
| 5092 | struct net_device *dev = adapter->netdev; |
| 5093 | int link, tc, kb, marker; |
| 5094 | u32 dv_id, rx_pba; |
| 5095 | |
| 5096 | /* Calculate max LAN frame size */ |
| 5097 | tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING; |
| 5098 | |
| 5099 | #ifdef IXGBE_FCOE |
| 5100 | /* FCoE traffic class uses FCOE jumbo frames */ |
Alexander Duyck | 800bd60 | 2012-06-02 00:11:02 +0000 | [diff] [blame] | 5101 | if ((dev->features & NETIF_F_FCOE_MTU) && |
| 5102 | (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) && |
| 5103 | (pb == ixgbe_fcoe_get_tc(adapter))) |
| 5104 | tc = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5105 | #endif |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 5106 | |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5107 | /* Calculate delay value for device */ |
| 5108 | switch (hw->mac.type) { |
| 5109 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5110 | case ixgbe_mac_X550: |
| 5111 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 5112 | case ixgbe_mac_x550em_a: |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5113 | dv_id = IXGBE_DV_X540(link, tc); |
| 5114 | break; |
| 5115 | default: |
| 5116 | dv_id = IXGBE_DV(link, tc); |
| 5117 | break; |
| 5118 | } |
| 5119 | |
| 5120 | /* Loopback switch introduces additional latency */ |
| 5121 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 5122 | dv_id += IXGBE_B2BT(tc); |
| 5123 | |
| 5124 | /* Delay value is calculated in bit times convert to KB */ |
| 5125 | kb = IXGBE_BT2KB(dv_id); |
| 5126 | rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10; |
| 5127 | |
| 5128 | marker = rx_pba - kb; |
| 5129 | |
| 5130 | /* It is possible that the packet buffer is not large enough |
| 5131 | * to provide required headroom. In this case throw an error |
| 5132 | * to user and a do the best we can. |
| 5133 | */ |
| 5134 | if (marker < 0) { |
| 5135 | e_warn(drv, "Packet Buffer(%i) can not provide enough" |
| 5136 | "headroom to support flow control." |
| 5137 | "Decrease MTU or number of traffic classes\n", pb); |
| 5138 | marker = tc + 1; |
| 5139 | } |
| 5140 | |
| 5141 | return marker; |
| 5142 | } |
| 5143 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 5144 | /** |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5145 | * ixgbe_lpbthresh - calculate low water mark for for flow control |
| 5146 | * |
| 5147 | * @adapter: board private structure to calculate for |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 5148 | * @pb: packet buffer to calculate |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5149 | */ |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 5150 | static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb) |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5151 | { |
| 5152 | struct ixgbe_hw *hw = &adapter->hw; |
| 5153 | struct net_device *dev = adapter->netdev; |
| 5154 | int tc; |
| 5155 | u32 dv_id; |
| 5156 | |
| 5157 | /* Calculate max LAN frame size */ |
| 5158 | tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN; |
| 5159 | |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 5160 | #ifdef IXGBE_FCOE |
| 5161 | /* FCoE traffic class uses FCOE jumbo frames */ |
| 5162 | if ((dev->features & NETIF_F_FCOE_MTU) && |
| 5163 | (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) && |
| 5164 | (pb == netdev_get_prio_tc_map(dev, adapter->fcoe.up))) |
| 5165 | tc = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 5166 | #endif |
| 5167 | |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5168 | /* Calculate delay value for device */ |
| 5169 | switch (hw->mac.type) { |
| 5170 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5171 | case ixgbe_mac_X550: |
| 5172 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 5173 | case ixgbe_mac_x550em_a: |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5174 | dv_id = IXGBE_LOW_DV_X540(tc); |
| 5175 | break; |
| 5176 | default: |
| 5177 | dv_id = IXGBE_LOW_DV(tc); |
| 5178 | break; |
| 5179 | } |
| 5180 | |
| 5181 | /* Delay value is calculated in bit times convert to KB */ |
| 5182 | return IXGBE_BT2KB(dv_id); |
| 5183 | } |
| 5184 | |
| 5185 | /* |
| 5186 | * ixgbe_pbthresh_setup - calculate and setup high low water marks |
| 5187 | */ |
| 5188 | static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter) |
| 5189 | { |
| 5190 | struct ixgbe_hw *hw = &adapter->hw; |
| 5191 | int num_tc = netdev_get_num_tc(adapter->netdev); |
| 5192 | int i; |
| 5193 | |
| 5194 | if (!num_tc) |
| 5195 | num_tc = 1; |
| 5196 | |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5197 | for (i = 0; i < num_tc; i++) { |
| 5198 | hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i); |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 5199 | hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i); |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5200 | |
| 5201 | /* Low water marks must not be larger than high water marks */ |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 5202 | if (hw->fc.low_water[i] > hw->fc.high_water[i]) |
| 5203 | hw->fc.low_water[i] = 0; |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5204 | } |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 5205 | |
| 5206 | for (; i < MAX_TRAFFIC_CLASS; i++) |
| 5207 | hw->fc.high_water[i] = 0; |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5208 | } |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 5209 | |
| 5210 | static void ixgbe_configure_pb(struct ixgbe_adapter *adapter) |
| 5211 | { |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 5212 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 5213 | int hdrm; |
| 5214 | u8 tc = netdev_get_num_tc(adapter->netdev); |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 5215 | |
| 5216 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 5217 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 5218 | hdrm = 32 << adapter->fdir_pballoc; |
| 5219 | else |
| 5220 | hdrm = 0; |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 5221 | |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 5222 | hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL); |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5223 | ixgbe_pbthresh_setup(adapter); |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 5224 | } |
| 5225 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5226 | static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter) |
| 5227 | { |
| 5228 | struct ixgbe_hw *hw = &adapter->hw; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 5229 | struct hlist_node *node2; |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5230 | struct ixgbe_fdir_filter *filter; |
| 5231 | |
| 5232 | spin_lock(&adapter->fdir_perfect_lock); |
| 5233 | |
| 5234 | if (!hlist_empty(&adapter->fdir_filter_list)) |
| 5235 | ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask); |
| 5236 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 5237 | hlist_for_each_entry_safe(filter, node2, |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5238 | &adapter->fdir_filter_list, fdir_node) { |
| 5239 | ixgbe_fdir_write_perfect_filter_82599(hw, |
Alexander Duyck | 1f4d518 | 2011-05-14 01:16:02 +0000 | [diff] [blame] | 5240 | &filter->filter, |
| 5241 | filter->sw_idx, |
| 5242 | (filter->action == IXGBE_FDIR_DROP_QUEUE) ? |
| 5243 | IXGBE_FDIR_DROP_QUEUE : |
| 5244 | adapter->rx_ring[filter->action]->reg_idx); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5245 | } |
| 5246 | |
| 5247 | spin_unlock(&adapter->fdir_perfect_lock); |
| 5248 | } |
| 5249 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5250 | static void ixgbe_macvlan_set_rx_mode(struct net_device *dev, unsigned int pool, |
| 5251 | struct ixgbe_adapter *adapter) |
| 5252 | { |
| 5253 | struct ixgbe_hw *hw = &adapter->hw; |
| 5254 | u32 vmolr; |
| 5255 | |
| 5256 | /* No unicast promiscuous support for VMDQ devices. */ |
| 5257 | vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(pool)); |
| 5258 | vmolr |= (IXGBE_VMOLR_ROMPE | IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE); |
| 5259 | |
| 5260 | /* clear the affected bit */ |
| 5261 | vmolr &= ~IXGBE_VMOLR_MPE; |
| 5262 | |
| 5263 | if (dev->flags & IFF_ALLMULTI) { |
| 5264 | vmolr |= IXGBE_VMOLR_MPE; |
| 5265 | } else { |
| 5266 | vmolr |= IXGBE_VMOLR_ROMPE; |
| 5267 | hw->mac.ops.update_mc_addr_list(hw, dev); |
| 5268 | } |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 5269 | ixgbe_write_uc_addr_list(adapter->netdev, pool); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5270 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(pool), vmolr); |
| 5271 | } |
| 5272 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5273 | static void ixgbe_fwd_psrtype(struct ixgbe_fwd_adapter *vadapter) |
| 5274 | { |
| 5275 | struct ixgbe_adapter *adapter = vadapter->real_adapter; |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 5276 | int rss_i = adapter->num_rx_queues_per_pool; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5277 | struct ixgbe_hw *hw = &adapter->hw; |
| 5278 | u16 pool = vadapter->pool; |
| 5279 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
| 5280 | IXGBE_PSRTYPE_UDPHDR | |
| 5281 | IXGBE_PSRTYPE_IPV4HDR | |
| 5282 | IXGBE_PSRTYPE_L2HDR | |
| 5283 | IXGBE_PSRTYPE_IPV6HDR; |
| 5284 | |
| 5285 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 5286 | return; |
| 5287 | |
| 5288 | if (rss_i > 3) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 5289 | psrtype |= 2u << 29; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5290 | else if (rss_i > 1) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 5291 | psrtype |= 1u << 29; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5292 | |
| 5293 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype); |
| 5294 | } |
| 5295 | |
| 5296 | /** |
| 5297 | * ixgbe_clean_rx_ring - Free Rx Buffers per Queue |
| 5298 | * @rx_ring: ring to free buffers from |
| 5299 | **/ |
| 5300 | static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring) |
| 5301 | { |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5302 | u16 i = rx_ring->next_to_clean; |
| 5303 | struct ixgbe_rx_buffer *rx_buffer = &rx_ring->rx_buffer_info[i]; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5304 | |
| 5305 | /* Free all the Rx ring sk_buffs */ |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5306 | while (i != rx_ring->next_to_alloc) { |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5307 | if (rx_buffer->skb) { |
| 5308 | struct sk_buff *skb = rx_buffer->skb; |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 5309 | if (IXGBE_CB(skb)->page_released) |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5310 | dma_unmap_page_attrs(rx_ring->dev, |
Alexander Duyck | f3213d9 | 2017-01-17 08:35:54 -0800 | [diff] [blame] | 5311 | IXGBE_CB(skb)->dma, |
| 5312 | ixgbe_rx_pg_size(rx_ring), |
| 5313 | DMA_FROM_DEVICE, |
| 5314 | IXGBE_RX_DMA_ATTR); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5315 | dev_kfree_skb(skb); |
| 5316 | } |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 5317 | |
Alexander Duyck | f3213d9 | 2017-01-17 08:35:54 -0800 | [diff] [blame] | 5318 | /* Invalidate cache lines that may have been written to by |
| 5319 | * device so that we avoid corrupting memory. |
| 5320 | */ |
| 5321 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 5322 | rx_buffer->dma, |
| 5323 | rx_buffer->page_offset, |
| 5324 | ixgbe_rx_bufsz(rx_ring), |
| 5325 | DMA_FROM_DEVICE); |
| 5326 | |
| 5327 | /* free resources associated with mapping */ |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5328 | dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma, |
Alexander Duyck | f3213d9 | 2017-01-17 08:35:54 -0800 | [diff] [blame] | 5329 | ixgbe_rx_pg_size(rx_ring), |
| 5330 | DMA_FROM_DEVICE, |
| 5331 | IXGBE_RX_DMA_ATTR); |
Alexander Duyck | 1b56cf4 | 2017-01-17 08:36:03 -0800 | [diff] [blame] | 5332 | __page_frag_cache_drain(rx_buffer->page, |
| 5333 | rx_buffer->pagecnt_bias); |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 5334 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5335 | i++; |
| 5336 | rx_buffer++; |
| 5337 | if (i == rx_ring->count) { |
| 5338 | i = 0; |
| 5339 | rx_buffer = rx_ring->rx_buffer_info; |
| 5340 | } |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5341 | } |
| 5342 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5343 | rx_ring->next_to_alloc = 0; |
| 5344 | rx_ring->next_to_clean = 0; |
| 5345 | rx_ring->next_to_use = 0; |
| 5346 | } |
| 5347 | |
| 5348 | static void ixgbe_disable_fwd_ring(struct ixgbe_fwd_adapter *vadapter, |
| 5349 | struct ixgbe_ring *rx_ring) |
| 5350 | { |
| 5351 | struct ixgbe_adapter *adapter = vadapter->real_adapter; |
| 5352 | int index = rx_ring->queue_index + vadapter->rx_base_queue; |
| 5353 | |
| 5354 | /* shutdown specific queue receive and wait for dma to settle */ |
| 5355 | ixgbe_disable_rx_queue(adapter, rx_ring); |
| 5356 | usleep_range(10000, 20000); |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 5357 | ixgbe_irq_disable_queues(adapter, BIT_ULL(index)); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5358 | ixgbe_clean_rx_ring(rx_ring); |
| 5359 | rx_ring->l2_accel_priv = NULL; |
| 5360 | } |
| 5361 | |
John Fastabend | ae72c8d | 2013-11-09 07:11:26 +0000 | [diff] [blame] | 5362 | static int ixgbe_fwd_ring_down(struct net_device *vdev, |
| 5363 | struct ixgbe_fwd_adapter *accel) |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5364 | { |
| 5365 | struct ixgbe_adapter *adapter = accel->real_adapter; |
| 5366 | unsigned int rxbase = accel->rx_base_queue; |
| 5367 | unsigned int txbase = accel->tx_base_queue; |
| 5368 | int i; |
| 5369 | |
| 5370 | netif_tx_stop_all_queues(vdev); |
| 5371 | |
| 5372 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 5373 | ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]); |
| 5374 | adapter->rx_ring[rxbase + i]->netdev = adapter->netdev; |
| 5375 | } |
| 5376 | |
| 5377 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 5378 | adapter->tx_ring[txbase + i]->l2_accel_priv = NULL; |
| 5379 | adapter->tx_ring[txbase + i]->netdev = adapter->netdev; |
| 5380 | } |
| 5381 | |
| 5382 | |
| 5383 | return 0; |
| 5384 | } |
| 5385 | |
| 5386 | static int ixgbe_fwd_ring_up(struct net_device *vdev, |
| 5387 | struct ixgbe_fwd_adapter *accel) |
| 5388 | { |
| 5389 | struct ixgbe_adapter *adapter = accel->real_adapter; |
| 5390 | unsigned int rxbase, txbase, queues; |
| 5391 | int i, baseq, err = 0; |
| 5392 | |
| 5393 | if (!test_bit(accel->pool, &adapter->fwd_bitmask)) |
| 5394 | return 0; |
| 5395 | |
| 5396 | baseq = accel->pool * adapter->num_rx_queues_per_pool; |
| 5397 | netdev_dbg(vdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n", |
| 5398 | accel->pool, adapter->num_rx_pools, |
| 5399 | baseq, baseq + adapter->num_rx_queues_per_pool, |
| 5400 | adapter->fwd_bitmask); |
| 5401 | |
| 5402 | accel->netdev = vdev; |
| 5403 | accel->rx_base_queue = rxbase = baseq; |
| 5404 | accel->tx_base_queue = txbase = baseq; |
| 5405 | |
| 5406 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) |
| 5407 | ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]); |
| 5408 | |
| 5409 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 5410 | adapter->rx_ring[rxbase + i]->netdev = vdev; |
| 5411 | adapter->rx_ring[rxbase + i]->l2_accel_priv = accel; |
| 5412 | ixgbe_configure_rx_ring(adapter, adapter->rx_ring[rxbase + i]); |
| 5413 | } |
| 5414 | |
| 5415 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 5416 | adapter->tx_ring[txbase + i]->netdev = vdev; |
| 5417 | adapter->tx_ring[txbase + i]->l2_accel_priv = accel; |
| 5418 | } |
| 5419 | |
| 5420 | queues = min_t(unsigned int, |
| 5421 | adapter->num_rx_queues_per_pool, vdev->num_tx_queues); |
| 5422 | err = netif_set_real_num_tx_queues(vdev, queues); |
| 5423 | if (err) |
| 5424 | goto fwd_queue_err; |
| 5425 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5426 | err = netif_set_real_num_rx_queues(vdev, queues); |
| 5427 | if (err) |
| 5428 | goto fwd_queue_err; |
| 5429 | |
| 5430 | if (is_valid_ether_addr(vdev->dev_addr)) |
Alexander Duyck | 361b534 | 2017-11-22 10:56:16 -0800 | [diff] [blame^] | 5431 | ixgbe_add_mac_filter(adapter, vdev->dev_addr, |
| 5432 | VMDQ_P(accel->pool)); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5433 | |
| 5434 | ixgbe_fwd_psrtype(accel); |
Alexander Duyck | 361b534 | 2017-11-22 10:56:16 -0800 | [diff] [blame^] | 5435 | ixgbe_macvlan_set_rx_mode(vdev, VMDQ_P(accel->pool), adapter); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5436 | return err; |
| 5437 | fwd_queue_err: |
| 5438 | ixgbe_fwd_ring_down(vdev, accel); |
| 5439 | return err; |
| 5440 | } |
| 5441 | |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 5442 | static int ixgbe_upper_dev_walk(struct net_device *upper, void *data) |
| 5443 | { |
| 5444 | if (netif_is_macvlan(upper)) { |
| 5445 | struct macvlan_dev *dfwd = netdev_priv(upper); |
| 5446 | struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv; |
| 5447 | |
| 5448 | if (dfwd->fwd_priv) |
| 5449 | ixgbe_fwd_ring_up(upper, vadapter); |
| 5450 | } |
| 5451 | |
| 5452 | return 0; |
| 5453 | } |
| 5454 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5455 | static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter) |
| 5456 | { |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 5457 | netdev_walk_all_upper_dev_rcu(adapter->netdev, |
| 5458 | ixgbe_upper_dev_walk, NULL); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5459 | } |
| 5460 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5461 | static void ixgbe_configure(struct ixgbe_adapter *adapter) |
| 5462 | { |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 5463 | struct ixgbe_hw *hw = &adapter->hw; |
| 5464 | |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 5465 | ixgbe_configure_pb(adapter); |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5466 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 5467 | ixgbe_configure_dcb(adapter); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5468 | #endif |
Alexander Duyck | b35d4d4 | 2012-05-23 05:39:25 +0000 | [diff] [blame] | 5469 | /* |
| 5470 | * We must restore virtualization before VLANs or else |
| 5471 | * the VLVF registers will not be populated |
| 5472 | */ |
| 5473 | ixgbe_configure_virtualization(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5474 | |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 5475 | ixgbe_set_rx_mode(adapter->netdev); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 5476 | ixgbe_restore_vlan(adapter); |
| 5477 | |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 5478 | switch (hw->mac.type) { |
| 5479 | case ixgbe_mac_82599EB: |
| 5480 | case ixgbe_mac_X540: |
| 5481 | hw->mac.ops.disable_rx_buff(hw); |
| 5482 | break; |
| 5483 | default: |
| 5484 | break; |
| 5485 | } |
| 5486 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5487 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 5488 | ixgbe_init_fdir_signature_82599(&adapter->hw, |
| 5489 | adapter->fdir_pballoc); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5490 | } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) { |
| 5491 | ixgbe_init_fdir_perfect_82599(&adapter->hw, |
| 5492 | adapter->fdir_pballoc); |
| 5493 | ixgbe_fdir_filter_restore(adapter); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5494 | } |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 5495 | |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 5496 | switch (hw->mac.type) { |
| 5497 | case ixgbe_mac_82599EB: |
| 5498 | case ixgbe_mac_X540: |
| 5499 | hw->mac.ops.enable_rx_buff(hw); |
| 5500 | break; |
| 5501 | default: |
| 5502 | break; |
| 5503 | } |
| 5504 | |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 5505 | #ifdef CONFIG_IXGBE_DCA |
| 5506 | /* configure DCA */ |
| 5507 | if (adapter->flags & IXGBE_FLAG_DCA_CAPABLE) |
| 5508 | ixgbe_setup_dca(adapter); |
| 5509 | #endif /* CONFIG_IXGBE_DCA */ |
| 5510 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 5511 | #ifdef IXGBE_FCOE |
| 5512 | /* configure FCoE L2 filters, redirection table, and Rx control */ |
| 5513 | ixgbe_configure_fcoe(adapter); |
| 5514 | |
| 5515 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5516 | ixgbe_configure_tx(adapter); |
| 5517 | ixgbe_configure_rx(adapter); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5518 | ixgbe_configure_dfwd(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5519 | } |
| 5520 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5521 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5522 | * ixgbe_sfp_link_config - set up SFP+ link |
| 5523 | * @adapter: pointer to private adapter struct |
| 5524 | **/ |
| 5525 | static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter) |
| 5526 | { |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5527 | /* |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 5528 | * We are assuming the worst case scenario here, and that |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5529 | * is that an SFP was inserted/removed after the reset |
| 5530 | * but before SFP detection was enabled. As such the best |
| 5531 | * solution is to just start searching as soon as we start |
| 5532 | */ |
| 5533 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 5534 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5535 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5536 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
Mark Rustad | 58e7cd2 | 2015-08-08 16:18:48 -0700 | [diff] [blame] | 5537 | adapter->sfp_poll_time = 0; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5538 | } |
| 5539 | |
| 5540 | /** |
| 5541 | * ixgbe_non_sfp_link_config - set up non-SFP+ link |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5542 | * @hw: pointer to private hardware struct |
| 5543 | * |
| 5544 | * Returns 0 on success, negative on failure |
| 5545 | **/ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5546 | 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] | 5547 | { |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 5548 | u32 speed; |
| 5549 | bool autoneg, link_up = false; |
Mark Rustad | a1e869d | 2015-04-10 10:36:36 -0700 | [diff] [blame] | 5550 | int ret = IXGBE_ERR_LINK_SETUP; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5551 | |
| 5552 | if (hw->mac.ops.check_link) |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 5553 | 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] | 5554 | |
| 5555 | if (ret) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 5556 | return ret; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5557 | |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 5558 | speed = hw->phy.autoneg_advertised; |
| 5559 | if ((!speed) && (hw->mac.ops.get_link_capabilities)) |
| 5560 | ret = hw->mac.ops.get_link_capabilities(hw, &speed, |
| 5561 | &autoneg); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5562 | if (ret) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 5563 | return ret; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5564 | |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 5565 | if (hw->mac.ops.setup_link) |
Josh Hay | fd0326f | 2012-12-15 03:28:30 +0000 | [diff] [blame] | 5566 | ret = hw->mac.ops.setup_link(hw, speed, link_up); |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 5567 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5568 | return ret; |
| 5569 | } |
| 5570 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5571 | static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5572 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5573 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5574 | u32 gpie = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5575 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 5576 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5577 | gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT | |
| 5578 | IXGBE_GPIE_OCD; |
| 5579 | gpie |= IXGBE_GPIE_EIAME; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 5580 | /* |
| 5581 | * use EIAM to auto-mask when MSI-X interrupt is asserted |
| 5582 | * this saves a register write for every interrupt |
| 5583 | */ |
| 5584 | switch (hw->mac.type) { |
| 5585 | case ixgbe_mac_82598EB: |
| 5586 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
| 5587 | break; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 5588 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5589 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5590 | case ixgbe_mac_X550: |
| 5591 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 5592 | case ixgbe_mac_x550em_a: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5593 | default: |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 5594 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF); |
| 5595 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF); |
| 5596 | break; |
| 5597 | } |
| 5598 | } else { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5599 | /* legacy interrupts, use EIAM to auto-mask when reading EICR, |
| 5600 | * specifically only auto mask tx and rx interrupts */ |
| 5601 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5602 | } |
| 5603 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5604 | /* XXX: to interrupt immediately for EICS writes, enable this */ |
| 5605 | /* gpie |= IXGBE_GPIE_EIMEN; */ |
| 5606 | |
| 5607 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 5608 | gpie &= ~IXGBE_GPIE_VTMODE_MASK; |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 5609 | |
| 5610 | switch (adapter->ring_feature[RING_F_VMDQ].mask) { |
| 5611 | case IXGBE_82599_VMDQ_8Q_MASK: |
| 5612 | gpie |= IXGBE_GPIE_VTMODE_16; |
| 5613 | break; |
| 5614 | case IXGBE_82599_VMDQ_4Q_MASK: |
| 5615 | gpie |= IXGBE_GPIE_VTMODE_32; |
| 5616 | break; |
| 5617 | default: |
| 5618 | gpie |= IXGBE_GPIE_VTMODE_64; |
| 5619 | break; |
| 5620 | } |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 5621 | } |
| 5622 | |
Alexander Duyck | 5fdd31f | 2011-07-21 00:40:45 +0000 | [diff] [blame] | 5623 | /* Enable Thermal over heat sensor interrupt */ |
Don Skidmore | f3df98e | 2011-08-17 10:15:21 +0000 | [diff] [blame] | 5624 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) { |
| 5625 | switch (adapter->hw.mac.type) { |
| 5626 | case ixgbe_mac_82599EB: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 5627 | gpie |= IXGBE_SDP0_GPIEN_8259X; |
Don Skidmore | f3df98e | 2011-08-17 10:15:21 +0000 | [diff] [blame] | 5628 | break; |
Don Skidmore | f3df98e | 2011-08-17 10:15:21 +0000 | [diff] [blame] | 5629 | default: |
| 5630 | break; |
| 5631 | } |
| 5632 | } |
Alexander Duyck | 5fdd31f | 2011-07-21 00:40:45 +0000 | [diff] [blame] | 5633 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5634 | /* Enable fan failure interrupt */ |
| 5635 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 5636 | gpie |= IXGBE_SDP1_GPIEN(hw); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 5637 | |
Don Skidmore | a023bbd | 2015-06-24 16:38:53 -0400 | [diff] [blame] | 5638 | switch (hw->mac.type) { |
| 5639 | case ixgbe_mac_82599EB: |
| 5640 | gpie |= IXGBE_SDP1_GPIEN_8259X | IXGBE_SDP2_GPIEN_8259X; |
| 5641 | break; |
| 5642 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 5643 | case ixgbe_mac_x550em_a: |
Don Skidmore | a023bbd | 2015-06-24 16:38:53 -0400 | [diff] [blame] | 5644 | gpie |= IXGBE_SDP0_GPIEN_X540; |
| 5645 | break; |
| 5646 | default: |
| 5647 | break; |
Don Skidmore | 2698b20 | 2011-04-13 07:01:52 +0000 | [diff] [blame] | 5648 | } |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5649 | |
| 5650 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 5651 | } |
| 5652 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 5653 | static void ixgbe_up_complete(struct ixgbe_adapter *adapter) |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5654 | { |
| 5655 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5656 | int err; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5657 | u32 ctrl_ext; |
| 5658 | |
| 5659 | ixgbe_get_hw_control(adapter); |
| 5660 | ixgbe_setup_gpie(adapter); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5661 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5662 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 5663 | ixgbe_configure_msix(adapter); |
| 5664 | else |
| 5665 | ixgbe_configure_msi_and_legacy(adapter); |
| 5666 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 5667 | /* enable the optics for 82599 SFP+ fiber */ |
| 5668 | if (hw->mac.ops.enable_tx_laser) |
Peter Waskiewicz | 61fac74 | 2010-04-27 00:38:15 +0000 | [diff] [blame] | 5669 | hw->mac.ops.enable_tx_laser(hw); |
| 5670 | |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 5671 | if (hw->phy.ops.set_phy_power) |
| 5672 | hw->phy.ops.set_phy_power(hw, true); |
| 5673 | |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 5674 | smp_mb__before_atomic(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5675 | clear_bit(__IXGBE_DOWN, &adapter->state); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5676 | ixgbe_napi_enable_all(adapter); |
| 5677 | |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 5678 | if (ixgbe_is_sfp(hw)) { |
| 5679 | ixgbe_sfp_link_config(adapter); |
| 5680 | } else { |
| 5681 | err = ixgbe_non_sfp_link_config(hw); |
| 5682 | if (err) |
| 5683 | e_err(probe, "link_config FAILED %d\n", err); |
| 5684 | } |
| 5685 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5686 | /* clear any pending interrupts, may auto mask */ |
| 5687 | IXGBE_READ_REG(hw, IXGBE_EICR); |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 5688 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5689 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5690 | /* |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5691 | * If this adapter has a fan, check to see if we had a failure |
| 5692 | * before we enabled the interrupt. |
| 5693 | */ |
| 5694 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 5695 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 5696 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5697 | e_crit(drv, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5698 | } |
| 5699 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5700 | /* bring the link up in the watchdog, this could race with our first |
| 5701 | * link up interrupt but shouldn't be a problem */ |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5702 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 5703 | adapter->link_check_timeout = jiffies; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5704 | mod_timer(&adapter->service_timer, jiffies); |
Greg Rose | c920569 | 2010-01-22 22:46:22 +0000 | [diff] [blame] | 5705 | |
| 5706 | /* Set PF Reset Done bit so PF/VF Mail Ops can work */ |
| 5707 | ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); |
| 5708 | ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD; |
| 5709 | IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5710 | } |
| 5711 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5712 | void ixgbe_reinit_locked(struct ixgbe_adapter *adapter) |
| 5713 | { |
| 5714 | WARN_ON(in_interrupt()); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5715 | /* put off any impending NetWatchDogTimeout */ |
Florian Westphal | 860e953 | 2016-05-03 16:33:13 +0200 | [diff] [blame] | 5716 | netif_trans_update(adapter->netdev); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5717 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5718 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 5719 | usleep_range(1000, 2000); |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 5720 | if (adapter->hw.phy.type == ixgbe_phy_fw) |
| 5721 | ixgbe_watchdog_link_is_down(adapter); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5722 | ixgbe_down(adapter); |
Greg Rose | 5809a1a | 2010-03-24 09:36:08 +0000 | [diff] [blame] | 5723 | /* |
| 5724 | * If SR-IOV enabled then wait a bit before bringing the adapter |
| 5725 | * back up to give the VFs time to respond to the reset. The |
| 5726 | * two second wait is based upon the watchdog timer cycle in |
| 5727 | * the VF driver. |
| 5728 | */ |
| 5729 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 5730 | msleep(2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5731 | ixgbe_up(adapter); |
| 5732 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
| 5733 | } |
| 5734 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 5735 | void ixgbe_up(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5736 | { |
| 5737 | /* hardware has been reset, we need to reload some things */ |
| 5738 | ixgbe_configure(adapter); |
| 5739 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 5740 | ixgbe_up_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5741 | } |
| 5742 | |
| 5743 | void ixgbe_reset(struct ixgbe_adapter *adapter) |
| 5744 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5745 | struct ixgbe_hw *hw = &adapter->hw; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 5746 | struct net_device *netdev = adapter->netdev; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 5747 | int err; |
| 5748 | |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 5749 | if (ixgbe_removed(hw->hw_addr)) |
| 5750 | return; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5751 | /* lock SFP init bit to prevent race conditions with the watchdog */ |
| 5752 | while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 5753 | usleep_range(1000, 2000); |
| 5754 | |
| 5755 | /* clear all SFP and link config related flags while holding SFP_INIT */ |
| 5756 | adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP | |
| 5757 | IXGBE_FLAG2_SFP_NEEDS_RESET); |
| 5758 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 5759 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 5760 | err = hw->mac.ops.init_hw(hw); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5761 | switch (err) { |
| 5762 | case 0: |
| 5763 | case IXGBE_ERR_SFP_NOT_PRESENT: |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5764 | case IXGBE_ERR_SFP_NOT_SUPPORTED: |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5765 | break; |
| 5766 | case IXGBE_ERR_MASTER_REQUESTS_PENDING: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5767 | e_dev_err("master disable timed out\n"); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5768 | break; |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 5769 | case IXGBE_ERR_EEPROM_VERSION: |
| 5770 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5771 | e_dev_warn("This device is a pre-production adapter/LOM. " |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 5772 | "Please be aware there may be issues associated with " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5773 | "your hardware. If you are experiencing problems " |
| 5774 | "please contact your Intel or hardware " |
| 5775 | "representative who provided you with this " |
| 5776 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 5777 | break; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5778 | default: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5779 | e_dev_err("Hardware Error: %d\n", err); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5780 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5781 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5782 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
Alexander Duyck | 0f079d2 | 2015-10-22 16:26:36 -0700 | [diff] [blame] | 5783 | |
| 5784 | /* flush entries out of MAC table */ |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 5785 | ixgbe_flush_sw_mac_table(adapter); |
Alexander Duyck | 0f079d2 | 2015-10-22 16:26:36 -0700 | [diff] [blame] | 5786 | __dev_uc_unsync(netdev, NULL); |
| 5787 | |
| 5788 | /* do not flush user set addresses */ |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 5789 | ixgbe_mac_set_default_filter(adapter); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 5790 | |
| 5791 | /* update SAN MAC vmdq pool selection */ |
| 5792 | if (hw->mac.san_mac_rar_index) |
| 5793 | hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0)); |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 5794 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 5795 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 5796 | ixgbe_ptp_reset(adapter); |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 5797 | |
| 5798 | if (hw->phy.ops.set_phy_power) { |
| 5799 | if (!netif_running(adapter->netdev) && !adapter->wol) |
| 5800 | hw->phy.ops.set_phy_power(hw, false); |
| 5801 | else |
| 5802 | hw->phy.ops.set_phy_power(hw, true); |
| 5803 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5804 | } |
| 5805 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5806 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5807 | * ixgbe_clean_tx_ring - Free Tx Buffers |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5808 | * @tx_ring: ring to be cleaned |
| 5809 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5810 | static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5811 | { |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5812 | u16 i = tx_ring->next_to_clean; |
| 5813 | struct ixgbe_tx_buffer *tx_buffer = &tx_ring->tx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5814 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5815 | while (i != tx_ring->next_to_use) { |
| 5816 | union ixgbe_adv_tx_desc *eop_desc, *tx_desc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5817 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5818 | /* Free all the Tx ring sk_buffs */ |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 5819 | if (ring_is_xdp(tx_ring)) |
| 5820 | page_frag_free(tx_buffer->data); |
| 5821 | else |
| 5822 | dev_kfree_skb_any(tx_buffer->skb); |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5823 | |
| 5824 | /* unmap skb header data */ |
| 5825 | dma_unmap_single(tx_ring->dev, |
| 5826 | dma_unmap_addr(tx_buffer, dma), |
| 5827 | dma_unmap_len(tx_buffer, len), |
| 5828 | DMA_TO_DEVICE); |
| 5829 | |
| 5830 | /* check for eop_desc to determine the end of the packet */ |
| 5831 | eop_desc = tx_buffer->next_to_watch; |
| 5832 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
| 5833 | |
| 5834 | /* unmap remaining buffers */ |
| 5835 | while (tx_desc != eop_desc) { |
| 5836 | tx_buffer++; |
| 5837 | tx_desc++; |
| 5838 | i++; |
| 5839 | if (unlikely(i == tx_ring->count)) { |
| 5840 | i = 0; |
| 5841 | tx_buffer = tx_ring->tx_buffer_info; |
| 5842 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
| 5843 | } |
| 5844 | |
| 5845 | /* unmap any remaining paged data */ |
| 5846 | if (dma_unmap_len(tx_buffer, len)) |
| 5847 | dma_unmap_page(tx_ring->dev, |
| 5848 | dma_unmap_addr(tx_buffer, dma), |
| 5849 | dma_unmap_len(tx_buffer, len), |
| 5850 | DMA_TO_DEVICE); |
| 5851 | } |
| 5852 | |
| 5853 | /* move us one more past the eop_desc for start of next pkt */ |
| 5854 | tx_buffer++; |
| 5855 | i++; |
| 5856 | if (unlikely(i == tx_ring->count)) { |
| 5857 | i = 0; |
| 5858 | tx_buffer = tx_ring->tx_buffer_info; |
| 5859 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5860 | } |
| 5861 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5862 | /* reset BQL for queue */ |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 5863 | if (!ring_is_xdp(tx_ring)) |
| 5864 | netdev_tx_reset_queue(txring_txq(tx_ring)); |
John Fastabend | dad8a3b | 2012-04-23 12:22:39 +0000 | [diff] [blame] | 5865 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5866 | /* reset next_to_use and next_to_clean */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5867 | tx_ring->next_to_use = 0; |
| 5868 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5869 | } |
| 5870 | |
| 5871 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5872 | * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues |
| 5873 | * @adapter: board private structure |
| 5874 | **/ |
| 5875 | static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter) |
| 5876 | { |
| 5877 | int i; |
| 5878 | |
| 5879 | for (i = 0; i < adapter->num_rx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5880 | ixgbe_clean_rx_ring(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5881 | } |
| 5882 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5883 | /** |
| 5884 | * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues |
| 5885 | * @adapter: board private structure |
| 5886 | **/ |
| 5887 | static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter) |
| 5888 | { |
| 5889 | int i; |
| 5890 | |
| 5891 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5892 | ixgbe_clean_tx_ring(adapter->tx_ring[i]); |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 5893 | for (i = 0; i < adapter->num_xdp_queues; i++) |
| 5894 | ixgbe_clean_tx_ring(adapter->xdp_ring[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5895 | } |
| 5896 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5897 | static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter) |
| 5898 | { |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 5899 | struct hlist_node *node2; |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5900 | struct ixgbe_fdir_filter *filter; |
| 5901 | |
| 5902 | spin_lock(&adapter->fdir_perfect_lock); |
| 5903 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 5904 | hlist_for_each_entry_safe(filter, node2, |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5905 | &adapter->fdir_filter_list, fdir_node) { |
| 5906 | hlist_del(&filter->fdir_node); |
| 5907 | kfree(filter); |
| 5908 | } |
| 5909 | adapter->fdir_filter_count = 0; |
| 5910 | |
| 5911 | spin_unlock(&adapter->fdir_perfect_lock); |
| 5912 | } |
| 5913 | |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 5914 | static int ixgbe_disable_macvlan(struct net_device *upper, void *data) |
| 5915 | { |
| 5916 | if (netif_is_macvlan(upper)) { |
| 5917 | struct macvlan_dev *vlan = netdev_priv(upper); |
| 5918 | |
| 5919 | if (vlan->fwd_priv) { |
| 5920 | netif_tx_stop_all_queues(upper); |
| 5921 | netif_carrier_off(upper); |
| 5922 | netif_tx_disable(upper); |
| 5923 | } |
| 5924 | } |
| 5925 | |
| 5926 | return 0; |
| 5927 | } |
| 5928 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5929 | void ixgbe_down(struct ixgbe_adapter *adapter) |
| 5930 | { |
| 5931 | struct net_device *netdev = adapter->netdev; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5932 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 5933 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5934 | |
| 5935 | /* signal that we are down to the interrupt handler */ |
Mark Rustad | c3049c8 | 2014-01-14 18:53:12 -0800 | [diff] [blame] | 5936 | if (test_and_set_bit(__IXGBE_DOWN, &adapter->state)) |
| 5937 | return; /* do nothing if already down */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5938 | |
| 5939 | /* disable receives */ |
Don Skidmore | 1f9ac57 | 2015-03-13 13:54:30 -0700 | [diff] [blame] | 5940 | hw->mac.ops.disable_rx(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5941 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 5942 | /* disable all enabled rx queues */ |
| 5943 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 5944 | /* this call also flushes the previous write */ |
| 5945 | ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]); |
| 5946 | |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 5947 | usleep_range(10000, 20000); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5948 | |
John Fastabend | 11393cc | 2017-07-17 09:29:40 -0700 | [diff] [blame] | 5949 | /* synchronize_sched() needed for pending XDP buffers to drain */ |
| 5950 | if (adapter->xdp_ring[0]) |
| 5951 | synchronize_sched(); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5952 | netif_tx_stop_all_queues(netdev); |
| 5953 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5954 | /* call carrier off first to avoid false dev_watchdog timeouts */ |
John Fastabend | c0dfb90 | 2010-04-27 02:13:39 +0000 | [diff] [blame] | 5955 | netif_carrier_off(netdev); |
| 5956 | netif_tx_disable(netdev); |
| 5957 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5958 | /* disable any upper devices */ |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 5959 | netdev_walk_all_upper_dev_rcu(adapter->netdev, |
| 5960 | ixgbe_disable_macvlan, NULL); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5961 | |
John Fastabend | c0dfb90 | 2010-04-27 02:13:39 +0000 | [diff] [blame] | 5962 | ixgbe_irq_disable(adapter); |
| 5963 | |
| 5964 | ixgbe_napi_disable_all(adapter); |
| 5965 | |
Emil Tantilov | 57ca2a4 | 2016-07-29 14:46:31 -0700 | [diff] [blame] | 5966 | clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state); |
| 5967 | adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5968 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 5969 | |
| 5970 | del_timer_sync(&adapter->service_timer); |
| 5971 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 5972 | if (adapter->num_vfs) { |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 5973 | /* Clear EITR Select mapping */ |
| 5974 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0); |
| 5975 | |
| 5976 | /* Mark all the VFs as inactive */ |
| 5977 | for (i = 0 ; i < adapter->num_vfs; i++) |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 5978 | adapter->vfinfo[i].clear_to_send = false; |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 5979 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 5980 | /* 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] | 5981 | ixgbe_ping_all_vfs(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5982 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5983 | /* Disable all VFTE/VFRE TX/RX */ |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 5984 | ixgbe_disable_tx_rx(adapter); |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 5985 | } |
| 5986 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5987 | /* disable transmits in the hardware now that interrupts are off */ |
| 5988 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 5989 | u8 reg_idx = adapter->tx_ring[i]->reg_idx; |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 5990 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5991 | } |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 5992 | for (i = 0; i < adapter->num_xdp_queues; i++) { |
| 5993 | u8 reg_idx = adapter->xdp_ring[i]->reg_idx; |
| 5994 | |
| 5995 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH); |
| 5996 | } |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 5997 | |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5998 | /* Disable the Tx DMA engine on 82599 and later MAC */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5999 | switch (hw->mac.type) { |
| 6000 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 6001 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6002 | case ixgbe_mac_X550: |
| 6003 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 6004 | case ixgbe_mac_x550em_a: |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 6005 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 6006 | (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) & |
| 6007 | ~IXGBE_DMATXCTL_TE)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6008 | break; |
| 6009 | default: |
| 6010 | break; |
| 6011 | } |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 6012 | |
Paul Larson | 6f4a0e4 | 2008-06-24 17:00:56 -0700 | [diff] [blame] | 6013 | if (!pci_channel_offline(adapter->pdev)) |
| 6014 | ixgbe_reset(adapter); |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 6015 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 6016 | /* power down the optics for 82599 SFP+ fiber */ |
| 6017 | if (hw->mac.ops.disable_tx_laser) |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 6018 | hw->mac.ops.disable_tx_laser(hw); |
| 6019 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6020 | ixgbe_clean_all_tx_rings(adapter); |
| 6021 | ixgbe_clean_all_rx_rings(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6022 | } |
| 6023 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6024 | /** |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 6025 | * ixgbe_eee_capable - helper function to determine EEE support on X550 |
| 6026 | * @adapter: board private structure |
| 6027 | */ |
| 6028 | static void ixgbe_set_eee_capable(struct ixgbe_adapter *adapter) |
| 6029 | { |
| 6030 | struct ixgbe_hw *hw = &adapter->hw; |
| 6031 | |
| 6032 | switch (hw->device_id) { |
| 6033 | case IXGBE_DEV_ID_X550EM_A_1G_T: |
| 6034 | case IXGBE_DEV_ID_X550EM_A_1G_T_L: |
| 6035 | if (!hw->phy.eee_speeds_supported) |
| 6036 | break; |
| 6037 | adapter->flags2 |= IXGBE_FLAG2_EEE_CAPABLE; |
| 6038 | if (!hw->phy.eee_speeds_advertised) |
| 6039 | break; |
| 6040 | adapter->flags2 |= IXGBE_FLAG2_EEE_ENABLED; |
| 6041 | break; |
| 6042 | default: |
| 6043 | adapter->flags2 &= ~IXGBE_FLAG2_EEE_CAPABLE; |
| 6044 | adapter->flags2 &= ~IXGBE_FLAG2_EEE_ENABLED; |
| 6045 | break; |
| 6046 | } |
| 6047 | } |
| 6048 | |
| 6049 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6050 | * ixgbe_tx_timeout - Respond to a Tx Hang |
| 6051 | * @netdev: network interface device structure |
| 6052 | **/ |
| 6053 | static void ixgbe_tx_timeout(struct net_device *netdev) |
| 6054 | { |
| 6055 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 6056 | |
| 6057 | /* Do the reset outside of interrupt context */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6058 | ixgbe_tx_timeout_reset(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6059 | } |
| 6060 | |
Usha Ketineni | 8829009 | 2016-04-26 05:00:26 -0700 | [diff] [blame] | 6061 | #ifdef CONFIG_IXGBE_DCB |
| 6062 | static void ixgbe_init_dcb(struct ixgbe_adapter *adapter) |
| 6063 | { |
| 6064 | struct ixgbe_hw *hw = &adapter->hw; |
| 6065 | struct tc_configuration *tc; |
| 6066 | int j; |
| 6067 | |
| 6068 | switch (hw->mac.type) { |
| 6069 | case ixgbe_mac_82598EB: |
| 6070 | case ixgbe_mac_82599EB: |
| 6071 | adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS; |
| 6072 | adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS; |
| 6073 | break; |
| 6074 | case ixgbe_mac_X540: |
| 6075 | case ixgbe_mac_X550: |
| 6076 | adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS; |
| 6077 | adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS; |
| 6078 | break; |
| 6079 | case ixgbe_mac_X550EM_x: |
| 6080 | case ixgbe_mac_x550em_a: |
| 6081 | default: |
| 6082 | adapter->dcb_cfg.num_tcs.pg_tcs = DEF_TRAFFIC_CLASS; |
| 6083 | adapter->dcb_cfg.num_tcs.pfc_tcs = DEF_TRAFFIC_CLASS; |
| 6084 | break; |
| 6085 | } |
| 6086 | |
| 6087 | /* Configure DCB traffic classes */ |
| 6088 | for (j = 0; j < MAX_TRAFFIC_CLASS; j++) { |
| 6089 | tc = &adapter->dcb_cfg.tc_config[j]; |
| 6090 | tc->path[DCB_TX_CONFIG].bwg_id = 0; |
| 6091 | tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1); |
| 6092 | tc->path[DCB_RX_CONFIG].bwg_id = 0; |
| 6093 | tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1); |
| 6094 | tc->dcb_pfc = pfc_disabled; |
| 6095 | } |
| 6096 | |
| 6097 | /* Initialize default user to priority mapping, UPx->TC0 */ |
| 6098 | tc = &adapter->dcb_cfg.tc_config[0]; |
| 6099 | tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF; |
| 6100 | tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF; |
| 6101 | |
| 6102 | adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100; |
| 6103 | adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100; |
| 6104 | adapter->dcb_cfg.pfc_mode_enable = false; |
| 6105 | adapter->dcb_set_bitmap = 0x00; |
| 6106 | if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE) |
| 6107 | adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE; |
| 6108 | memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg, |
| 6109 | sizeof(adapter->temp_dcb_cfg)); |
| 6110 | } |
| 6111 | #endif |
| 6112 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 6113 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6114 | * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter) |
| 6115 | * @adapter: board private structure to initialize |
| 6116 | * |
| 6117 | * ixgbe_sw_init initializes the Adapter private data structure. |
| 6118 | * Fields are initialized based on PCI device information and |
| 6119 | * OS network device settings (MTU size). |
| 6120 | **/ |
Emil Tantilov | 55570b6 | 2016-10-12 12:34:25 -0700 | [diff] [blame] | 6121 | static int ixgbe_sw_init(struct ixgbe_adapter *adapter, |
| 6122 | const struct ixgbe_info *ii) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6123 | { |
| 6124 | struct ixgbe_hw *hw = &adapter->hw; |
| 6125 | struct pci_dev *pdev = adapter->pdev; |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 6126 | unsigned int rss, fdir; |
Jacob Keller | cb6d0f5 | 2012-12-04 06:03:14 +0000 | [diff] [blame] | 6127 | u32 fwsm; |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 6128 | int i; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6129 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 6130 | /* PCI config space info */ |
| 6131 | |
| 6132 | hw->vendor_id = pdev->vendor; |
| 6133 | hw->device_id = pdev->device; |
| 6134 | hw->revision_id = pdev->revision; |
| 6135 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 6136 | hw->subsystem_device_id = pdev->subsystem_device; |
| 6137 | |
Emil Tantilov | 55570b6 | 2016-10-12 12:34:25 -0700 | [diff] [blame] | 6138 | /* get_invariants needs the device IDs */ |
| 6139 | ii->get_invariants(hw); |
| 6140 | |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 6141 | /* Set common capability flags and settings */ |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 6142 | rss = min_t(int, ixgbe_max_rss_indices(adapter), num_online_cpus()); |
Alexander Duyck | c087663 | 2012-05-10 00:01:46 +0000 | [diff] [blame] | 6143 | adapter->ring_feature[RING_F_RSS].limit = rss; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 6144 | adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 6145 | adapter->max_q_vectors = MAX_Q_VECTORS_82599; |
| 6146 | adapter->atr_sample_rate = 20; |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 6147 | fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus()); |
| 6148 | adapter->ring_feature[RING_F_FDIR].limit = fdir; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 6149 | adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K; |
| 6150 | #ifdef CONFIG_IXGBE_DCA |
| 6151 | adapter->flags |= IXGBE_FLAG_DCA_CAPABLE; |
| 6152 | #endif |
Usha Ketineni | 8829009 | 2016-04-26 05:00:26 -0700 | [diff] [blame] | 6153 | #ifdef CONFIG_IXGBE_DCB |
| 6154 | adapter->flags |= IXGBE_FLAG_DCB_CAPABLE; |
| 6155 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
| 6156 | #endif |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 6157 | #ifdef IXGBE_FCOE |
| 6158 | adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE; |
| 6159 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 6160 | #ifdef CONFIG_IXGBE_DCB |
| 6161 | /* Default traffic class to use for FCoE */ |
| 6162 | adapter->fcoe.up = IXGBE_FCOE_DEFTC; |
| 6163 | #endif /* CONFIG_IXGBE_DCB */ |
| 6164 | #endif /* IXGBE_FCOE */ |
| 6165 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 6166 | /* initialize static ixgbe jump table entries */ |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 6167 | adapter->jump_tables[0] = kzalloc(sizeof(*adapter->jump_tables[0]), |
| 6168 | GFP_KERNEL); |
| 6169 | if (!adapter->jump_tables[0]) |
| 6170 | return -ENOMEM; |
| 6171 | adapter->jump_tables[0]->mat = ixgbe_ipv4_fields; |
| 6172 | |
| 6173 | for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) |
| 6174 | adapter->jump_tables[i] = NULL; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 6175 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 6176 | adapter->mac_table = kzalloc(sizeof(struct ixgbe_mac_addr) * |
| 6177 | hw->mac.num_rar_entries, |
| 6178 | GFP_ATOMIC); |
Alexander Duyck | 530fd82 | 2015-11-02 17:09:29 -0800 | [diff] [blame] | 6179 | if (!adapter->mac_table) |
| 6180 | return -ENOMEM; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 6181 | |
Tony Nguyen | 3dfbfc7 | 2017-04-13 07:26:05 -0700 | [diff] [blame] | 6182 | if (ixgbe_init_rss_key(adapter)) |
| 6183 | return -ENOMEM; |
| 6184 | |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 6185 | /* Set MAC specific capability flags and exceptions */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6186 | switch (hw->mac.type) { |
| 6187 | case ixgbe_mac_82598EB: |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 6188 | adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 6189 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 6190 | if (hw->device_id == IXGBE_DEV_ID_82598AT) |
| 6191 | adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 6192 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 6193 | adapter->max_q_vectors = MAX_Q_VECTORS_82598; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 6194 | adapter->ring_feature[RING_F_FDIR].limit = 0; |
| 6195 | adapter->atr_sample_rate = 0; |
| 6196 | adapter->fdir_pballoc = 0; |
| 6197 | #ifdef IXGBE_FCOE |
| 6198 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
| 6199 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 6200 | #ifdef CONFIG_IXGBE_DCB |
| 6201 | adapter->fcoe.up = 0; |
| 6202 | #endif /* IXGBE_DCB */ |
| 6203 | #endif /* IXGBE_FCOE */ |
| 6204 | break; |
| 6205 | case ixgbe_mac_82599EB: |
| 6206 | if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM) |
| 6207 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6208 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 6209 | case ixgbe_mac_X540: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 6210 | fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw)); |
Jacob Keller | cb6d0f5 | 2012-12-04 06:03:14 +0000 | [diff] [blame] | 6211 | if (fwsm & IXGBE_FWSM_TS_ENABLED) |
| 6212 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6213 | break; |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 6214 | case ixgbe_mac_x550em_a: |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 6215 | adapter->flags |= IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE; |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 6216 | switch (hw->device_id) { |
| 6217 | case IXGBE_DEV_ID_X550EM_A_1G_T: |
| 6218 | case IXGBE_DEV_ID_X550EM_A_1G_T_L: |
| 6219 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
| 6220 | break; |
| 6221 | default: |
| 6222 | break; |
| 6223 | } |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 6224 | /* fall through */ |
| 6225 | case ixgbe_mac_X550EM_x: |
Usha Ketineni | 8829009 | 2016-04-26 05:00:26 -0700 | [diff] [blame] | 6226 | #ifdef CONFIG_IXGBE_DCB |
| 6227 | adapter->flags &= ~IXGBE_FLAG_DCB_CAPABLE; |
| 6228 | #endif |
| 6229 | #ifdef IXGBE_FCOE |
| 6230 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
| 6231 | #ifdef CONFIG_IXGBE_DCB |
| 6232 | adapter->fcoe.up = 0; |
| 6233 | #endif /* IXGBE_DCB */ |
| 6234 | #endif /* IXGBE_FCOE */ |
| 6235 | /* Fall Through */ |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6236 | case ixgbe_mac_X550: |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 6237 | if (hw->mac.type == ixgbe_mac_X550) |
| 6238 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6239 | #ifdef CONFIG_IXGBE_DCA |
| 6240 | adapter->flags &= ~IXGBE_FLAG_DCA_CAPABLE; |
| 6241 | #endif |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 6242 | adapter->flags |= IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE; |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6243 | break; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6244 | default: |
| 6245 | break; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 6246 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 6247 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 6248 | #ifdef IXGBE_FCOE |
| 6249 | /* FCoE support exists, always init the FCoE lock */ |
| 6250 | spin_lock_init(&adapter->fcoe.lock); |
| 6251 | |
| 6252 | #endif |
Alexander Duyck | 1fc5f03 | 2011-06-02 04:28:39 +0000 | [diff] [blame] | 6253 | /* n-tuple support exists, always init our spinlock */ |
| 6254 | spin_lock_init(&adapter->fdir_perfect_lock); |
| 6255 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 6256 | #ifdef CONFIG_IXGBE_DCB |
Usha Ketineni | 8829009 | 2016-04-26 05:00:26 -0700 | [diff] [blame] | 6257 | ixgbe_init_dcb(adapter); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 6258 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6259 | |
| 6260 | /* default flow control settings */ |
Don Skidmore | cd7664f | 2009-03-31 21:33:44 +0000 | [diff] [blame] | 6261 | hw->fc.requested_mode = ixgbe_fc_full; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 6262 | hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */ |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 6263 | ixgbe_pbthresh_setup(adapter); |
Jesse Brandeburg | 2b9ade9 | 2008-08-26 04:27:10 -0700 | [diff] [blame] | 6264 | hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE; |
| 6265 | hw->fc.send_xon = true; |
Don Skidmore | 73d80953d | 2013-07-31 02:19:24 +0000 | [diff] [blame] | 6266 | hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6267 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 6268 | #ifdef CONFIG_PCI_IOV |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 6269 | if (max_vfs > 0) |
| 6270 | 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] | 6271 | |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 6272 | /* assign number of SR-IOV VFs */ |
| 6273 | if (hw->mac.type != ixgbe_mac_82598EB) { |
ethan.zhao | dcc23e3 | 2014-01-16 19:41:04 -0800 | [diff] [blame] | 6274 | if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) { |
Emil Tantilov | 5c11f00 | 2017-01-20 14:11:56 -0800 | [diff] [blame] | 6275 | max_vfs = 0; |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 6276 | e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n"); |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 6277 | } |
| 6278 | } |
| 6279 | #endif /* CONFIG_PCI_IOV */ |
| 6280 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 6281 | /* enable itr by default in dynamic mode */ |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 6282 | adapter->rx_itr_setting = 1; |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 6283 | adapter->tx_itr_setting = 1; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 6284 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 6285 | /* set default ring sizes */ |
| 6286 | adapter->tx_ring_count = IXGBE_DEFAULT_TXD; |
| 6287 | adapter->rx_ring_count = IXGBE_DEFAULT_RXD; |
| 6288 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 6289 | /* set default work limits */ |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 6290 | adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 6291 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6292 | /* initialize eeprom parameters */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 6293 | if (ixgbe_init_eeprom_params_generic(hw)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 6294 | e_dev_err("EEPROM initialization failed\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6295 | return -EIO; |
| 6296 | } |
| 6297 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 6298 | /* PF holds first pool slot */ |
| 6299 | set_bit(0, &adapter->fwd_bitmask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6300 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 6301 | |
| 6302 | return 0; |
| 6303 | } |
| 6304 | |
| 6305 | /** |
| 6306 | * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 6307 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6308 | * |
| 6309 | * Return 0 on success, negative on failure |
| 6310 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6311 | int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6312 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6313 | struct device *dev = tx_ring->dev; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 6314 | int orig_node = dev_to_node(dev); |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 6315 | int ring_node = -1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6316 | int size; |
| 6317 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 6318 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 6319 | |
| 6320 | if (tx_ring->q_vector) |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 6321 | ring_node = tx_ring->q_vector->numa_node; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 6322 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 6323 | tx_ring->tx_buffer_info = vmalloc_node(size, ring_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 6324 | if (!tx_ring->tx_buffer_info) |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 6325 | tx_ring->tx_buffer_info = vmalloc(size); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 6326 | if (!tx_ring->tx_buffer_info) |
| 6327 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6328 | |
| 6329 | /* round up to nearest 4K */ |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 6330 | tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 6331 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6332 | |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 6333 | set_dev_node(dev, ring_node); |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 6334 | tx_ring->desc = dma_alloc_coherent(dev, |
| 6335 | tx_ring->size, |
| 6336 | &tx_ring->dma, |
| 6337 | GFP_KERNEL); |
| 6338 | set_dev_node(dev, orig_node); |
| 6339 | if (!tx_ring->desc) |
| 6340 | tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size, |
| 6341 | &tx_ring->dma, GFP_KERNEL); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 6342 | if (!tx_ring->desc) |
| 6343 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6344 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 6345 | tx_ring->next_to_use = 0; |
| 6346 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6347 | return 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 6348 | |
| 6349 | err: |
| 6350 | vfree(tx_ring->tx_buffer_info); |
| 6351 | tx_ring->tx_buffer_info = NULL; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6352 | 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] | 6353 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6354 | } |
| 6355 | |
| 6356 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6357 | * ixgbe_setup_all_tx_resources - allocate all queues Tx resources |
| 6358 | * @adapter: board private structure |
| 6359 | * |
| 6360 | * If this function returns with an error, then it's possible one or |
| 6361 | * more of the rings is populated (while the rest are not). It is the |
| 6362 | * callers duty to clean those orphaned rings. |
| 6363 | * |
| 6364 | * Return 0 on success, negative on failure |
| 6365 | **/ |
| 6366 | static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) |
| 6367 | { |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 6368 | int i, j = 0, err = 0; |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6369 | |
| 6370 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6371 | err = ixgbe_setup_tx_resources(adapter->tx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6372 | if (!err) |
| 6373 | continue; |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6374 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 6375 | e_err(probe, "Allocation for Tx Queue %u failed\n", i); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6376 | goto err_setup_tx; |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6377 | } |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 6378 | for (j = 0; j < adapter->num_xdp_queues; j++) { |
| 6379 | err = ixgbe_setup_tx_resources(adapter->xdp_ring[j]); |
| 6380 | if (!err) |
| 6381 | continue; |
| 6382 | |
| 6383 | e_err(probe, "Allocation for Tx Queue %u failed\n", j); |
| 6384 | goto err_setup_tx; |
| 6385 | } |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6386 | |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6387 | return 0; |
| 6388 | err_setup_tx: |
| 6389 | /* rewind the index freeing the rings as we go */ |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 6390 | while (j--) |
| 6391 | ixgbe_free_tx_resources(adapter->xdp_ring[j]); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6392 | while (i--) |
| 6393 | ixgbe_free_tx_resources(adapter->tx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6394 | return err; |
| 6395 | } |
| 6396 | |
| 6397 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6398 | * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 6399 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6400 | * |
| 6401 | * Returns 0 on success, negative on failure |
| 6402 | **/ |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 6403 | int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter, |
| 6404 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6405 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6406 | struct device *dev = rx_ring->dev; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 6407 | int orig_node = dev_to_node(dev); |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 6408 | int ring_node = -1; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6409 | int size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6410 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 6411 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 6412 | |
| 6413 | if (rx_ring->q_vector) |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 6414 | ring_node = rx_ring->q_vector->numa_node; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 6415 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 6416 | rx_ring->rx_buffer_info = vmalloc_node(size, ring_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 6417 | if (!rx_ring->rx_buffer_info) |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 6418 | rx_ring->rx_buffer_info = vmalloc(size); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6419 | if (!rx_ring->rx_buffer_info) |
| 6420 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6421 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6422 | /* Round up to nearest 4K */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 6423 | rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); |
| 6424 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6425 | |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 6426 | set_dev_node(dev, ring_node); |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 6427 | rx_ring->desc = dma_alloc_coherent(dev, |
| 6428 | rx_ring->size, |
| 6429 | &rx_ring->dma, |
| 6430 | GFP_KERNEL); |
| 6431 | set_dev_node(dev, orig_node); |
| 6432 | if (!rx_ring->desc) |
| 6433 | rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size, |
| 6434 | &rx_ring->dma, GFP_KERNEL); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6435 | if (!rx_ring->desc) |
| 6436 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6437 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 6438 | rx_ring->next_to_clean = 0; |
| 6439 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6440 | |
Jesper Dangaard Brouer | 99ffc5a | 2018-01-03 11:25:29 +0100 | [diff] [blame] | 6441 | /* XDP RX-queue info */ |
| 6442 | if (xdp_rxq_info_reg(&rx_ring->xdp_rxq, adapter->netdev, |
| 6443 | rx_ring->queue_index) < 0) |
| 6444 | goto err; |
| 6445 | |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 6446 | rx_ring->xdp_prog = adapter->xdp_prog; |
| 6447 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6448 | return 0; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6449 | err: |
| 6450 | vfree(rx_ring->rx_buffer_info); |
| 6451 | rx_ring->rx_buffer_info = NULL; |
| 6452 | 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] | 6453 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6454 | } |
| 6455 | |
| 6456 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6457 | * ixgbe_setup_all_rx_resources - allocate all queues Rx resources |
| 6458 | * @adapter: board private structure |
| 6459 | * |
| 6460 | * If this function returns with an error, then it's possible one or |
| 6461 | * more of the rings is populated (while the rest are not). It is the |
| 6462 | * callers duty to clean those orphaned rings. |
| 6463 | * |
| 6464 | * Return 0 on success, negative on failure |
| 6465 | **/ |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6466 | static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) |
| 6467 | { |
| 6468 | int i, err = 0; |
| 6469 | |
| 6470 | for (i = 0; i < adapter->num_rx_queues; i++) { |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 6471 | err = ixgbe_setup_rx_resources(adapter, adapter->rx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6472 | if (!err) |
| 6473 | continue; |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6474 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 6475 | e_err(probe, "Allocation for Rx Queue %u failed\n", i); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6476 | goto err_setup_rx; |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6477 | } |
| 6478 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 6479 | #ifdef IXGBE_FCOE |
| 6480 | err = ixgbe_setup_fcoe_ddp_resources(adapter); |
| 6481 | if (!err) |
| 6482 | #endif |
| 6483 | return 0; |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6484 | err_setup_rx: |
| 6485 | /* rewind the index freeing the rings as we go */ |
| 6486 | while (i--) |
| 6487 | ixgbe_free_rx_resources(adapter->rx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6488 | return err; |
| 6489 | } |
| 6490 | |
| 6491 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6492 | * ixgbe_free_tx_resources - Free Tx Resources per Queue |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6493 | * @tx_ring: Tx descriptor ring for a specific queue |
| 6494 | * |
| 6495 | * Free all transmit software resources |
| 6496 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6497 | void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6498 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6499 | ixgbe_clean_tx_ring(tx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6500 | |
| 6501 | vfree(tx_ring->tx_buffer_info); |
| 6502 | tx_ring->tx_buffer_info = NULL; |
| 6503 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6504 | /* if not set, then don't free */ |
| 6505 | if (!tx_ring->desc) |
| 6506 | return; |
| 6507 | |
| 6508 | dma_free_coherent(tx_ring->dev, tx_ring->size, |
| 6509 | tx_ring->desc, tx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6510 | |
| 6511 | tx_ring->desc = NULL; |
| 6512 | } |
| 6513 | |
| 6514 | /** |
| 6515 | * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues |
| 6516 | * @adapter: board private structure |
| 6517 | * |
| 6518 | * Free all transmit software resources |
| 6519 | **/ |
| 6520 | static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter) |
| 6521 | { |
| 6522 | int i; |
| 6523 | |
| 6524 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 6525 | if (adapter->tx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6526 | ixgbe_free_tx_resources(adapter->tx_ring[i]); |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 6527 | for (i = 0; i < adapter->num_xdp_queues; i++) |
| 6528 | if (adapter->xdp_ring[i]->desc) |
| 6529 | ixgbe_free_tx_resources(adapter->xdp_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6530 | } |
| 6531 | |
| 6532 | /** |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6533 | * ixgbe_free_rx_resources - Free Rx Resources |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6534 | * @rx_ring: ring to clean the resources from |
| 6535 | * |
| 6536 | * Free all receive software resources |
| 6537 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6538 | void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6539 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6540 | ixgbe_clean_rx_ring(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6541 | |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 6542 | rx_ring->xdp_prog = NULL; |
Jesper Dangaard Brouer | 99ffc5a | 2018-01-03 11:25:29 +0100 | [diff] [blame] | 6543 | xdp_rxq_info_unreg(&rx_ring->xdp_rxq); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6544 | vfree(rx_ring->rx_buffer_info); |
| 6545 | rx_ring->rx_buffer_info = NULL; |
| 6546 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6547 | /* if not set, then don't free */ |
| 6548 | if (!rx_ring->desc) |
| 6549 | return; |
| 6550 | |
| 6551 | dma_free_coherent(rx_ring->dev, rx_ring->size, |
| 6552 | rx_ring->desc, rx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6553 | |
| 6554 | rx_ring->desc = NULL; |
| 6555 | } |
| 6556 | |
| 6557 | /** |
| 6558 | * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues |
| 6559 | * @adapter: board private structure |
| 6560 | * |
| 6561 | * Free all receive software resources |
| 6562 | **/ |
| 6563 | static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter) |
| 6564 | { |
| 6565 | int i; |
| 6566 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 6567 | #ifdef IXGBE_FCOE |
| 6568 | ixgbe_free_fcoe_ddp_resources(adapter); |
| 6569 | |
| 6570 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6571 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 6572 | if (adapter->rx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6573 | ixgbe_free_rx_resources(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6574 | } |
| 6575 | |
| 6576 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6577 | * ixgbe_change_mtu - Change the Maximum Transfer Unit |
| 6578 | * @netdev: network interface device structure |
| 6579 | * @new_mtu: new value for maximum frame size |
| 6580 | * |
| 6581 | * Returns 0 on success, negative on failure |
| 6582 | **/ |
| 6583 | static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu) |
| 6584 | { |
| 6585 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 655309e | 2012-02-08 07:50:35 +0000 | [diff] [blame] | 6586 | |
| 6587 | /* |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 6588 | * For 82599EB we cannot allow legacy VFs to enable their receive |
| 6589 | * paths when MTU greater than 1500 is configured. So display a |
| 6590 | * warning that legacy VFs will be disabled. |
Alexander Duyck | 655309e | 2012-02-08 07:50:35 +0000 | [diff] [blame] | 6591 | */ |
| 6592 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && |
| 6593 | (adapter->hw.mac.type == ixgbe_mac_82599EB) && |
Jarod Wilson | 91c527a | 2016-10-17 15:54:05 -0400 | [diff] [blame] | 6594 | (new_mtu > ETH_DATA_LEN)) |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 6595 | e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6596 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 6597 | 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] | 6598 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6599 | /* must set new MTU before calling down or up */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6600 | netdev->mtu = new_mtu; |
| 6601 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 6602 | if (netif_running(netdev)) |
| 6603 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6604 | |
| 6605 | return 0; |
| 6606 | } |
| 6607 | |
| 6608 | /** |
| 6609 | * ixgbe_open - Called when a network interface is made active |
| 6610 | * @netdev: network interface device structure |
| 6611 | * |
| 6612 | * Returns 0 on success, negative value on failure |
| 6613 | * |
| 6614 | * The open entry point is called when a network interface is made |
| 6615 | * active by the system (IFF_UP). At this point all resources needed |
| 6616 | * for transmit and receive operations are allocated, the interrupt |
| 6617 | * handler is registered with the OS, the watchdog timer is started, |
| 6618 | * and the stack is notified that the interface is ready. |
| 6619 | **/ |
Stefan Assmann | 6c211fe1 | 2016-02-03 09:20:48 +0100 | [diff] [blame] | 6620 | int ixgbe_open(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6621 | { |
| 6622 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 6623 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 6624 | int err, queues; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6625 | |
Auke Kok | 4bebfaa | 2008-02-11 09:26:01 -0800 | [diff] [blame] | 6626 | /* disallow open during test */ |
| 6627 | if (test_bit(__IXGBE_TESTING, &adapter->state)) |
| 6628 | return -EBUSY; |
| 6629 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 6630 | netif_carrier_off(netdev); |
| 6631 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6632 | /* allocate transmit descriptors */ |
| 6633 | err = ixgbe_setup_all_tx_resources(adapter); |
| 6634 | if (err) |
| 6635 | goto err_setup_tx; |
| 6636 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6637 | /* allocate receive descriptors */ |
| 6638 | err = ixgbe_setup_all_rx_resources(adapter); |
| 6639 | if (err) |
| 6640 | goto err_setup_rx; |
| 6641 | |
| 6642 | ixgbe_configure(adapter); |
| 6643 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6644 | err = ixgbe_request_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6645 | if (err) |
| 6646 | goto err_req_irq; |
| 6647 | |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6648 | /* Notify the stack of the actual queue counts. */ |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 6649 | if (adapter->num_rx_pools > 1) |
| 6650 | queues = adapter->num_rx_queues_per_pool; |
| 6651 | else |
| 6652 | queues = adapter->num_tx_queues; |
| 6653 | |
| 6654 | err = netif_set_real_num_tx_queues(netdev, queues); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6655 | if (err) |
| 6656 | goto err_set_queues; |
| 6657 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 6658 | if (adapter->num_rx_pools > 1 && |
| 6659 | adapter->num_rx_queues > IXGBE_MAX_L2A_QUEUES) |
| 6660 | queues = IXGBE_MAX_L2A_QUEUES; |
| 6661 | else |
| 6662 | queues = adapter->num_rx_queues; |
| 6663 | err = netif_set_real_num_rx_queues(netdev, queues); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6664 | if (err) |
| 6665 | goto err_set_queues; |
| 6666 | |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6667 | ixgbe_ptp_init(adapter); |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6668 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 6669 | ixgbe_up_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6670 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 6671 | ixgbe_clear_udp_tunnel_port(adapter, IXGBE_VXLANCTRL_ALL_UDPPORT_MASK); |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 6672 | udp_tunnel_get_rx_info(netdev); |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 6673 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6674 | return 0; |
| 6675 | |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6676 | err_set_queues: |
| 6677 | ixgbe_free_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6678 | err_req_irq: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 6679 | ixgbe_free_all_rx_resources(adapter); |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 6680 | if (hw->phy.ops.set_phy_power && !adapter->wol) |
| 6681 | hw->phy.ops.set_phy_power(&adapter->hw, false); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6682 | err_setup_rx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 6683 | ixgbe_free_all_tx_resources(adapter); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6684 | err_setup_tx: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6685 | ixgbe_reset(adapter); |
| 6686 | |
| 6687 | return err; |
| 6688 | } |
| 6689 | |
Jacob Keller | a0cccce | 2014-05-16 05:12:29 +0000 | [diff] [blame] | 6690 | static void ixgbe_close_suspend(struct ixgbe_adapter *adapter) |
| 6691 | { |
| 6692 | ixgbe_ptp_suspend(adapter); |
| 6693 | |
Don Skidmore | 6ac7439 | 2015-06-17 17:34:31 -0400 | [diff] [blame] | 6694 | if (adapter->hw.phy.ops.enter_lplu) { |
| 6695 | adapter->hw.phy.reset_disable = true; |
| 6696 | ixgbe_down(adapter); |
| 6697 | adapter->hw.phy.ops.enter_lplu(&adapter->hw); |
| 6698 | adapter->hw.phy.reset_disable = false; |
| 6699 | } else { |
| 6700 | ixgbe_down(adapter); |
| 6701 | } |
| 6702 | |
Jacob Keller | a0cccce | 2014-05-16 05:12:29 +0000 | [diff] [blame] | 6703 | ixgbe_free_irq(adapter); |
| 6704 | |
| 6705 | ixgbe_free_all_tx_resources(adapter); |
| 6706 | ixgbe_free_all_rx_resources(adapter); |
| 6707 | } |
| 6708 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6709 | /** |
| 6710 | * ixgbe_close - Disables a network interface |
| 6711 | * @netdev: network interface device structure |
| 6712 | * |
| 6713 | * Returns 0, this is not allowed to fail |
| 6714 | * |
| 6715 | * The close entry point is called when an interface is de-activated |
| 6716 | * by the OS. The hardware is still under the drivers control, but |
| 6717 | * needs to be disabled. A global MAC reset is issued to stop the |
| 6718 | * hardware, and all transmit and receive resources are freed. |
| 6719 | **/ |
Stefan Assmann | 6c211fe1 | 2016-02-03 09:20:48 +0100 | [diff] [blame] | 6720 | int ixgbe_close(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6721 | { |
| 6722 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6723 | |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6724 | ixgbe_ptp_stop(adapter); |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6725 | |
Emil Tantilov | f7f37e7 | 2016-11-11 10:07:47 -0800 | [diff] [blame] | 6726 | if (netif_device_present(netdev)) |
| 6727 | ixgbe_close_suspend(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6728 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 6729 | ixgbe_fdir_filter_exit(adapter); |
| 6730 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 6731 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6732 | |
| 6733 | return 0; |
| 6734 | } |
| 6735 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6736 | #ifdef CONFIG_PM |
| 6737 | static int ixgbe_resume(struct pci_dev *pdev) |
| 6738 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 6739 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 6740 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6741 | u32 err; |
| 6742 | |
Mark Rustad | 0391bbe | 2014-02-28 15:48:55 -0800 | [diff] [blame] | 6743 | adapter->hw.hw_addr = adapter->io_addr; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6744 | pci_set_power_state(pdev, PCI_D0); |
| 6745 | pci_restore_state(pdev); |
Don Skidmore | 656ab81 | 2009-12-23 21:19:19 -0800 | [diff] [blame] | 6746 | /* |
| 6747 | * pci_restore_state clears dev->state_saved so call |
| 6748 | * pci_save_state to restore it. |
| 6749 | */ |
| 6750 | pci_save_state(pdev); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 6751 | |
| 6752 | err = pci_enable_device_mem(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6753 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 6754 | e_dev_err("Cannot enable PCI device from suspend\n"); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6755 | return err; |
| 6756 | } |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 6757 | smp_mb__before_atomic(); |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 6758 | clear_bit(__IXGBE_DISABLED, &adapter->state); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6759 | pci_set_master(pdev); |
| 6760 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 6761 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6762 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6763 | ixgbe_reset(adapter); |
| 6764 | |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 6765 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
| 6766 | |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6767 | rtnl_lock(); |
| 6768 | err = ixgbe_init_interrupt_scheme(adapter); |
| 6769 | if (!err && netif_running(netdev)) |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 6770 | err = ixgbe_open(netdev); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6771 | |
Emil Tantilov | f7f37e7 | 2016-11-11 10:07:47 -0800 | [diff] [blame] | 6772 | |
| 6773 | if (!err) |
| 6774 | netif_device_attach(netdev); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6775 | rtnl_unlock(); |
| 6776 | |
Emil Tantilov | f7f37e7 | 2016-11-11 10:07:47 -0800 | [diff] [blame] | 6777 | return err; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6778 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6779 | #endif /* CONFIG_PM */ |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6780 | |
| 6781 | static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6782 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 6783 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 6784 | struct net_device *netdev = adapter->netdev; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6785 | struct ixgbe_hw *hw = &adapter->hw; |
Emil Tantilov | d9d11eb | 2017-10-10 13:20:01 -0700 | [diff] [blame] | 6786 | u32 ctrl; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6787 | u32 wufc = adapter->wol; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6788 | #ifdef CONFIG_PM |
| 6789 | int retval = 0; |
| 6790 | #endif |
| 6791 | |
Emil Tantilov | f7f37e7 | 2016-11-11 10:07:47 -0800 | [diff] [blame] | 6792 | rtnl_lock(); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6793 | netif_device_detach(netdev); |
| 6794 | |
Jacob Keller | a0cccce | 2014-05-16 05:12:29 +0000 | [diff] [blame] | 6795 | if (netif_running(netdev)) |
| 6796 | ixgbe_close_suspend(adapter); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6797 | |
Alexander Duyck | 5f5ae6f | 2010-11-16 19:26:52 -0800 | [diff] [blame] | 6798 | ixgbe_clear_interrupt_scheme(adapter); |
Emil Tantilov | f7f37e7 | 2016-11-11 10:07:47 -0800 | [diff] [blame] | 6799 | rtnl_unlock(); |
Alexander Duyck | 5f5ae6f | 2010-11-16 19:26:52 -0800 | [diff] [blame] | 6800 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6801 | #ifdef CONFIG_PM |
| 6802 | retval = pci_save_state(pdev); |
| 6803 | if (retval) |
| 6804 | return retval; |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 6805 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6806 | #endif |
Jacob Keller | f4f1040 | 2013-06-25 07:59:23 +0000 | [diff] [blame] | 6807 | if (hw->mac.ops.stop_link_on_d3) |
| 6808 | hw->mac.ops.stop_link_on_d3(hw); |
| 6809 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6810 | if (wufc) { |
Emil Tantilov | d9d11eb | 2017-10-10 13:20:01 -0700 | [diff] [blame] | 6811 | u32 fctrl; |
| 6812 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6813 | ixgbe_set_rx_mode(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6814 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 6815 | /* enable the optics for 82599 SFP+ fiber as we can WoL */ |
| 6816 | if (hw->mac.ops.enable_tx_laser) |
Don Skidmore | c509e75 | 2012-04-05 08:12:05 +0000 | [diff] [blame] | 6817 | hw->mac.ops.enable_tx_laser(hw); |
| 6818 | |
Emil Tantilov | d9d11eb | 2017-10-10 13:20:01 -0700 | [diff] [blame] | 6819 | /* enable the reception of multicast packets */ |
| 6820 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 6821 | fctrl |= IXGBE_FCTRL_MPE; |
| 6822 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6823 | |
| 6824 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 6825 | ctrl |= IXGBE_CTRL_GIO_DIS; |
| 6826 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); |
| 6827 | |
| 6828 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc); |
| 6829 | } else { |
| 6830 | IXGBE_WRITE_REG(hw, IXGBE_WUC, 0); |
| 6831 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0); |
| 6832 | } |
| 6833 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6834 | switch (hw->mac.type) { |
| 6835 | case ixgbe_mac_82598EB: |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 6836 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6837 | break; |
| 6838 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 6839 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6840 | case ixgbe_mac_X550: |
| 6841 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 6842 | case ixgbe_mac_x550em_a: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6843 | pci_wake_from_d3(pdev, !!wufc); |
| 6844 | break; |
| 6845 | default: |
| 6846 | break; |
| 6847 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6848 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6849 | *enable_wake = !!wufc; |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 6850 | if (hw->phy.ops.set_phy_power && !*enable_wake) |
| 6851 | hw->phy.ops.set_phy_power(hw, false); |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6852 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6853 | ixgbe_release_hw_control(adapter); |
| 6854 | |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 6855 | if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state)) |
| 6856 | pci_disable_device(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6857 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6858 | return 0; |
| 6859 | } |
| 6860 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6861 | #ifdef CONFIG_PM |
| 6862 | static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state) |
| 6863 | { |
| 6864 | int retval; |
| 6865 | bool wake; |
| 6866 | |
| 6867 | retval = __ixgbe_shutdown(pdev, &wake); |
| 6868 | if (retval) |
| 6869 | return retval; |
| 6870 | |
| 6871 | if (wake) { |
| 6872 | pci_prepare_to_sleep(pdev); |
| 6873 | } else { |
| 6874 | pci_wake_from_d3(pdev, false); |
| 6875 | pci_set_power_state(pdev, PCI_D3hot); |
| 6876 | } |
| 6877 | |
| 6878 | return 0; |
| 6879 | } |
| 6880 | #endif /* CONFIG_PM */ |
| 6881 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6882 | static void ixgbe_shutdown(struct pci_dev *pdev) |
| 6883 | { |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6884 | bool wake; |
| 6885 | |
| 6886 | __ixgbe_shutdown(pdev, &wake); |
| 6887 | |
| 6888 | if (system_state == SYSTEM_POWER_OFF) { |
| 6889 | pci_wake_from_d3(pdev, wake); |
| 6890 | pci_set_power_state(pdev, PCI_D3hot); |
| 6891 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6892 | } |
| 6893 | |
| 6894 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6895 | * ixgbe_update_stats - Update the board statistics counters. |
| 6896 | * @adapter: board private structure |
| 6897 | **/ |
| 6898 | void ixgbe_update_stats(struct ixgbe_adapter *adapter) |
| 6899 | { |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 6900 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6901 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6902 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6903 | u64 total_mpc = 0; |
| 6904 | u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6905 | u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0; |
| 6906 | u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0; |
Jesper Dangaard Brouer | 86e2349 | 2017-09-04 20:40:22 +0200 | [diff] [blame] | 6907 | u64 alloc_rx_page = 0; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 6908 | u64 bytes = 0, packets = 0, hw_csum_rx_error = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6909 | |
Don Skidmore | d08935c | 2010-06-11 13:20:29 +0000 | [diff] [blame] | 6910 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 6911 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 6912 | return; |
| 6913 | |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 6914 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 6915 | u64 rsc_count = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 6916 | u64 rsc_flush = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 6917 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6918 | rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count; |
| 6919 | rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 6920 | } |
| 6921 | adapter->rsc_total_count = rsc_count; |
| 6922 | adapter->rsc_total_flush = rsc_flush; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 6923 | } |
| 6924 | |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6925 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 6926 | struct ixgbe_ring *rx_ring = adapter->rx_ring[i]; |
| 6927 | non_eop_descs += rx_ring->rx_stats.non_eop_descs; |
Jesper Dangaard Brouer | 86e2349 | 2017-09-04 20:40:22 +0200 | [diff] [blame] | 6928 | alloc_rx_page += rx_ring->rx_stats.alloc_rx_page; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6929 | alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed; |
| 6930 | alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 6931 | hw_csum_rx_error += rx_ring->rx_stats.csum_err; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6932 | bytes += rx_ring->stats.bytes; |
| 6933 | packets += rx_ring->stats.packets; |
| 6934 | } |
Mallikarjuna R Chilakala | eb985f0 | 2009-12-15 11:56:59 +0000 | [diff] [blame] | 6935 | adapter->non_eop_descs = non_eop_descs; |
Jesper Dangaard Brouer | 86e2349 | 2017-09-04 20:40:22 +0200 | [diff] [blame] | 6936 | adapter->alloc_rx_page = alloc_rx_page; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6937 | adapter->alloc_rx_page_failed = alloc_rx_page_failed; |
| 6938 | adapter->alloc_rx_buff_failed = alloc_rx_buff_failed; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 6939 | adapter->hw_csum_rx_error = hw_csum_rx_error; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6940 | netdev->stats.rx_bytes = bytes; |
| 6941 | netdev->stats.rx_packets = packets; |
| 6942 | |
| 6943 | bytes = 0; |
| 6944 | packets = 0; |
| 6945 | /* gather some stats to the adapter struct that are per queue */ |
| 6946 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 6947 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 6948 | restart_queue += tx_ring->tx_stats.restart_queue; |
| 6949 | tx_busy += tx_ring->tx_stats.tx_busy; |
| 6950 | bytes += tx_ring->stats.bytes; |
| 6951 | packets += tx_ring->stats.packets; |
| 6952 | } |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 6953 | for (i = 0; i < adapter->num_xdp_queues; i++) { |
| 6954 | struct ixgbe_ring *xdp_ring = adapter->xdp_ring[i]; |
| 6955 | |
| 6956 | restart_queue += xdp_ring->tx_stats.restart_queue; |
| 6957 | tx_busy += xdp_ring->tx_stats.tx_busy; |
| 6958 | bytes += xdp_ring->stats.bytes; |
| 6959 | packets += xdp_ring->stats.packets; |
| 6960 | } |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6961 | adapter->restart_queue = restart_queue; |
| 6962 | adapter->tx_busy = tx_busy; |
| 6963 | netdev->stats.tx_bytes = bytes; |
| 6964 | netdev->stats.tx_packets = packets; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 6965 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6966 | hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS); |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6967 | |
| 6968 | /* 8 register reads */ |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6969 | for (i = 0; i < 8; i++) { |
| 6970 | /* for packet buffers not used, the register should read 0 */ |
| 6971 | mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i)); |
| 6972 | missed_rx += mpc; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6973 | hwstats->mpc[i] += mpc; |
| 6974 | total_mpc += hwstats->mpc[i]; |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6975 | hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i)); |
| 6976 | hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6977 | switch (hw->mac.type) { |
| 6978 | case ixgbe_mac_82598EB: |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6979 | hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i)); |
| 6980 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i)); |
| 6981 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i)); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6982 | hwstats->pxonrxc[i] += |
| 6983 | IXGBE_READ_REG(hw, IXGBE_PXONRXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6984 | break; |
| 6985 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 6986 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6987 | case ixgbe_mac_X550: |
| 6988 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 6989 | case ixgbe_mac_x550em_a: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6990 | hwstats->pxonrxc[i] += |
| 6991 | IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6992 | break; |
| 6993 | default: |
| 6994 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6995 | } |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6996 | } |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6997 | |
| 6998 | /*16 register reads */ |
| 6999 | for (i = 0; i < 16; i++) { |
| 7000 | hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i)); |
| 7001 | hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i)); |
| 7002 | if ((hw->mac.type == ixgbe_mac_82599EB) || |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 7003 | (hw->mac.type == ixgbe_mac_X540) || |
| 7004 | (hw->mac.type == ixgbe_mac_X550) || |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 7005 | (hw->mac.type == ixgbe_mac_X550EM_x) || |
| 7006 | (hw->mac.type == ixgbe_mac_x550em_a)) { |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 7007 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i)); |
| 7008 | IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */ |
| 7009 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i)); |
| 7010 | IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */ |
| 7011 | } |
| 7012 | } |
| 7013 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 7014 | hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 7015 | /* work around hardware counting issue */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 7016 | hwstats->gprc -= missed_rx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7017 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 7018 | ixgbe_update_xoff_received(adapter); |
| 7019 | |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 7020 | /* 82598 hardware only has a 32 bit counter in the high register */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 7021 | switch (hw->mac.type) { |
| 7022 | case ixgbe_mac_82598EB: |
| 7023 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 7024 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH); |
| 7025 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH); |
| 7026 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH); |
| 7027 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 7028 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 7029 | case ixgbe_mac_X550: |
| 7030 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 7031 | case ixgbe_mac_x550em_a: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 7032 | /* OS2BMC stats are X540 and later */ |
Emil Tantilov | 58f6bcf | 2011-04-21 08:43:43 +0000 | [diff] [blame] | 7033 | hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC); |
| 7034 | hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC); |
| 7035 | hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC); |
| 7036 | hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC); |
Tony Nguyen | 93df946 | 2017-05-31 04:43:47 -0700 | [diff] [blame] | 7037 | /* fall through */ |
Emil Tantilov | 58f6bcf | 2011-04-21 08:43:43 +0000 | [diff] [blame] | 7038 | case ixgbe_mac_82599EB: |
Alexander Duyck | a4d4f62 | 2012-03-28 08:03:32 +0000 | [diff] [blame] | 7039 | for (i = 0; i < 16; i++) |
| 7040 | adapter->hw_rx_no_dma_resources += |
| 7041 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 7042 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 7043 | IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 7044 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 7045 | IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 7046 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 7047 | IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 7048 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 7049 | hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH); |
| 7050 | hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS); |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 7051 | #ifdef IXGBE_FCOE |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 7052 | hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC); |
| 7053 | hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC); |
| 7054 | hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC); |
| 7055 | hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC); |
| 7056 | hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC); |
| 7057 | hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC); |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 7058 | /* Add up per cpu counters for total ddp aloc fail */ |
Alexander Duyck | 5a1ee27 | 2012-05-05 17:14:28 +0000 | [diff] [blame] | 7059 | if (adapter->fcoe.ddp_pool) { |
| 7060 | struct ixgbe_fcoe *fcoe = &adapter->fcoe; |
| 7061 | struct ixgbe_fcoe_ddp_pool *ddp_pool; |
| 7062 | unsigned int cpu; |
| 7063 | u64 noddp = 0, noddp_ext_buff = 0; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 7064 | for_each_possible_cpu(cpu) { |
Alexander Duyck | 5a1ee27 | 2012-05-05 17:14:28 +0000 | [diff] [blame] | 7065 | ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu); |
| 7066 | noddp += ddp_pool->noddp; |
| 7067 | noddp_ext_buff += ddp_pool->noddp_ext_buff; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 7068 | } |
Alexander Duyck | 5a1ee27 | 2012-05-05 17:14:28 +0000 | [diff] [blame] | 7069 | hwstats->fcoe_noddp = noddp; |
| 7070 | hwstats->fcoe_noddp_ext_buff = noddp_ext_buff; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 7071 | } |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 7072 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 7073 | break; |
| 7074 | default: |
| 7075 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7076 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7077 | bprc = IXGBE_READ_REG(hw, IXGBE_BPRC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 7078 | hwstats->bprc += bprc; |
| 7079 | hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7080 | if (hw->mac.type == ixgbe_mac_82598EB) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 7081 | hwstats->mprc -= bprc; |
| 7082 | hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC); |
| 7083 | hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64); |
| 7084 | hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127); |
| 7085 | hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255); |
| 7086 | hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511); |
| 7087 | hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023); |
| 7088 | hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522); |
| 7089 | hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 7090 | lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 7091 | hwstats->lxontxc += lxon; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 7092 | lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 7093 | hwstats->lxofftxc += lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 7094 | hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC); |
| 7095 | hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 7096 | /* |
| 7097 | * 82598 errata - tx of flow control packets is included in tx counters |
| 7098 | */ |
| 7099 | xon_off_tot = lxon + lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 7100 | hwstats->gptc -= xon_off_tot; |
| 7101 | hwstats->mptc -= xon_off_tot; |
| 7102 | hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN)); |
| 7103 | hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 7104 | hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC); |
| 7105 | hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC); |
| 7106 | hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR); |
| 7107 | hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64); |
| 7108 | hwstats->ptc64 -= xon_off_tot; |
| 7109 | hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127); |
| 7110 | hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255); |
| 7111 | hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511); |
| 7112 | hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023); |
| 7113 | hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522); |
| 7114 | hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7115 | |
| 7116 | /* Fill out the OS statistics structure */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 7117 | netdev->stats.multicast = hwstats->mprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7118 | |
| 7119 | /* Rx Errors */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 7120 | netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 7121 | netdev->stats.rx_dropped = 0; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 7122 | netdev->stats.rx_length_errors = hwstats->rlec; |
| 7123 | netdev->stats.rx_crc_errors = hwstats->crcerrs; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 7124 | netdev->stats.rx_missed_errors = total_mpc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7125 | } |
| 7126 | |
| 7127 | /** |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 7128 | * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7129 | * @adapter: pointer to the device adapter structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7130 | **/ |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 7131 | static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7132 | { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7133 | struct ixgbe_hw *hw = &adapter->hw; |
| 7134 | int i; |
| 7135 | |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 7136 | if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 7137 | return; |
| 7138 | |
| 7139 | adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 7140 | |
| 7141 | /* if interface is down do nothing */ |
| 7142 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 7143 | return; |
| 7144 | |
| 7145 | /* do nothing if we are not using signature filters */ |
| 7146 | if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) |
| 7147 | return; |
| 7148 | |
| 7149 | adapter->fdir_overflow++; |
| 7150 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7151 | if (ixgbe_reinit_fdir_tables_82599(hw) == 0) { |
| 7152 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 7153 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 7154 | &(adapter->tx_ring[i]->state)); |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 7155 | for (i = 0; i < adapter->num_xdp_queues; i++) |
| 7156 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, |
| 7157 | &adapter->xdp_ring[i]->state); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 7158 | /* re-enable flow director interrupts */ |
| 7159 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7160 | } else { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7161 | e_err(probe, "failed to finish FDIR re-initialization, " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7162 | "ignored adding FDIR ATR filters\n"); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7163 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7164 | } |
| 7165 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7166 | /** |
| 7167 | * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7168 | * @adapter: pointer to the device adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7169 | * |
| 7170 | * This function serves two purposes. First it strobes the interrupt lines |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 7171 | * in order to make certain interrupts are occurring. Secondly it sets the |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7172 | * 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] | 7173 | * determine if a hang has occurred. |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7174 | */ |
| 7175 | static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter) |
| 7176 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7177 | struct ixgbe_hw *hw = &adapter->hw; |
| 7178 | u64 eics = 0; |
| 7179 | int i; |
| 7180 | |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 7181 | /* If we're down, removing or resetting, just bail */ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7182 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 7183 | test_bit(__IXGBE_REMOVING, &adapter->state) || |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7184 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 7185 | return; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 7186 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7187 | /* Force detection of hung controller */ |
| 7188 | if (netif_carrier_ok(adapter->netdev)) { |
| 7189 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 7190 | set_check_for_tx_hang(adapter->tx_ring[i]); |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 7191 | for (i = 0; i < adapter->num_xdp_queues; i++) |
| 7192 | set_check_for_tx_hang(adapter->xdp_ring[i]); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7193 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 7194 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 7195 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 7196 | /* |
| 7197 | * for legacy and MSI interrupts don't set any bits |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 7198 | * that are enabled for EIAM, because this operation |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 7199 | * would set *both* EIMS and EICS for any bit in EIAM |
| 7200 | */ |
| 7201 | IXGBE_WRITE_REG(hw, IXGBE_EICS, |
| 7202 | (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER)); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7203 | } else { |
| 7204 | /* get one bit for every active tx/rx interrupt vector */ |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 7205 | for (i = 0; i < adapter->num_q_vectors; i++) { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7206 | struct ixgbe_q_vector *qv = adapter->q_vector[i]; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 7207 | if (qv->rx.ring || qv->tx.ring) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 7208 | eics |= BIT_ULL(i); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7209 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 7210 | } |
| 7211 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7212 | /* Cause software interrupt to ensure rings are cleaned */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 7213 | ixgbe_irq_rearm_queues(adapter, eics); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 7214 | } |
| 7215 | |
| 7216 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7217 | * ixgbe_watchdog_update_link - update the link status |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7218 | * @adapter: pointer to the device adapter structure |
| 7219 | * @link_speed: pointer to a u32 to store the link_speed |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 7220 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7221 | static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter) |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7222 | { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7223 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7224 | u32 link_speed = adapter->link_speed; |
| 7225 | bool link_up = adapter->link_up; |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 7226 | bool pfc_en = adapter->dcb_cfg.pfc_mode_enable; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7227 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7228 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) |
| 7229 | return; |
| 7230 | |
| 7231 | if (hw->mac.ops.check_link) { |
| 7232 | 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] | 7233 | } else { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7234 | /* always assume link is up, if no check link function */ |
| 7235 | link_speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 7236 | link_up = true; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7237 | } |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 7238 | |
| 7239 | if (adapter->ixgbe_ieee_pfc) |
| 7240 | pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en); |
| 7241 | |
Alexander Duyck | 3ebe8fd | 2012-04-25 04:36:38 +0000 | [diff] [blame] | 7242 | if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) { |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 7243 | hw->mac.ops.fc_enable(hw); |
Alexander Duyck | 3ebe8fd | 2012-04-25 04:36:38 +0000 | [diff] [blame] | 7244 | ixgbe_set_rx_drop_en(adapter); |
| 7245 | } |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7246 | |
| 7247 | if (link_up || |
| 7248 | time_after(jiffies, (adapter->link_check_timeout + |
| 7249 | IXGBE_TRY_LINK_TIMEOUT))) { |
| 7250 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 7251 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC); |
| 7252 | IXGBE_WRITE_FLUSH(hw); |
| 7253 | } |
| 7254 | |
| 7255 | adapter->link_up = link_up; |
| 7256 | adapter->link_speed = link_speed; |
| 7257 | } |
| 7258 | |
Alexander Duyck | 107d301 | 2012-10-02 00:17:03 +0000 | [diff] [blame] | 7259 | static void ixgbe_update_default_up(struct ixgbe_adapter *adapter) |
| 7260 | { |
| 7261 | #ifdef CONFIG_IXGBE_DCB |
| 7262 | struct net_device *netdev = adapter->netdev; |
| 7263 | struct dcb_app app = { |
| 7264 | .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE, |
| 7265 | .protocol = 0, |
| 7266 | }; |
| 7267 | u8 up = 0; |
| 7268 | |
| 7269 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE) |
| 7270 | up = dcb_ieee_getapp_mask(netdev, &app); |
| 7271 | |
| 7272 | adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0; |
| 7273 | #endif |
| 7274 | } |
| 7275 | |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 7276 | static int ixgbe_enable_macvlan(struct net_device *upper, void *data) |
| 7277 | { |
| 7278 | if (netif_is_macvlan(upper)) { |
| 7279 | struct macvlan_dev *vlan = netdev_priv(upper); |
| 7280 | |
| 7281 | if (vlan->fwd_priv) |
| 7282 | netif_tx_wake_all_queues(upper); |
| 7283 | } |
| 7284 | |
| 7285 | return 0; |
| 7286 | } |
| 7287 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7288 | /** |
| 7289 | * ixgbe_watchdog_link_is_up - update netif_carrier status and |
| 7290 | * print link up message |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7291 | * @adapter: pointer to the device adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7292 | **/ |
| 7293 | static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter) |
| 7294 | { |
| 7295 | struct net_device *netdev = adapter->netdev; |
| 7296 | struct ixgbe_hw *hw = &adapter->hw; |
| 7297 | u32 link_speed = adapter->link_speed; |
Mark Rustad | 454adb0 | 2015-07-10 14:19:22 -0700 | [diff] [blame] | 7298 | const char *speed_str; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7299 | bool flow_rx, flow_tx; |
| 7300 | |
| 7301 | /* only continue if link was previously down */ |
| 7302 | if (netif_carrier_ok(netdev)) |
| 7303 | return; |
| 7304 | |
| 7305 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 7306 | |
| 7307 | switch (hw->mac.type) { |
| 7308 | case ixgbe_mac_82598EB: { |
| 7309 | u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 7310 | u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS); |
| 7311 | flow_rx = !!(frctl & IXGBE_FCTRL_RFCE); |
| 7312 | flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X); |
| 7313 | } |
| 7314 | break; |
| 7315 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 7316 | case ixgbe_mac_X550: |
| 7317 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 7318 | case ixgbe_mac_x550em_a: |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7319 | case ixgbe_mac_82599EB: { |
| 7320 | u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN); |
| 7321 | u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG); |
| 7322 | flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE); |
| 7323 | flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X); |
| 7324 | } |
| 7325 | break; |
| 7326 | default: |
| 7327 | flow_tx = false; |
| 7328 | flow_rx = false; |
| 7329 | break; |
| 7330 | } |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7331 | |
Jacob Keller | 6cb562d | 2012-12-05 07:24:41 +0000 | [diff] [blame] | 7332 | adapter->last_rx_ptp_check = jiffies; |
| 7333 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 7334 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 7335 | ixgbe_ptp_start_cyclecounter(adapter); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7336 | |
Mark Rustad | 454adb0 | 2015-07-10 14:19:22 -0700 | [diff] [blame] | 7337 | switch (link_speed) { |
| 7338 | case IXGBE_LINK_SPEED_10GB_FULL: |
| 7339 | speed_str = "10 Gbps"; |
| 7340 | break; |
| 7341 | case IXGBE_LINK_SPEED_2_5GB_FULL: |
| 7342 | speed_str = "2.5 Gbps"; |
| 7343 | break; |
| 7344 | case IXGBE_LINK_SPEED_1GB_FULL: |
| 7345 | speed_str = "1 Gbps"; |
| 7346 | break; |
| 7347 | case IXGBE_LINK_SPEED_100_FULL: |
| 7348 | speed_str = "100 Mbps"; |
| 7349 | break; |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 7350 | case IXGBE_LINK_SPEED_10_FULL: |
| 7351 | speed_str = "10 Mbps"; |
| 7352 | break; |
Mark Rustad | 454adb0 | 2015-07-10 14:19:22 -0700 | [diff] [blame] | 7353 | default: |
| 7354 | speed_str = "unknown speed"; |
| 7355 | break; |
| 7356 | } |
| 7357 | 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] | 7358 | ((flow_rx && flow_tx) ? "RX/TX" : |
| 7359 | (flow_rx ? "RX" : |
| 7360 | (flow_tx ? "TX" : "None")))); |
| 7361 | |
| 7362 | netif_carrier_on(netdev); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7363 | ixgbe_check_vf_rate_limit(adapter); |
Alexander Duyck | befa2af | 2012-05-05 05:30:38 +0000 | [diff] [blame] | 7364 | |
Emil Tantilov | cdc04dc | 2014-03-20 03:47:53 +0000 | [diff] [blame] | 7365 | /* enable transmits */ |
| 7366 | netif_tx_wake_all_queues(adapter->netdev); |
| 7367 | |
| 7368 | /* enable any upper devices */ |
| 7369 | rtnl_lock(); |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 7370 | netdev_walk_all_upper_dev_rcu(adapter->netdev, |
| 7371 | ixgbe_enable_macvlan, NULL); |
Emil Tantilov | cdc04dc | 2014-03-20 03:47:53 +0000 | [diff] [blame] | 7372 | rtnl_unlock(); |
| 7373 | |
Alexander Duyck | 107d301 | 2012-10-02 00:17:03 +0000 | [diff] [blame] | 7374 | /* update the default user priority for VFs */ |
| 7375 | ixgbe_update_default_up(adapter); |
| 7376 | |
Alexander Duyck | befa2af | 2012-05-05 05:30:38 +0000 | [diff] [blame] | 7377 | /* ping all the active vfs to let them know link has changed */ |
| 7378 | ixgbe_ping_all_vfs(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7379 | } |
| 7380 | |
| 7381 | /** |
| 7382 | * ixgbe_watchdog_link_is_down - update netif_carrier status and |
| 7383 | * print link down message |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7384 | * @adapter: pointer to the adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7385 | **/ |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 7386 | static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7387 | { |
| 7388 | struct net_device *netdev = adapter->netdev; |
| 7389 | struct ixgbe_hw *hw = &adapter->hw; |
| 7390 | |
| 7391 | adapter->link_up = false; |
| 7392 | adapter->link_speed = 0; |
| 7393 | |
| 7394 | /* only continue if link was up previously */ |
| 7395 | if (!netif_carrier_ok(netdev)) |
| 7396 | return; |
| 7397 | |
| 7398 | /* poll for SFP+ cable when link is down */ |
| 7399 | if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB) |
| 7400 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 7401 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 7402 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 7403 | ixgbe_ptp_start_cyclecounter(adapter); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7404 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7405 | e_info(drv, "NIC Link is Down\n"); |
| 7406 | netif_carrier_off(netdev); |
Alexander Duyck | befa2af | 2012-05-05 05:30:38 +0000 | [diff] [blame] | 7407 | |
| 7408 | /* ping all the active vfs to let them know link has changed */ |
| 7409 | ixgbe_ping_all_vfs(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7410 | } |
| 7411 | |
Emil Tantilov | 07923c1 | 2014-08-12 07:12:08 +0000 | [diff] [blame] | 7412 | static bool ixgbe_ring_tx_pending(struct ixgbe_adapter *adapter) |
| 7413 | { |
| 7414 | int i; |
| 7415 | |
| 7416 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 7417 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 7418 | |
| 7419 | if (tx_ring->next_to_use != tx_ring->next_to_clean) |
| 7420 | return true; |
| 7421 | } |
| 7422 | |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 7423 | for (i = 0; i < adapter->num_xdp_queues; i++) { |
| 7424 | struct ixgbe_ring *ring = adapter->xdp_ring[i]; |
| 7425 | |
| 7426 | if (ring->next_to_use != ring->next_to_clean) |
| 7427 | return true; |
| 7428 | } |
| 7429 | |
Emil Tantilov | 07923c1 | 2014-08-12 07:12:08 +0000 | [diff] [blame] | 7430 | return false; |
| 7431 | } |
| 7432 | |
| 7433 | static bool ixgbe_vf_tx_pending(struct ixgbe_adapter *adapter) |
| 7434 | { |
| 7435 | struct ixgbe_hw *hw = &adapter->hw; |
| 7436 | struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ]; |
| 7437 | u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask); |
| 7438 | |
| 7439 | int i, j; |
| 7440 | |
| 7441 | if (!adapter->num_vfs) |
| 7442 | return false; |
| 7443 | |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 7444 | /* resetting the PF is only needed for MAC before X550 */ |
| 7445 | if (hw->mac.type >= ixgbe_mac_X550) |
| 7446 | return false; |
| 7447 | |
Emil Tantilov | 07923c1 | 2014-08-12 07:12:08 +0000 | [diff] [blame] | 7448 | for (i = 0; i < adapter->num_vfs; i++) { |
| 7449 | for (j = 0; j < q_per_pool; j++) { |
| 7450 | u32 h, t; |
| 7451 | |
| 7452 | h = IXGBE_READ_REG(hw, IXGBE_PVFTDHN(q_per_pool, i, j)); |
| 7453 | t = IXGBE_READ_REG(hw, IXGBE_PVFTDTN(q_per_pool, i, j)); |
| 7454 | |
| 7455 | if (h != t) |
| 7456 | return true; |
| 7457 | } |
| 7458 | } |
| 7459 | |
| 7460 | return false; |
| 7461 | } |
| 7462 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7463 | /** |
| 7464 | * ixgbe_watchdog_flush_tx - flush queues on link down |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7465 | * @adapter: pointer to the device adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7466 | **/ |
| 7467 | static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter) |
| 7468 | { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7469 | if (!netif_carrier_ok(adapter->netdev)) { |
Emil Tantilov | 07923c1 | 2014-08-12 07:12:08 +0000 | [diff] [blame] | 7470 | if (ixgbe_ring_tx_pending(adapter) || |
| 7471 | ixgbe_vf_tx_pending(adapter)) { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7472 | /* We've lost link, so the controller stops DMA, |
| 7473 | * but we've got queued Tx work that's never going |
| 7474 | * to get done, so reset controller to flush Tx. |
| 7475 | * (Do the reset outside of interrupt context). |
| 7476 | */ |
Jacob Keller | 12ff3f3 | 2012-12-01 07:57:17 +0000 | [diff] [blame] | 7477 | 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] | 7478 | set_bit(__IXGBE_RESET_REQUESTED, &adapter->state); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7479 | } |
| 7480 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7481 | } |
| 7482 | |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7483 | #ifdef CONFIG_PCI_IOV |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7484 | static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter) |
| 7485 | { |
| 7486 | struct ixgbe_hw *hw = &adapter->hw; |
| 7487 | struct pci_dev *pdev = adapter->pdev; |
Mark Rustad | 988d130 | 2015-10-30 15:29:34 -0700 | [diff] [blame] | 7488 | unsigned int vf; |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7489 | u32 gpc; |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7490 | |
| 7491 | if (!(netif_carrier_ok(adapter->netdev))) |
| 7492 | return; |
| 7493 | |
| 7494 | gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC); |
| 7495 | if (gpc) /* If incrementing then no need for the check below */ |
| 7496 | return; |
| 7497 | /* Check to see if a bad DMA write target from an errant or |
| 7498 | * malicious VF has caused a PCIe error. If so then we can |
| 7499 | * issue a VFLR to the offending VF(s) and then resume without |
| 7500 | * requesting a full slot reset. |
| 7501 | */ |
| 7502 | |
| 7503 | if (!pdev) |
| 7504 | return; |
| 7505 | |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7506 | /* check status reg for all VFs owned by this PF */ |
Mark Rustad | 988d130 | 2015-10-30 15:29:34 -0700 | [diff] [blame] | 7507 | for (vf = 0; vf < adapter->num_vfs; ++vf) { |
| 7508 | struct pci_dev *vfdev = adapter->vfinfo[vf].vfdev; |
| 7509 | u16 status_reg; |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7510 | |
Mark Rustad | 988d130 | 2015-10-30 15:29:34 -0700 | [diff] [blame] | 7511 | if (!vfdev) |
| 7512 | continue; |
| 7513 | pci_read_config_word(vfdev, PCI_STATUS, &status_reg); |
| 7514 | if (status_reg != IXGBE_FAILED_READ_CFG_WORD && |
| 7515 | status_reg & PCI_STATUS_REC_MASTER_ABORT) |
Christoph Hellwig | 63af8f7 | 2017-04-14 21:11:28 +0200 | [diff] [blame] | 7516 | pcie_flr(vfdev); |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7517 | } |
| 7518 | } |
| 7519 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 7520 | static void ixgbe_spoof_check(struct ixgbe_adapter *adapter) |
| 7521 | { |
| 7522 | u32 ssvpc; |
| 7523 | |
Greg Rose | 0584d99 | 2012-08-08 00:00:58 +0000 | [diff] [blame] | 7524 | /* Do not perform spoof check for 82598 or if not in IOV mode */ |
| 7525 | if (adapter->hw.mac.type == ixgbe_mac_82598EB || |
| 7526 | adapter->num_vfs == 0) |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 7527 | return; |
| 7528 | |
| 7529 | ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC); |
| 7530 | |
| 7531 | /* |
| 7532 | * ssvpc register is cleared on read, if zero then no |
| 7533 | * spoofed packets in the last interval. |
| 7534 | */ |
| 7535 | if (!ssvpc) |
| 7536 | return; |
| 7537 | |
Emil Tantilov | d6ea075 | 2012-08-08 06:28:37 +0000 | [diff] [blame] | 7538 | e_warn(drv, "%u Spoofed packets detected\n", ssvpc); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 7539 | } |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7540 | #else |
| 7541 | static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused *adapter) |
| 7542 | { |
| 7543 | } |
| 7544 | |
| 7545 | static void |
| 7546 | ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused *adapter) |
| 7547 | { |
| 7548 | } |
| 7549 | #endif /* CONFIG_PCI_IOV */ |
| 7550 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 7551 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7552 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7553 | * ixgbe_watchdog_subtask - check and bring link up |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7554 | * @adapter: pointer to the device adapter structure |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 7555 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7556 | static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 7557 | { |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 7558 | /* if interface is down, removing or resetting, do nothing */ |
Emil Tantilov | 7edebf9 | 2011-08-27 07:18:37 +0000 | [diff] [blame] | 7559 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 7560 | test_bit(__IXGBE_REMOVING, &adapter->state) || |
Emil Tantilov | 7edebf9 | 2011-08-27 07:18:37 +0000 | [diff] [blame] | 7561 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7562 | return; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 7563 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7564 | ixgbe_watchdog_update_link(adapter); |
John Fastabend | 10eec95 | 2010-02-03 14:23:32 +0000 | [diff] [blame] | 7565 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7566 | if (adapter->link_up) |
| 7567 | ixgbe_watchdog_link_is_up(adapter); |
| 7568 | else |
| 7569 | ixgbe_watchdog_link_is_down(adapter); |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 7570 | |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7571 | ixgbe_check_for_bad_vf(adapter); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 7572 | ixgbe_spoof_check(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7573 | ixgbe_update_stats(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7574 | |
| 7575 | ixgbe_watchdog_flush_tx(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7576 | } |
| 7577 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7578 | /** |
| 7579 | * ixgbe_sfp_detection_subtask - poll for SFP+ cable |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7580 | * @adapter: the ixgbe adapter structure |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7581 | **/ |
| 7582 | static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter) |
| 7583 | { |
| 7584 | struct ixgbe_hw *hw = &adapter->hw; |
| 7585 | s32 err; |
| 7586 | |
| 7587 | /* not searching for SFP so there is nothing to do here */ |
| 7588 | if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) && |
| 7589 | !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 7590 | return; |
| 7591 | |
Mark Rustad | 58e7cd2 | 2015-08-08 16:18:48 -0700 | [diff] [blame] | 7592 | if (adapter->sfp_poll_time && |
| 7593 | time_after(adapter->sfp_poll_time, jiffies)) |
| 7594 | return; /* If not yet time to poll for SFP */ |
| 7595 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7596 | /* someone else is in init, wait until next service event */ |
| 7597 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 7598 | return; |
| 7599 | |
Mark Rustad | 58e7cd2 | 2015-08-08 16:18:48 -0700 | [diff] [blame] | 7600 | adapter->sfp_poll_time = jiffies + IXGBE_SFP_POLL_JIFFIES - 1; |
| 7601 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7602 | err = hw->phy.ops.identify_sfp(hw); |
| 7603 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 7604 | goto sfp_out; |
| 7605 | |
| 7606 | if (err == IXGBE_ERR_SFP_NOT_PRESENT) { |
| 7607 | /* If no cable is present, then we need to reset |
| 7608 | * the next time we find a good cable. */ |
| 7609 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 7610 | } |
| 7611 | |
| 7612 | /* exit on error */ |
| 7613 | if (err) |
| 7614 | goto sfp_out; |
| 7615 | |
| 7616 | /* exit if reset not needed */ |
| 7617 | if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 7618 | goto sfp_out; |
| 7619 | |
| 7620 | adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 7621 | |
| 7622 | /* |
| 7623 | * A module may be identified correctly, but the EEPROM may not have |
| 7624 | * support for that module. setup_sfp() will fail in that case, so |
| 7625 | * we should not allow that module to load. |
| 7626 | */ |
| 7627 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 7628 | err = hw->phy.ops.reset(hw); |
| 7629 | else |
| 7630 | err = hw->mac.ops.setup_sfp(hw); |
| 7631 | |
| 7632 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 7633 | goto sfp_out; |
| 7634 | |
| 7635 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 7636 | e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type); |
| 7637 | |
| 7638 | sfp_out: |
| 7639 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 7640 | |
| 7641 | if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) && |
| 7642 | (adapter->netdev->reg_state == NETREG_REGISTERED)) { |
| 7643 | e_dev_err("failed to initialize because an unsupported " |
| 7644 | "SFP+ module type was detected.\n"); |
| 7645 | e_dev_err("Reload the driver after installing a " |
| 7646 | "supported module.\n"); |
| 7647 | unregister_netdev(adapter->netdev); |
| 7648 | } |
| 7649 | } |
| 7650 | |
| 7651 | /** |
| 7652 | * ixgbe_sfp_link_config_subtask - set up link SFP after module install |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7653 | * @adapter: the ixgbe adapter structure |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7654 | **/ |
| 7655 | static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter) |
| 7656 | { |
| 7657 | struct ixgbe_hw *hw = &adapter->hw; |
Paul Greenwalt | 3ead7c2 | 2017-10-24 11:00:40 -0400 | [diff] [blame] | 7658 | u32 cap_speed; |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 7659 | u32 speed; |
| 7660 | bool autoneg = false; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7661 | |
| 7662 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG)) |
| 7663 | return; |
| 7664 | |
| 7665 | /* someone else is in init, wait until next service event */ |
| 7666 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 7667 | return; |
| 7668 | |
| 7669 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 7670 | |
Paul Greenwalt | 3ead7c2 | 2017-10-24 11:00:40 -0400 | [diff] [blame] | 7671 | hw->mac.ops.get_link_capabilities(hw, &cap_speed, &autoneg); |
Emil Tantilov | ed33ff6 | 2013-08-30 07:55:24 +0000 | [diff] [blame] | 7672 | |
Paul Greenwalt | 3ead7c2 | 2017-10-24 11:00:40 -0400 | [diff] [blame] | 7673 | /* advertise highest capable link speed */ |
| 7674 | if (!autoneg && (cap_speed & IXGBE_LINK_SPEED_10GB_FULL)) |
| 7675 | speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 7676 | else |
| 7677 | speed = cap_speed & (IXGBE_LINK_SPEED_10GB_FULL | |
| 7678 | IXGBE_LINK_SPEED_1GB_FULL); |
Emil Tantilov | ed33ff6 | 2013-08-30 07:55:24 +0000 | [diff] [blame] | 7679 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7680 | if (hw->mac.ops.setup_link) |
Josh Hay | fd0326f | 2012-12-15 03:28:30 +0000 | [diff] [blame] | 7681 | hw->mac.ops.setup_link(hw, speed, true); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7682 | |
| 7683 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 7684 | adapter->link_check_timeout = jiffies; |
| 7685 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 7686 | } |
| 7687 | |
| 7688 | /** |
| 7689 | * ixgbe_service_timer - Timer Call-back |
| 7690 | * @data: pointer to adapter cast into an unsigned long |
| 7691 | **/ |
Kees Cook | 26566ea | 2017-10-16 17:29:35 -0700 | [diff] [blame] | 7692 | static void ixgbe_service_timer(struct timer_list *t) |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7693 | { |
Kees Cook | 26566ea | 2017-10-16 17:29:35 -0700 | [diff] [blame] | 7694 | struct ixgbe_adapter *adapter = from_timer(adapter, t, service_timer); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7695 | unsigned long next_event_offset; |
| 7696 | |
| 7697 | /* poll faster when waiting for link */ |
| 7698 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 7699 | next_event_offset = HZ / 10; |
| 7700 | else |
| 7701 | next_event_offset = HZ * 2; |
| 7702 | |
| 7703 | /* Reset the timer */ |
| 7704 | mod_timer(&adapter->service_timer, next_event_offset + jiffies); |
| 7705 | |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7706 | ixgbe_service_event_schedule(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7707 | } |
| 7708 | |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 7709 | static void ixgbe_phy_interrupt_subtask(struct ixgbe_adapter *adapter) |
| 7710 | { |
| 7711 | struct ixgbe_hw *hw = &adapter->hw; |
| 7712 | u32 status; |
| 7713 | |
| 7714 | if (!(adapter->flags2 & IXGBE_FLAG2_PHY_INTERRUPT)) |
| 7715 | return; |
| 7716 | |
| 7717 | adapter->flags2 &= ~IXGBE_FLAG2_PHY_INTERRUPT; |
| 7718 | |
| 7719 | if (!hw->phy.ops.handle_lasi) |
| 7720 | return; |
| 7721 | |
| 7722 | status = hw->phy.ops.handle_lasi(&adapter->hw); |
| 7723 | if (status != IXGBE_ERR_OVERTEMP) |
| 7724 | return; |
| 7725 | |
| 7726 | e_crit(drv, "%s\n", ixgbe_overheat_msg); |
| 7727 | } |
| 7728 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7729 | static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter) |
| 7730 | { |
Emil Tantilov | 57ca2a4 | 2016-07-29 14:46:31 -0700 | [diff] [blame] | 7731 | if (!test_and_clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state)) |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7732 | return; |
| 7733 | |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 7734 | /* If we're already down, removing or resetting, just bail */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7735 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 7736 | test_bit(__IXGBE_REMOVING, &adapter->state) || |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7737 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 7738 | return; |
| 7739 | |
| 7740 | ixgbe_dump(adapter); |
| 7741 | netdev_err(adapter->netdev, "Reset adapter\n"); |
| 7742 | adapter->tx_timeout_count++; |
| 7743 | |
John Fastabend | 8f4c5c9 | 2014-01-16 02:30:05 -0800 | [diff] [blame] | 7744 | rtnl_lock(); |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7745 | ixgbe_reinit_locked(adapter); |
John Fastabend | 8f4c5c9 | 2014-01-16 02:30:05 -0800 | [diff] [blame] | 7746 | rtnl_unlock(); |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7747 | } |
| 7748 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7749 | /** |
| 7750 | * ixgbe_service_task - manages and runs subtasks |
| 7751 | * @work: pointer to work_struct containing our data |
| 7752 | **/ |
| 7753 | static void ixgbe_service_task(struct work_struct *work) |
| 7754 | { |
| 7755 | struct ixgbe_adapter *adapter = container_of(work, |
| 7756 | struct ixgbe_adapter, |
| 7757 | service_task); |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 7758 | if (ixgbe_removed(adapter->hw.hw_addr)) { |
| 7759 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 7760 | rtnl_lock(); |
| 7761 | ixgbe_down(adapter); |
| 7762 | rtnl_unlock(); |
| 7763 | } |
| 7764 | ixgbe_service_event_complete(adapter); |
| 7765 | return; |
| 7766 | } |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 7767 | if (adapter->flags2 & IXGBE_FLAG2_UDP_TUN_REREG_NEEDED) { |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 7768 | rtnl_lock(); |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 7769 | adapter->flags2 &= ~IXGBE_FLAG2_UDP_TUN_REREG_NEEDED; |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 7770 | udp_tunnel_get_rx_info(adapter->netdev); |
| 7771 | rtnl_unlock(); |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7772 | } |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7773 | ixgbe_reset_subtask(adapter); |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 7774 | ixgbe_phy_interrupt_subtask(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7775 | ixgbe_sfp_detection_subtask(adapter); |
| 7776 | ixgbe_sfp_link_config_subtask(adapter); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 7777 | ixgbe_check_overtemp_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7778 | ixgbe_watchdog_subtask(adapter); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 7779 | ixgbe_fdir_reinit_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7780 | ixgbe_check_hang_subtask(adapter); |
Jacob Keller | 891dc08 | 2012-12-05 07:24:46 +0000 | [diff] [blame] | 7781 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 7782 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) { |
Jacob Keller | 891dc08 | 2012-12-05 07:24:46 +0000 | [diff] [blame] | 7783 | ixgbe_ptp_overflow_check(adapter); |
| 7784 | ixgbe_ptp_rx_hang(adapter); |
Jacob Keller | 622a2ef | 2017-05-03 10:29:04 -0700 | [diff] [blame] | 7785 | ixgbe_ptp_tx_hang(adapter); |
Jacob Keller | 891dc08 | 2012-12-05 07:24:46 +0000 | [diff] [blame] | 7786 | } |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7787 | |
| 7788 | ixgbe_service_event_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7789 | } |
| 7790 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7791 | static int ixgbe_tso(struct ixgbe_ring *tx_ring, |
| 7792 | struct ixgbe_tx_buffer *first, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7793 | u8 *hdr_len) |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7794 | { |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7795 | u32 vlan_macip_lens, type_tucmd, mss_l4len_idx; |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7796 | struct sk_buff *skb = first->skb; |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7797 | union { |
| 7798 | struct iphdr *v4; |
| 7799 | struct ipv6hdr *v6; |
| 7800 | unsigned char *hdr; |
| 7801 | } ip; |
| 7802 | union { |
| 7803 | struct tcphdr *tcp; |
| 7804 | unsigned char *hdr; |
| 7805 | } l4; |
| 7806 | u32 paylen, l4_offset; |
Francois Romieu | 2049e1f | 2014-03-30 03:14:27 +0000 | [diff] [blame] | 7807 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7808 | |
Alexander Duyck | 8f4fbb9 | 2012-10-30 06:01:40 +0000 | [diff] [blame] | 7809 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 7810 | return 0; |
| 7811 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7812 | if (!skb_is_gso(skb)) |
| 7813 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7814 | |
Francois Romieu | 2049e1f | 2014-03-30 03:14:27 +0000 | [diff] [blame] | 7815 | err = skb_cow_head(skb, 0); |
| 7816 | if (err < 0) |
| 7817 | return err; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 7818 | |
Scott Peterson | 2a20525 | 2016-11-18 11:25:42 -0800 | [diff] [blame] | 7819 | if (eth_p_mpls(first->protocol)) |
| 7820 | ip.hdr = skb_inner_network_header(skb); |
| 7821 | else |
| 7822 | ip.hdr = skb_network_header(skb); |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7823 | l4.hdr = skb_checksum_start(skb); |
| 7824 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7825 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
| 7826 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 7827 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7828 | /* initialize outer IP header fields */ |
| 7829 | if (ip.v4->version == 4) { |
Alexander Duyck | c54cdc3 | 2016-11-28 10:42:29 -0500 | [diff] [blame] | 7830 | unsigned char *csum_start = skb_checksum_start(skb); |
| 7831 | unsigned char *trans_start = ip.hdr + (ip.v4->ihl * 4); |
| 7832 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7833 | /* IP header will have to cancel out any data that |
| 7834 | * is not a part of the outer IP header |
| 7835 | */ |
Alexander Duyck | c54cdc3 | 2016-11-28 10:42:29 -0500 | [diff] [blame] | 7836 | ip.v4->check = csum_fold(csum_partial(trans_start, |
| 7837 | csum_start - trans_start, |
| 7838 | 0)); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7839 | type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7840 | |
| 7841 | ip.v4->tot_len = 0; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7842 | first->tx_flags |= IXGBE_TX_FLAGS_TSO | |
| 7843 | IXGBE_TX_FLAGS_CSUM | |
| 7844 | IXGBE_TX_FLAGS_IPV4; |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7845 | } else { |
| 7846 | ip.v6->payload_len = 0; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7847 | first->tx_flags |= IXGBE_TX_FLAGS_TSO | |
| 7848 | IXGBE_TX_FLAGS_CSUM; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7849 | } |
| 7850 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7851 | /* determine offset of inner transport header */ |
| 7852 | l4_offset = l4.hdr - skb->data; |
| 7853 | |
| 7854 | /* compute length of segmentation header */ |
| 7855 | *hdr_len = (l4.tcp->doff * 4) + l4_offset; |
| 7856 | |
| 7857 | /* remove payload length from inner checksum */ |
| 7858 | paylen = skb->len - l4_offset; |
| 7859 | csum_replace_by_diff(&l4.tcp->check, htonl(paylen)); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7860 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 7861 | /* update gso size and bytecount with header size */ |
| 7862 | first->gso_segs = skb_shinfo(skb)->gso_segs; |
| 7863 | first->bytecount += (first->gso_segs - 1) * *hdr_len; |
| 7864 | |
Alexander Duyck | c44f5f5 | 2012-10-30 06:01:45 +0000 | [diff] [blame] | 7865 | /* mss_l4len_id: use 0 as index for TSO */ |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7866 | mss_l4len_idx = (*hdr_len - l4_offset) << IXGBE_ADVTXD_L4LEN_SHIFT; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7867 | mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7868 | |
| 7869 | /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */ |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7870 | vlan_macip_lens = l4.hdr - ip.hdr; |
| 7871 | vlan_macip_lens |= (ip.hdr - skb->data) << IXGBE_ADVTXD_MACLEN_SHIFT; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7872 | vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7873 | |
| 7874 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7875 | mss_l4len_idx); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7876 | |
| 7877 | return 1; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 7878 | } |
| 7879 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7880 | static inline bool ixgbe_ipv6_csum_is_sctp(struct sk_buff *skb) |
| 7881 | { |
| 7882 | unsigned int offset = 0; |
| 7883 | |
| 7884 | ipv6_find_hdr(skb, &offset, IPPROTO_SCTP, NULL, NULL); |
| 7885 | |
| 7886 | return offset == skb_checksum_start_offset(skb); |
| 7887 | } |
| 7888 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7889 | static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring, |
| 7890 | struct ixgbe_tx_buffer *first) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7891 | { |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7892 | struct sk_buff *skb = first->skb; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7893 | u32 vlan_macip_lens = 0; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7894 | u32 type_tucmd = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7895 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7896 | if (skb->ip_summed != CHECKSUM_PARTIAL) { |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7897 | csum_failed: |
| 7898 | if (!(first->tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | |
| 7899 | IXGBE_TX_FLAGS_CC))) |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7900 | return; |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7901 | goto no_csum; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7902 | } |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 7903 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7904 | switch (skb->csum_offset) { |
| 7905 | case offsetof(struct tcphdr, check): |
| 7906 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 7907 | /* fall through */ |
| 7908 | case offsetof(struct udphdr, check): |
| 7909 | break; |
| 7910 | case offsetof(struct sctphdr, checksum): |
| 7911 | /* validate that this is actually an SCTP request */ |
| 7912 | if (((first->protocol == htons(ETH_P_IP)) && |
| 7913 | (ip_hdr(skb)->protocol == IPPROTO_SCTP)) || |
| 7914 | ((first->protocol == htons(ETH_P_IPV6)) && |
| 7915 | ixgbe_ipv6_csum_is_sctp(skb))) { |
| 7916 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
| 7917 | break; |
| 7918 | } |
| 7919 | /* fall through */ |
| 7920 | default: |
| 7921 | skb_checksum_help(skb); |
| 7922 | goto csum_failed; |
| 7923 | } |
| 7924 | |
| 7925 | /* update TX checksum flag */ |
| 7926 | first->tx_flags |= IXGBE_TX_FLAGS_CSUM; |
| 7927 | vlan_macip_lens = skb_checksum_start_offset(skb) - |
| 7928 | skb_network_offset(skb); |
Mark Rustad | 36a92d7 | 2015-11-18 09:21:28 -0800 | [diff] [blame] | 7929 | no_csum: |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7930 | /* vlan_macip_lens: MACLEN, VLAN tag */ |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7931 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7932 | vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7933 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7934 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, 0); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7935 | } |
| 7936 | |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7937 | #define IXGBE_SET_FLAG(_input, _flag, _result) \ |
| 7938 | ((_flag <= _result) ? \ |
| 7939 | ((u32)(_input & _flag) * (_result / _flag)) : \ |
| 7940 | ((u32)(_input & _flag) / (_flag / _result))) |
| 7941 | |
| 7942 | 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] | 7943 | { |
| 7944 | /* set type for advanced descriptor with frame checksum insertion */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7945 | u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA | |
| 7946 | IXGBE_ADVTXD_DCMD_DEXT | |
| 7947 | IXGBE_ADVTXD_DCMD_IFCS; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7948 | |
| 7949 | /* set HW vlan bit if vlan is present */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7950 | cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN, |
| 7951 | IXGBE_ADVTXD_DCMD_VLE); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7952 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7953 | /* set segmentation enable bits for TSO/FSO */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7954 | cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO, |
| 7955 | IXGBE_ADVTXD_DCMD_TSE); |
| 7956 | |
| 7957 | /* set timestamp bit if present */ |
| 7958 | cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP, |
| 7959 | IXGBE_ADVTXD_MAC_TSTAMP); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7960 | |
Alexander Duyck | 62748b7 | 2012-07-20 08:09:01 +0000 | [diff] [blame] | 7961 | /* insert frame checksum */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7962 | 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] | 7963 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7964 | return cmd_type; |
| 7965 | } |
| 7966 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7967 | static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc, |
| 7968 | u32 tx_flags, unsigned int paylen) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7969 | { |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7970 | u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7971 | |
| 7972 | /* enable L4 checksum for TSO and TX checksum offload */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7973 | olinfo_status |= IXGBE_SET_FLAG(tx_flags, |
| 7974 | IXGBE_TX_FLAGS_CSUM, |
| 7975 | IXGBE_ADVTXD_POPTS_TXSM); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7976 | |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 7977 | /* enble IPv4 checksum for TSO */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7978 | olinfo_status |= IXGBE_SET_FLAG(tx_flags, |
| 7979 | IXGBE_TX_FLAGS_IPV4, |
| 7980 | IXGBE_ADVTXD_POPTS_IXSM); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7981 | |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 7982 | /* |
| 7983 | * Check Context must be set if Tx switch is enabled, which it |
| 7984 | * always is for case where virtual functions are running |
| 7985 | */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7986 | olinfo_status |= IXGBE_SET_FLAG(tx_flags, |
| 7987 | IXGBE_TX_FLAGS_CC, |
| 7988 | IXGBE_ADVTXD_CC); |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 7989 | |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7990 | tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7991 | } |
| 7992 | |
Daniel Borkmann | 2367a17 | 2014-08-26 19:34:18 +0200 | [diff] [blame] | 7993 | static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size) |
| 7994 | { |
| 7995 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 7996 | |
| 7997 | /* Herbert's original patch had: |
| 7998 | * smp_mb__after_netif_stop_queue(); |
| 7999 | * but since that doesn't exist yet, just open code it. |
| 8000 | */ |
| 8001 | smp_mb(); |
| 8002 | |
| 8003 | /* We need to check again in a case another CPU has just |
| 8004 | * made room available. |
| 8005 | */ |
| 8006 | if (likely(ixgbe_desc_unused(tx_ring) < size)) |
| 8007 | return -EBUSY; |
| 8008 | |
| 8009 | /* A reprieve! - use start_queue because it doesn't call schedule */ |
| 8010 | netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 8011 | ++tx_ring->tx_stats.restart_queue; |
| 8012 | return 0; |
| 8013 | } |
| 8014 | |
| 8015 | static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size) |
| 8016 | { |
| 8017 | if (likely(ixgbe_desc_unused(tx_ring) >= size)) |
| 8018 | return 0; |
| 8019 | |
| 8020 | return __ixgbe_maybe_stop_tx(tx_ring, size); |
| 8021 | } |
| 8022 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8023 | #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \ |
| 8024 | IXGBE_TXD_CMD_RS) |
| 8025 | |
Jacob Keller | 5fef124 | 2017-05-03 10:28:56 -0700 | [diff] [blame] | 8026 | static int ixgbe_tx_map(struct ixgbe_ring *tx_ring, |
| 8027 | struct ixgbe_tx_buffer *first, |
| 8028 | const u8 hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8029 | { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 8030 | struct sk_buff *skb = first->skb; |
| 8031 | struct ixgbe_tx_buffer *tx_buffer; |
| 8032 | union ixgbe_adv_tx_desc *tx_desc; |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 8033 | struct skb_frag_struct *frag; |
| 8034 | dma_addr_t dma; |
| 8035 | unsigned int data_len, size; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 8036 | u32 tx_flags = first->tx_flags; |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 8037 | u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8038 | u16 i = tx_ring->next_to_use; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8039 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 8040 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
| 8041 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 8042 | ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len); |
| 8043 | |
| 8044 | size = skb_headlen(skb); |
| 8045 | data_len = skb->data_len; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 8046 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8047 | #ifdef IXGBE_FCOE |
| 8048 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 8049 | if (data_len < sizeof(struct fcoe_crc_eof)) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8050 | size -= sizeof(struct fcoe_crc_eof) - data_len; |
| 8051 | data_len = 0; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 8052 | } else { |
| 8053 | data_len -= sizeof(struct fcoe_crc_eof); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 8054 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8055 | } |
| 8056 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8057 | #endif |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 8058 | 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] | 8059 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 8060 | tx_buffer = first; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8061 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 8062 | for (frag = &skb_shinfo(skb)->frags[0];; frag++) { |
| 8063 | if (dma_mapping_error(tx_ring->dev, dma)) |
| 8064 | goto dma_error; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8065 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 8066 | /* record length, and DMA address */ |
| 8067 | dma_unmap_len_set(tx_buffer, len, size); |
| 8068 | dma_unmap_addr_set(tx_buffer, dma, dma); |
| 8069 | |
| 8070 | tx_desc->read.buffer_addr = cpu_to_le64(dma); |
| 8071 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 8072 | while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8073 | tx_desc->read.cmd_type_len = |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 8074 | cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8075 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8076 | i++; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 8077 | tx_desc++; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8078 | if (i == tx_ring->count) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 8079 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8080 | i = 0; |
| 8081 | } |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 8082 | tx_desc->read.olinfo_status = 0; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 8083 | |
| 8084 | dma += IXGBE_MAX_DATA_PER_TXD; |
| 8085 | size -= IXGBE_MAX_DATA_PER_TXD; |
| 8086 | |
| 8087 | tx_desc->read.buffer_addr = cpu_to_le64(dma); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8088 | } |
| 8089 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 8090 | if (likely(!data_len)) |
| 8091 | break; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8092 | |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 8093 | tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8094 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 8095 | i++; |
| 8096 | tx_desc++; |
| 8097 | if (i == tx_ring->count) { |
| 8098 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
| 8099 | i = 0; |
| 8100 | } |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 8101 | tx_desc->read.olinfo_status = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8102 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8103 | #ifdef IXGBE_FCOE |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 8104 | size = min_t(unsigned int, data_len, skb_frag_size(frag)); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8105 | #else |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 8106 | size = skb_frag_size(frag); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8107 | #endif |
| 8108 | data_len -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8109 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 8110 | dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size, |
| 8111 | DMA_TO_DEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8112 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 8113 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8114 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 8115 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 8116 | /* write last descriptor with RS and EOP bits */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 8117 | cmd_type |= size | IXGBE_TXD_CMD; |
| 8118 | tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8119 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 8120 | netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount); |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 8121 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8122 | /* set the timestamp */ |
| 8123 | first->time_stamp = jiffies; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8124 | |
| 8125 | /* |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 8126 | * Force memory writes to complete before letting h/w know there |
| 8127 | * are new descriptors to fetch. (Only applicable for weak-ordered |
| 8128 | * memory model archs, such as IA-64). |
| 8129 | * |
| 8130 | * We also need this memory barrier to make certain all of the |
| 8131 | * status bits have been updated before next_to_watch is written. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8132 | */ |
| 8133 | wmb(); |
| 8134 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8135 | /* set next_to_watch value indicating a packet is present */ |
| 8136 | first->next_to_watch = tx_desc; |
| 8137 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 8138 | i++; |
| 8139 | if (i == tx_ring->count) |
| 8140 | i = 0; |
| 8141 | |
| 8142 | tx_ring->next_to_use = i; |
| 8143 | |
Daniel Borkmann | 2367a17 | 2014-08-26 19:34:18 +0200 | [diff] [blame] | 8144 | ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED); |
| 8145 | |
| 8146 | if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) { |
Alexander Duyck | ad435ec | 2014-11-14 00:56:35 +0000 | [diff] [blame] | 8147 | writel(i, tx_ring->tail); |
| 8148 | |
| 8149 | /* we need this if more than one processor can write to our tail |
| 8150 | * at a time, it synchronizes IO on IA64/Altix systems |
| 8151 | */ |
| 8152 | mmiowb(); |
Daniel Borkmann | 9c938cd | 2014-08-24 15:42:16 +0200 | [diff] [blame] | 8153 | } |
Daniel Borkmann | 2367a17 | 2014-08-26 19:34:18 +0200 | [diff] [blame] | 8154 | |
Jacob Keller | 5fef124 | 2017-05-03 10:28:56 -0700 | [diff] [blame] | 8155 | return 0; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8156 | dma_error: |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 8157 | dev_err(tx_ring->dev, "TX DMA map failed\n"); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8158 | |
| 8159 | /* clear dma mappings for failed tx_buffer_info map */ |
Alexander Duyck | 069db9c | 2017-10-19 17:07:13 -0400 | [diff] [blame] | 8160 | for (;;) { |
| 8161 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 8162 | if (dma_unmap_len(tx_buffer, len)) |
| 8163 | dma_unmap_page(tx_ring->dev, |
| 8164 | dma_unmap_addr(tx_buffer, dma), |
| 8165 | dma_unmap_len(tx_buffer, len), |
| 8166 | DMA_TO_DEVICE); |
| 8167 | dma_unmap_len_set(tx_buffer, len, 0); |
Alexander Duyck | 069db9c | 2017-10-19 17:07:13 -0400 | [diff] [blame] | 8168 | if (tx_buffer == first) |
| 8169 | break; |
| 8170 | if (i == 0) |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 8171 | i += tx_ring->count; |
Alexander Duyck | 069db9c | 2017-10-19 17:07:13 -0400 | [diff] [blame] | 8172 | i--; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8173 | } |
| 8174 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 8175 | dev_kfree_skb_any(first->skb); |
| 8176 | first->skb = NULL; |
| 8177 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8178 | tx_ring->next_to_use = i; |
Jacob Keller | 5fef124 | 2017-05-03 10:28:56 -0700 | [diff] [blame] | 8179 | |
| 8180 | return -1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8181 | } |
| 8182 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 8183 | static void ixgbe_atr(struct ixgbe_ring *ring, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 8184 | struct ixgbe_tx_buffer *first) |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 8185 | { |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 8186 | struct ixgbe_q_vector *q_vector = ring->q_vector; |
| 8187 | union ixgbe_atr_hash_dword input = { .dword = 0 }; |
| 8188 | union ixgbe_atr_hash_dword common = { .dword = 0 }; |
| 8189 | union { |
| 8190 | unsigned char *network; |
| 8191 | struct iphdr *ipv4; |
| 8192 | struct ipv6hdr *ipv6; |
| 8193 | } hdr; |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 8194 | struct tcphdr *th; |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 8195 | unsigned int hlen; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8196 | struct sk_buff *skb; |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 8197 | __be16 vlan_id; |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 8198 | int l4_proto; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 8199 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 8200 | /* if ring doesn't have a interrupt vector, cannot perform ATR */ |
| 8201 | if (!q_vector) |
Guillaume Gaudonville | d3ead24 | 2010-06-29 18:29:00 +0000 | [diff] [blame] | 8202 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 8203 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 8204 | /* do nothing if sampling is disabled */ |
| 8205 | if (!ring->atr_sample_rate) |
| 8206 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 8207 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 8208 | ring->atr_count++; |
| 8209 | |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 8210 | /* currently only IPv4/IPv6 with TCP is supported */ |
| 8211 | if ((first->protocol != htons(ETH_P_IP)) && |
| 8212 | (first->protocol != htons(ETH_P_IPV6))) |
| 8213 | return; |
| 8214 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 8215 | /* snag network header to get L4 type and address */ |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8216 | skb = first->skb; |
| 8217 | hdr.network = skb_network_header(skb); |
Sowmini Varadhan | 9f3c750 | 2016-10-24 15:36:39 -0700 | [diff] [blame] | 8218 | if (unlikely(hdr.network <= skb->data)) |
| 8219 | return; |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 8220 | if (skb->encapsulation && |
| 8221 | first->protocol == htons(ETH_P_IP) && |
Sowmini Varadhan | 5202882 | 2016-10-24 15:36:38 -0700 | [diff] [blame] | 8222 | hdr.ipv4->protocol == IPPROTO_UDP) { |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8223 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 8224 | |
Sowmini Varadhan | 9f3c750 | 2016-10-24 15:36:39 -0700 | [diff] [blame] | 8225 | if (unlikely(skb_tail_pointer(skb) < hdr.network + |
| 8226 | VXLAN_HEADROOM)) |
| 8227 | return; |
| 8228 | |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 8229 | /* verify the port is recognized as VXLAN */ |
| 8230 | if (adapter->vxlan_port && |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 8231 | udp_hdr(skb)->dest == adapter->vxlan_port) |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 8232 | hdr.network = skb_inner_network_header(skb); |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 8233 | |
| 8234 | if (adapter->geneve_port && |
| 8235 | udp_hdr(skb)->dest == adapter->geneve_port) |
| 8236 | hdr.network = skb_inner_network_header(skb); |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 8237 | } |
| 8238 | |
Sowmini Varadhan | 9f3c750 | 2016-10-24 15:36:39 -0700 | [diff] [blame] | 8239 | /* Make sure we have at least [minimum IPv4 header + TCP] |
| 8240 | * or [IPv6 header] bytes |
| 8241 | */ |
| 8242 | if (unlikely(skb_tail_pointer(skb) < hdr.network + 40)) |
| 8243 | return; |
| 8244 | |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 8245 | /* Currently only IPv4/IPv6 with TCP is supported */ |
| 8246 | switch (hdr.ipv4->version) { |
| 8247 | case IPVERSION: |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 8248 | /* access ihl as u8 to avoid unaligned access on ia64 */ |
| 8249 | hlen = (hdr.network[0] & 0x0F) << 2; |
| 8250 | l4_proto = hdr.ipv4->protocol; |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 8251 | break; |
| 8252 | case 6: |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 8253 | hlen = hdr.network - skb->data; |
| 8254 | l4_proto = ipv6_find_hdr(skb, &hlen, IPPROTO_TCP, NULL, NULL); |
| 8255 | hlen -= hdr.network - skb->data; |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 8256 | break; |
| 8257 | default: |
| 8258 | return; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8259 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 8260 | |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 8261 | if (l4_proto != IPPROTO_TCP) |
| 8262 | return; |
| 8263 | |
Sowmini Varadhan | 9f3c750 | 2016-10-24 15:36:39 -0700 | [diff] [blame] | 8264 | if (unlikely(skb_tail_pointer(skb) < hdr.network + |
| 8265 | hlen + sizeof(struct tcphdr))) |
| 8266 | return; |
| 8267 | |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 8268 | th = (struct tcphdr *)(hdr.network + hlen); |
| 8269 | |
| 8270 | /* skip this packet since the socket is closing */ |
| 8271 | if (th->fin) |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 8272 | return; |
| 8273 | |
| 8274 | /* sample on all syn packets or once every atr sample count */ |
| 8275 | if (!th->syn && (ring->atr_count < ring->atr_sample_rate)) |
| 8276 | return; |
| 8277 | |
| 8278 | /* reset sample count */ |
| 8279 | ring->atr_count = 0; |
| 8280 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 8281 | vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT); |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 8282 | |
| 8283 | /* |
| 8284 | * src and dst are inverted, think how the receiver sees them |
| 8285 | * |
| 8286 | * The input is broken into two sections, a non-compressed section |
| 8287 | * containing vm_pool, vlan_id, and flow_type. The rest of the data |
| 8288 | * is XORed together and stored in the compressed dword. |
| 8289 | */ |
| 8290 | input.formatted.vlan_id = vlan_id; |
| 8291 | |
| 8292 | /* |
| 8293 | * since src port and flex bytes occupy the same word XOR them together |
| 8294 | * and write the value to source port portion of compressed dword |
| 8295 | */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 8296 | 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] | 8297 | common.port.src ^= th->dest ^ htons(ETH_P_8021Q); |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 8298 | else |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 8299 | common.port.src ^= th->dest ^ first->protocol; |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 8300 | common.port.dst ^= th->source; |
| 8301 | |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 8302 | switch (hdr.ipv4->version) { |
| 8303 | case IPVERSION: |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 8304 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4; |
| 8305 | common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr; |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 8306 | break; |
| 8307 | case 6: |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 8308 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6; |
| 8309 | common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^ |
| 8310 | hdr.ipv6->saddr.s6_addr32[1] ^ |
| 8311 | hdr.ipv6->saddr.s6_addr32[2] ^ |
| 8312 | hdr.ipv6->saddr.s6_addr32[3] ^ |
| 8313 | hdr.ipv6->daddr.s6_addr32[0] ^ |
| 8314 | hdr.ipv6->daddr.s6_addr32[1] ^ |
| 8315 | hdr.ipv6->daddr.s6_addr32[2] ^ |
| 8316 | hdr.ipv6->daddr.s6_addr32[3]; |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 8317 | break; |
| 8318 | default: |
| 8319 | break; |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 8320 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 8321 | |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 8322 | if (hdr.network != skb_network_header(skb)) |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8323 | input.formatted.flow_type |= IXGBE_ATR_L4TYPE_TUNNEL_MASK; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8324 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 8325 | /* 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] | 8326 | ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw, |
| 8327 | input, common, ring->queue_index); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 8328 | } |
| 8329 | |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 8330 | 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] | 8331 | void *accel_priv, select_queue_fallback_t fallback) |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 8332 | { |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 8333 | struct ixgbe_fwd_adapter *fwd_adapter = accel_priv; |
| 8334 | #ifdef IXGBE_FCOE |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 8335 | struct ixgbe_adapter *adapter; |
| 8336 | struct ixgbe_ring_feature *f; |
| 8337 | int txq; |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 8338 | #endif |
| 8339 | |
| 8340 | if (fwd_adapter) |
| 8341 | return skb->queue_mapping + fwd_adapter->tx_base_queue; |
| 8342 | |
| 8343 | #ifdef IXGBE_FCOE |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 8344 | |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 8345 | /* |
| 8346 | * only execute the code below if protocol is FCoE |
| 8347 | * or FIP and we have FCoE enabled on the adapter |
| 8348 | */ |
| 8349 | switch (vlan_get_protocol(skb)) { |
Joe Perches | a1108ff | 2014-03-13 05:19:25 +0000 | [diff] [blame] | 8350 | case htons(ETH_P_FCOE): |
| 8351 | case htons(ETH_P_FIP): |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 8352 | adapter = netdev_priv(dev); |
Alexander Duyck | c087663 | 2012-05-10 00:01:46 +0000 | [diff] [blame] | 8353 | |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 8354 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 8355 | break; |
Tony Nguyen | 93df946 | 2017-05-31 04:43:47 -0700 | [diff] [blame] | 8356 | /* fall through */ |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 8357 | default: |
Daniel Borkmann | 99932d4 | 2014-02-16 15:55:20 +0100 | [diff] [blame] | 8358 | return fallback(dev, skb); |
Krishna Kumar | fdd3d63 | 2010-02-03 13:13:10 +0000 | [diff] [blame] | 8359 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 8360 | |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 8361 | f = &adapter->ring_feature[RING_F_FCOE]; |
| 8362 | |
| 8363 | txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) : |
| 8364 | smp_processor_id(); |
| 8365 | |
| 8366 | while (txq >= f->indices) |
| 8367 | txq -= f->indices; |
| 8368 | |
| 8369 | return txq + f->offset; |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 8370 | #else |
Daniel Borkmann | 99932d4 | 2014-02-16 15:55:20 +0100 | [diff] [blame] | 8371 | return fallback(dev, skb); |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 8372 | #endif |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 8373 | } |
| 8374 | |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 8375 | static int ixgbe_xmit_xdp_ring(struct ixgbe_adapter *adapter, |
| 8376 | struct xdp_buff *xdp) |
| 8377 | { |
| 8378 | struct ixgbe_ring *ring = adapter->xdp_ring[smp_processor_id()]; |
| 8379 | struct ixgbe_tx_buffer *tx_buffer; |
| 8380 | union ixgbe_adv_tx_desc *tx_desc; |
| 8381 | u32 len, cmd_type; |
| 8382 | dma_addr_t dma; |
| 8383 | u16 i; |
| 8384 | |
| 8385 | len = xdp->data_end - xdp->data; |
| 8386 | |
| 8387 | if (unlikely(!ixgbe_desc_unused(ring))) |
| 8388 | return IXGBE_XDP_CONSUMED; |
| 8389 | |
| 8390 | dma = dma_map_single(ring->dev, xdp->data, len, DMA_TO_DEVICE); |
| 8391 | if (dma_mapping_error(ring->dev, dma)) |
| 8392 | return IXGBE_XDP_CONSUMED; |
| 8393 | |
| 8394 | /* record the location of the first descriptor for this packet */ |
| 8395 | tx_buffer = &ring->tx_buffer_info[ring->next_to_use]; |
| 8396 | tx_buffer->bytecount = len; |
| 8397 | tx_buffer->gso_segs = 1; |
| 8398 | tx_buffer->protocol = 0; |
| 8399 | |
| 8400 | i = ring->next_to_use; |
| 8401 | tx_desc = IXGBE_TX_DESC(ring, i); |
| 8402 | |
| 8403 | dma_unmap_len_set(tx_buffer, len, len); |
| 8404 | dma_unmap_addr_set(tx_buffer, dma, dma); |
| 8405 | tx_buffer->data = xdp->data; |
| 8406 | tx_desc->read.buffer_addr = cpu_to_le64(dma); |
| 8407 | |
| 8408 | /* put descriptor type bits */ |
| 8409 | cmd_type = IXGBE_ADVTXD_DTYP_DATA | |
| 8410 | IXGBE_ADVTXD_DCMD_DEXT | |
| 8411 | IXGBE_ADVTXD_DCMD_IFCS; |
| 8412 | cmd_type |= len | IXGBE_TXD_CMD; |
| 8413 | tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type); |
| 8414 | tx_desc->read.olinfo_status = |
| 8415 | cpu_to_le32(len << IXGBE_ADVTXD_PAYLEN_SHIFT); |
| 8416 | |
John Fastabend | 7379f97 | 2017-03-28 09:47:03 -0700 | [diff] [blame] | 8417 | /* Avoid any potential race with xdp_xmit and cleanup */ |
| 8418 | smp_wmb(); |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 8419 | |
| 8420 | /* set next_to_watch value indicating a packet is present */ |
| 8421 | i++; |
| 8422 | if (i == ring->count) |
| 8423 | i = 0; |
| 8424 | |
| 8425 | tx_buffer->next_to_watch = tx_desc; |
| 8426 | ring->next_to_use = i; |
| 8427 | |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 8428 | return IXGBE_XDP_TX; |
| 8429 | } |
| 8430 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 8431 | netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb, |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 8432 | struct ixgbe_adapter *adapter, |
| 8433 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8434 | { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8435 | struct ixgbe_tx_buffer *first; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 8436 | int tso; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8437 | u32 tx_flags = 0; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 8438 | unsigned short f; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 8439 | u16 count = TXD_USE_COUNT(skb_headlen(skb)); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8440 | __be16 protocol = skb->protocol; |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 8441 | u8 hdr_len = 0; |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 8442 | |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 8443 | /* |
| 8444 | * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD, |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 8445 | * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD, |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 8446 | * + 2 desc gap to keep tail from touching head, |
| 8447 | * + 1 desc for context descriptor, |
| 8448 | * otherwise try next time |
| 8449 | */ |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 8450 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) |
| 8451 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size); |
Alexander Duyck | 7f66162 | 2013-02-09 01:19:55 +0000 | [diff] [blame] | 8452 | |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 8453 | if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) { |
| 8454 | tx_ring->tx_stats.tx_busy++; |
| 8455 | return NETDEV_TX_BUSY; |
| 8456 | } |
| 8457 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 8458 | /* record the location of the first descriptor for this packet */ |
| 8459 | first = &tx_ring->tx_buffer_info[tx_ring->next_to_use]; |
| 8460 | first->skb = skb; |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 8461 | first->bytecount = skb->len; |
| 8462 | first->gso_segs = 1; |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 8463 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8464 | /* 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] | 8465 | if (skb_vlan_tag_present(skb)) { |
| 8466 | tx_flags |= skb_vlan_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8467 | tx_flags |= IXGBE_TX_FLAGS_HW_VLAN; |
| 8468 | /* 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] | 8469 | } else if (protocol == htons(ETH_P_8021Q)) { |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8470 | struct vlan_hdr *vhdr, _vhdr; |
| 8471 | vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr); |
| 8472 | if (!vhdr) |
| 8473 | goto out_drop; |
| 8474 | |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 8475 | tx_flags |= ntohs(vhdr->h_vlan_TCI) << |
| 8476 | IXGBE_TX_FLAGS_VLAN_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8477 | tx_flags |= IXGBE_TX_FLAGS_SW_VLAN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8478 | } |
Toshiaki Makita | 0213668 | 2015-01-29 20:37:09 +0900 | [diff] [blame] | 8479 | protocol = vlan_get_protocol(skb); |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 8480 | |
Mark Rustad | d523493 | 2014-08-09 07:02:09 +0000 | [diff] [blame] | 8481 | if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && |
Jacob Keller | 4cc74c0 | 2017-05-03 10:29:00 -0700 | [diff] [blame] | 8482 | adapter->ptp_clock) { |
| 8483 | if (!test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS, |
| 8484 | &adapter->state)) { |
| 8485 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; |
| 8486 | tx_flags |= IXGBE_TX_FLAGS_TSTAMP; |
Jacob Keller | 891dc08 | 2012-12-05 07:24:46 +0000 | [diff] [blame] | 8487 | |
Jacob Keller | 4cc74c0 | 2017-05-03 10:29:00 -0700 | [diff] [blame] | 8488 | /* schedule check for Tx timestamp */ |
| 8489 | adapter->ptp_tx_skb = skb_get(skb); |
| 8490 | adapter->ptp_tx_start = jiffies; |
| 8491 | schedule_work(&adapter->ptp_tx_work); |
| 8492 | } else { |
| 8493 | adapter->tx_hwtstamp_skipped++; |
| 8494 | } |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 8495 | } |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 8496 | |
Jakub Kicinski | ff29a86 | 2014-03-15 14:55:16 +0000 | [diff] [blame] | 8497 | skb_tx_timestamp(skb); |
| 8498 | |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 8499 | #ifdef CONFIG_PCI_IOV |
| 8500 | /* |
| 8501 | * Use the l2switch_enable flag - would be false if the DMA |
| 8502 | * Tx switch had been disabled. |
| 8503 | */ |
| 8504 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 8505 | tx_flags |= IXGBE_TX_FLAGS_CC; |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 8506 | |
| 8507 | #endif |
John Fastabend | 32701dc | 2011-09-27 03:51:56 +0000 | [diff] [blame] | 8508 | /* 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] | 8509 | if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && |
Alexander Duyck | 09dca47 | 2011-07-20 00:09:10 +0000 | [diff] [blame] | 8510 | ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) || |
| 8511 | (skb->priority != TC_PRIO_CONTROL))) { |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8512 | tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK; |
John Fastabend | 32701dc | 2011-09-27 03:51:56 +0000 | [diff] [blame] | 8513 | tx_flags |= (skb->priority & 0x7) << |
| 8514 | IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8515 | if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) { |
| 8516 | struct vlan_ethhdr *vhdr; |
Francois Romieu | 2049e1f | 2014-03-30 03:14:27 +0000 | [diff] [blame] | 8517 | |
| 8518 | if (skb_cow_head(skb, 0)) |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8519 | goto out_drop; |
| 8520 | vhdr = (struct vlan_ethhdr *)skb->data; |
| 8521 | vhdr->h_vlan_TCI = htons(tx_flags >> |
| 8522 | IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 8523 | } else { |
| 8524 | tx_flags |= IXGBE_TX_FLAGS_HW_VLAN; |
| 8525 | } |
| 8526 | } |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 8527 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 8528 | /* record initial flags and protocol */ |
| 8529 | first->tx_flags = tx_flags; |
| 8530 | first->protocol = protocol; |
| 8531 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 8532 | #ifdef IXGBE_FCOE |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8533 | /* setup tx offload for FCoE */ |
Joe Perches | a1108ff | 2014-03-13 05:19:25 +0000 | [diff] [blame] | 8534 | if ((protocol == htons(ETH_P_FCOE)) && |
Alexander Duyck | a58915c | 2012-05-25 06:38:18 +0000 | [diff] [blame] | 8535 | (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) { |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 8536 | tso = ixgbe_fso(tx_ring, first, &hdr_len); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 8537 | if (tso < 0) |
| 8538 | goto out_drop; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8539 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8540 | goto xmit_fcoe; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 8541 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8542 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8543 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 8544 | tso = ixgbe_tso(tx_ring, first, &hdr_len); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8545 | if (tso < 0) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8546 | goto out_drop; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 8547 | else if (!tso) |
| 8548 | ixgbe_tx_csum(tx_ring, first); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8549 | |
| 8550 | /* add the ATR filter if ATR is on */ |
| 8551 | if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state)) |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 8552 | ixgbe_atr(tx_ring, first); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8553 | |
| 8554 | #ifdef IXGBE_FCOE |
| 8555 | xmit_fcoe: |
| 8556 | #endif /* IXGBE_FCOE */ |
Jacob Keller | 5fef124 | 2017-05-03 10:28:56 -0700 | [diff] [blame] | 8557 | if (ixgbe_tx_map(tx_ring, first, hdr_len)) |
| 8558 | goto cleanup_tx_timestamp; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8559 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8560 | return NETDEV_TX_OK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 8561 | |
| 8562 | out_drop: |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 8563 | dev_kfree_skb_any(first->skb); |
| 8564 | first->skb = NULL; |
Jacob Keller | 5fef124 | 2017-05-03 10:28:56 -0700 | [diff] [blame] | 8565 | cleanup_tx_timestamp: |
| 8566 | if (unlikely(tx_flags & IXGBE_TX_FLAGS_TSTAMP)) { |
| 8567 | dev_kfree_skb_any(adapter->ptp_tx_skb); |
| 8568 | adapter->ptp_tx_skb = NULL; |
| 8569 | cancel_work_sync(&adapter->ptp_tx_work); |
| 8570 | clear_bit_unlock(__IXGBE_PTP_TX_IN_PROGRESS, &adapter->state); |
| 8571 | } |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 8572 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 8573 | return NETDEV_TX_OK; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8574 | } |
| 8575 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8576 | static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb, |
| 8577 | struct net_device *netdev, |
| 8578 | struct ixgbe_ring *ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8579 | { |
| 8580 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 8581 | struct ixgbe_ring *tx_ring; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8582 | |
Alexander Duyck | a50c29d | 2012-02-08 07:50:40 +0000 | [diff] [blame] | 8583 | /* |
| 8584 | * The minimum packet size for olinfo paylen is 17 so pad the skb |
| 8585 | * in order to meet this minimum size requirement. |
| 8586 | */ |
Alexander Duyck | a94d9e2 | 2014-12-03 08:17:39 -0800 | [diff] [blame] | 8587 | if (skb_put_padto(skb, 17)) |
| 8588 | return NETDEV_TX_OK; |
Alexander Duyck | a50c29d | 2012-02-08 07:50:40 +0000 | [diff] [blame] | 8589 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8590 | tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping]; |
| 8591 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8592 | return ixgbe_xmit_frame_ring(skb, adapter, tx_ring); |
| 8593 | } |
| 8594 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8595 | static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, |
| 8596 | struct net_device *netdev) |
| 8597 | { |
| 8598 | return __ixgbe_xmit_frame(skb, netdev, NULL); |
| 8599 | } |
| 8600 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8601 | /** |
| 8602 | * ixgbe_set_mac - Change the Ethernet Address of the NIC |
| 8603 | * @netdev: network interface device structure |
| 8604 | * @p: pointer to an address structure |
| 8605 | * |
| 8606 | * Returns 0 on success, negative on failure |
| 8607 | **/ |
| 8608 | static int ixgbe_set_mac(struct net_device *netdev, void *p) |
| 8609 | { |
| 8610 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8611 | struct ixgbe_hw *hw = &adapter->hw; |
| 8612 | struct sockaddr *addr = p; |
| 8613 | |
| 8614 | if (!is_valid_ether_addr(addr->sa_data)) |
| 8615 | return -EADDRNOTAVAIL; |
| 8616 | |
| 8617 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 8618 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8619 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 8620 | ixgbe_mac_set_default_filter(adapter); |
| 8621 | |
| 8622 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8623 | } |
| 8624 | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 8625 | static int |
| 8626 | ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr) |
| 8627 | { |
| 8628 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8629 | struct ixgbe_hw *hw = &adapter->hw; |
| 8630 | u16 value; |
| 8631 | int rc; |
| 8632 | |
| 8633 | if (prtad != hw->phy.mdio.prtad) |
| 8634 | return -EINVAL; |
| 8635 | rc = hw->phy.ops.read_reg(hw, addr, devad, &value); |
| 8636 | if (!rc) |
| 8637 | rc = value; |
| 8638 | return rc; |
| 8639 | } |
| 8640 | |
| 8641 | static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad, |
| 8642 | u16 addr, u16 value) |
| 8643 | { |
| 8644 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8645 | struct ixgbe_hw *hw = &adapter->hw; |
| 8646 | |
| 8647 | if (prtad != hw->phy.mdio.prtad) |
| 8648 | return -EINVAL; |
| 8649 | return hw->phy.ops.write_reg(hw, addr, devad, value); |
| 8650 | } |
| 8651 | |
| 8652 | static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd) |
| 8653 | { |
| 8654 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8655 | |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 8656 | switch (cmd) { |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 8657 | case SIOCSHWTSTAMP: |
Jacob Keller | 93501d4 | 2014-02-28 15:48:58 -0800 | [diff] [blame] | 8658 | return ixgbe_ptp_set_ts_config(adapter, req); |
| 8659 | case SIOCGHWTSTAMP: |
| 8660 | return ixgbe_ptp_get_ts_config(adapter, req); |
Mark D Rustad | e0f06bb | 2016-08-31 10:34:28 -0700 | [diff] [blame] | 8661 | case SIOCGMIIPHY: |
| 8662 | if (!adapter->hw.phy.ops.read_reg) |
| 8663 | return -EOPNOTSUPP; |
| 8664 | /* fall through */ |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 8665 | default: |
| 8666 | return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd); |
| 8667 | } |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 8668 | } |
| 8669 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8670 | /** |
| 8671 | * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 8672 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8673 | * @netdev: network interface device structure |
| 8674 | * |
| 8675 | * Returns non-zero on failure |
| 8676 | **/ |
| 8677 | static int ixgbe_add_sanmac_netdev(struct net_device *dev) |
| 8678 | { |
| 8679 | int err = 0; |
| 8680 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 8681 | struct ixgbe_hw *hw = &adapter->hw; |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8682 | |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 8683 | if (is_valid_ether_addr(hw->mac.san_addr)) { |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8684 | rtnl_lock(); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 8685 | 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] | 8686 | rtnl_unlock(); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 8687 | |
| 8688 | /* update SAN MAC vmdq pool selection */ |
| 8689 | hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0)); |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8690 | } |
| 8691 | return err; |
| 8692 | } |
| 8693 | |
| 8694 | /** |
| 8695 | * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 8696 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8697 | * @netdev: network interface device structure |
| 8698 | * |
| 8699 | * Returns non-zero on failure |
| 8700 | **/ |
| 8701 | static int ixgbe_del_sanmac_netdev(struct net_device *dev) |
| 8702 | { |
| 8703 | int err = 0; |
| 8704 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 8705 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 8706 | |
| 8707 | if (is_valid_ether_addr(mac->san_addr)) { |
| 8708 | rtnl_lock(); |
| 8709 | err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 8710 | rtnl_unlock(); |
| 8711 | } |
| 8712 | return err; |
| 8713 | } |
| 8714 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8715 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 8716 | /* |
| 8717 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 8718 | * without having to re-enable interrupts. It's not called while |
| 8719 | * the interrupt routine is executing. |
| 8720 | */ |
| 8721 | static void ixgbe_netpoll(struct net_device *netdev) |
| 8722 | { |
| 8723 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 8724 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8725 | |
Alexander Duyck | 1a647bd | 2010-01-13 01:49:13 +0000 | [diff] [blame] | 8726 | /* if interface is down do nothing */ |
| 8727 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 8728 | return; |
| 8729 | |
Alexander Duyck | 856f606 | 2015-02-25 17:45:54 +0000 | [diff] [blame] | 8730 | /* loop through and schedule all active queues */ |
| 8731 | for (i = 0; i < adapter->num_q_vectors; i++) |
| 8732 | ixgbe_msix_clean_rings(0, adapter->q_vector[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8733 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8734 | |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 8735 | #endif |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 8736 | |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 8737 | static void ixgbe_get_ring_stats64(struct rtnl_link_stats64 *stats, |
| 8738 | struct ixgbe_ring *ring) |
| 8739 | { |
| 8740 | u64 bytes, packets; |
| 8741 | unsigned int start; |
| 8742 | |
| 8743 | if (ring) { |
| 8744 | do { |
| 8745 | start = u64_stats_fetch_begin_irq(&ring->syncp); |
| 8746 | packets = ring->stats.packets; |
| 8747 | bytes = ring->stats.bytes; |
| 8748 | } while (u64_stats_fetch_retry_irq(&ring->syncp, start)); |
| 8749 | stats->tx_packets += packets; |
| 8750 | stats->tx_bytes += bytes; |
| 8751 | } |
| 8752 | } |
| 8753 | |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 8754 | static void ixgbe_get_stats64(struct net_device *netdev, |
| 8755 | struct rtnl_link_stats64 *stats) |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8756 | { |
| 8757 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8758 | int i; |
| 8759 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8760 | rcu_read_lock(); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8761 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Mark Rutland | 6aa7de0 | 2017-10-23 14:07:29 -0700 | [diff] [blame] | 8762 | struct ixgbe_ring *ring = READ_ONCE(adapter->rx_ring[i]); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8763 | u64 bytes, packets; |
| 8764 | unsigned int start; |
| 8765 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8766 | if (ring) { |
| 8767 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 8768 | start = u64_stats_fetch_begin_irq(&ring->syncp); |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8769 | packets = ring->stats.packets; |
| 8770 | bytes = ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 8771 | } while (u64_stats_fetch_retry_irq(&ring->syncp, start)); |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8772 | stats->rx_packets += packets; |
| 8773 | stats->rx_bytes += bytes; |
| 8774 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8775 | } |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 8776 | |
| 8777 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Mark Rutland | 6aa7de0 | 2017-10-23 14:07:29 -0700 | [diff] [blame] | 8778 | struct ixgbe_ring *ring = READ_ONCE(adapter->tx_ring[i]); |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 8779 | |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 8780 | ixgbe_get_ring_stats64(stats, ring); |
| 8781 | } |
| 8782 | for (i = 0; i < adapter->num_xdp_queues; i++) { |
Mark Rutland | 6aa7de0 | 2017-10-23 14:07:29 -0700 | [diff] [blame] | 8783 | struct ixgbe_ring *ring = READ_ONCE(adapter->xdp_ring[i]); |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 8784 | |
| 8785 | ixgbe_get_ring_stats64(stats, ring); |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 8786 | } |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8787 | rcu_read_unlock(); |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 8788 | |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8789 | /* following stats updated by ixgbe_watchdog_task() */ |
| 8790 | stats->multicast = netdev->stats.multicast; |
| 8791 | stats->rx_errors = netdev->stats.rx_errors; |
| 8792 | stats->rx_length_errors = netdev->stats.rx_length_errors; |
| 8793 | stats->rx_crc_errors = netdev->stats.rx_crc_errors; |
| 8794 | stats->rx_missed_errors = netdev->stats.rx_missed_errors; |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8795 | } |
| 8796 | |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 8797 | #ifdef CONFIG_IXGBE_DCB |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 8798 | /** |
| 8799 | * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid. |
| 8800 | * @adapter: pointer to ixgbe_adapter |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8801 | * @tc: number of traffic classes currently enabled |
| 8802 | * |
| 8803 | * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm |
| 8804 | * 802.1Q priority maps to a packet buffer that exists. |
| 8805 | */ |
| 8806 | static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc) |
| 8807 | { |
| 8808 | struct ixgbe_hw *hw = &adapter->hw; |
| 8809 | u32 reg, rsave; |
| 8810 | int i; |
| 8811 | |
| 8812 | /* 82598 have a static priority to TC mapping that can not |
| 8813 | * be changed so no validation is needed. |
| 8814 | */ |
| 8815 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 8816 | return; |
| 8817 | |
| 8818 | reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC); |
| 8819 | rsave = reg; |
| 8820 | |
| 8821 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 8822 | u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT); |
| 8823 | |
| 8824 | /* If up2tc is out of bounds default to zero */ |
| 8825 | if (up2tc > tc) |
| 8826 | reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT); |
| 8827 | } |
| 8828 | |
| 8829 | if (reg != rsave) |
| 8830 | IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg); |
| 8831 | |
| 8832 | return; |
| 8833 | } |
| 8834 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 8835 | /** |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 8836 | * ixgbe_set_prio_tc_map - Configure netdev prio tc map |
| 8837 | * @adapter: Pointer to adapter struct |
| 8838 | * |
| 8839 | * Populate the netdev user priority to tc map |
| 8840 | */ |
| 8841 | static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter) |
| 8842 | { |
| 8843 | struct net_device *dev = adapter->netdev; |
| 8844 | struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg; |
| 8845 | struct ieee_ets *ets = adapter->ixgbe_ieee_ets; |
| 8846 | u8 prio; |
| 8847 | |
| 8848 | for (prio = 0; prio < MAX_USER_PRIORITY; prio++) { |
| 8849 | u8 tc = 0; |
| 8850 | |
| 8851 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) |
| 8852 | tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio); |
| 8853 | else if (ets) |
| 8854 | tc = ets->prio_tc[prio]; |
| 8855 | |
| 8856 | netdev_set_prio_tc_map(dev, prio, tc); |
| 8857 | } |
| 8858 | } |
| 8859 | |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 8860 | #endif /* CONFIG_IXGBE_DCB */ |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 8861 | /** |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 8862 | * ixgbe_setup_tc - configure net_device for multiple traffic classes |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8863 | * |
| 8864 | * @netdev: net device to configure |
| 8865 | * @tc: number of traffic classes to enable |
| 8866 | */ |
| 8867 | int ixgbe_setup_tc(struct net_device *dev, u8 tc) |
| 8868 | { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8869 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 8870 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8871 | bool pools; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8872 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8873 | /* Hardware supports up to 8 traffic classes */ |
Emil Tantilov | 7e3f5c8 | 2015-07-09 12:28:59 -0700 | [diff] [blame] | 8874 | if (tc > adapter->dcb_cfg.num_tcs.pg_tcs) |
| 8875 | return -EINVAL; |
| 8876 | |
| 8877 | if (hw->mac.type == ixgbe_mac_82598EB && tc && tc < MAX_TRAFFIC_CLASS) |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8878 | return -EINVAL; |
| 8879 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8880 | pools = (find_first_zero_bit(&adapter->fwd_bitmask, 32) > 1); |
| 8881 | if (tc && pools && adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS) |
| 8882 | return -EBUSY; |
| 8883 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8884 | /* Hardware has to reinitialize queues and interrupts to |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 8885 | * match packet buffer alignment. Unfortunately, the |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8886 | * hardware is not flexible enough to do this dynamically. |
| 8887 | */ |
| 8888 | if (netif_running(dev)) |
| 8889 | ixgbe_close(dev); |
Alexander Duyck | bf4d67d | 2015-10-20 13:28:17 -0700 | [diff] [blame] | 8890 | else |
| 8891 | ixgbe_reset(adapter); |
| 8892 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8893 | ixgbe_clear_interrupt_scheme(adapter); |
| 8894 | |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 8895 | #ifdef CONFIG_IXGBE_DCB |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8896 | if (tc) { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8897 | netdev_set_num_tc(dev, tc); |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 8898 | ixgbe_set_prio_tc_map(adapter); |
| 8899 | |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8900 | adapter->flags |= IXGBE_FLAG_DCB_ENABLED; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8901 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 8902 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 8903 | adapter->last_lfc_mode = adapter->hw.fc.requested_mode; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8904 | adapter->hw.fc.requested_mode = ixgbe_fc_none; |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 8905 | } |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8906 | } else { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8907 | netdev_reset_tc(dev); |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 8908 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 8909 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 8910 | adapter->hw.fc.requested_mode = adapter->last_lfc_mode; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8911 | |
| 8912 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8913 | |
| 8914 | adapter->temp_dcb_cfg.pfc_mode_enable = false; |
| 8915 | adapter->dcb_cfg.pfc_mode_enable = false; |
| 8916 | } |
| 8917 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8918 | ixgbe_validate_rtr(adapter, tc); |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 8919 | |
| 8920 | #endif /* CONFIG_IXGBE_DCB */ |
| 8921 | ixgbe_init_interrupt_scheme(adapter); |
| 8922 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8923 | if (netif_running(dev)) |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 8924 | return ixgbe_open(dev); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8925 | |
| 8926 | return 0; |
| 8927 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8928 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8929 | static int ixgbe_delete_clsu32(struct ixgbe_adapter *adapter, |
| 8930 | struct tc_cls_u32_offload *cls) |
| 8931 | { |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8932 | u32 hdl = cls->knode.handle; |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8933 | u32 uhtid = TC_U32_USERHTID(cls->knode.handle); |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8934 | u32 loc = cls->knode.handle & 0xfffff; |
| 8935 | int err = 0, i, j; |
| 8936 | struct ixgbe_jump_table *jump = NULL; |
| 8937 | |
| 8938 | if (loc > IXGBE_MAX_HW_ENTRIES) |
| 8939 | return -EINVAL; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8940 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8941 | if ((uhtid != 0x800) && (uhtid >= IXGBE_MAX_LINK_HANDLE)) |
| 8942 | return -EINVAL; |
| 8943 | |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8944 | /* Clear this filter in the link data it is associated with */ |
| 8945 | if (uhtid != 0x800) { |
| 8946 | jump = adapter->jump_tables[uhtid]; |
Amritha Nambiar | 12746fd | 2016-05-16 18:33:20 -0700 | [diff] [blame] | 8947 | if (!jump) |
| 8948 | return -EINVAL; |
| 8949 | if (!test_bit(loc - 1, jump->child_loc_map)) |
| 8950 | return -EINVAL; |
| 8951 | clear_bit(loc - 1, jump->child_loc_map); |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8952 | } |
| 8953 | |
| 8954 | /* Check if the filter being deleted is a link */ |
| 8955 | for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) { |
| 8956 | jump = adapter->jump_tables[i]; |
| 8957 | if (jump && jump->link_hdl == hdl) { |
| 8958 | /* Delete filters in the hardware in the child hash |
| 8959 | * table associated with this link |
| 8960 | */ |
| 8961 | for (j = 0; j < IXGBE_MAX_HW_ENTRIES; j++) { |
| 8962 | if (!test_bit(j, jump->child_loc_map)) |
| 8963 | continue; |
| 8964 | spin_lock(&adapter->fdir_perfect_lock); |
| 8965 | err = ixgbe_update_ethtool_fdir_entry(adapter, |
| 8966 | NULL, |
| 8967 | j + 1); |
| 8968 | spin_unlock(&adapter->fdir_perfect_lock); |
| 8969 | clear_bit(j, jump->child_loc_map); |
| 8970 | } |
| 8971 | /* Remove resources for this link */ |
| 8972 | kfree(jump->input); |
| 8973 | kfree(jump->mask); |
| 8974 | kfree(jump); |
| 8975 | adapter->jump_tables[i] = NULL; |
| 8976 | return err; |
| 8977 | } |
| 8978 | } |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8979 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8980 | spin_lock(&adapter->fdir_perfect_lock); |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8981 | err = ixgbe_update_ethtool_fdir_entry(adapter, NULL, loc); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8982 | spin_unlock(&adapter->fdir_perfect_lock); |
| 8983 | return err; |
| 8984 | } |
| 8985 | |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8986 | static int ixgbe_configure_clsu32_add_hnode(struct ixgbe_adapter *adapter, |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8987 | struct tc_cls_u32_offload *cls) |
| 8988 | { |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8989 | u32 uhtid = TC_U32_USERHTID(cls->hnode.handle); |
| 8990 | |
| 8991 | if (uhtid >= IXGBE_MAX_LINK_HANDLE) |
| 8992 | return -EINVAL; |
| 8993 | |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8994 | /* This ixgbe devices do not support hash tables at the moment |
| 8995 | * so abort when given hash tables. |
| 8996 | */ |
| 8997 | if (cls->hnode.divisor > 0) |
| 8998 | return -EINVAL; |
| 8999 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 9000 | set_bit(uhtid - 1, &adapter->tables); |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 9001 | return 0; |
| 9002 | } |
| 9003 | |
| 9004 | static int ixgbe_configure_clsu32_del_hnode(struct ixgbe_adapter *adapter, |
| 9005 | struct tc_cls_u32_offload *cls) |
| 9006 | { |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 9007 | u32 uhtid = TC_U32_USERHTID(cls->hnode.handle); |
| 9008 | |
| 9009 | if (uhtid >= IXGBE_MAX_LINK_HANDLE) |
| 9010 | return -EINVAL; |
| 9011 | |
| 9012 | clear_bit(uhtid - 1, &adapter->tables); |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 9013 | return 0; |
| 9014 | } |
| 9015 | |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 9016 | #ifdef CONFIG_NET_CLS_ACT |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 9017 | struct upper_walk_data { |
| 9018 | struct ixgbe_adapter *adapter; |
| 9019 | u64 action; |
| 9020 | int ifindex; |
| 9021 | u8 queue; |
| 9022 | }; |
| 9023 | |
| 9024 | static int get_macvlan_queue(struct net_device *upper, void *_data) |
| 9025 | { |
| 9026 | if (netif_is_macvlan(upper)) { |
| 9027 | struct macvlan_dev *dfwd = netdev_priv(upper); |
| 9028 | struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv; |
| 9029 | struct upper_walk_data *data = _data; |
| 9030 | struct ixgbe_adapter *adapter = data->adapter; |
| 9031 | int ifindex = data->ifindex; |
| 9032 | |
| 9033 | if (vadapter && vadapter->netdev->ifindex == ifindex) { |
| 9034 | data->queue = adapter->rx_ring[vadapter->rx_base_queue]->reg_idx; |
| 9035 | data->action = data->queue; |
| 9036 | return 1; |
| 9037 | } |
| 9038 | } |
| 9039 | |
| 9040 | return 0; |
| 9041 | } |
| 9042 | |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 9043 | static int handle_redirect_action(struct ixgbe_adapter *adapter, int ifindex, |
| 9044 | u8 *queue, u64 *action) |
| 9045 | { |
Alexander Duyck | 361b534 | 2017-11-22 10:56:16 -0800 | [diff] [blame^] | 9046 | struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ]; |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 9047 | unsigned int num_vfs = adapter->num_vfs, vf; |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 9048 | struct upper_walk_data data; |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 9049 | struct net_device *upper; |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 9050 | |
| 9051 | /* redirect to a SRIOV VF */ |
| 9052 | for (vf = 0; vf < num_vfs; ++vf) { |
| 9053 | upper = pci_get_drvdata(adapter->vfinfo[vf].vfdev); |
| 9054 | if (upper->ifindex == ifindex) { |
Alexander Duyck | 361b534 | 2017-11-22 10:56:16 -0800 | [diff] [blame^] | 9055 | *queue = vf * __ALIGN_MASK(1, ~vmdq->mask); |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 9056 | *action = vf + 1; |
| 9057 | *action <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF; |
| 9058 | return 0; |
| 9059 | } |
| 9060 | } |
| 9061 | |
| 9062 | /* redirect to a offloaded macvlan netdev */ |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 9063 | data.adapter = adapter; |
| 9064 | data.ifindex = ifindex; |
| 9065 | data.action = 0; |
| 9066 | data.queue = 0; |
| 9067 | if (netdev_walk_all_upper_dev_rcu(adapter->netdev, |
| 9068 | get_macvlan_queue, &data)) { |
| 9069 | *action = data.action; |
| 9070 | *queue = data.queue; |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 9071 | |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 9072 | return 0; |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 9073 | } |
| 9074 | |
| 9075 | return -EINVAL; |
| 9076 | } |
| 9077 | |
| 9078 | static int parse_tc_actions(struct ixgbe_adapter *adapter, |
| 9079 | struct tcf_exts *exts, u64 *action, u8 *queue) |
| 9080 | { |
| 9081 | const struct tc_action *a; |
WANG Cong | 22dc13c | 2016-08-13 22:35:00 -0700 | [diff] [blame] | 9082 | LIST_HEAD(actions); |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 9083 | int err; |
| 9084 | |
Jiri Pirko | 3bcc0ce | 2017-08-04 14:28:58 +0200 | [diff] [blame] | 9085 | if (!tcf_exts_has_actions(exts)) |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 9086 | return -EINVAL; |
| 9087 | |
WANG Cong | 22dc13c | 2016-08-13 22:35:00 -0700 | [diff] [blame] | 9088 | tcf_exts_to_list(exts, &actions); |
| 9089 | list_for_each_entry(a, &actions, list) { |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 9090 | |
| 9091 | /* Drop action */ |
| 9092 | if (is_tcf_gact_shot(a)) { |
| 9093 | *action = IXGBE_FDIR_DROP_QUEUE; |
| 9094 | *queue = IXGBE_FDIR_DROP_QUEUE; |
| 9095 | return 0; |
| 9096 | } |
| 9097 | |
| 9098 | /* Redirect to a VF or a offloaded macvlan */ |
Shmulik Ladkani | 5724b8b | 2016-10-13 09:06:43 +0300 | [diff] [blame] | 9099 | if (is_tcf_mirred_egress_redirect(a)) { |
Cong Wang | 9f8a739 | 2017-12-05 16:17:26 -0800 | [diff] [blame] | 9100 | struct net_device *dev = tcf_mirred_dev(a); |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 9101 | |
Cong Wang | 9f8a739 | 2017-12-05 16:17:26 -0800 | [diff] [blame] | 9102 | if (!dev) |
| 9103 | return -EINVAL; |
| 9104 | err = handle_redirect_action(adapter, dev->ifindex, queue, |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 9105 | action); |
| 9106 | if (err == 0) |
| 9107 | return err; |
| 9108 | } |
| 9109 | } |
| 9110 | |
| 9111 | return -EINVAL; |
| 9112 | } |
| 9113 | #else |
| 9114 | static int parse_tc_actions(struct ixgbe_adapter *adapter, |
| 9115 | struct tcf_exts *exts, u64 *action, u8 *queue) |
| 9116 | { |
| 9117 | return -EINVAL; |
| 9118 | } |
| 9119 | #endif /* CONFIG_NET_CLS_ACT */ |
| 9120 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9121 | static int ixgbe_clsu32_build_input(struct ixgbe_fdir_filter *input, |
| 9122 | union ixgbe_atr_input *mask, |
| 9123 | struct tc_cls_u32_offload *cls, |
| 9124 | struct ixgbe_mat_field *field_ptr, |
| 9125 | struct ixgbe_nexthdr *nexthdr) |
| 9126 | { |
| 9127 | int i, j, off; |
| 9128 | __be32 val, m; |
| 9129 | bool found_entry = false, found_jump_field = false; |
| 9130 | |
| 9131 | for (i = 0; i < cls->knode.sel->nkeys; i++) { |
| 9132 | off = cls->knode.sel->keys[i].off; |
| 9133 | val = cls->knode.sel->keys[i].val; |
| 9134 | m = cls->knode.sel->keys[i].mask; |
| 9135 | |
| 9136 | for (j = 0; field_ptr[j].val; j++) { |
| 9137 | if (field_ptr[j].off == off) { |
| 9138 | field_ptr[j].val(input, mask, val, m); |
| 9139 | input->filter.formatted.flow_type |= |
| 9140 | field_ptr[j].type; |
| 9141 | found_entry = true; |
| 9142 | break; |
| 9143 | } |
| 9144 | } |
| 9145 | if (nexthdr) { |
| 9146 | if (nexthdr->off == cls->knode.sel->keys[i].off && |
| 9147 | nexthdr->val == cls->knode.sel->keys[i].val && |
| 9148 | nexthdr->mask == cls->knode.sel->keys[i].mask) |
| 9149 | found_jump_field = true; |
| 9150 | else |
| 9151 | continue; |
| 9152 | } |
| 9153 | } |
| 9154 | |
| 9155 | if (nexthdr && !found_jump_field) |
| 9156 | return -EINVAL; |
| 9157 | |
| 9158 | if (!found_entry) |
| 9159 | return 0; |
| 9160 | |
| 9161 | mask->formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK | |
| 9162 | IXGBE_ATR_L4TYPE_MASK; |
| 9163 | |
| 9164 | if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4) |
| 9165 | mask->formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK; |
| 9166 | |
| 9167 | return 0; |
| 9168 | } |
| 9169 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9170 | static int ixgbe_configure_clsu32(struct ixgbe_adapter *adapter, |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9171 | struct tc_cls_u32_offload *cls) |
| 9172 | { |
Jiri Pirko | 5fd9fc4 | 2017-08-07 10:15:29 +0200 | [diff] [blame] | 9173 | __be16 protocol = cls->common.protocol; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9174 | u32 loc = cls->knode.handle & 0xfffff; |
| 9175 | struct ixgbe_hw *hw = &adapter->hw; |
| 9176 | struct ixgbe_mat_field *field_ptr; |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9177 | struct ixgbe_fdir_filter *input = NULL; |
| 9178 | union ixgbe_atr_input *mask = NULL; |
| 9179 | struct ixgbe_jump_table *jump = NULL; |
| 9180 | int i, err = -EINVAL; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9181 | u8 queue; |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 9182 | u32 uhtid, link_uhtid; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9183 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 9184 | uhtid = TC_U32_USERHTID(cls->knode.handle); |
| 9185 | link_uhtid = TC_U32_USERHTID(cls->knode.link_handle); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9186 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 9187 | /* At the moment cls_u32 jumps to network layer and skips past |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9188 | * L2 headers. The canonical method to match L2 frames is to use |
| 9189 | * negative values. However this is error prone at best but really |
| 9190 | * 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] | 9191 | * 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] | 9192 | * headers when needed. |
| 9193 | */ |
| 9194 | if (protocol != htons(ETH_P_IP)) |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9195 | return err; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9196 | |
| 9197 | if (loc >= ((1024 << adapter->fdir_pballoc) - 2)) { |
| 9198 | e_err(drv, "Location out of range\n"); |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9199 | return err; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9200 | } |
| 9201 | |
| 9202 | /* cls u32 is a graph starting at root node 0x800. The driver tracks |
| 9203 | * links and also the fields used to advance the parser across each |
| 9204 | * link (e.g. nexthdr/eat parameters from 'tc'). This way we can map |
| 9205 | * the u32 graph onto the hardware parse graph denoted in ixgbe_model.h |
| 9206 | * To add support for new nodes update ixgbe_model.h parse structures |
| 9207 | * this function _should_ be generic try not to hardcode values here. |
| 9208 | */ |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 9209 | if (uhtid == 0x800) { |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9210 | field_ptr = (adapter->jump_tables[0])->mat; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9211 | } else { |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 9212 | if (uhtid >= IXGBE_MAX_LINK_HANDLE) |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9213 | return err; |
| 9214 | if (!adapter->jump_tables[uhtid]) |
| 9215 | return err; |
| 9216 | field_ptr = (adapter->jump_tables[uhtid])->mat; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9217 | } |
| 9218 | |
| 9219 | if (!field_ptr) |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9220 | return err; |
| 9221 | |
| 9222 | /* At this point we know the field_ptr is valid and need to either |
| 9223 | * build cls_u32 link or attach filter. Because adding a link to |
| 9224 | * a handle that does not exist is invalid and the same for adding |
| 9225 | * rules to handles that don't exist. |
| 9226 | */ |
| 9227 | |
| 9228 | if (link_uhtid) { |
| 9229 | struct ixgbe_nexthdr *nexthdr = ixgbe_ipv4_jumps; |
| 9230 | |
| 9231 | if (link_uhtid >= IXGBE_MAX_LINK_HANDLE) |
| 9232 | return err; |
| 9233 | |
| 9234 | if (!test_bit(link_uhtid - 1, &adapter->tables)) |
| 9235 | return err; |
| 9236 | |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 9237 | /* Multiple filters as links to the same hash table are not |
| 9238 | * supported. To add a new filter with the same next header |
| 9239 | * but different match/jump conditions, create a new hash table |
| 9240 | * and link to it. |
| 9241 | */ |
| 9242 | if (adapter->jump_tables[link_uhtid] && |
| 9243 | (adapter->jump_tables[link_uhtid])->link_hdl) { |
| 9244 | e_err(drv, "Link filter exists for link: %x\n", |
| 9245 | link_uhtid); |
| 9246 | return err; |
| 9247 | } |
| 9248 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9249 | for (i = 0; nexthdr[i].jump; i++) { |
| 9250 | if (nexthdr[i].o != cls->knode.sel->offoff || |
| 9251 | nexthdr[i].s != cls->knode.sel->offshift || |
| 9252 | nexthdr[i].m != cls->knode.sel->offmask) |
| 9253 | return err; |
| 9254 | |
| 9255 | jump = kzalloc(sizeof(*jump), GFP_KERNEL); |
| 9256 | if (!jump) |
| 9257 | return -ENOMEM; |
| 9258 | input = kzalloc(sizeof(*input), GFP_KERNEL); |
| 9259 | if (!input) { |
| 9260 | err = -ENOMEM; |
| 9261 | goto free_jump; |
| 9262 | } |
| 9263 | mask = kzalloc(sizeof(*mask), GFP_KERNEL); |
| 9264 | if (!mask) { |
| 9265 | err = -ENOMEM; |
Amritha Nambiar | 12746fd | 2016-05-16 18:33:20 -0700 | [diff] [blame] | 9266 | goto free_input; |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9267 | } |
| 9268 | jump->input = input; |
| 9269 | jump->mask = mask; |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 9270 | jump->link_hdl = cls->knode.handle; |
| 9271 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9272 | err = ixgbe_clsu32_build_input(input, mask, cls, |
| 9273 | field_ptr, &nexthdr[i]); |
| 9274 | if (!err) { |
| 9275 | jump->mat = nexthdr[i].jump; |
| 9276 | adapter->jump_tables[link_uhtid] = jump; |
| 9277 | break; |
| 9278 | } |
| 9279 | } |
| 9280 | return 0; |
| 9281 | } |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9282 | |
| 9283 | input = kzalloc(sizeof(*input), GFP_KERNEL); |
| 9284 | if (!input) |
| 9285 | return -ENOMEM; |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9286 | mask = kzalloc(sizeof(*mask), GFP_KERNEL); |
| 9287 | if (!mask) { |
| 9288 | err = -ENOMEM; |
Amritha Nambiar | 12746fd | 2016-05-16 18:33:20 -0700 | [diff] [blame] | 9289 | goto free_input; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9290 | } |
| 9291 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9292 | if ((uhtid != 0x800) && (adapter->jump_tables[uhtid])) { |
| 9293 | if ((adapter->jump_tables[uhtid])->input) |
| 9294 | memcpy(input, (adapter->jump_tables[uhtid])->input, |
| 9295 | sizeof(*input)); |
| 9296 | if ((adapter->jump_tables[uhtid])->mask) |
| 9297 | memcpy(mask, (adapter->jump_tables[uhtid])->mask, |
| 9298 | sizeof(*mask)); |
Amritha Nambiar | 12746fd | 2016-05-16 18:33:20 -0700 | [diff] [blame] | 9299 | |
| 9300 | /* Lookup in all child hash tables if this location is already |
| 9301 | * filled with a filter |
| 9302 | */ |
| 9303 | for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) { |
| 9304 | struct ixgbe_jump_table *link = adapter->jump_tables[i]; |
| 9305 | |
| 9306 | if (link && (test_bit(loc - 1, link->child_loc_map))) { |
| 9307 | e_err(drv, "Filter exists in location: %x\n", |
| 9308 | loc); |
| 9309 | err = -EINVAL; |
| 9310 | goto err_out; |
| 9311 | } |
| 9312 | } |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9313 | } |
| 9314 | err = ixgbe_clsu32_build_input(input, mask, cls, field_ptr, NULL); |
| 9315 | if (err) |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9316 | goto err_out; |
| 9317 | |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 9318 | err = parse_tc_actions(adapter, cls->knode.exts, &input->action, |
| 9319 | &queue); |
| 9320 | if (err < 0) |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9321 | goto err_out; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9322 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9323 | input->sw_idx = loc; |
| 9324 | |
| 9325 | spin_lock(&adapter->fdir_perfect_lock); |
| 9326 | |
| 9327 | if (hlist_empty(&adapter->fdir_filter_list)) { |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9328 | memcpy(&adapter->fdir_mask, mask, sizeof(*mask)); |
| 9329 | err = ixgbe_fdir_set_input_mask_82599(hw, mask); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9330 | if (err) |
| 9331 | goto err_out_w_lock; |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9332 | } else if (memcmp(&adapter->fdir_mask, mask, sizeof(*mask))) { |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9333 | err = -EINVAL; |
| 9334 | goto err_out_w_lock; |
| 9335 | } |
| 9336 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9337 | ixgbe_atr_compute_perfect_hash_82599(&input->filter, mask); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9338 | err = ixgbe_fdir_write_perfect_filter_82599(hw, &input->filter, |
| 9339 | input->sw_idx, queue); |
| 9340 | if (!err) |
| 9341 | ixgbe_update_ethtool_fdir_entry(adapter, input, input->sw_idx); |
| 9342 | spin_unlock(&adapter->fdir_perfect_lock); |
| 9343 | |
Amritha Nambiar | 12746fd | 2016-05-16 18:33:20 -0700 | [diff] [blame] | 9344 | if ((uhtid != 0x800) && (adapter->jump_tables[uhtid])) |
| 9345 | set_bit(loc - 1, (adapter->jump_tables[uhtid])->child_loc_map); |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 9346 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9347 | kfree(mask); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9348 | return err; |
| 9349 | err_out_w_lock: |
| 9350 | spin_unlock(&adapter->fdir_perfect_lock); |
| 9351 | err_out: |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 9352 | kfree(mask); |
Amritha Nambiar | 12746fd | 2016-05-16 18:33:20 -0700 | [diff] [blame] | 9353 | free_input: |
| 9354 | kfree(input); |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9355 | free_jump: |
| 9356 | kfree(jump); |
| 9357 | return err; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9358 | } |
| 9359 | |
Jiri Pirko | 6ea30f8 | 2017-10-19 15:50:41 +0200 | [diff] [blame] | 9360 | static int ixgbe_setup_tc_cls_u32(struct ixgbe_adapter *adapter, |
Jiri Pirko | bc32afd | 2017-08-07 10:15:21 +0200 | [diff] [blame] | 9361 | struct tc_cls_u32_offload *cls_u32) |
| 9362 | { |
Jiri Pirko | 6ea30f8 | 2017-10-19 15:50:41 +0200 | [diff] [blame] | 9363 | if (cls_u32->common.chain_index) |
Jiri Pirko | bc32afd | 2017-08-07 10:15:21 +0200 | [diff] [blame] | 9364 | return -EOPNOTSUPP; |
| 9365 | |
| 9366 | switch (cls_u32->command) { |
| 9367 | case TC_CLSU32_NEW_KNODE: |
| 9368 | case TC_CLSU32_REPLACE_KNODE: |
Jiri Pirko | 5fd9fc4 | 2017-08-07 10:15:29 +0200 | [diff] [blame] | 9369 | return ixgbe_configure_clsu32(adapter, cls_u32); |
Jiri Pirko | bc32afd | 2017-08-07 10:15:21 +0200 | [diff] [blame] | 9370 | case TC_CLSU32_DELETE_KNODE: |
| 9371 | return ixgbe_delete_clsu32(adapter, cls_u32); |
| 9372 | case TC_CLSU32_NEW_HNODE: |
| 9373 | case TC_CLSU32_REPLACE_HNODE: |
Jiri Pirko | 5fd9fc4 | 2017-08-07 10:15:29 +0200 | [diff] [blame] | 9374 | return ixgbe_configure_clsu32_add_hnode(adapter, cls_u32); |
Jiri Pirko | bc32afd | 2017-08-07 10:15:21 +0200 | [diff] [blame] | 9375 | case TC_CLSU32_DELETE_HNODE: |
| 9376 | return ixgbe_configure_clsu32_del_hnode(adapter, cls_u32); |
| 9377 | default: |
| 9378 | return -EOPNOTSUPP; |
| 9379 | } |
| 9380 | } |
| 9381 | |
Jiri Pirko | 6ea30f8 | 2017-10-19 15:50:41 +0200 | [diff] [blame] | 9382 | static int ixgbe_setup_tc_block_cb(enum tc_setup_type type, void *type_data, |
| 9383 | void *cb_priv) |
| 9384 | { |
| 9385 | struct ixgbe_adapter *adapter = cb_priv; |
| 9386 | |
Jiri Pirko | 44ae12a | 2017-11-01 11:47:39 +0100 | [diff] [blame] | 9387 | if (!tc_can_offload(adapter->netdev)) |
| 9388 | return -EOPNOTSUPP; |
| 9389 | |
Jiri Pirko | 6ea30f8 | 2017-10-19 15:50:41 +0200 | [diff] [blame] | 9390 | switch (type) { |
| 9391 | case TC_SETUP_CLSU32: |
| 9392 | return ixgbe_setup_tc_cls_u32(adapter, type_data); |
| 9393 | default: |
| 9394 | return -EOPNOTSUPP; |
| 9395 | } |
| 9396 | } |
| 9397 | |
| 9398 | static int ixgbe_setup_tc_block(struct net_device *dev, |
| 9399 | struct tc_block_offload *f) |
| 9400 | { |
| 9401 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 9402 | |
| 9403 | if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS) |
| 9404 | return -EOPNOTSUPP; |
| 9405 | |
| 9406 | switch (f->command) { |
| 9407 | case TC_BLOCK_BIND: |
| 9408 | return tcf_block_cb_register(f->block, ixgbe_setup_tc_block_cb, |
| 9409 | adapter, adapter); |
| 9410 | case TC_BLOCK_UNBIND: |
| 9411 | tcf_block_cb_unregister(f->block, ixgbe_setup_tc_block_cb, |
| 9412 | adapter); |
| 9413 | return 0; |
| 9414 | default: |
| 9415 | return -EOPNOTSUPP; |
| 9416 | } |
| 9417 | } |
| 9418 | |
Jiri Pirko | bc32afd | 2017-08-07 10:15:21 +0200 | [diff] [blame] | 9419 | static int ixgbe_setup_tc_mqprio(struct net_device *dev, |
| 9420 | struct tc_mqprio_qopt *mqprio) |
| 9421 | { |
| 9422 | mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS; |
| 9423 | return ixgbe_setup_tc(dev, mqprio->num_tc); |
| 9424 | } |
| 9425 | |
Jiri Pirko | 2572ac5 | 2017-08-07 10:15:17 +0200 | [diff] [blame] | 9426 | static int __ixgbe_setup_tc(struct net_device *dev, enum tc_setup_type type, |
Jiri Pirko | de4784c | 2017-08-07 10:15:32 +0200 | [diff] [blame] | 9427 | void *type_data) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 9428 | { |
Jiri Pirko | bc32afd | 2017-08-07 10:15:21 +0200 | [diff] [blame] | 9429 | switch (type) { |
Jiri Pirko | 6ea30f8 | 2017-10-19 15:50:41 +0200 | [diff] [blame] | 9430 | case TC_SETUP_BLOCK: |
| 9431 | return ixgbe_setup_tc_block(dev, type_data); |
Nogah Frankel | 575ed7d | 2017-11-06 07:23:42 +0100 | [diff] [blame] | 9432 | case TC_SETUP_QDISC_MQPRIO: |
Jiri Pirko | de4784c | 2017-08-07 10:15:32 +0200 | [diff] [blame] | 9433 | return ixgbe_setup_tc_mqprio(dev, type_data); |
Jiri Pirko | bc32afd | 2017-08-07 10:15:21 +0200 | [diff] [blame] | 9434 | default: |
Jiri Pirko | a5fcf8a | 2017-06-06 17:00:16 +0200 | [diff] [blame] | 9435 | return -EOPNOTSUPP; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9436 | } |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 9437 | } |
| 9438 | |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 9439 | #ifdef CONFIG_PCI_IOV |
| 9440 | void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter) |
| 9441 | { |
| 9442 | struct net_device *netdev = adapter->netdev; |
| 9443 | |
| 9444 | rtnl_lock(); |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 9445 | ixgbe_setup_tc(netdev, netdev_get_num_tc(netdev)); |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 9446 | rtnl_unlock(); |
| 9447 | } |
| 9448 | |
| 9449 | #endif |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9450 | void ixgbe_do_reset(struct net_device *netdev) |
| 9451 | { |
| 9452 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 9453 | |
| 9454 | if (netif_running(netdev)) |
| 9455 | ixgbe_reinit_locked(adapter); |
| 9456 | else |
| 9457 | ixgbe_reset(adapter); |
| 9458 | } |
| 9459 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 9460 | static netdev_features_t ixgbe_fix_features(struct net_device *netdev, |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9461 | netdev_features_t features) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9462 | { |
| 9463 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 9464 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9465 | /* If Rx checksum is disabled, then RSC/LRO should also be disabled */ |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9466 | if (!(features & NETIF_F_RXCSUM)) |
| 9467 | features &= ~NETIF_F_LRO; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9468 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9469 | /* Turn off LRO if not RSC capable */ |
| 9470 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) |
| 9471 | features &= ~NETIF_F_LRO; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9472 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9473 | return features; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9474 | } |
| 9475 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 9476 | static int ixgbe_set_features(struct net_device *netdev, |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9477 | netdev_features_t features) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9478 | { |
| 9479 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9480 | netdev_features_t changed = netdev->features ^ features; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9481 | bool need_reset = false; |
| 9482 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9483 | /* Make sure RSC matches LRO, reset if change */ |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9484 | if (!(features & NETIF_F_LRO)) { |
| 9485 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9486 | need_reset = true; |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9487 | adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED; |
| 9488 | } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) && |
| 9489 | !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) { |
| 9490 | if (adapter->rx_itr_setting == 1 || |
| 9491 | adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) { |
| 9492 | adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED; |
| 9493 | need_reset = true; |
| 9494 | } else if ((changed ^ features) & NETIF_F_LRO) { |
| 9495 | e_info(probe, "rx-usecs set too low, " |
| 9496 | "disabling RSC\n"); |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9497 | } |
| 9498 | } |
| 9499 | |
| 9500 | /* |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9501 | * Check if Flow Director n-tuple support or hw_tc support was |
| 9502 | * enabled or disabled. If the state changed, we need to reset. |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9503 | */ |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9504 | if ((features & NETIF_F_NTUPLE) || (features & NETIF_F_HW_TC)) { |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9505 | /* turn off ATR, enable perfect filters and reset */ |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 9506 | if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) |
| 9507 | need_reset = true; |
| 9508 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9509 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 9510 | adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9511 | } else { |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 9512 | /* turn off perfect filters, enable ATR and reset */ |
| 9513 | if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 9514 | need_reset = true; |
| 9515 | |
| 9516 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 9517 | |
| 9518 | /* We cannot enable ATR if SR-IOV is enabled */ |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9519 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED || |
| 9520 | /* We cannot enable ATR if we have 2 or more tcs */ |
| 9521 | (netdev_get_num_tc(netdev) > 1) || |
| 9522 | /* We cannot enable ATR if RSS is disabled */ |
| 9523 | (adapter->ring_feature[RING_F_RSS].limit <= 1) || |
| 9524 | /* A sample rate of 0 indicates ATR disabled */ |
| 9525 | (!adapter->atr_sample_rate)) |
| 9526 | ; /* do nothing not supported */ |
| 9527 | else /* otherwise supported and set the flag */ |
| 9528 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9529 | } |
| 9530 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 9531 | if (changed & NETIF_F_RXALL) |
| 9532 | need_reset = true; |
| 9533 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9534 | netdev->features = features; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 9535 | |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 9536 | if ((adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) { |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9537 | if (features & NETIF_F_RXCSUM) { |
| 9538 | adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED; |
| 9539 | } else { |
| 9540 | u32 port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK; |
| 9541 | |
| 9542 | ixgbe_clear_udp_tunnel_port(adapter, port_mask); |
| 9543 | } |
| 9544 | } |
| 9545 | |
| 9546 | if ((adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)) { |
| 9547 | if (features & NETIF_F_RXCSUM) { |
| 9548 | adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED; |
| 9549 | } else { |
| 9550 | u32 port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK; |
| 9551 | |
| 9552 | ixgbe_clear_udp_tunnel_port(adapter, port_mask); |
| 9553 | } |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 9554 | } |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 9555 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9556 | if (need_reset) |
| 9557 | ixgbe_do_reset(netdev); |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 9558 | else if (changed & (NETIF_F_HW_VLAN_CTAG_RX | |
| 9559 | NETIF_F_HW_VLAN_CTAG_FILTER)) |
| 9560 | ixgbe_set_rx_mode(netdev); |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9561 | |
| 9562 | return 0; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9563 | } |
| 9564 | |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9565 | /** |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9566 | * ixgbe_add_udp_tunnel_port - Get notifications about adding UDP tunnel ports |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9567 | * @dev: The port's netdev |
Sabrina Dubroca | e5de25d | 2016-07-11 13:12:28 +0200 | [diff] [blame] | 9568 | * @ti: Tunnel endpoint information |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9569 | **/ |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9570 | static void ixgbe_add_udp_tunnel_port(struct net_device *dev, |
| 9571 | struct udp_tunnel_info *ti) |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9572 | { |
| 9573 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 9574 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 9575 | __be16 port = ti->port; |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9576 | u32 port_shift = 0; |
| 9577 | u32 reg; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 9578 | |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 9579 | if (ti->sa_family != AF_INET) |
| 9580 | return; |
| 9581 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9582 | switch (ti->type) { |
| 9583 | case UDP_TUNNEL_TYPE_VXLAN: |
| 9584 | if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) |
| 9585 | return; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9586 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9587 | if (adapter->vxlan_port == port) |
| 9588 | return; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9589 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9590 | if (adapter->vxlan_port) { |
| 9591 | netdev_info(dev, |
| 9592 | "VXLAN port %d set, not adding port %d\n", |
| 9593 | ntohs(adapter->vxlan_port), |
| 9594 | ntohs(port)); |
| 9595 | return; |
| 9596 | } |
| 9597 | |
| 9598 | adapter->vxlan_port = port; |
| 9599 | break; |
| 9600 | case UDP_TUNNEL_TYPE_GENEVE: |
| 9601 | if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)) |
| 9602 | return; |
| 9603 | |
| 9604 | if (adapter->geneve_port == port) |
| 9605 | return; |
| 9606 | |
| 9607 | if (adapter->geneve_port) { |
| 9608 | netdev_info(dev, |
| 9609 | "GENEVE port %d set, not adding port %d\n", |
| 9610 | ntohs(adapter->geneve_port), |
| 9611 | ntohs(port)); |
| 9612 | return; |
| 9613 | } |
| 9614 | |
| 9615 | port_shift = IXGBE_VXLANCTRL_GENEVE_UDPPORT_SHIFT; |
| 9616 | adapter->geneve_port = port; |
| 9617 | break; |
| 9618 | default: |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9619 | return; |
| 9620 | } |
| 9621 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9622 | reg = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) | ntohs(port) << port_shift; |
| 9623 | IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, reg); |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9624 | } |
| 9625 | |
| 9626 | /** |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9627 | * ixgbe_del_udp_tunnel_port - Get notifications about removing UDP tunnel ports |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9628 | * @dev: The port's netdev |
Sabrina Dubroca | e5de25d | 2016-07-11 13:12:28 +0200 | [diff] [blame] | 9629 | * @ti: Tunnel endpoint information |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9630 | **/ |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9631 | static void ixgbe_del_udp_tunnel_port(struct net_device *dev, |
| 9632 | struct udp_tunnel_info *ti) |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9633 | { |
| 9634 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9635 | u32 port_mask; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9636 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9637 | if (ti->type != UDP_TUNNEL_TYPE_VXLAN && |
| 9638 | ti->type != UDP_TUNNEL_TYPE_GENEVE) |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 9639 | return; |
| 9640 | |
| 9641 | if (ti->sa_family != AF_INET) |
| 9642 | return; |
| 9643 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9644 | switch (ti->type) { |
| 9645 | case UDP_TUNNEL_TYPE_VXLAN: |
| 9646 | if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) |
| 9647 | return; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 9648 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9649 | if (adapter->vxlan_port != ti->port) { |
| 9650 | netdev_info(dev, "VXLAN port %d not found\n", |
| 9651 | ntohs(ti->port)); |
| 9652 | return; |
| 9653 | } |
| 9654 | |
| 9655 | port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK; |
| 9656 | break; |
| 9657 | case UDP_TUNNEL_TYPE_GENEVE: |
| 9658 | if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)) |
| 9659 | return; |
| 9660 | |
| 9661 | if (adapter->geneve_port != ti->port) { |
| 9662 | netdev_info(dev, "GENEVE port %d not found\n", |
| 9663 | ntohs(ti->port)); |
| 9664 | return; |
| 9665 | } |
| 9666 | |
| 9667 | port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK; |
| 9668 | break; |
| 9669 | default: |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9670 | return; |
| 9671 | } |
| 9672 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9673 | ixgbe_clear_udp_tunnel_port(adapter, port_mask); |
| 9674 | adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9675 | } |
| 9676 | |
stephen hemminger | edc7d57 | 2012-10-01 12:32:33 +0000 | [diff] [blame] | 9677 | static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 9678 | struct net_device *dev, |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 9679 | const unsigned char *addr, u16 vid, |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 9680 | u16 flags) |
| 9681 | { |
Alexander Duyck | bcfd343 | 2014-07-17 02:11:22 +0000 | [diff] [blame] | 9682 | /* guarantee we can provide a unique filter for the unicast address */ |
Ben Hutchings | 46acc46 | 2012-11-01 09:11:11 +0000 | [diff] [blame] | 9683 | if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) { |
Alexander Duyck | 2f9be16 | 2015-10-22 16:26:42 -0700 | [diff] [blame] | 9684 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 9685 | u16 pool = VMDQ_P(0); |
| 9686 | |
| 9687 | if (netdev_uc_count(dev) >= ixgbe_available_rars(adapter, pool)) |
Alexander Duyck | bcfd343 | 2014-07-17 02:11:22 +0000 | [diff] [blame] | 9688 | return -ENOMEM; |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 9689 | } |
| 9690 | |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 9691 | return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags); |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 9692 | } |
| 9693 | |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9694 | /** |
| 9695 | * ixgbe_configure_bridge_mode - set various bridge modes |
| 9696 | * @adapter - the private structure |
| 9697 | * @mode - requested bridge mode |
| 9698 | * |
| 9699 | * Configure some settings require for various bridge modes. |
| 9700 | **/ |
| 9701 | static int ixgbe_configure_bridge_mode(struct ixgbe_adapter *adapter, |
| 9702 | __u16 mode) |
| 9703 | { |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 9704 | struct ixgbe_hw *hw = &adapter->hw; |
| 9705 | unsigned int p, num_pools; |
| 9706 | u32 vmdctl; |
| 9707 | |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9708 | switch (mode) { |
| 9709 | case BRIDGE_MODE_VEPA: |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 9710 | /* disable Tx loopback, rely on switch hairpin mode */ |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9711 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, 0); |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 9712 | |
| 9713 | /* must enable Rx switching replication to allow multicast |
| 9714 | * packet reception on all VFs, and to enable source address |
| 9715 | * pruning. |
| 9716 | */ |
| 9717 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL); |
| 9718 | vmdctl |= IXGBE_VT_CTL_REPLEN; |
| 9719 | IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl); |
| 9720 | |
| 9721 | /* enable Rx source address pruning. Note, this requires |
| 9722 | * replication to be enabled or else it does nothing. |
| 9723 | */ |
| 9724 | num_pools = adapter->num_vfs + adapter->num_rx_pools; |
| 9725 | for (p = 0; p < num_pools; p++) { |
| 9726 | if (hw->mac.ops.set_source_address_pruning) |
| 9727 | hw->mac.ops.set_source_address_pruning(hw, |
| 9728 | true, |
| 9729 | p); |
| 9730 | } |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9731 | break; |
| 9732 | case BRIDGE_MODE_VEB: |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 9733 | /* enable Tx loopback for internal VF/PF communication */ |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9734 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, |
| 9735 | IXGBE_PFDTXGSWC_VT_LBEN); |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 9736 | |
| 9737 | /* disable Rx switching replication unless we have SR-IOV |
| 9738 | * virtual functions |
| 9739 | */ |
| 9740 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL); |
| 9741 | if (!adapter->num_vfs) |
| 9742 | vmdctl &= ~IXGBE_VT_CTL_REPLEN; |
| 9743 | IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl); |
| 9744 | |
| 9745 | /* disable Rx source address pruning, since we don't expect to |
| 9746 | * be receiving external loopback of our transmitted frames. |
| 9747 | */ |
| 9748 | num_pools = adapter->num_vfs + adapter->num_rx_pools; |
| 9749 | for (p = 0; p < num_pools; p++) { |
| 9750 | if (hw->mac.ops.set_source_address_pruning) |
| 9751 | hw->mac.ops.set_source_address_pruning(hw, |
| 9752 | false, |
| 9753 | p); |
| 9754 | } |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9755 | break; |
| 9756 | default: |
| 9757 | return -EINVAL; |
| 9758 | } |
| 9759 | |
| 9760 | adapter->bridge_mode = mode; |
| 9761 | |
| 9762 | e_info(drv, "enabling bridge mode: %s\n", |
| 9763 | mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
| 9764 | |
| 9765 | return 0; |
| 9766 | } |
| 9767 | |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9768 | static int ixgbe_ndo_bridge_setlink(struct net_device *dev, |
Roopa Prabhu | add511b | 2015-01-29 22:40:12 -0800 | [diff] [blame] | 9769 | struct nlmsghdr *nlh, u16 flags) |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9770 | { |
| 9771 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 9772 | struct nlattr *attr, *br_spec; |
| 9773 | int rem; |
| 9774 | |
| 9775 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 9776 | return -EOPNOTSUPP; |
| 9777 | |
| 9778 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
Thomas Graf | 4ea85e8 | 2014-11-26 13:42:18 +0100 | [diff] [blame] | 9779 | if (!br_spec) |
| 9780 | return -EINVAL; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9781 | |
| 9782 | nla_for_each_nested(attr, br_spec, rem) { |
Mark Rustad | a1e869d | 2015-04-10 10:36:36 -0700 | [diff] [blame] | 9783 | int status; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9784 | __u16 mode; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9785 | |
| 9786 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 9787 | continue; |
| 9788 | |
Thomas Graf | b7c1a31 | 2014-11-26 13:42:17 +0100 | [diff] [blame] | 9789 | if (nla_len(attr) < sizeof(mode)) |
| 9790 | return -EINVAL; |
| 9791 | |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9792 | mode = nla_get_u16(attr); |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9793 | status = ixgbe_configure_bridge_mode(adapter, mode); |
| 9794 | if (status) |
| 9795 | return status; |
Don Skidmore | aa2bacb | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9796 | |
| 9797 | break; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9798 | } |
| 9799 | |
| 9800 | return 0; |
| 9801 | } |
| 9802 | |
| 9803 | 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] | 9804 | struct net_device *dev, |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 9805 | u32 filter_mask, int nlflags) |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9806 | { |
| 9807 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9808 | |
| 9809 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 9810 | return 0; |
| 9811 | |
Don Skidmore | aa2bacb | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9812 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, |
Scott Feldman | 7d4f8d8 | 2015-06-22 00:27:17 -0700 | [diff] [blame] | 9813 | adapter->bridge_mode, 0, 0, nlflags, |
| 9814 | filter_mask, NULL); |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9815 | } |
| 9816 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9817 | static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev) |
| 9818 | { |
| 9819 | struct ixgbe_fwd_adapter *fwd_adapter = NULL; |
| 9820 | struct ixgbe_adapter *adapter = netdev_priv(pdev); |
Jacob Keller | aac2f1b | 2014-08-21 06:17:59 +0000 | [diff] [blame] | 9821 | int used_pools = adapter->num_vfs + adapter->num_rx_pools; |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 9822 | unsigned int limit; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9823 | int pool, err; |
| 9824 | |
Jacob Keller | aac2f1b | 2014-08-21 06:17:59 +0000 | [diff] [blame] | 9825 | /* Hardware has a limited number of available pools. Each VF, and the |
| 9826 | * PF require a pool. Check to ensure we don't attempt to use more |
| 9827 | * then the available number of pools. |
| 9828 | */ |
| 9829 | if (used_pools >= IXGBE_MAX_VF_FUNCTIONS) |
| 9830 | return ERR_PTR(-EINVAL); |
| 9831 | |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 9832 | #ifdef CONFIG_RPS |
| 9833 | if (vdev->num_rx_queues != vdev->num_tx_queues) { |
| 9834 | netdev_info(pdev, "%s: Only supports a single queue count for TX and RX\n", |
| 9835 | vdev->name); |
| 9836 | return ERR_PTR(-EINVAL); |
| 9837 | } |
| 9838 | #endif |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9839 | /* Check for hardware restriction on number of rx/tx queues */ |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 9840 | if (vdev->num_tx_queues > IXGBE_MAX_L2A_QUEUES || |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9841 | vdev->num_tx_queues == IXGBE_BAD_L2A_QUEUE) { |
| 9842 | netdev_info(pdev, |
| 9843 | "%s: Supports RX/TX Queue counts 1,2, and 4\n", |
| 9844 | pdev->name); |
| 9845 | return ERR_PTR(-EINVAL); |
| 9846 | } |
| 9847 | |
| 9848 | if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && |
| 9849 | adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS - 1) || |
| 9850 | (adapter->num_rx_pools > IXGBE_MAX_MACVLANS)) |
| 9851 | return ERR_PTR(-EBUSY); |
| 9852 | |
Maninder Singh | bc52f95 | 2015-06-19 09:37:55 +0530 | [diff] [blame] | 9853 | fwd_adapter = kzalloc(sizeof(*fwd_adapter), GFP_KERNEL); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9854 | if (!fwd_adapter) |
| 9855 | return ERR_PTR(-ENOMEM); |
| 9856 | |
| 9857 | pool = find_first_zero_bit(&adapter->fwd_bitmask, 32); |
| 9858 | adapter->num_rx_pools++; |
| 9859 | set_bit(pool, &adapter->fwd_bitmask); |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 9860 | limit = find_last_bit(&adapter->fwd_bitmask, 32); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9861 | |
| 9862 | /* Enable VMDq flag so device will be set in VM mode */ |
| 9863 | adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED | IXGBE_FLAG_SRIOV_ENABLED; |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 9864 | adapter->ring_feature[RING_F_VMDQ].limit = limit + 1; |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 9865 | adapter->ring_feature[RING_F_RSS].limit = vdev->num_tx_queues; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9866 | |
| 9867 | /* Force reinit of ring allocation with VMDQ enabled */ |
| 9868 | err = ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev)); |
| 9869 | if (err) |
| 9870 | goto fwd_add_err; |
| 9871 | fwd_adapter->pool = pool; |
| 9872 | fwd_adapter->real_adapter = adapter; |
Emil Tantilov | a3b8cb1 | 2016-09-22 15:06:52 -0700 | [diff] [blame] | 9873 | |
| 9874 | if (netif_running(pdev)) { |
| 9875 | err = ixgbe_fwd_ring_up(vdev, fwd_adapter); |
| 9876 | if (err) |
| 9877 | goto fwd_add_err; |
| 9878 | netif_tx_start_all_queues(vdev); |
| 9879 | } |
| 9880 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9881 | return fwd_adapter; |
| 9882 | fwd_add_err: |
| 9883 | /* unwind counter and free adapter struct */ |
| 9884 | netdev_info(pdev, |
| 9885 | "%s: dfwd hardware acceleration failed\n", vdev->name); |
| 9886 | clear_bit(pool, &adapter->fwd_bitmask); |
| 9887 | adapter->num_rx_pools--; |
| 9888 | kfree(fwd_adapter); |
| 9889 | return ERR_PTR(err); |
| 9890 | } |
| 9891 | |
| 9892 | static void ixgbe_fwd_del(struct net_device *pdev, void *priv) |
| 9893 | { |
| 9894 | struct ixgbe_fwd_adapter *fwd_adapter = priv; |
| 9895 | struct ixgbe_adapter *adapter = fwd_adapter->real_adapter; |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 9896 | unsigned int limit; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9897 | |
| 9898 | clear_bit(fwd_adapter->pool, &adapter->fwd_bitmask); |
| 9899 | adapter->num_rx_pools--; |
| 9900 | |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 9901 | limit = find_last_bit(&adapter->fwd_bitmask, 32); |
| 9902 | adapter->ring_feature[RING_F_VMDQ].limit = limit + 1; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9903 | ixgbe_fwd_ring_down(fwd_adapter->netdev, fwd_adapter); |
Shannon Nelson | f5a71ca | 2017-08-15 08:59:54 -0700 | [diff] [blame] | 9904 | |
| 9905 | /* go back to full RSS if we're done with our VMQs */ |
| 9906 | if (adapter->ring_feature[RING_F_VMDQ].limit == 1) { |
| 9907 | int rss = min_t(int, ixgbe_max_rss_indices(adapter), |
| 9908 | num_online_cpus()); |
| 9909 | |
| 9910 | adapter->flags &= ~IXGBE_FLAG_VMDQ_ENABLED; |
| 9911 | adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED; |
| 9912 | adapter->ring_feature[RING_F_RSS].limit = rss; |
| 9913 | } |
| 9914 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9915 | ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev)); |
| 9916 | netdev_dbg(pdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n", |
| 9917 | fwd_adapter->pool, adapter->num_rx_pools, |
| 9918 | fwd_adapter->rx_base_queue, |
| 9919 | fwd_adapter->rx_base_queue + adapter->num_rx_queues_per_pool, |
| 9920 | adapter->fwd_bitmask); |
| 9921 | kfree(fwd_adapter); |
| 9922 | } |
| 9923 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9924 | #define IXGBE_MAX_MAC_HDR_LEN 127 |
| 9925 | #define IXGBE_MAX_NETWORK_HDR_LEN 511 |
| 9926 | |
Mark Rustad | f467bc0 | 2015-06-15 11:33:20 -0700 | [diff] [blame] | 9927 | static netdev_features_t |
| 9928 | ixgbe_features_check(struct sk_buff *skb, struct net_device *dev, |
| 9929 | netdev_features_t features) |
| 9930 | { |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9931 | unsigned int network_hdr_len, mac_hdr_len; |
Mark Rustad | f467bc0 | 2015-06-15 11:33:20 -0700 | [diff] [blame] | 9932 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9933 | /* Make certain the headers can be described by a context descriptor */ |
| 9934 | mac_hdr_len = skb_network_header(skb) - skb->data; |
| 9935 | if (unlikely(mac_hdr_len > IXGBE_MAX_MAC_HDR_LEN)) |
| 9936 | return features & ~(NETIF_F_HW_CSUM | |
| 9937 | NETIF_F_SCTP_CRC | |
| 9938 | NETIF_F_HW_VLAN_CTAG_TX | |
| 9939 | NETIF_F_TSO | |
| 9940 | NETIF_F_TSO6); |
| 9941 | |
| 9942 | network_hdr_len = skb_checksum_start(skb) - skb_network_header(skb); |
| 9943 | if (unlikely(network_hdr_len > IXGBE_MAX_NETWORK_HDR_LEN)) |
| 9944 | return features & ~(NETIF_F_HW_CSUM | |
| 9945 | NETIF_F_SCTP_CRC | |
| 9946 | NETIF_F_TSO | |
| 9947 | NETIF_F_TSO6); |
| 9948 | |
| 9949 | /* We can only support IPV4 TSO in tunnels if we can mangle the |
| 9950 | * inner IP ID field, so strip TSO if MANGLEID is not supported. |
| 9951 | */ |
| 9952 | if (skb->encapsulation && !(features & NETIF_F_TSO_MANGLEID)) |
| 9953 | features &= ~NETIF_F_TSO; |
Mark Rustad | f467bc0 | 2015-06-15 11:33:20 -0700 | [diff] [blame] | 9954 | |
| 9955 | return features; |
| 9956 | } |
| 9957 | |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 9958 | static int ixgbe_xdp_setup(struct net_device *dev, struct bpf_prog *prog) |
| 9959 | { |
| 9960 | int i, frame_size = dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; |
| 9961 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 9962 | struct bpf_prog *old_prog; |
| 9963 | |
| 9964 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 9965 | return -EINVAL; |
| 9966 | |
| 9967 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
| 9968 | return -EINVAL; |
| 9969 | |
| 9970 | /* verify ixgbe ring attributes are sufficient for XDP */ |
| 9971 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 9972 | struct ixgbe_ring *ring = adapter->rx_ring[i]; |
| 9973 | |
| 9974 | if (ring_is_rsc_enabled(ring)) |
| 9975 | return -EINVAL; |
| 9976 | |
| 9977 | if (frame_size > ixgbe_rx_bufsz(ring)) |
| 9978 | return -EINVAL; |
| 9979 | } |
| 9980 | |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 9981 | if (nr_cpu_ids > MAX_XDP_QUEUES) |
| 9982 | return -ENOMEM; |
| 9983 | |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 9984 | old_prog = xchg(&adapter->xdp_prog, prog); |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 9985 | |
| 9986 | /* If transitioning XDP modes reconfigure rings */ |
| 9987 | if (!!prog != !!old_prog) { |
| 9988 | int err = ixgbe_setup_tc(dev, netdev_get_num_tc(dev)); |
| 9989 | |
| 9990 | if (err) { |
| 9991 | rcu_assign_pointer(adapter->xdp_prog, old_prog); |
| 9992 | return -EINVAL; |
| 9993 | } |
| 9994 | } else { |
| 9995 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 9996 | xchg(&adapter->rx_ring[i]->xdp_prog, adapter->xdp_prog); |
| 9997 | } |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 9998 | |
| 9999 | if (old_prog) |
| 10000 | bpf_prog_put(old_prog); |
| 10001 | |
| 10002 | return 0; |
| 10003 | } |
| 10004 | |
Jakub Kicinski | f4e6352 | 2017-11-03 13:56:16 -0700 | [diff] [blame] | 10005 | static int ixgbe_xdp(struct net_device *dev, struct netdev_bpf *xdp) |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 10006 | { |
| 10007 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 10008 | |
| 10009 | switch (xdp->command) { |
| 10010 | case XDP_SETUP_PROG: |
| 10011 | return ixgbe_xdp_setup(dev, xdp->prog); |
| 10012 | case XDP_QUERY_PROG: |
| 10013 | xdp->prog_attached = !!(adapter->xdp_prog); |
Martin KaFai Lau | 4792093 | 2017-06-15 17:29:15 -0700 | [diff] [blame] | 10014 | xdp->prog_id = adapter->xdp_prog ? |
| 10015 | adapter->xdp_prog->aux->id : 0; |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 10016 | return 0; |
| 10017 | default: |
| 10018 | return -EINVAL; |
| 10019 | } |
| 10020 | } |
| 10021 | |
John Fastabend | 6453073 | 2017-07-17 09:28:12 -0700 | [diff] [blame] | 10022 | static int ixgbe_xdp_xmit(struct net_device *dev, struct xdp_buff *xdp) |
| 10023 | { |
| 10024 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 10025 | struct ixgbe_ring *ring; |
| 10026 | int err; |
| 10027 | |
| 10028 | if (unlikely(test_bit(__IXGBE_DOWN, &adapter->state))) |
Jesper Dangaard Brouer | 2886447 | 2017-08-24 12:33:13 +0200 | [diff] [blame] | 10029 | return -ENETDOWN; |
John Fastabend | 6453073 | 2017-07-17 09:28:12 -0700 | [diff] [blame] | 10030 | |
| 10031 | /* During program transitions its possible adapter->xdp_prog is assigned |
| 10032 | * but ring has not been configured yet. In this case simply abort xmit. |
| 10033 | */ |
| 10034 | ring = adapter->xdp_prog ? adapter->xdp_ring[smp_processor_id()] : NULL; |
| 10035 | if (unlikely(!ring)) |
Jesper Dangaard Brouer | 2886447 | 2017-08-24 12:33:13 +0200 | [diff] [blame] | 10036 | return -ENXIO; |
John Fastabend | 6453073 | 2017-07-17 09:28:12 -0700 | [diff] [blame] | 10037 | |
| 10038 | err = ixgbe_xmit_xdp_ring(adapter, xdp); |
| 10039 | if (err != IXGBE_XDP_TX) |
Jesper Dangaard Brouer | d2cee2e | 2017-08-17 18:22:32 +0200 | [diff] [blame] | 10040 | return -ENOSPC; |
John Fastabend | 6453073 | 2017-07-17 09:28:12 -0700 | [diff] [blame] | 10041 | |
John Fastabend | 11393cc | 2017-07-17 09:29:40 -0700 | [diff] [blame] | 10042 | return 0; |
| 10043 | } |
| 10044 | |
| 10045 | static void ixgbe_xdp_flush(struct net_device *dev) |
| 10046 | { |
| 10047 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 10048 | struct ixgbe_ring *ring; |
| 10049 | |
| 10050 | /* Its possible the device went down between xdp xmit and flush so |
| 10051 | * we need to ensure device is still up. |
| 10052 | */ |
| 10053 | if (unlikely(test_bit(__IXGBE_DOWN, &adapter->state))) |
| 10054 | return; |
| 10055 | |
| 10056 | ring = adapter->xdp_prog ? adapter->xdp_ring[smp_processor_id()] : NULL; |
| 10057 | if (unlikely(!ring)) |
| 10058 | return; |
| 10059 | |
John Fastabend | 6453073 | 2017-07-17 09:28:12 -0700 | [diff] [blame] | 10060 | /* Force memory writes to complete before letting h/w know there |
| 10061 | * are new descriptors to fetch. |
| 10062 | */ |
| 10063 | wmb(); |
John Fastabend | 6453073 | 2017-07-17 09:28:12 -0700 | [diff] [blame] | 10064 | writel(ring->next_to_use, ring->tail); |
| 10065 | |
John Fastabend | 11393cc | 2017-07-17 09:29:40 -0700 | [diff] [blame] | 10066 | return; |
John Fastabend | 6453073 | 2017-07-17 09:28:12 -0700 | [diff] [blame] | 10067 | } |
| 10068 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 10069 | static const struct net_device_ops ixgbe_netdev_ops = { |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 10070 | .ndo_open = ixgbe_open, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 10071 | .ndo_stop = ixgbe_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 10072 | .ndo_start_xmit = ixgbe_xmit_frame, |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 10073 | .ndo_select_queue = ixgbe_select_queue, |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 10074 | .ndo_set_rx_mode = ixgbe_set_rx_mode, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 10075 | .ndo_validate_addr = eth_validate_addr, |
| 10076 | .ndo_set_mac_address = ixgbe_set_mac, |
| 10077 | .ndo_change_mtu = ixgbe_change_mtu, |
| 10078 | .ndo_tx_timeout = ixgbe_tx_timeout, |
Rostislav Pehlivanov | c04f90e | 2016-01-27 18:33:30 +0000 | [diff] [blame] | 10079 | .ndo_set_tx_maxrate = ixgbe_tx_maxrate, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 10080 | .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid, |
| 10081 | .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid, |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 10082 | .ndo_do_ioctl = ixgbe_ioctl, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 10083 | .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac, |
| 10084 | .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan, |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 10085 | .ndo_set_vf_rate = ixgbe_ndo_set_vf_bw, |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 10086 | .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk, |
Vlad Zolotarov | e65ce0d | 2015-03-30 21:35:24 +0300 | [diff] [blame] | 10087 | .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] | 10088 | .ndo_set_vf_trust = ixgbe_ndo_set_vf_trust, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 10089 | .ndo_get_vf_config = ixgbe_ndo_get_vf_config, |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 10090 | .ndo_get_stats64 = ixgbe_get_stats64, |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 10091 | .ndo_setup_tc = __ixgbe_setup_tc, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 10092 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 10093 | .ndo_poll_controller = ixgbe_netpoll, |
| 10094 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 10095 | #ifdef IXGBE_FCOE |
| 10096 | .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get, |
Yi Zou | 68a683c | 2011-02-01 07:22:16 +0000 | [diff] [blame] | 10097 | .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 10098 | .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put, |
Yi Zou | 8450ff8 | 2009-08-31 12:32:14 +0000 | [diff] [blame] | 10099 | .ndo_fcoe_enable = ixgbe_fcoe_enable, |
| 10100 | .ndo_fcoe_disable = ixgbe_fcoe_disable, |
Yi Zou | 61a1fa1 | 2009-10-28 18:24:56 +0000 | [diff] [blame] | 10101 | .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn, |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 10102 | .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 10103 | #endif /* IXGBE_FCOE */ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 10104 | .ndo_set_features = ixgbe_set_features, |
| 10105 | .ndo_fix_features = ixgbe_fix_features, |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 10106 | .ndo_fdb_add = ixgbe_ndo_fdb_add, |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 10107 | .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink, |
| 10108 | .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink, |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 10109 | .ndo_dfwd_add_station = ixgbe_fwd_add, |
| 10110 | .ndo_dfwd_del_station = ixgbe_fwd_del, |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 10111 | .ndo_udp_tunnel_add = ixgbe_add_udp_tunnel_port, |
| 10112 | .ndo_udp_tunnel_del = ixgbe_del_udp_tunnel_port, |
Mark Rustad | f467bc0 | 2015-06-15 11:33:20 -0700 | [diff] [blame] | 10113 | .ndo_features_check = ixgbe_features_check, |
Jakub Kicinski | f4e6352 | 2017-11-03 13:56:16 -0700 | [diff] [blame] | 10114 | .ndo_bpf = ixgbe_xdp, |
John Fastabend | 6453073 | 2017-07-17 09:28:12 -0700 | [diff] [blame] | 10115 | .ndo_xdp_xmit = ixgbe_xdp_xmit, |
John Fastabend | 11393cc | 2017-07-17 09:29:40 -0700 | [diff] [blame] | 10116 | .ndo_xdp_flush = ixgbe_xdp_flush, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 10117 | }; |
| 10118 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 10119 | /** |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 10120 | * ixgbe_enumerate_functions - Get the number of ports this device has |
| 10121 | * @adapter: adapter structure |
| 10122 | * |
| 10123 | * This function enumerates the phsyical functions co-located on a single slot, |
| 10124 | * in order to determine how many ports a device has. This is most useful in |
| 10125 | * determining the required GT/s of PCIe bandwidth necessary for optimal |
| 10126 | * performance. |
| 10127 | **/ |
| 10128 | static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter) |
| 10129 | { |
Jacob Keller | caafb95 | 2014-07-19 07:17:17 +0000 | [diff] [blame] | 10130 | struct pci_dev *entry, *pdev = adapter->pdev; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 10131 | int physfns = 0; |
| 10132 | |
Jacob Keller | f1f9657 | 2013-08-31 02:45:38 +0000 | [diff] [blame] | 10133 | /* Some cards can not use the generic count PCIe functions method, |
| 10134 | * because they are behind a parent switch, so we hardcode these with |
| 10135 | * the correct number of functions. |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 10136 | */ |
Jacob Keller | 8818970 | 2014-07-19 07:17:16 +0000 | [diff] [blame] | 10137 | if (ixgbe_pcie_from_parent(&adapter->hw)) |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 10138 | physfns = 4; |
Jacob Keller | 8818970 | 2014-07-19 07:17:16 +0000 | [diff] [blame] | 10139 | |
| 10140 | list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) { |
| 10141 | /* don't count virtual functions */ |
Jacob Keller | caafb95 | 2014-07-19 07:17:17 +0000 | [diff] [blame] | 10142 | if (entry->is_virtfn) |
| 10143 | continue; |
| 10144 | |
| 10145 | /* When the devices on the bus don't all match our device ID, |
| 10146 | * we can't reliably determine the correct number of |
| 10147 | * functions. This can occur if a function has been direct |
| 10148 | * attached to a virtual machine using VT-d, for example. In |
| 10149 | * this case, simply return -1 to indicate this. |
| 10150 | */ |
| 10151 | if ((entry->vendor != pdev->vendor) || |
| 10152 | (entry->device != pdev->device)) |
| 10153 | return -1; |
| 10154 | |
| 10155 | physfns++; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 10156 | } |
| 10157 | |
| 10158 | return physfns; |
| 10159 | } |
| 10160 | |
| 10161 | /** |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 10162 | * ixgbe_wol_supported - Check whether device supports WoL |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 10163 | * @adapter: the adapter private structure |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 10164 | * @device_id: the device ID |
| 10165 | * @subdev_id: the subsystem device ID |
| 10166 | * |
| 10167 | * This function is used by probe and ethtool to determine |
| 10168 | * which devices have WoL support |
| 10169 | * |
| 10170 | **/ |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 10171 | bool ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id, |
| 10172 | u16 subdevice_id) |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 10173 | { |
| 10174 | struct ixgbe_hw *hw = &adapter->hw; |
| 10175 | u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 10176 | |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 10177 | /* WOL not supported on 82598 */ |
| 10178 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 10179 | return false; |
| 10180 | |
| 10181 | /* check eeprom to see if WOL is enabled for X540 and newer */ |
| 10182 | if (hw->mac.type >= ixgbe_mac_X540) { |
| 10183 | if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) || |
| 10184 | ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) && |
| 10185 | (hw->bus.func == 0))) |
| 10186 | return true; |
| 10187 | } |
| 10188 | |
| 10189 | /* WOL is determined based on device IDs for 82599 MACs */ |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 10190 | switch (device_id) { |
| 10191 | case IXGBE_DEV_ID_82599_SFP: |
| 10192 | /* Only these subdevices could supports WOL */ |
| 10193 | switch (subdevice_id) { |
| 10194 | case IXGBE_SUBDEV_ID_82599_560FLR: |
Emil Tantilov | 00103a6c | 2016-04-21 11:37:06 -0700 | [diff] [blame] | 10195 | case IXGBE_SUBDEV_ID_82599_LOM_SNAP6: |
| 10196 | case IXGBE_SUBDEV_ID_82599_SFP_WOL0: |
| 10197 | case IXGBE_SUBDEV_ID_82599_SFP_2OCP: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 10198 | /* only support first port */ |
| 10199 | if (hw->bus.func != 0) |
| 10200 | break; |
Tony Nguyen | 93df946 | 2017-05-31 04:43:47 -0700 | [diff] [blame] | 10201 | /* fall through */ |
Emil Tantilov | 5700ff2 | 2013-04-18 08:18:55 +0000 | [diff] [blame] | 10202 | case IXGBE_SUBDEV_ID_82599_SP_560FLR: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 10203 | case IXGBE_SUBDEV_ID_82599_SFP: |
Don Skidmore | b6dfd93 | 2012-07-11 07:17:42 +0000 | [diff] [blame] | 10204 | case IXGBE_SUBDEV_ID_82599_RNDC: |
Emil Tantilov | f8a06c2 | 2012-08-16 08:13:07 +0000 | [diff] [blame] | 10205 | case IXGBE_SUBDEV_ID_82599_ECNA_DP: |
Emil Tantilov | 00103a6c | 2016-04-21 11:37:06 -0700 | [diff] [blame] | 10206 | case IXGBE_SUBDEV_ID_82599_SFP_1OCP: |
| 10207 | case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM1: |
| 10208 | case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM2: |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 10209 | return true; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 10210 | } |
| 10211 | break; |
Don Skidmore | 5daebbb | 2013-04-05 05:49:34 +0000 | [diff] [blame] | 10212 | case IXGBE_DEV_ID_82599EN_SFP: |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 10213 | /* Only these subdevices support WOL */ |
Don Skidmore | 5daebbb | 2013-04-05 05:49:34 +0000 | [diff] [blame] | 10214 | switch (subdevice_id) { |
| 10215 | case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1: |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 10216 | return true; |
Don Skidmore | 5daebbb | 2013-04-05 05:49:34 +0000 | [diff] [blame] | 10217 | } |
| 10218 | break; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 10219 | case IXGBE_DEV_ID_82599_COMBO_BACKPLANE: |
| 10220 | /* All except this subdevice support WOL */ |
| 10221 | if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ) |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 10222 | return true; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 10223 | break; |
| 10224 | case IXGBE_DEV_ID_82599_KX4: |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 10225 | return true; |
| 10226 | default: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 10227 | break; |
| 10228 | } |
| 10229 | |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 10230 | return false; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 10231 | } |
| 10232 | |
| 10233 | /** |
Paul Greenwalt | 73834ae | 2017-10-27 10:32:40 -0400 | [diff] [blame] | 10234 | * ixgbe_set_fw_version - Set FW version |
| 10235 | * @adapter: the adapter private structure |
| 10236 | * |
| 10237 | * This function is used by probe and ethtool to determine the FW version to |
| 10238 | * format to display. The FW version is taken from the EEPROM/NVM. |
| 10239 | */ |
| 10240 | static void ixgbe_set_fw_version(struct ixgbe_adapter *adapter) |
| 10241 | { |
| 10242 | struct ixgbe_hw *hw = &adapter->hw; |
| 10243 | struct ixgbe_nvm_version nvm_ver; |
| 10244 | |
| 10245 | ixgbe_get_oem_prod_version(hw, &nvm_ver); |
| 10246 | if (nvm_ver.oem_valid) { |
| 10247 | snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id), |
| 10248 | "%x.%x.%x", nvm_ver.oem_major, nvm_ver.oem_minor, |
| 10249 | nvm_ver.oem_release); |
| 10250 | return; |
| 10251 | } |
| 10252 | |
| 10253 | ixgbe_get_etk_id(hw, &nvm_ver); |
| 10254 | ixgbe_get_orom_version(hw, &nvm_ver); |
| 10255 | |
| 10256 | if (nvm_ver.or_valid) { |
| 10257 | snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id), |
| 10258 | "0x%08x, %d.%d.%d", nvm_ver.etk_id, nvm_ver.or_major, |
| 10259 | nvm_ver.or_build, nvm_ver.or_patch); |
| 10260 | return; |
| 10261 | } |
| 10262 | |
| 10263 | /* Set ETrack ID format */ |
| 10264 | snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id), |
| 10265 | "0x%08x", nvm_ver.etk_id); |
| 10266 | } |
| 10267 | |
| 10268 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10269 | * ixgbe_probe - Device Initialization Routine |
| 10270 | * @pdev: PCI device information struct |
| 10271 | * @ent: entry in ixgbe_pci_tbl |
| 10272 | * |
| 10273 | * Returns 0 on success, negative on failure |
| 10274 | * |
| 10275 | * ixgbe_probe initializes an adapter identified by a pci_dev structure. |
| 10276 | * The OS initialization, configuring of the adapter private structure, |
| 10277 | * and a hardware reset occur. |
| 10278 | **/ |
Greg Kroah-Hartman | 1dd06ae | 2012-12-06 14:30:56 +0000 | [diff] [blame] | 10279 | 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] | 10280 | { |
| 10281 | struct net_device *netdev; |
| 10282 | struct ixgbe_adapter *adapter = NULL; |
| 10283 | struct ixgbe_hw *hw; |
| 10284 | const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data]; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 10285 | int i, err, pci_using_dac, expected_gts; |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 10286 | unsigned int indices = MAX_TX_QUEUES; |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 10287 | u8 part_str[IXGBE_PBANUM_LENGTH]; |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 10288 | bool disable_dev = false; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 10289 | #ifdef IXGBE_FCOE |
| 10290 | u16 device_caps; |
| 10291 | #endif |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 10292 | u32 eec; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10293 | |
Andy Gospodarek | bded64a | 2010-07-21 06:40:31 +0000 | [diff] [blame] | 10294 | /* Catch broken hardware that put the wrong VF device ID in |
| 10295 | * the PCIe SR-IOV capability. |
| 10296 | */ |
| 10297 | if (pdev->is_virtfn) { |
| 10298 | WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n", |
| 10299 | pci_name(pdev), pdev->vendor, pdev->device); |
| 10300 | return -EINVAL; |
| 10301 | } |
| 10302 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 10303 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10304 | if (err) |
| 10305 | return err; |
| 10306 | |
Russell King | f5f2eda | 2013-06-10 12:47:42 +0100 | [diff] [blame] | 10307 | if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10308 | pci_using_dac = 1; |
| 10309 | } else { |
Russell King | f5f2eda | 2013-06-10 12:47:42 +0100 | [diff] [blame] | 10310 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10311 | if (err) { |
Russell King | f5f2eda | 2013-06-10 12:47:42 +0100 | [diff] [blame] | 10312 | dev_err(&pdev->dev, |
| 10313 | "No usable DMA configuration, aborting\n"); |
| 10314 | goto err_dma; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10315 | } |
| 10316 | pci_using_dac = 0; |
| 10317 | } |
| 10318 | |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 10319 | err = pci_request_mem_regions(pdev, ixgbe_driver_name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10320 | if (err) { |
Dan Carpenter | b8bc042 | 2010-07-27 00:05:56 +0000 | [diff] [blame] | 10321 | dev_err(&pdev->dev, |
| 10322 | "pci_request_selected_regions failed 0x%x\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10323 | goto err_pci_reg; |
| 10324 | } |
| 10325 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 10326 | pci_enable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10327 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10328 | pci_set_master(pdev); |
Wendy Xiong | fb3b27b | 2008-04-23 11:09:24 -0700 | [diff] [blame] | 10329 | pci_save_state(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10330 | |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 10331 | if (ii->mac == ixgbe_mac_82598EB) { |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 10332 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 10333 | /* 8 TC w/ 4 queues per TC */ |
| 10334 | indices = 4 * MAX_TRAFFIC_CLASS; |
| 10335 | #else |
| 10336 | indices = IXGBE_MAX_RSS_INDICES; |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 10337 | #endif |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 10338 | } |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 10339 | |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 10340 | netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10341 | if (!netdev) { |
| 10342 | err = -ENOMEM; |
| 10343 | goto err_alloc_etherdev; |
| 10344 | } |
| 10345 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10346 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 10347 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10348 | adapter = netdev_priv(netdev); |
| 10349 | |
| 10350 | adapter->netdev = netdev; |
| 10351 | adapter->pdev = pdev; |
| 10352 | hw = &adapter->hw; |
| 10353 | hw->back = adapter; |
stephen hemminger | b3f4d59 | 2012-03-13 06:04:20 +0000 | [diff] [blame] | 10354 | adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10355 | |
Jeff Kirsher | 0585798 | 2008-09-11 19:57:00 -0700 | [diff] [blame] | 10356 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 10357 | pci_resource_len(pdev, 0)); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 10358 | adapter->io_addr = hw->hw_addr; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10359 | if (!hw->hw_addr) { |
| 10360 | err = -EIO; |
| 10361 | goto err_ioremap; |
| 10362 | } |
| 10363 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 10364 | netdev->netdev_ops = &ixgbe_netdev_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10365 | ixgbe_set_ethtool_ops(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10366 | netdev->watchdog_timeo = 5 * HZ; |
Mark Rustad | 339de30 | 2014-06-06 01:57:06 +0000 | [diff] [blame] | 10367 | strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10368 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10369 | /* Setup hw api */ |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 10370 | hw->mac.ops = *ii->mac_ops; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 10371 | hw->mac.type = ii->mac; |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 10372 | hw->mvals = ii->mvals; |
Emil Tantilov | b71f6c4 | 2016-10-10 14:54:03 -0700 | [diff] [blame] | 10373 | if (ii->link_ops) |
| 10374 | hw->link.ops = *ii->link_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10375 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 10376 | /* EEPROM */ |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 10377 | hw->eeprom.ops = *ii->eeprom_ops; |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 10378 | eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw)); |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 10379 | if (ixgbe_removed(hw->hw_addr)) { |
| 10380 | err = -EIO; |
| 10381 | goto err_ioremap; |
| 10382 | } |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 10383 | /* 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] | 10384 | if (!(eec & BIT(8))) |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 10385 | hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic; |
| 10386 | |
| 10387 | /* PHY */ |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 10388 | hw->phy.ops = *ii->phy_ops; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 10389 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 10390 | /* ixgbe_identify_phy_generic will set prtad and mmds properly */ |
| 10391 | hw->phy.mdio.prtad = MDIO_PRTAD_NONE; |
| 10392 | hw->phy.mdio.mmds = 0; |
| 10393 | hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 10394 | hw->phy.mdio.dev = netdev; |
| 10395 | hw->phy.mdio.mdio_read = ixgbe_mdio_read; |
| 10396 | hw->phy.mdio.mdio_write = ixgbe_mdio_write; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 10397 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10398 | /* setup the private structure */ |
Emil Tantilov | 55570b6 | 2016-10-12 12:34:25 -0700 | [diff] [blame] | 10399 | err = ixgbe_sw_init(adapter, ii); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10400 | if (err) |
| 10401 | goto err_sw_init; |
| 10402 | |
Don Skidmore | dbd15b8 | 2016-03-09 16:45:00 -0500 | [diff] [blame] | 10403 | /* Make sure the SWFW semaphore is in a valid state */ |
| 10404 | if (hw->mac.ops.init_swfw_sync) |
| 10405 | hw->mac.ops.init_swfw_sync(hw); |
| 10406 | |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 10407 | /* Make it possible the adapter to be woken up via WOL */ |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 10408 | switch (adapter->hw.mac.type) { |
| 10409 | case ixgbe_mac_82599EB: |
| 10410 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 10411 | case ixgbe_mac_X550: |
| 10412 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 10413 | case ixgbe_mac_x550em_a: |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 10414 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 10415 | break; |
| 10416 | default: |
| 10417 | break; |
| 10418 | } |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 10419 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 10420 | /* |
| 10421 | * If there is a fan on this device and it has failed log the |
| 10422 | * failure. |
| 10423 | */ |
| 10424 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 10425 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 10426 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 10427 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 10428 | } |
| 10429 | |
Peter P Waskiewicz Jr | 8ef78ad | 2012-02-01 09:19:21 +0000 | [diff] [blame] | 10430 | if (allow_unsupported_sfp) |
| 10431 | hw->allow_unsupported_sfp = allow_unsupported_sfp; |
| 10432 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 10433 | /* reset_hw fills in the perm_addr as well */ |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 10434 | hw->phy.reset_if_overtemp = true; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 10435 | err = hw->mac.ops.reset_hw(hw); |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 10436 | hw->phy.reset_if_overtemp = false; |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 10437 | ixgbe_set_eee_capable(adapter); |
Mark Rustad | 29a8dca | 2015-08-08 16:17:46 -0700 | [diff] [blame] | 10438 | if (err == IXGBE_ERR_SFP_NOT_PRESENT) { |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 10439 | err = 0; |
| 10440 | } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 1b1bf31 | 2013-07-31 05:27:04 +0000 | [diff] [blame] | 10441 | e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n"); |
| 10442 | e_dev_err("Reload the driver after installing a supported module.\n"); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 10443 | goto err_sw_init; |
| 10444 | } else if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 10445 | e_dev_err("HW Init failed: %d\n", err); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 10446 | goto err_sw_init; |
| 10447 | } |
| 10448 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 10449 | #ifdef CONFIG_PCI_IOV |
Greg Rose | 60a1a68 | 2012-12-11 08:26:33 +0000 | [diff] [blame] | 10450 | /* SR-IOV not supported on the 82598 */ |
| 10451 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 10452 | goto skip_sriov; |
| 10453 | /* Mailbox */ |
| 10454 | ixgbe_init_mbx_params_pf(hw); |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 10455 | hw->mbx.ops = ii->mbx_ops; |
ethan.zhao | dcc23e3 | 2014-01-16 19:41:04 -0800 | [diff] [blame] | 10456 | pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT); |
Emil Tantilov | 5c11f00 | 2017-01-20 14:11:56 -0800 | [diff] [blame] | 10457 | ixgbe_enable_sriov(adapter, max_vfs); |
Greg Rose | 60a1a68 | 2012-12-11 08:26:33 +0000 | [diff] [blame] | 10458 | skip_sriov: |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 10459 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 10460 | #endif |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 10461 | netdev->features = NETIF_F_SG | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 10462 | NETIF_F_TSO | |
| 10463 | NETIF_F_TSO6 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 10464 | NETIF_F_RXHASH | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 10465 | NETIF_F_RXCSUM | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 10466 | NETIF_F_HW_CSUM; |
| 10467 | |
| 10468 | #define IXGBE_GSO_PARTIAL_FEATURES (NETIF_F_GSO_GRE | \ |
| 10469 | NETIF_F_GSO_GRE_CSUM | \ |
Tom Herbert | 7e13318 | 2016-05-18 09:06:10 -0700 | [diff] [blame] | 10470 | NETIF_F_GSO_IPXIP4 | \ |
Alexander Duyck | bf2d1df | 2016-05-18 10:44:53 -0700 | [diff] [blame] | 10471 | NETIF_F_GSO_IPXIP6 | \ |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 10472 | NETIF_F_GSO_UDP_TUNNEL | \ |
| 10473 | NETIF_F_GSO_UDP_TUNNEL_CSUM) |
| 10474 | |
| 10475 | netdev->gso_partial_features = IXGBE_GSO_PARTIAL_FEATURES; |
| 10476 | netdev->features |= NETIF_F_GSO_PARTIAL | |
| 10477 | IXGBE_GSO_PARTIAL_FEATURES; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10478 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 10479 | if (hw->mac.type >= ixgbe_mac_82599EB) |
Tom Herbert | 53692b1 | 2015-12-14 11:19:41 -0800 | [diff] [blame] | 10480 | netdev->features |= NETIF_F_SCTP_CRC; |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 10481 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 10482 | /* copy netdev features into list of user selectable features */ |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 10483 | netdev->hw_features |= netdev->features | |
Alexander Duyck | 3d95182 | 2016-08-12 09:53:39 -0700 | [diff] [blame] | 10484 | NETIF_F_HW_VLAN_CTAG_FILTER | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 10485 | NETIF_F_HW_VLAN_CTAG_RX | |
| 10486 | NETIF_F_HW_VLAN_CTAG_TX | |
| 10487 | NETIF_F_RXALL | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 10488 | NETIF_F_HW_L2FW_DOFFLOAD; |
| 10489 | |
| 10490 | if (hw->mac.type >= ixgbe_mac_82599EB) |
| 10491 | netdev->hw_features |= NETIF_F_NTUPLE | |
| 10492 | NETIF_F_HW_TC; |
| 10493 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 10494 | if (pci_using_dac) |
| 10495 | netdev->features |= NETIF_F_HIGHDMA; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 10496 | |
Alexander Duyck | 5eee87c | 2016-05-11 13:23:34 -0700 | [diff] [blame] | 10497 | netdev->vlan_features |= netdev->features | NETIF_F_TSO_MANGLEID; |
| 10498 | netdev->hw_enc_features |= netdev->vlan_features; |
Scott Peterson | 2a20525 | 2016-11-18 11:25:42 -0800 | [diff] [blame] | 10499 | netdev->mpls_features |= NETIF_F_SG | |
| 10500 | NETIF_F_TSO | |
| 10501 | NETIF_F_TSO6 | |
| 10502 | NETIF_F_HW_CSUM; |
| 10503 | netdev->mpls_features |= IXGBE_GSO_PARTIAL_FEATURES; |
Alexander Duyck | 5eee87c | 2016-05-11 13:23:34 -0700 | [diff] [blame] | 10504 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 10505 | /* set this bit last since it cannot be part of vlan_features */ |
| 10506 | netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER | |
| 10507 | NETIF_F_HW_VLAN_CTAG_RX | |
| 10508 | NETIF_F_HW_VLAN_CTAG_TX; |
| 10509 | |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 10510 | netdev->priv_flags |= IFF_UNICAST_FLT; |
Ben Greear | f43f313 | 2012-03-06 09:42:04 +0000 | [diff] [blame] | 10511 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 10512 | |
Jarod Wilson | 91c527a | 2016-10-17 15:54:05 -0400 | [diff] [blame] | 10513 | /* MTU range: 68 - 9710 */ |
| 10514 | netdev->min_mtu = ETH_MIN_MTU; |
| 10515 | netdev->max_mtu = IXGBE_MAX_JUMBO_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN); |
| 10516 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 10517 | #ifdef CONFIG_IXGBE_DCB |
Usha Ketineni | 8829009 | 2016-04-26 05:00:26 -0700 | [diff] [blame] | 10518 | if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE) |
Stephen Hemminger | 3f40c74 | 2016-11-21 09:52:40 -0800 | [diff] [blame] | 10519 | netdev->dcbnl_ops = &ixgbe_dcbnl_ops; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 10520 | #endif |
| 10521 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 10522 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 10523 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 10524 | unsigned int fcoe_l; |
| 10525 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 10526 | if (hw->mac.ops.get_device_caps) { |
| 10527 | hw->mac.ops.get_device_caps(hw, &device_caps); |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 10528 | if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS) |
| 10529 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 10530 | } |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 10531 | |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 10532 | |
| 10533 | fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus()); |
| 10534 | adapter->ring_feature[RING_F_FCOE].limit = fcoe_l; |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 10535 | |
Alexander Duyck | a58915c | 2012-05-25 06:38:18 +0000 | [diff] [blame] | 10536 | netdev->features |= NETIF_F_FSO | |
| 10537 | NETIF_F_FCOE_CRC; |
| 10538 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 10539 | netdev->vlan_features |= NETIF_F_FSO | |
| 10540 | NETIF_F_FCOE_CRC | |
| 10541 | NETIF_F_FCOE_MTU; |
Yi Zou | 5e09d7f | 2010-07-19 13:59:52 +0000 | [diff] [blame] | 10542 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 10543 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10544 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 10545 | if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) |
| 10546 | netdev->hw_features |= NETIF_F_LRO; |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 10547 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 10548 | netdev->features |= NETIF_F_LRO; |
| 10549 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10550 | /* make sure the EEPROM is good */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 10551 | if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 10552 | e_dev_err("The EEPROM Checksum Is Not Valid\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10553 | err = -EIO; |
Alexander Duyck | 35937c0 | 2012-02-08 07:51:37 +0000 | [diff] [blame] | 10554 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10555 | } |
| 10556 | |
Sowmini Varadhan | c7374b5 | 2016-01-12 19:32:30 -0800 | [diff] [blame] | 10557 | eth_platform_get_mac_address(&adapter->pdev->dev, |
| 10558 | adapter->hw.mac.perm_addr); |
Martin K Petersen | c762dff | 2014-11-15 14:24:51 +0000 | [diff] [blame] | 10559 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10560 | memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10561 | |
Jiri Pirko | aaeb6cd | 2013-01-08 01:38:26 +0000 | [diff] [blame] | 10562 | if (!is_valid_ether_addr(netdev->dev_addr)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 10563 | e_dev_err("invalid MAC address\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10564 | err = -EIO; |
Alexander Duyck | 35937c0 | 2012-02-08 07:51:37 +0000 | [diff] [blame] | 10565 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10566 | } |
| 10567 | |
Tushar Dave | 5676804 | 2016-01-07 14:17:03 -0800 | [diff] [blame] | 10568 | /* Set hw->mac.addr to permanent MAC address */ |
| 10569 | ether_addr_copy(hw->mac.addr, hw->mac.perm_addr); |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 10570 | ixgbe_mac_set_default_filter(adapter); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 10571 | |
Kees Cook | 26566ea | 2017-10-16 17:29:35 -0700 | [diff] [blame] | 10572 | timer_setup(&adapter->service_timer, ixgbe_service_timer, 0); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10573 | |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 10574 | if (ixgbe_removed(hw->hw_addr)) { |
| 10575 | err = -EIO; |
| 10576 | goto err_sw_init; |
| 10577 | } |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 10578 | INIT_WORK(&adapter->service_task, ixgbe_service_task); |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 10579 | set_bit(__IXGBE_SERVICE_INITED, &adapter->state); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 10580 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10581 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 10582 | err = ixgbe_init_interrupt_scheme(adapter); |
| 10583 | if (err) |
| 10584 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10585 | |
Liwei Song | b09457e | 2016-12-04 22:40:44 -0500 | [diff] [blame] | 10586 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 10587 | u64_stats_init(&adapter->rx_ring[i]->syncp); |
| 10588 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 10589 | u64_stats_init(&adapter->tx_ring[i]->syncp); |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 10590 | for (i = 0; i < adapter->num_xdp_queues; i++) |
| 10591 | u64_stats_init(&adapter->xdp_ring[i]->syncp); |
| 10592 | |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 10593 | /* WOL not supported for all devices */ |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 10594 | adapter->wol = 0; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 10595 | hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap); |
Jacob Keller | 6b92b0b | 2013-04-13 05:40:37 +0000 | [diff] [blame] | 10596 | hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device, |
Don Skidmore | b8f8363 | 2013-02-28 08:08:44 +0000 | [diff] [blame] | 10597 | pdev->subsystem_device); |
Jacob Keller | 6b92b0b | 2013-04-13 05:40:37 +0000 | [diff] [blame] | 10598 | if (hw->wol_enabled) |
Andy Gospodarek | 9417c46 | 2011-07-16 07:31:33 +0000 | [diff] [blame] | 10599 | adapter->wol = IXGBE_WUFC_MAG; |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 10600 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 10601 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 10602 | |
Emil Tantilov | 15e5209 | 2011-09-29 05:01:29 +0000 | [diff] [blame] | 10603 | /* save off EEPROM version number */ |
Paul Greenwalt | 73834ae | 2017-10-27 10:32:40 -0400 | [diff] [blame] | 10604 | ixgbe_set_fw_version(adapter); |
Emil Tantilov | 15e5209 | 2011-09-29 05:01:29 +0000 | [diff] [blame] | 10605 | |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 10606 | /* pick up the PCI bus settings for reporting later */ |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 10607 | if (ixgbe_pcie_from_parent(hw)) |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 10608 | ixgbe_get_parent_bus_info(adapter); |
Don Skidmore | f9328bc | 2015-06-18 13:24:06 -0400 | [diff] [blame] | 10609 | else |
| 10610 | hw->mac.ops.get_bus_info(hw); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 10611 | |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 10612 | /* calculate the expected PCIe bandwidth required for optimal |
| 10613 | * performance. Note that some older parts will never have enough |
| 10614 | * bandwidth due to being older generation PCIe parts. We clamp these |
| 10615 | * parts to ensure no warning is displayed if it can't be fixed. |
| 10616 | */ |
| 10617 | switch (hw->mac.type) { |
| 10618 | case ixgbe_mac_82598EB: |
| 10619 | expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16); |
| 10620 | break; |
| 10621 | default: |
| 10622 | expected_gts = ixgbe_enumerate_functions(adapter) * 10; |
| 10623 | break; |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 10624 | } |
Jacob Keller | caafb95 | 2014-07-19 07:17:17 +0000 | [diff] [blame] | 10625 | |
| 10626 | /* don't check link if we failed to enumerate functions */ |
| 10627 | if (expected_gts > 0) |
| 10628 | ixgbe_check_minimum_link(adapter, expected_gts); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 10629 | |
Mark Rustad | 339de30 | 2014-06-06 01:57:06 +0000 | [diff] [blame] | 10630 | err = ixgbe_read_pba_string_generic(hw, part_str, sizeof(part_str)); |
Jacob Keller | 6a2aae5 | 2013-10-18 05:09:24 +0000 | [diff] [blame] | 10631 | if (err) |
Mark Rustad | 339de30 | 2014-06-06 01:57:06 +0000 | [diff] [blame] | 10632 | strlcpy(part_str, "Unknown", sizeof(part_str)); |
Jacob Keller | 6a2aae5 | 2013-10-18 05:09:24 +0000 | [diff] [blame] | 10633 | if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present) |
| 10634 | e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n", |
| 10635 | hw->mac.type, hw->phy.type, hw->phy.sfp_type, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 10636 | part_str); |
Jacob Keller | 6a2aae5 | 2013-10-18 05:09:24 +0000 | [diff] [blame] | 10637 | else |
| 10638 | e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n", |
| 10639 | hw->mac.type, hw->phy.type, part_str); |
| 10640 | |
| 10641 | e_dev_info("%pM\n", netdev->dev_addr); |
| 10642 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10643 | /* reset the hardware with the new settings */ |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 10644 | err = hw->mac.ops.start_hw(hw); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 10645 | if (err == IXGBE_ERR_EEPROM_VERSION) { |
| 10646 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 10647 | e_dev_warn("This device is a pre-production adapter/LOM. " |
| 10648 | "Please be aware there may be issues associated " |
| 10649 | "with your hardware. If you are experiencing " |
| 10650 | "problems please contact your Intel or hardware " |
| 10651 | "representative who provided you with this " |
| 10652 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 10653 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10654 | strcpy(netdev->name, "eth%d"); |
Jeff Mahoney | a09c0fc | 2017-06-03 18:01:17 -0400 | [diff] [blame] | 10655 | pci_set_drvdata(pdev, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10656 | err = register_netdev(netdev); |
| 10657 | if (err) |
| 10658 | goto err_register; |
| 10659 | |
Emil Tantilov | 0fb6a55 | 2014-12-04 03:03:38 +0000 | [diff] [blame] | 10660 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 10661 | /* power down the optics for 82599 SFP+ fiber */ |
| 10662 | if (hw->mac.ops.disable_tx_laser) |
Emil Tantilov | 93d3ce8 | 2011-10-19 07:59:55 +0000 | [diff] [blame] | 10663 | hw->mac.ops.disable_tx_laser(hw); |
| 10664 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 10665 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 10666 | netif_carrier_off(netdev); |
| 10667 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 10668 | #ifdef CONFIG_IXGBE_DCA |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 10669 | if (dca_add_requester(&pdev->dev) == 0) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10670 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10671 | ixgbe_setup_dca(adapter); |
| 10672 | } |
| 10673 | #endif |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 10674 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 10675 | 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] | 10676 | for (i = 0; i < adapter->num_vfs; i++) |
| 10677 | ixgbe_vf_configuration(pdev, (i | 0x10000000)); |
| 10678 | } |
| 10679 | |
Jacob Keller | 2466dd9 | 2011-09-08 03:50:54 +0000 | [diff] [blame] | 10680 | /* firmware requires driver version to be 0xFFFFFFFF |
| 10681 | * since os does not support feature |
| 10682 | */ |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 10683 | if (hw->mac.ops.set_fw_drv_ver) |
Tony Nguyen | cb8e051 | 2016-10-26 16:25:18 -0700 | [diff] [blame] | 10684 | hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, 0xFF, |
| 10685 | sizeof(ixgbe_driver_version) - 1, |
| 10686 | ixgbe_driver_version); |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 10687 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 10688 | /* add san mac addr to netdev */ |
| 10689 | ixgbe_add_sanmac_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10690 | |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 10691 | e_dev_info("%s\n", ixgbe_default_device_descr); |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 10692 | |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 10693 | #ifdef CONFIG_IXGBE_HWMON |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 10694 | if (ixgbe_sysfs_init(adapter)) |
| 10695 | e_err(probe, "failed to allocate sysfs resources\n"); |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 10696 | #endif /* CONFIG_IXGBE_HWMON */ |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 10697 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 10698 | ixgbe_dbg_adapter_init(adapter); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 10699 | |
Emil Tantilov | d1a35ee | 2014-05-13 08:24:00 +0000 | [diff] [blame] | 10700 | /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */ |
| 10701 | 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] | 10702 | hw->mac.ops.setup_link(hw, |
| 10703 | IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL, |
| 10704 | true); |
| 10705 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10706 | return 0; |
| 10707 | |
| 10708 | err_register: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 10709 | ixgbe_release_hw_control(adapter); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 10710 | ixgbe_clear_interrupt_scheme(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10711 | err_sw_init: |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 10712 | ixgbe_disable_sriov(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 10713 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 10714 | iounmap(adapter->io_addr); |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 10715 | kfree(adapter->jump_tables[0]); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 10716 | kfree(adapter->mac_table); |
Tony Nguyen | 3dfbfc7 | 2017-04-13 07:26:05 -0700 | [diff] [blame] | 10717 | kfree(adapter->rss_key); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10718 | err_ioremap: |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 10719 | disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10720 | free_netdev(netdev); |
| 10721 | err_alloc_etherdev: |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 10722 | pci_release_mem_regions(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10723 | err_pci_reg: |
| 10724 | err_dma: |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 10725 | if (!adapter || disable_dev) |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10726 | pci_disable_device(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10727 | return err; |
| 10728 | } |
| 10729 | |
| 10730 | /** |
| 10731 | * ixgbe_remove - Device Removal Routine |
| 10732 | * @pdev: PCI device information struct |
| 10733 | * |
| 10734 | * ixgbe_remove is called by the PCI subsystem to alert the driver |
| 10735 | * that it should release a PCI device. The could be caused by a |
| 10736 | * Hot-Plug event, or because the driver is going to be removed from |
| 10737 | * memory. |
| 10738 | **/ |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 10739 | static void ixgbe_remove(struct pci_dev *pdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10740 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 10741 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
Emil Tantilov | 0fb6a55 | 2014-12-04 03:03:38 +0000 | [diff] [blame] | 10742 | struct net_device *netdev; |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 10743 | bool disable_dev; |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 10744 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10745 | |
Emil Tantilov | 0fb6a55 | 2014-12-04 03:03:38 +0000 | [diff] [blame] | 10746 | /* if !adapter then we already cleaned up in probe */ |
| 10747 | if (!adapter) |
| 10748 | return; |
| 10749 | |
| 10750 | netdev = adapter->netdev; |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 10751 | ixgbe_dbg_adapter_exit(adapter); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 10752 | |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 10753 | set_bit(__IXGBE_REMOVING, &adapter->state); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 10754 | cancel_work_sync(&adapter->service_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10755 | |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 10756 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 10757 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10758 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 10759 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 10760 | dca_remove_requester(&pdev->dev); |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 10761 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 10762 | IXGBE_DCA_CTRL_DCA_DISABLE); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10763 | } |
| 10764 | |
| 10765 | #endif |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 10766 | #ifdef CONFIG_IXGBE_HWMON |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 10767 | ixgbe_sysfs_exit(adapter); |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 10768 | #endif /* CONFIG_IXGBE_HWMON */ |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 10769 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 10770 | /* remove the added san mac */ |
| 10771 | ixgbe_del_sanmac_netdev(netdev); |
| 10772 | |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 10773 | #ifdef CONFIG_PCI_IOV |
Alex Williamson | 7837e28 | 2015-07-10 15:31:34 -0600 | [diff] [blame] | 10774 | ixgbe_disable_sriov(adapter); |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 10775 | #endif |
Alex Williamson | 6b010e9 | 2015-07-29 14:38:21 -0600 | [diff] [blame] | 10776 | if (netdev->reg_state == NETREG_REGISTERED) |
| 10777 | unregister_netdev(netdev); |
| 10778 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 10779 | ixgbe_clear_interrupt_scheme(adapter); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 10780 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 10781 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10782 | |
Alexander Duyck | 2b1588c | 2012-03-17 02:39:16 +0000 | [diff] [blame] | 10783 | #ifdef CONFIG_DCB |
| 10784 | kfree(adapter->ixgbe_ieee_pfc); |
| 10785 | kfree(adapter->ixgbe_ieee_ets); |
| 10786 | |
| 10787 | #endif |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 10788 | iounmap(adapter->io_addr); |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 10789 | pci_release_mem_regions(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10790 | |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 10791 | e_dev_info("complete\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 10792 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 10793 | for (i = 0; i < IXGBE_MAX_LINK_HANDLE; i++) { |
| 10794 | if (adapter->jump_tables[i]) { |
| 10795 | kfree(adapter->jump_tables[i]->input); |
| 10796 | kfree(adapter->jump_tables[i]->mask); |
| 10797 | } |
| 10798 | kfree(adapter->jump_tables[i]); |
| 10799 | } |
| 10800 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 10801 | kfree(adapter->mac_table); |
Tony Nguyen | 3dfbfc7 | 2017-04-13 07:26:05 -0700 | [diff] [blame] | 10802 | kfree(adapter->rss_key); |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 10803 | disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10804 | free_netdev(netdev); |
| 10805 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 10806 | pci_disable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10807 | |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 10808 | if (disable_dev) |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10809 | pci_disable_device(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10810 | } |
| 10811 | |
| 10812 | /** |
| 10813 | * ixgbe_io_error_detected - called when PCI error is detected |
| 10814 | * @pdev: Pointer to PCI device |
| 10815 | * @state: The current pci connection state |
| 10816 | * |
| 10817 | * This function is called after a PCI bus error affecting |
| 10818 | * this device has been detected. |
| 10819 | */ |
| 10820 | 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] | 10821 | pci_channel_state_t state) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10822 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 10823 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 10824 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10825 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10826 | #ifdef CONFIG_PCI_IOV |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 10827 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10828 | struct pci_dev *bdev, *vfdev; |
| 10829 | u32 dw0, dw1, dw2, dw3; |
| 10830 | int vf, pos; |
| 10831 | u16 req_id, pf_func; |
| 10832 | |
| 10833 | if (adapter->hw.mac.type == ixgbe_mac_82598EB || |
| 10834 | adapter->num_vfs == 0) |
| 10835 | goto skip_bad_vf_detection; |
| 10836 | |
| 10837 | bdev = pdev->bus->self; |
Yijing Wang | 62f87c0 | 2012-07-24 17:20:03 +0800 | [diff] [blame] | 10838 | while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT)) |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10839 | bdev = bdev->bus->self; |
| 10840 | |
| 10841 | if (!bdev) |
| 10842 | goto skip_bad_vf_detection; |
| 10843 | |
| 10844 | pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR); |
| 10845 | if (!pos) |
| 10846 | goto skip_bad_vf_detection; |
| 10847 | |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 10848 | dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG); |
| 10849 | dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4); |
| 10850 | dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8); |
| 10851 | dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12); |
| 10852 | if (ixgbe_removed(hw->hw_addr)) |
| 10853 | goto skip_bad_vf_detection; |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10854 | |
| 10855 | req_id = dw1 >> 16; |
| 10856 | /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */ |
| 10857 | if (!(req_id & 0x0080)) |
| 10858 | goto skip_bad_vf_detection; |
| 10859 | |
| 10860 | pf_func = req_id & 0x01; |
| 10861 | if ((pf_func & 1) == (pdev->devfn & 1)) { |
| 10862 | unsigned int device_id; |
| 10863 | |
| 10864 | vf = (req_id & 0x7F) >> 1; |
| 10865 | e_dev_err("VF %d has caused a PCIe error\n", vf); |
| 10866 | e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: " |
| 10867 | "%8.8x\tdw3: %8.8x\n", |
| 10868 | dw0, dw1, dw2, dw3); |
| 10869 | switch (adapter->hw.mac.type) { |
| 10870 | case ixgbe_mac_82599EB: |
| 10871 | device_id = IXGBE_82599_VF_DEVICE_ID; |
| 10872 | break; |
| 10873 | case ixgbe_mac_X540: |
| 10874 | device_id = IXGBE_X540_VF_DEVICE_ID; |
| 10875 | break; |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 10876 | case ixgbe_mac_X550: |
| 10877 | device_id = IXGBE_DEV_ID_X550_VF; |
| 10878 | break; |
| 10879 | case ixgbe_mac_X550EM_x: |
| 10880 | device_id = IXGBE_DEV_ID_X550EM_X_VF; |
| 10881 | break; |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 10882 | case ixgbe_mac_x550em_a: |
| 10883 | device_id = IXGBE_DEV_ID_X550EM_A_VF; |
| 10884 | break; |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10885 | default: |
| 10886 | device_id = 0; |
| 10887 | break; |
| 10888 | } |
| 10889 | |
| 10890 | /* Find the pci device of the offending VF */ |
Jon Mason | 36e9031 | 2012-07-19 21:02:09 +0000 | [diff] [blame] | 10891 | vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL); |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10892 | while (vfdev) { |
| 10893 | if (vfdev->devfn == (req_id & 0xFF)) |
| 10894 | break; |
Jon Mason | 36e9031 | 2012-07-19 21:02:09 +0000 | [diff] [blame] | 10895 | vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10896 | device_id, vfdev); |
| 10897 | } |
| 10898 | /* |
| 10899 | * There's a slim chance the VF could have been hot plugged, |
| 10900 | * so if it is no longer present we don't need to issue the |
| 10901 | * VFLR. Just clean up the AER in that case. |
| 10902 | */ |
| 10903 | if (vfdev) { |
Christoph Hellwig | 63af8f7 | 2017-04-14 21:11:28 +0200 | [diff] [blame] | 10904 | pcie_flr(vfdev); |
Greg Rose | b4fafbe | 2012-12-13 01:14:06 +0000 | [diff] [blame] | 10905 | /* Free device reference count */ |
| 10906 | pci_dev_put(vfdev); |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10907 | } |
| 10908 | |
| 10909 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 10910 | } |
| 10911 | |
| 10912 | /* |
| 10913 | * Even though the error may have occurred on the other port |
| 10914 | * we still need to increment the vf error reference count for |
| 10915 | * both ports because the I/O resume function will be called |
| 10916 | * for both of them. |
| 10917 | */ |
| 10918 | adapter->vferr_refcount++; |
| 10919 | |
| 10920 | return PCI_ERS_RESULT_RECOVERED; |
| 10921 | |
| 10922 | skip_bad_vf_detection: |
| 10923 | #endif /* CONFIG_PCI_IOV */ |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 10924 | if (!test_bit(__IXGBE_SERVICE_INITED, &adapter->state)) |
| 10925 | return PCI_ERS_RESULT_DISCONNECT; |
| 10926 | |
Emil Tantilov | b64666a | 2017-09-29 10:55:42 -0700 | [diff] [blame] | 10927 | if (!netif_device_present(netdev)) |
| 10928 | return PCI_ERS_RESULT_DISCONNECT; |
| 10929 | |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10930 | rtnl_lock(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10931 | netif_device_detach(netdev); |
| 10932 | |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10933 | if (state == pci_channel_io_perm_failure) { |
| 10934 | rtnl_unlock(); |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 10935 | return PCI_ERS_RESULT_DISCONNECT; |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10936 | } |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 10937 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10938 | if (netif_running(netdev)) |
Emil Tantilov | 126db13 | 2016-11-16 09:48:02 -0800 | [diff] [blame] | 10939 | ixgbe_close_suspend(adapter); |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10940 | |
| 10941 | if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state)) |
| 10942 | pci_disable_device(pdev); |
| 10943 | rtnl_unlock(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10944 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 10945 | /* Request a slot reset. */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10946 | return PCI_ERS_RESULT_NEED_RESET; |
| 10947 | } |
| 10948 | |
| 10949 | /** |
| 10950 | * ixgbe_io_slot_reset - called after the pci bus has been reset. |
| 10951 | * @pdev: Pointer to PCI device |
| 10952 | * |
| 10953 | * Restart the card from scratch, as if from a cold-boot. |
| 10954 | */ |
| 10955 | static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev) |
| 10956 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 10957 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10958 | pci_ers_result_t result; |
| 10959 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10960 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 10961 | if (pci_enable_device_mem(pdev)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 10962 | 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] | 10963 | result = PCI_ERS_RESULT_DISCONNECT; |
| 10964 | } else { |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 10965 | smp_mb__before_atomic(); |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10966 | clear_bit(__IXGBE_DISABLED, &adapter->state); |
Mark Rustad | 0391bbe | 2014-02-28 15:48:55 -0800 | [diff] [blame] | 10967 | adapter->hw.hw_addr = adapter->io_addr; |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10968 | pci_set_master(pdev); |
| 10969 | pci_restore_state(pdev); |
Breno Leitao | c0e1f68 | 2009-11-10 08:37:47 +0000 | [diff] [blame] | 10970 | pci_save_state(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10971 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 10972 | pci_wake_from_d3(pdev, false); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10973 | |
| 10974 | ixgbe_reset(adapter); |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 10975 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10976 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10977 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10978 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10979 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 10980 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 10981 | e_dev_err("pci_cleanup_aer_uncorrect_error_status " |
| 10982 | "failed 0x%0x\n", err); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10983 | /* non-fatal, continue */ |
| 10984 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10985 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10986 | return result; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10987 | } |
| 10988 | |
| 10989 | /** |
| 10990 | * ixgbe_io_resume - called when traffic can start flowing again. |
| 10991 | * @pdev: Pointer to PCI device |
| 10992 | * |
| 10993 | * This callback is called when the error recovery driver tells us that |
| 10994 | * its OK to resume normal operation. |
| 10995 | */ |
| 10996 | static void ixgbe_io_resume(struct pci_dev *pdev) |
| 10997 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 10998 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 10999 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 11000 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 11001 | #ifdef CONFIG_PCI_IOV |
| 11002 | if (adapter->vferr_refcount) { |
| 11003 | e_info(drv, "Resuming after VF err\n"); |
| 11004 | adapter->vferr_refcount--; |
| 11005 | return; |
| 11006 | } |
| 11007 | |
| 11008 | #endif |
Emil Tantilov | 126db13 | 2016-11-16 09:48:02 -0800 | [diff] [blame] | 11009 | rtnl_lock(); |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 11010 | if (netif_running(netdev)) |
Emil Tantilov | 126db13 | 2016-11-16 09:48:02 -0800 | [diff] [blame] | 11011 | ixgbe_open(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 11012 | |
| 11013 | netif_device_attach(netdev); |
Emil Tantilov | 126db13 | 2016-11-16 09:48:02 -0800 | [diff] [blame] | 11014 | rtnl_unlock(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 11015 | } |
| 11016 | |
Stephen Hemminger | 3646f0e | 2012-09-07 09:33:15 -0700 | [diff] [blame] | 11017 | static const struct pci_error_handlers ixgbe_err_handler = { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 11018 | .error_detected = ixgbe_io_error_detected, |
| 11019 | .slot_reset = ixgbe_io_slot_reset, |
| 11020 | .resume = ixgbe_io_resume, |
| 11021 | }; |
| 11022 | |
| 11023 | static struct pci_driver ixgbe_driver = { |
| 11024 | .name = ixgbe_driver_name, |
| 11025 | .id_table = ixgbe_pci_tbl, |
| 11026 | .probe = ixgbe_probe, |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 11027 | .remove = ixgbe_remove, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 11028 | #ifdef CONFIG_PM |
| 11029 | .suspend = ixgbe_suspend, |
| 11030 | .resume = ixgbe_resume, |
| 11031 | #endif |
| 11032 | .shutdown = ixgbe_shutdown, |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 11033 | .sriov_configure = ixgbe_pci_sriov_configure, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 11034 | .err_handler = &ixgbe_err_handler |
| 11035 | }; |
| 11036 | |
| 11037 | /** |
| 11038 | * ixgbe_init_module - Driver Registration Routine |
| 11039 | * |
| 11040 | * ixgbe_init_module is the first routine called when the driver is |
| 11041 | * loaded. All it does is register with the PCI subsystem. |
| 11042 | **/ |
| 11043 | static int __init ixgbe_init_module(void) |
| 11044 | { |
| 11045 | int ret; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 11046 | pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version); |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 11047 | pr_info("%s\n", ixgbe_copyright); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 11048 | |
Mark Rustad | 780484d | 2015-10-21 17:21:10 -0700 | [diff] [blame] | 11049 | ixgbe_wq = create_singlethread_workqueue(ixgbe_driver_name); |
| 11050 | if (!ixgbe_wq) { |
| 11051 | pr_err("%s: Failed to create workqueue\n", ixgbe_driver_name); |
| 11052 | return -ENOMEM; |
| 11053 | } |
| 11054 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 11055 | ixgbe_dbg_init(); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 11056 | |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 11057 | ret = pci_register_driver(&ixgbe_driver); |
| 11058 | if (ret) { |
Wei Yongjun | 6b83687 | 2016-07-12 15:17:02 +0000 | [diff] [blame] | 11059 | destroy_workqueue(ixgbe_wq); |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 11060 | ixgbe_dbg_exit(); |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 11061 | return ret; |
| 11062 | } |
| 11063 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 11064 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 11065 | dca_register_notify(&dca_notifier); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 11066 | #endif |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 11067 | |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 11068 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 11069 | } |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 11070 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 11071 | module_init(ixgbe_init_module); |
| 11072 | |
| 11073 | /** |
| 11074 | * ixgbe_exit_module - Driver Exit Cleanup Routine |
| 11075 | * |
| 11076 | * ixgbe_exit_module is called just before the driver is removed |
| 11077 | * from memory. |
| 11078 | **/ |
| 11079 | static void __exit ixgbe_exit_module(void) |
| 11080 | { |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 11081 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 11082 | dca_unregister_notify(&dca_notifier); |
| 11083 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 11084 | pci_unregister_driver(&ixgbe_driver); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 11085 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 11086 | ixgbe_dbg_exit(); |
Mark Rustad | 780484d | 2015-10-21 17:21:10 -0700 | [diff] [blame] | 11087 | if (ixgbe_wq) { |
| 11088 | destroy_workqueue(ixgbe_wq); |
| 11089 | ixgbe_wq = NULL; |
| 11090 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 11091 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 11092 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 11093 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 11094 | static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 11095 | void *p) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 11096 | { |
| 11097 | int ret_val; |
| 11098 | |
| 11099 | ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 11100 | __ixgbe_notify_dca); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 11101 | |
| 11102 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; |
| 11103 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 11104 | |
Alexander Duyck | b453368 | 2009-03-31 21:32:42 +0000 | [diff] [blame] | 11105 | #endif /* CONFIG_IXGBE_DCA */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 11106 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 11107 | module_exit(ixgbe_exit_module); |
| 11108 | |
| 11109 | /* ixgbe_main.c */ |