Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel 10 Gigabit PCI Express Linux driver |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 4 | Copyright(c) 1999 - 2016 Intel Corporation. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms and conditions of the GNU General Public License, |
| 8 | version 2, as published by the Free Software Foundation. |
| 9 | |
| 10 | This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License along with |
| 16 | this program; if not, write to the Free Software Foundation, Inc., |
| 17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | |
| 19 | The full GNU General Public License is included in this distribution in |
| 20 | the file called "COPYING". |
| 21 | |
| 22 | Contact Information: |
Jacob Keller | b89aae7 | 2014-02-22 01:23:50 +0000 | [diff] [blame] | 23 | Linux NICS <linux.nics@intel.com> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 24 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 26 | |
| 27 | *******************************************************************************/ |
| 28 | |
| 29 | #include <linux/types.h> |
| 30 | #include <linux/module.h> |
| 31 | #include <linux/pci.h> |
| 32 | #include <linux/netdevice.h> |
| 33 | #include <linux/vmalloc.h> |
| 34 | #include <linux/string.h> |
| 35 | #include <linux/in.h> |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 36 | #include <linux/interrupt.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 37 | #include <linux/ip.h> |
| 38 | #include <linux/tcp.h> |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 39 | #include <linux/sctp.h> |
Lucy Liu | 6012786 | 2009-07-22 14:07:33 +0000 | [diff] [blame] | 40 | #include <linux/pkt_sched.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 41 | #include <linux/ipv6.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 42 | #include <linux/slab.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 43 | #include <net/checksum.h> |
| 44 | #include <net/ip6_checksum.h> |
Martin K Petersen | c762dff | 2014-11-15 14:24:51 +0000 | [diff] [blame] | 45 | #include <linux/etherdevice.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 46 | #include <linux/ethtool.h> |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 47 | #include <linux/if.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 48 | #include <linux/if_vlan.h> |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 49 | #include <linux/if_macvlan.h> |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 50 | #include <linux/if_bridge.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 51 | #include <linux/prefetch.h> |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 52 | #include <scsi/fc/fc_fcoe.h> |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 53 | #include <net/vxlan.h> |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 54 | #include <net/pkt_cls.h> |
| 55 | #include <net/tc_act/tc_gact.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 56 | |
| 57 | #include "ixgbe.h" |
| 58 | #include "ixgbe_common.h" |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 59 | #include "ixgbe_dcb_82599.h" |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 60 | #include "ixgbe_sriov.h" |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 61 | #include "ixgbe_model.h" |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 62 | |
| 63 | char ixgbe_driver_name[] = "ixgbe"; |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 64 | static const char ixgbe_driver_string[] = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 65 | "Intel(R) 10 Gigabit PCI Express Network Driver"; |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 66 | #ifdef IXGBE_FCOE |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 67 | char ixgbe_default_device_descr[] = |
| 68 | "Intel(R) 10 Gigabit Network Connection"; |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 69 | #else |
| 70 | static char ixgbe_default_device_descr[] = |
| 71 | "Intel(R) 10 Gigabit Network Connection"; |
| 72 | #endif |
Mark Rustad | 10ef00f | 2016-04-01 12:18:51 -0700 | [diff] [blame] | 73 | #define DRV_VERSION "4.4.0-k" |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 74 | const char ixgbe_driver_version[] = DRV_VERSION; |
Don Skidmore | a52055e | 2011-02-23 09:58:39 +0000 | [diff] [blame] | 75 | static const char ixgbe_copyright[] = |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 76 | "Copyright (c) 1999-2016 Intel Corporation."; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 77 | |
Don Skidmore | f44e751 | 2015-06-09 16:36:23 -0700 | [diff] [blame] | 78 | static const char ixgbe_overheat_msg[] = "Network adapter has been stopped because it has over heated. Restart the computer. If the problem persists, power off the system and replace the adapter"; |
| 79 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 80 | static const struct ixgbe_info *ixgbe_info_tbl[] = { |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 81 | [board_82598] = &ixgbe_82598_info, |
| 82 | [board_82599] = &ixgbe_82599_info, |
| 83 | [board_X540] = &ixgbe_X540_info, |
| 84 | [board_X550] = &ixgbe_X550_info, |
| 85 | [board_X550EM_x] = &ixgbe_X550EM_x_info, |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 86 | [board_x550em_a] = &ixgbe_x550em_a_info, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | /* ixgbe_pci_tbl - PCI Device ID Table |
| 90 | * |
| 91 | * Wildcard entries (PCI_ANY_ID) should come last |
| 92 | * Last entry must be all 0s |
| 93 | * |
| 94 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 95 | * Class, Class Mask, private data (not used) } |
| 96 | */ |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 97 | static const struct pci_device_id ixgbe_pci_tbl[] = { |
Alexander Duyck | 54239c6 | 2011-07-15 03:06:06 +0000 | [diff] [blame] | 98 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 }, |
| 99 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 }, |
| 100 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 }, |
| 101 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 }, |
| 102 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 }, |
| 103 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 }, |
| 104 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 }, |
| 105 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 }, |
| 106 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 }, |
| 107 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 }, |
| 108 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 }, |
| 109 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 }, |
| 110 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 }, |
| 111 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 }, |
| 112 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 }, |
| 113 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 }, |
| 114 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 }, |
| 115 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 }, |
| 116 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 }, |
| 117 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 }, |
| 118 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 }, |
| 119 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 }, |
| 120 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 }, |
| 121 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 }, |
| 122 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 }, |
| 123 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 }, |
Don Skidmore | 8f58332 | 2013-07-27 06:25:38 +0000 | [diff] [blame] | 124 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_QSFP_SF_QP), board_82599 }, |
Emil Tantilov | 7d14528 | 2011-09-08 08:30:14 +0000 | [diff] [blame] | 125 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 }, |
Emil Tantilov | 9e791e4 | 2011-11-04 06:43:29 +0000 | [diff] [blame] | 126 | {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] | 127 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 }, |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 128 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T), board_X550}, |
Mark Rustad | a711ad8 | 2016-03-21 11:21:31 -0700 | [diff] [blame] | 129 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T1), board_X550}, |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 130 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KX4), board_X550EM_x}, |
| 131 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KR), board_X550EM_x}, |
Don Skidmore | deda562 | 2015-06-09 17:39:46 -0700 | [diff] [blame] | 132 | {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] | 133 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_SFP), board_X550EM_x}, |
Mark Rustad | f572b2c | 2016-04-01 12:18:46 -0700 | [diff] [blame] | 134 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR), board_x550em_a }, |
| 135 | {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] | 136 | {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] | 137 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII), board_x550em_a }, |
| 138 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII_L), board_x550em_a }, |
Mark Rustad | 2d40cd1 | 2016-04-01 12:18:35 -0700 | [diff] [blame] | 139 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP), board_x550em_a }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 140 | /* required last entry */ |
| 141 | {0, } |
| 142 | }; |
| 143 | MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl); |
| 144 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 145 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 146 | static int ixgbe_notify_dca(struct notifier_block *, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 147 | void *p); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 148 | static struct notifier_block dca_notifier = { |
| 149 | .notifier_call = ixgbe_notify_dca, |
| 150 | .next = NULL, |
| 151 | .priority = 0 |
| 152 | }; |
| 153 | #endif |
| 154 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 155 | #ifdef CONFIG_PCI_IOV |
| 156 | static unsigned int max_vfs; |
| 157 | module_param(max_vfs, uint, 0); |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 158 | MODULE_PARM_DESC(max_vfs, |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 159 | "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] | 160 | #endif /* CONFIG_PCI_IOV */ |
| 161 | |
Peter P Waskiewicz Jr | 8ef78ad | 2012-02-01 09:19:21 +0000 | [diff] [blame] | 162 | static unsigned int allow_unsupported_sfp; |
| 163 | module_param(allow_unsupported_sfp, uint, 0); |
| 164 | MODULE_PARM_DESC(allow_unsupported_sfp, |
| 165 | "Allow unsupported and untested SFP+ modules on 82599-based adapters"); |
| 166 | |
stephen hemminger | b3f4d59 | 2012-03-13 06:04:20 +0000 | [diff] [blame] | 167 | #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK) |
| 168 | static int debug = -1; |
| 169 | module_param(debug, int, 0); |
| 170 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 171 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 172 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 173 | MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver"); |
| 174 | MODULE_LICENSE("GPL"); |
| 175 | MODULE_VERSION(DRV_VERSION); |
| 176 | |
Mark Rustad | 780484d | 2015-10-21 17:21:10 -0700 | [diff] [blame] | 177 | static struct workqueue_struct *ixgbe_wq; |
| 178 | |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 179 | static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev); |
| 180 | |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 181 | static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter *adapter, |
| 182 | u32 reg, u16 *value) |
| 183 | { |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 184 | struct pci_dev *parent_dev; |
| 185 | struct pci_bus *parent_bus; |
| 186 | |
| 187 | parent_bus = adapter->pdev->bus->parent; |
| 188 | if (!parent_bus) |
| 189 | return -1; |
| 190 | |
| 191 | parent_dev = parent_bus->self; |
| 192 | if (!parent_dev) |
| 193 | return -1; |
| 194 | |
Yijing Wang | c0798ed | 2013-09-04 17:30:08 +0000 | [diff] [blame] | 195 | if (!pci_is_pcie(parent_dev)) |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 196 | return -1; |
| 197 | |
Yijing Wang | c0798ed | 2013-09-04 17:30:08 +0000 | [diff] [blame] | 198 | pcie_capability_read_word(parent_dev, reg, value); |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 199 | if (*value == IXGBE_FAILED_READ_CFG_WORD && |
| 200 | ixgbe_check_cfg_remove(&adapter->hw, parent_dev)) |
| 201 | return -1; |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 202 | return 0; |
| 203 | } |
| 204 | |
| 205 | static s32 ixgbe_get_parent_bus_info(struct ixgbe_adapter *adapter) |
| 206 | { |
| 207 | struct ixgbe_hw *hw = &adapter->hw; |
| 208 | u16 link_status = 0; |
| 209 | int err; |
| 210 | |
| 211 | hw->bus.type = ixgbe_bus_type_pci_express; |
| 212 | |
| 213 | /* Get the negotiated link width and speed from PCI config space of the |
| 214 | * parent, as this device is behind a switch |
| 215 | */ |
| 216 | err = ixgbe_read_pci_cfg_word_parent(adapter, 18, &link_status); |
| 217 | |
| 218 | /* assume caller will handle error case */ |
| 219 | if (err) |
| 220 | return err; |
| 221 | |
| 222 | hw->bus.width = ixgbe_convert_bus_width(link_status); |
| 223 | hw->bus.speed = ixgbe_convert_bus_speed(link_status); |
| 224 | |
| 225 | return 0; |
| 226 | } |
| 227 | |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 228 | /** |
| 229 | * ixgbe_check_from_parent - Determine whether PCIe info should come from parent |
| 230 | * @hw: hw specific details |
| 231 | * |
| 232 | * This function is used by probe to determine whether a device's PCI-Express |
| 233 | * bandwidth details should be gathered from the parent bus instead of from the |
| 234 | * device. Used to ensure that various locations all have the correct device ID |
| 235 | * checks. |
| 236 | */ |
| 237 | static inline bool ixgbe_pcie_from_parent(struct ixgbe_hw *hw) |
| 238 | { |
| 239 | switch (hw->device_id) { |
| 240 | case IXGBE_DEV_ID_82599_SFP_SF_QP: |
Don Skidmore | 8f58332 | 2013-07-27 06:25:38 +0000 | [diff] [blame] | 241 | case IXGBE_DEV_ID_82599_QSFP_SF_QP: |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 242 | return true; |
| 243 | default: |
| 244 | return false; |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | static void ixgbe_check_minimum_link(struct ixgbe_adapter *adapter, |
| 249 | int expected_gts) |
| 250 | { |
Don Skidmore | f9328bc | 2015-06-18 13:24:06 -0400 | [diff] [blame] | 251 | struct ixgbe_hw *hw = &adapter->hw; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 252 | int max_gts = 0; |
| 253 | enum pci_bus_speed speed = PCI_SPEED_UNKNOWN; |
| 254 | enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN; |
| 255 | struct pci_dev *pdev; |
| 256 | |
Don Skidmore | f9328bc | 2015-06-18 13:24:06 -0400 | [diff] [blame] | 257 | /* Some devices are not connected over PCIe and thus do not negotiate |
| 258 | * speed. These devices do not have valid bus info, and thus any report |
| 259 | * we generate may not be correct. |
| 260 | */ |
| 261 | if (hw->bus.type == ixgbe_bus_type_internal) |
| 262 | return; |
| 263 | |
Jacob Keller | 56d1392 | 2015-06-10 11:44:45 -0700 | [diff] [blame] | 264 | /* determine whether to use the parent device */ |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 265 | if (ixgbe_pcie_from_parent(&adapter->hw)) |
| 266 | pdev = adapter->pdev->bus->parent->self; |
| 267 | else |
| 268 | pdev = adapter->pdev; |
| 269 | |
| 270 | if (pcie_get_minimum_link(pdev, &speed, &width) || |
| 271 | speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) { |
| 272 | e_dev_warn("Unable to determine PCI Express bandwidth.\n"); |
| 273 | return; |
| 274 | } |
| 275 | |
| 276 | switch (speed) { |
| 277 | case PCIE_SPEED_2_5GT: |
| 278 | /* 8b/10b encoding reduces max throughput by 20% */ |
| 279 | max_gts = 2 * width; |
| 280 | break; |
| 281 | case PCIE_SPEED_5_0GT: |
| 282 | /* 8b/10b encoding reduces max throughput by 20% */ |
| 283 | max_gts = 4 * width; |
| 284 | break; |
| 285 | case PCIE_SPEED_8_0GT: |
Jacob Keller | 9f0a433 | 2013-10-18 05:09:19 +0000 | [diff] [blame] | 286 | /* 128b/130b encoding reduces throughput by less than 2% */ |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 287 | max_gts = 8 * width; |
| 288 | break; |
| 289 | default: |
| 290 | e_dev_warn("Unable to determine PCI Express bandwidth.\n"); |
| 291 | return; |
| 292 | } |
| 293 | |
| 294 | e_dev_info("PCI Express bandwidth of %dGT/s available\n", |
| 295 | max_gts); |
| 296 | e_dev_info("(Speed:%s, Width: x%d, Encoding Loss:%s)\n", |
| 297 | (speed == PCIE_SPEED_8_0GT ? "8.0GT/s" : |
| 298 | speed == PCIE_SPEED_5_0GT ? "5.0GT/s" : |
| 299 | speed == PCIE_SPEED_2_5GT ? "2.5GT/s" : |
| 300 | "Unknown"), |
| 301 | width, |
| 302 | (speed == PCIE_SPEED_2_5GT ? "20%" : |
| 303 | speed == PCIE_SPEED_5_0GT ? "20%" : |
Jacob Keller | 9f0a433 | 2013-10-18 05:09:19 +0000 | [diff] [blame] | 304 | speed == PCIE_SPEED_8_0GT ? "<2%" : |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 305 | "Unknown")); |
| 306 | |
| 307 | if (max_gts < expected_gts) { |
| 308 | e_dev_warn("This is not sufficient for optimal performance of this card.\n"); |
| 309 | e_dev_warn("For optimal performance, at least %dGT/s of bandwidth is required.\n", |
| 310 | expected_gts); |
| 311 | e_dev_warn("A slot with more lanes and/or higher speed is suggested.\n"); |
| 312 | } |
| 313 | } |
| 314 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 315 | static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter) |
| 316 | { |
| 317 | if (!test_bit(__IXGBE_DOWN, &adapter->state) && |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 318 | !test_bit(__IXGBE_REMOVING, &adapter->state) && |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 319 | !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state)) |
Mark Rustad | 780484d | 2015-10-21 17:21:10 -0700 | [diff] [blame] | 320 | queue_work(ixgbe_wq, &adapter->service_task); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 321 | } |
| 322 | |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 323 | static void ixgbe_remove_adapter(struct ixgbe_hw *hw) |
| 324 | { |
| 325 | struct ixgbe_adapter *adapter = hw->back; |
| 326 | |
| 327 | if (!hw->hw_addr) |
| 328 | return; |
| 329 | hw->hw_addr = NULL; |
| 330 | e_dev_err("Adapter removed\n"); |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 331 | if (test_bit(__IXGBE_SERVICE_INITED, &adapter->state)) |
| 332 | ixgbe_service_event_schedule(adapter); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 333 | } |
| 334 | |
Mark Rustad | f8e2472 | 2014-03-18 07:03:40 +0000 | [diff] [blame] | 335 | static void ixgbe_check_remove(struct ixgbe_hw *hw, u32 reg) |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 336 | { |
| 337 | u32 value; |
| 338 | |
| 339 | /* The following check not only optimizes a bit by not |
| 340 | * performing a read on the status register when the |
| 341 | * register just read was a status register read that |
| 342 | * returned IXGBE_FAILED_READ_REG. It also blocks any |
| 343 | * potential recursion. |
| 344 | */ |
| 345 | if (reg == IXGBE_STATUS) { |
| 346 | ixgbe_remove_adapter(hw); |
| 347 | return; |
| 348 | } |
| 349 | value = ixgbe_read_reg(hw, IXGBE_STATUS); |
| 350 | if (value == IXGBE_FAILED_READ_REG) |
| 351 | ixgbe_remove_adapter(hw); |
| 352 | } |
| 353 | |
Mark Rustad | f8e2472 | 2014-03-18 07:03:40 +0000 | [diff] [blame] | 354 | /** |
| 355 | * ixgbe_read_reg - Read from device register |
| 356 | * @hw: hw specific details |
| 357 | * @reg: offset of register to read |
| 358 | * |
| 359 | * Returns : value read or IXGBE_FAILED_READ_REG if removed |
| 360 | * |
| 361 | * This function is used to read device registers. It checks for device |
| 362 | * removal by confirming any read that returns all ones by checking the |
| 363 | * status register value for all ones. This function avoids reading from |
| 364 | * the hardware if a removal was previously detected in which case it |
| 365 | * returns IXGBE_FAILED_READ_REG (all ones). |
| 366 | */ |
| 367 | u32 ixgbe_read_reg(struct ixgbe_hw *hw, u32 reg) |
| 368 | { |
| 369 | u8 __iomem *reg_addr = ACCESS_ONCE(hw->hw_addr); |
| 370 | u32 value; |
| 371 | |
| 372 | if (ixgbe_removed(reg_addr)) |
| 373 | return IXGBE_FAILED_READ_REG; |
Mark Rustad | 2f2219b | 2016-04-07 10:43:50 -0700 | [diff] [blame] | 374 | if (unlikely(hw->phy.nw_mng_if_sel & |
| 375 | IXGBE_NW_MNG_IF_SEL_ENABLE_10_100M)) { |
| 376 | struct ixgbe_adapter *adapter; |
| 377 | int i; |
| 378 | |
| 379 | for (i = 0; i < 200; ++i) { |
| 380 | value = readl(reg_addr + IXGBE_MAC_SGMII_BUSY); |
| 381 | if (likely(!value)) |
| 382 | goto writes_completed; |
| 383 | if (value == IXGBE_FAILED_READ_REG) { |
| 384 | ixgbe_remove_adapter(hw); |
| 385 | return IXGBE_FAILED_READ_REG; |
| 386 | } |
| 387 | udelay(5); |
| 388 | } |
| 389 | |
| 390 | adapter = hw->back; |
| 391 | e_warn(hw, "register writes incomplete %08x\n", value); |
| 392 | } |
| 393 | |
| 394 | writes_completed: |
Mark Rustad | f8e2472 | 2014-03-18 07:03:40 +0000 | [diff] [blame] | 395 | value = readl(reg_addr + reg); |
| 396 | if (unlikely(value == IXGBE_FAILED_READ_REG)) |
| 397 | ixgbe_check_remove(hw, reg); |
| 398 | return value; |
| 399 | } |
| 400 | |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 401 | static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev) |
| 402 | { |
| 403 | u16 value; |
| 404 | |
| 405 | pci_read_config_word(pdev, PCI_VENDOR_ID, &value); |
| 406 | if (value == IXGBE_FAILED_READ_CFG_WORD) { |
| 407 | ixgbe_remove_adapter(hw); |
| 408 | return true; |
| 409 | } |
| 410 | return false; |
| 411 | } |
| 412 | |
| 413 | u16 ixgbe_read_pci_cfg_word(struct ixgbe_hw *hw, u32 reg) |
| 414 | { |
| 415 | struct ixgbe_adapter *adapter = hw->back; |
| 416 | u16 value; |
| 417 | |
| 418 | if (ixgbe_removed(hw->hw_addr)) |
| 419 | return IXGBE_FAILED_READ_CFG_WORD; |
| 420 | pci_read_config_word(adapter->pdev, reg, &value); |
| 421 | if (value == IXGBE_FAILED_READ_CFG_WORD && |
| 422 | ixgbe_check_cfg_remove(hw, adapter->pdev)) |
| 423 | return IXGBE_FAILED_READ_CFG_WORD; |
| 424 | return value; |
| 425 | } |
| 426 | |
| 427 | #ifdef CONFIG_PCI_IOV |
| 428 | static u32 ixgbe_read_pci_cfg_dword(struct ixgbe_hw *hw, u32 reg) |
| 429 | { |
| 430 | struct ixgbe_adapter *adapter = hw->back; |
| 431 | u32 value; |
| 432 | |
| 433 | if (ixgbe_removed(hw->hw_addr)) |
| 434 | return IXGBE_FAILED_READ_CFG_DWORD; |
| 435 | pci_read_config_dword(adapter->pdev, reg, &value); |
| 436 | if (value == IXGBE_FAILED_READ_CFG_DWORD && |
| 437 | ixgbe_check_cfg_remove(hw, adapter->pdev)) |
| 438 | return IXGBE_FAILED_READ_CFG_DWORD; |
| 439 | return value; |
| 440 | } |
| 441 | #endif /* CONFIG_PCI_IOV */ |
| 442 | |
Jacob Keller | ed19231 | 2014-02-22 01:23:53 +0000 | [diff] [blame] | 443 | void ixgbe_write_pci_cfg_word(struct ixgbe_hw *hw, u32 reg, u16 value) |
| 444 | { |
| 445 | struct ixgbe_adapter *adapter = hw->back; |
| 446 | |
| 447 | if (ixgbe_removed(hw->hw_addr)) |
| 448 | return; |
| 449 | pci_write_config_word(adapter->pdev, reg, value); |
| 450 | } |
| 451 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 452 | static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter) |
| 453 | { |
| 454 | BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state)); |
| 455 | |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 456 | /* flush memory to make sure state is correct before next watchdog */ |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 457 | smp_mb__before_atomic(); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 458 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
| 459 | } |
| 460 | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 461 | struct ixgbe_reg_info { |
| 462 | u32 ofs; |
| 463 | char *name; |
| 464 | }; |
| 465 | |
| 466 | static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = { |
| 467 | |
| 468 | /* General Registers */ |
| 469 | {IXGBE_CTRL, "CTRL"}, |
| 470 | {IXGBE_STATUS, "STATUS"}, |
| 471 | {IXGBE_CTRL_EXT, "CTRL_EXT"}, |
| 472 | |
| 473 | /* Interrupt Registers */ |
| 474 | {IXGBE_EICR, "EICR"}, |
| 475 | |
| 476 | /* RX Registers */ |
| 477 | {IXGBE_SRRCTL(0), "SRRCTL"}, |
| 478 | {IXGBE_DCA_RXCTRL(0), "DRXCTL"}, |
| 479 | {IXGBE_RDLEN(0), "RDLEN"}, |
| 480 | {IXGBE_RDH(0), "RDH"}, |
| 481 | {IXGBE_RDT(0), "RDT"}, |
| 482 | {IXGBE_RXDCTL(0), "RXDCTL"}, |
| 483 | {IXGBE_RDBAL(0), "RDBAL"}, |
| 484 | {IXGBE_RDBAH(0), "RDBAH"}, |
| 485 | |
| 486 | /* TX Registers */ |
| 487 | {IXGBE_TDBAL(0), "TDBAL"}, |
| 488 | {IXGBE_TDBAH(0), "TDBAH"}, |
| 489 | {IXGBE_TDLEN(0), "TDLEN"}, |
| 490 | {IXGBE_TDH(0), "TDH"}, |
| 491 | {IXGBE_TDT(0), "TDT"}, |
| 492 | {IXGBE_TXDCTL(0), "TXDCTL"}, |
| 493 | |
| 494 | /* List Terminator */ |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 495 | { .name = NULL } |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 496 | }; |
| 497 | |
| 498 | |
| 499 | /* |
| 500 | * ixgbe_regdump - register printout routine |
| 501 | */ |
| 502 | static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo) |
| 503 | { |
| 504 | int i = 0, j = 0; |
| 505 | char rname[16]; |
| 506 | u32 regs[64]; |
| 507 | |
| 508 | switch (reginfo->ofs) { |
| 509 | case IXGBE_SRRCTL(0): |
| 510 | for (i = 0; i < 64; i++) |
| 511 | regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i)); |
| 512 | break; |
| 513 | case IXGBE_DCA_RXCTRL(0): |
| 514 | for (i = 0; i < 64; i++) |
| 515 | regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i)); |
| 516 | break; |
| 517 | case IXGBE_RDLEN(0): |
| 518 | for (i = 0; i < 64; i++) |
| 519 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i)); |
| 520 | break; |
| 521 | case IXGBE_RDH(0): |
| 522 | for (i = 0; i < 64; i++) |
| 523 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i)); |
| 524 | break; |
| 525 | case IXGBE_RDT(0): |
| 526 | for (i = 0; i < 64; i++) |
| 527 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i)); |
| 528 | break; |
| 529 | case IXGBE_RXDCTL(0): |
| 530 | for (i = 0; i < 64; i++) |
| 531 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i)); |
| 532 | break; |
| 533 | case IXGBE_RDBAL(0): |
| 534 | for (i = 0; i < 64; i++) |
| 535 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i)); |
| 536 | break; |
| 537 | case IXGBE_RDBAH(0): |
| 538 | for (i = 0; i < 64; i++) |
| 539 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i)); |
| 540 | break; |
| 541 | case IXGBE_TDBAL(0): |
| 542 | for (i = 0; i < 64; i++) |
| 543 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i)); |
| 544 | break; |
| 545 | case IXGBE_TDBAH(0): |
| 546 | for (i = 0; i < 64; i++) |
| 547 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i)); |
| 548 | break; |
| 549 | case IXGBE_TDLEN(0): |
| 550 | for (i = 0; i < 64; i++) |
| 551 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i)); |
| 552 | break; |
| 553 | case IXGBE_TDH(0): |
| 554 | for (i = 0; i < 64; i++) |
| 555 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i)); |
| 556 | break; |
| 557 | case IXGBE_TDT(0): |
| 558 | for (i = 0; i < 64; i++) |
| 559 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i)); |
| 560 | break; |
| 561 | case IXGBE_TXDCTL(0): |
| 562 | for (i = 0; i < 64; i++) |
| 563 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i)); |
| 564 | break; |
| 565 | default: |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 566 | pr_info("%-15s %08x\n", reginfo->name, |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 567 | IXGBE_READ_REG(hw, reginfo->ofs)); |
| 568 | return; |
| 569 | } |
| 570 | |
| 571 | for (i = 0; i < 8; i++) { |
| 572 | snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 573 | pr_err("%-15s", rname); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 574 | for (j = 0; j < 8; j++) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 575 | pr_cont(" %08x", regs[i*8+j]); |
| 576 | pr_cont("\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | } |
| 580 | |
| 581 | /* |
| 582 | * ixgbe_dump - Print registers, tx-rings and rx-rings |
| 583 | */ |
| 584 | static void ixgbe_dump(struct ixgbe_adapter *adapter) |
| 585 | { |
| 586 | struct net_device *netdev = adapter->netdev; |
| 587 | struct ixgbe_hw *hw = &adapter->hw; |
| 588 | struct ixgbe_reg_info *reginfo; |
| 589 | int n = 0; |
| 590 | struct ixgbe_ring *tx_ring; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 591 | struct ixgbe_tx_buffer *tx_buffer; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 592 | union ixgbe_adv_tx_desc *tx_desc; |
| 593 | struct my_u0 { u64 a; u64 b; } *u0; |
| 594 | struct ixgbe_ring *rx_ring; |
| 595 | union ixgbe_adv_rx_desc *rx_desc; |
| 596 | struct ixgbe_rx_buffer *rx_buffer_info; |
| 597 | u32 staterr; |
| 598 | int i = 0; |
| 599 | |
| 600 | if (!netif_msg_hw(adapter)) |
| 601 | return; |
| 602 | |
| 603 | /* Print netdevice Info */ |
| 604 | if (netdev) { |
| 605 | dev_info(&adapter->pdev->dev, "Net device Info\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 606 | pr_info("Device Name state " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 607 | "trans_start last_rx\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 608 | pr_info("%-15s %016lX %016lX %016lX\n", |
| 609 | netdev->name, |
| 610 | netdev->state, |
| 611 | netdev->trans_start, |
| 612 | netdev->last_rx); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | /* Print Registers */ |
| 616 | dev_info(&adapter->pdev->dev, "Register Dump\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 617 | pr_info(" Register Name Value\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 618 | for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl; |
| 619 | reginfo->name; reginfo++) { |
| 620 | ixgbe_regdump(hw, reginfo); |
| 621 | } |
| 622 | |
| 623 | /* Print TX Ring Summary */ |
| 624 | if (!netdev || !netif_running(netdev)) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 625 | return; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 626 | |
| 627 | dev_info(&adapter->pdev->dev, "TX Rings Summary\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 628 | pr_info(" %s %s %s %s\n", |
| 629 | "Queue [NTU] [NTC] [bi(ntc)->dma ]", |
| 630 | "leng", "ntw", "timestamp"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 631 | for (n = 0; n < adapter->num_tx_queues; n++) { |
| 632 | tx_ring = adapter->tx_ring[n]; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 633 | tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean]; |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 634 | pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n", |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 635 | n, tx_ring->next_to_use, tx_ring->next_to_clean, |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 636 | (u64)dma_unmap_addr(tx_buffer, dma), |
| 637 | dma_unmap_len(tx_buffer, len), |
| 638 | tx_buffer->next_to_watch, |
| 639 | (u64)tx_buffer->time_stamp); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | /* Print TX Rings */ |
| 643 | if (!netif_msg_tx_done(adapter)) |
| 644 | goto rx_ring_summary; |
| 645 | |
| 646 | dev_info(&adapter->pdev->dev, "TX Rings Dump\n"); |
| 647 | |
| 648 | /* Transmit Descriptor Formats |
| 649 | * |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 650 | * 82598 Advanced Transmit Descriptor |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 651 | * +--------------------------------------------------------------+ |
| 652 | * 0 | Buffer Address [63:0] | |
| 653 | * +--------------------------------------------------------------+ |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 654 | * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 655 | * +--------------------------------------------------------------+ |
| 656 | * 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] | 657 | * |
| 658 | * 82598 Advanced Transmit Descriptor (Write-Back Format) |
| 659 | * +--------------------------------------------------------------+ |
| 660 | * 0 | RSV [63:0] | |
| 661 | * +--------------------------------------------------------------+ |
| 662 | * 8 | RSV | STA | NXTSEQ | |
| 663 | * +--------------------------------------------------------------+ |
| 664 | * 63 36 35 32 31 0 |
| 665 | * |
| 666 | * 82599+ Advanced Transmit Descriptor |
| 667 | * +--------------------------------------------------------------+ |
| 668 | * 0 | Buffer Address [63:0] | |
| 669 | * +--------------------------------------------------------------+ |
| 670 | * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN | |
| 671 | * +--------------------------------------------------------------+ |
| 672 | * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0 |
| 673 | * |
| 674 | * 82599+ Advanced Transmit Descriptor (Write-Back Format) |
| 675 | * +--------------------------------------------------------------+ |
| 676 | * 0 | RSV [63:0] | |
| 677 | * +--------------------------------------------------------------+ |
| 678 | * 8 | RSV | STA | RSV | |
| 679 | * +--------------------------------------------------------------+ |
| 680 | * 63 36 35 32 31 0 |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 681 | */ |
| 682 | |
| 683 | for (n = 0; n < adapter->num_tx_queues; n++) { |
| 684 | tx_ring = adapter->tx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 685 | pr_info("------------------------------------\n"); |
| 686 | pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index); |
| 687 | pr_info("------------------------------------\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 688 | pr_info("%s%s %s %s %s %s\n", |
| 689 | "T [desc] [address 63:0 ] ", |
| 690 | "[PlPOIdStDDt Ln] [bi->dma ] ", |
| 691 | "leng", "ntw", "timestamp", "bi->skb"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 692 | |
| 693 | for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 694 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 695 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 696 | u0 = (struct my_u0 *)tx_desc; |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 697 | if (dma_unmap_len(tx_buffer, len) > 0) { |
| 698 | pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p", |
| 699 | i, |
| 700 | le64_to_cpu(u0->a), |
| 701 | le64_to_cpu(u0->b), |
| 702 | (u64)dma_unmap_addr(tx_buffer, dma), |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 703 | dma_unmap_len(tx_buffer, len), |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 704 | tx_buffer->next_to_watch, |
| 705 | (u64)tx_buffer->time_stamp, |
| 706 | tx_buffer->skb); |
| 707 | if (i == tx_ring->next_to_use && |
| 708 | i == tx_ring->next_to_clean) |
| 709 | pr_cont(" NTC/U\n"); |
| 710 | else if (i == tx_ring->next_to_use) |
| 711 | pr_cont(" NTU\n"); |
| 712 | else if (i == tx_ring->next_to_clean) |
| 713 | pr_cont(" NTC\n"); |
| 714 | else |
| 715 | pr_cont("\n"); |
| 716 | |
| 717 | if (netif_msg_pktdata(adapter) && |
| 718 | tx_buffer->skb) |
| 719 | print_hex_dump(KERN_INFO, "", |
| 720 | DUMP_PREFIX_ADDRESS, 16, 1, |
| 721 | tx_buffer->skb->data, |
| 722 | dma_unmap_len(tx_buffer, len), |
| 723 | true); |
| 724 | } |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 725 | } |
| 726 | } |
| 727 | |
| 728 | /* Print RX Rings Summary */ |
| 729 | rx_ring_summary: |
| 730 | dev_info(&adapter->pdev->dev, "RX Rings Summary\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 731 | pr_info("Queue [NTU] [NTC]\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 732 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 733 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 734 | pr_info("%5d %5X %5X\n", |
| 735 | n, rx_ring->next_to_use, rx_ring->next_to_clean); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | /* Print RX Rings */ |
| 739 | if (!netif_msg_rx_status(adapter)) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 740 | return; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 741 | |
| 742 | dev_info(&adapter->pdev->dev, "RX Rings Dump\n"); |
| 743 | |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 744 | /* Receive Descriptor Formats |
| 745 | * |
| 746 | * 82598 Advanced Receive Descriptor (Read) Format |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 747 | * 63 1 0 |
| 748 | * +-----------------------------------------------------+ |
| 749 | * 0 | Packet Buffer Address [63:1] |A0/NSE| |
| 750 | * +----------------------------------------------+------+ |
| 751 | * 8 | Header Buffer Address [63:1] | DD | |
| 752 | * +-----------------------------------------------------+ |
| 753 | * |
| 754 | * |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 755 | * 82598 Advanced Receive Descriptor (Write-Back) Format |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 756 | * |
| 757 | * 63 48 47 32 31 30 21 20 16 15 4 3 0 |
| 758 | * +------------------------------------------------------+ |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 759 | * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS | |
| 760 | * | Packet | IP | | | | Type | Type | |
| 761 | * | Checksum | Ident | | | | | | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 762 | * +------------------------------------------------------+ |
| 763 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | |
| 764 | * +------------------------------------------------------+ |
| 765 | * 63 48 47 32 31 20 19 0 |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 766 | * |
| 767 | * 82599+ Advanced Receive Descriptor (Read) Format |
| 768 | * 63 1 0 |
| 769 | * +-----------------------------------------------------+ |
| 770 | * 0 | Packet Buffer Address [63:1] |A0/NSE| |
| 771 | * +----------------------------------------------+------+ |
| 772 | * 8 | Header Buffer Address [63:1] | DD | |
| 773 | * +-----------------------------------------------------+ |
| 774 | * |
| 775 | * |
| 776 | * 82599+ Advanced Receive Descriptor (Write-Back) Format |
| 777 | * |
| 778 | * 63 48 47 32 31 30 21 20 17 16 4 3 0 |
| 779 | * +------------------------------------------------------+ |
| 780 | * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS | |
| 781 | * |/ RTT / PCoE_PARAM | | | CNT | Type | Type | |
| 782 | * |/ Flow Dir Flt ID | | | | | | |
| 783 | * +------------------------------------------------------+ |
| 784 | * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP | |
| 785 | * +------------------------------------------------------+ |
| 786 | * 63 48 47 32 31 20 19 0 |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 787 | */ |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 788 | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 789 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 790 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 791 | pr_info("------------------------------------\n"); |
| 792 | pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index); |
| 793 | pr_info("------------------------------------\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 794 | pr_info("%s%s%s", |
| 795 | "R [desc] [ PktBuf A0] ", |
| 796 | "[ HeadBuf DD] [bi->dma ] [bi->skb ] ", |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 797 | "<-- Adv Rx Read format\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 798 | pr_info("%s%s%s", |
| 799 | "RWB[desc] [PcsmIpSHl PtRs] ", |
| 800 | "[vl er S cks ln] ---------------- [bi->skb ] ", |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 801 | "<-- Adv Rx Write-Back format\n"); |
| 802 | |
| 803 | for (i = 0; i < rx_ring->count; i++) { |
| 804 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 805 | rx_desc = IXGBE_RX_DESC(rx_ring, i); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 806 | u0 = (struct my_u0 *)rx_desc; |
| 807 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 808 | if (staterr & IXGBE_RXD_STAT_DD) { |
| 809 | /* Descriptor Done */ |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 810 | pr_info("RWB[0x%03X] %016llX " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 811 | "%016llX ---------------- %p", i, |
| 812 | le64_to_cpu(u0->a), |
| 813 | le64_to_cpu(u0->b), |
| 814 | rx_buffer_info->skb); |
| 815 | } else { |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 816 | pr_info("R [0x%03X] %016llX " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 817 | "%016llX %016llX %p", i, |
| 818 | le64_to_cpu(u0->a), |
| 819 | le64_to_cpu(u0->b), |
| 820 | (u64)rx_buffer_info->dma, |
| 821 | rx_buffer_info->skb); |
| 822 | |
Emil Tantilov | 9c50c03 | 2012-07-26 01:21:24 +0000 | [diff] [blame] | 823 | if (netif_msg_pktdata(adapter) && |
| 824 | rx_buffer_info->dma) { |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 825 | print_hex_dump(KERN_INFO, "", |
| 826 | DUMP_PREFIX_ADDRESS, 16, 1, |
Emil Tantilov | 9c50c03 | 2012-07-26 01:21:24 +0000 | [diff] [blame] | 827 | page_address(rx_buffer_info->page) + |
| 828 | rx_buffer_info->page_offset, |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 829 | ixgbe_rx_bufsz(rx_ring), true); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 830 | } |
| 831 | } |
| 832 | |
| 833 | if (i == rx_ring->next_to_use) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 834 | pr_cont(" NTU\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 835 | else if (i == rx_ring->next_to_clean) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 836 | pr_cont(" NTC\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 837 | else |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 838 | pr_cont("\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 839 | |
| 840 | } |
| 841 | } |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 842 | } |
| 843 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 844 | static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter) |
| 845 | { |
| 846 | u32 ctrl_ext; |
| 847 | |
| 848 | /* Let firmware take over control of h/w */ |
| 849 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 850 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 851 | ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter) |
| 855 | { |
| 856 | u32 ctrl_ext; |
| 857 | |
| 858 | /* Let firmware know the driver has taken over */ |
| 859 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 860 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 861 | ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 862 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 863 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 864 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 865 | * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors |
| 866 | * @adapter: pointer to adapter struct |
| 867 | * @direction: 0 for Rx, 1 for Tx, -1 for other causes |
| 868 | * @queue: queue to map the corresponding interrupt to |
| 869 | * @msix_vector: the vector to map to the corresponding queue |
| 870 | * |
| 871 | */ |
| 872 | static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 873 | u8 queue, u8 msix_vector) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 874 | { |
| 875 | u32 ivar, index; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 876 | struct ixgbe_hw *hw = &adapter->hw; |
| 877 | switch (hw->mac.type) { |
| 878 | case ixgbe_mac_82598EB: |
| 879 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 880 | if (direction == -1) |
| 881 | direction = 0; |
| 882 | index = (((direction * 64) + queue) >> 2) & 0x1F; |
| 883 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index)); |
| 884 | ivar &= ~(0xFF << (8 * (queue & 0x3))); |
| 885 | ivar |= (msix_vector << (8 * (queue & 0x3))); |
| 886 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar); |
| 887 | break; |
| 888 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 889 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 890 | case ixgbe_mac_X550: |
| 891 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 892 | case ixgbe_mac_x550em_a: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 893 | if (direction == -1) { |
| 894 | /* other causes */ |
| 895 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 896 | index = ((queue & 1) * 8); |
| 897 | ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC); |
| 898 | ivar &= ~(0xFF << index); |
| 899 | ivar |= (msix_vector << index); |
| 900 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar); |
| 901 | break; |
| 902 | } else { |
| 903 | /* tx or rx causes */ |
| 904 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 905 | index = ((16 * (queue & 1)) + (8 * direction)); |
| 906 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1)); |
| 907 | ivar &= ~(0xFF << index); |
| 908 | ivar |= (msix_vector << index); |
| 909 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar); |
| 910 | break; |
| 911 | } |
| 912 | default: |
| 913 | break; |
| 914 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 915 | } |
| 916 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 917 | static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 918 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 919 | { |
| 920 | u32 mask; |
| 921 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 922 | switch (adapter->hw.mac.type) { |
| 923 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 924 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 925 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 926 | break; |
| 927 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 928 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 929 | case ixgbe_mac_X550: |
| 930 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 931 | case ixgbe_mac_x550em_a: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 932 | mask = (qmask & 0xFFFFFFFF); |
| 933 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask); |
| 934 | mask = (qmask >> 32); |
| 935 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 936 | break; |
| 937 | default: |
| 938 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 939 | } |
| 940 | } |
| 941 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 942 | void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *ring, |
| 943 | struct ixgbe_tx_buffer *tx_buffer) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 944 | { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 945 | if (tx_buffer->skb) { |
| 946 | dev_kfree_skb_any(tx_buffer->skb); |
| 947 | if (dma_unmap_len(tx_buffer, len)) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 948 | dma_unmap_single(ring->dev, |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 949 | dma_unmap_addr(tx_buffer, dma), |
| 950 | dma_unmap_len(tx_buffer, len), |
| 951 | DMA_TO_DEVICE); |
| 952 | } else if (dma_unmap_len(tx_buffer, len)) { |
| 953 | dma_unmap_page(ring->dev, |
| 954 | dma_unmap_addr(tx_buffer, dma), |
| 955 | dma_unmap_len(tx_buffer, len), |
| 956 | DMA_TO_DEVICE); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 957 | } |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 958 | tx_buffer->next_to_watch = NULL; |
| 959 | tx_buffer->skb = NULL; |
| 960 | dma_unmap_len_set(tx_buffer, len, 0); |
| 961 | /* tx_buffer must be completely set up in the transmit path */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 962 | } |
| 963 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 964 | static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter) |
| 965 | { |
| 966 | struct ixgbe_hw *hw = &adapter->hw; |
| 967 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
| 968 | int i; |
| 969 | u32 data; |
| 970 | |
| 971 | if ((hw->fc.current_mode != ixgbe_fc_full) && |
| 972 | (hw->fc.current_mode != ixgbe_fc_rx_pause)) |
| 973 | return; |
| 974 | |
| 975 | switch (hw->mac.type) { |
| 976 | case ixgbe_mac_82598EB: |
| 977 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); |
| 978 | break; |
| 979 | default: |
| 980 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); |
| 981 | } |
| 982 | hwstats->lxoffrxc += data; |
| 983 | |
| 984 | /* refill credits (no tx hang) if we received xoff */ |
| 985 | if (!data) |
| 986 | return; |
| 987 | |
| 988 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 989 | clear_bit(__IXGBE_HANG_CHECK_ARMED, |
| 990 | &adapter->tx_ring[i]->state); |
| 991 | } |
| 992 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 993 | static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 994 | { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 995 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 996 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 997 | u32 xoff[8] = {0}; |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 998 | u8 tc; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 999 | int i; |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 1000 | bool pfc_en = adapter->dcb_cfg.pfc_mode_enable; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1001 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 1002 | if (adapter->ixgbe_ieee_pfc) |
| 1003 | pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1004 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 1005 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) { |
| 1006 | ixgbe_update_xoff_rx_lfc(adapter); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1007 | return; |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 1008 | } |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1009 | |
| 1010 | /* update stats for each tc, only valid with PFC enabled */ |
| 1011 | for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) { |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 1012 | u32 pxoffrxc; |
| 1013 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1014 | switch (hw->mac.type) { |
| 1015 | case ixgbe_mac_82598EB: |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 1016 | pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i)); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1017 | break; |
| 1018 | default: |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 1019 | pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i)); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1020 | } |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 1021 | hwstats->pxoffrxc[i] += pxoffrxc; |
| 1022 | /* Get the TC for given UP */ |
| 1023 | tc = netdev_get_prio_tc_map(adapter->netdev, i); |
| 1024 | xoff[tc] += pxoffrxc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1027 | /* disarm tx queues that have received xoff frames */ |
| 1028 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 1029 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1030 | |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 1031 | tc = tx_ring->dcb_tc; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1032 | if (xoff[tc]) |
| 1033 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
| 1034 | } |
| 1035 | } |
| 1036 | |
| 1037 | static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring) |
| 1038 | { |
Alexander Duyck | 7d7ce68 | 2012-02-08 07:50:51 +0000 | [diff] [blame] | 1039 | return ring->stats.packets; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring) |
| 1043 | { |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 1044 | struct ixgbe_adapter *adapter; |
| 1045 | struct ixgbe_hw *hw; |
| 1046 | u32 head, tail; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1047 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 1048 | if (ring->l2_accel_priv) |
| 1049 | adapter = ring->l2_accel_priv->real_adapter; |
| 1050 | else |
| 1051 | adapter = netdev_priv(ring->netdev); |
| 1052 | |
| 1053 | hw = &adapter->hw; |
| 1054 | head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx)); |
| 1055 | tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx)); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1056 | |
| 1057 | if (head != tail) |
| 1058 | return (head < tail) ? |
| 1059 | tail - head : (tail + ring->count - head); |
| 1060 | |
| 1061 | return 0; |
| 1062 | } |
| 1063 | |
| 1064 | static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring) |
| 1065 | { |
| 1066 | u32 tx_done = ixgbe_get_tx_completed(tx_ring); |
| 1067 | u32 tx_done_old = tx_ring->tx_stats.tx_done_old; |
| 1068 | u32 tx_pending = ixgbe_get_tx_pending(tx_ring); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1069 | |
| 1070 | clear_check_for_tx_hang(tx_ring); |
| 1071 | |
| 1072 | /* |
| 1073 | * Check for a hung queue, but be thorough. This verifies |
| 1074 | * that a transmit has been completed since the previous |
| 1075 | * check AND there is at least one packet pending. The |
| 1076 | * ARMED bit is set to indicate a potential hang. The |
| 1077 | * bit is cleared if a pause frame is received to remove |
| 1078 | * false hang detection due to PFC or 802.3x frames. By |
| 1079 | * requiring this to fail twice we avoid races with |
| 1080 | * pfc clearing the ARMED bit and conditions where we |
| 1081 | * run the check_tx_hang logic with a transmit completion |
| 1082 | * pending but without time to complete it yet. |
| 1083 | */ |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 1084 | if (tx_done_old == tx_done && tx_pending) |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1085 | /* make sure it is true for two checks in a row */ |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 1086 | return test_and_set_bit(__IXGBE_HANG_CHECK_ARMED, |
| 1087 | &tx_ring->state); |
| 1088 | /* update completed stats and continue */ |
| 1089 | tx_ring->tx_stats.tx_done_old = tx_done; |
| 1090 | /* reset the countdown */ |
| 1091 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1092 | |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 1093 | return false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1094 | } |
| 1095 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 1096 | /** |
| 1097 | * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout |
| 1098 | * @adapter: driver private struct |
| 1099 | **/ |
| 1100 | static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter) |
| 1101 | { |
| 1102 | |
| 1103 | /* Do the reset outside of interrupt context */ |
| 1104 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1105 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; |
Jacob Keller | 12ff3f3 | 2012-12-01 07:57:17 +0000 | [diff] [blame] | 1106 | e_warn(drv, "initiating reset due to tx timeout\n"); |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 1107 | ixgbe_service_event_schedule(adapter); |
| 1108 | } |
| 1109 | } |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1110 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1111 | /** |
Rostislav Pehlivanov | c04f90e | 2016-01-27 18:33:30 +0000 | [diff] [blame] | 1112 | * ixgbe_tx_maxrate - callback to set the maximum per-queue bitrate |
| 1113 | **/ |
| 1114 | static int ixgbe_tx_maxrate(struct net_device *netdev, |
| 1115 | int queue_index, u32 maxrate) |
| 1116 | { |
| 1117 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1118 | struct ixgbe_hw *hw = &adapter->hw; |
| 1119 | u32 bcnrc_val = ixgbe_link_mbps(adapter); |
| 1120 | |
| 1121 | if (!maxrate) |
| 1122 | return 0; |
| 1123 | |
| 1124 | /* Calculate the rate factor values to set */ |
| 1125 | bcnrc_val <<= IXGBE_RTTBCNRC_RF_INT_SHIFT; |
| 1126 | bcnrc_val /= maxrate; |
| 1127 | |
| 1128 | /* clear everything but the rate factor */ |
| 1129 | bcnrc_val &= IXGBE_RTTBCNRC_RF_INT_MASK | |
| 1130 | IXGBE_RTTBCNRC_RF_DEC_MASK; |
| 1131 | |
| 1132 | /* enable the rate scheduler */ |
| 1133 | bcnrc_val |= IXGBE_RTTBCNRC_RS_ENA; |
| 1134 | |
| 1135 | IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, queue_index); |
| 1136 | IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val); |
| 1137 | |
| 1138 | return 0; |
| 1139 | } |
| 1140 | |
| 1141 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1142 | * ixgbe_clean_tx_irq - Reclaim resources after transmit completes |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1143 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1144 | * @tx_ring: tx ring to clean |
Alexander Duyck | 8220bbc | 2016-03-07 09:30:09 -0800 | [diff] [blame] | 1145 | * @napi_budget: Used to determine if we are in netpoll |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1146 | **/ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1147 | 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] | 1148 | struct ixgbe_ring *tx_ring, int napi_budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1149 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1150 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1151 | struct ixgbe_tx_buffer *tx_buffer; |
| 1152 | union ixgbe_adv_tx_desc *tx_desc; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1153 | unsigned int total_bytes = 0, total_packets = 0; |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 1154 | unsigned int budget = q_vector->tx.work_limit; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1155 | unsigned int i = tx_ring->next_to_clean; |
| 1156 | |
| 1157 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1158 | return true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1159 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1160 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1161 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1162 | i -= tx_ring->count; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 1163 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1164 | do { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1165 | union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1166 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1167 | /* if next_to_watch is not set then there is no work pending */ |
| 1168 | if (!eop_desc) |
| 1169 | break; |
| 1170 | |
Alexander Duyck | 7f83a9e | 2012-02-08 07:49:23 +0000 | [diff] [blame] | 1171 | /* prevent any other reads prior to eop_desc */ |
Alexander Duyck | 7e63bf4 | 2013-01-08 07:00:58 +0000 | [diff] [blame] | 1172 | read_barrier_depends(); |
Alexander Duyck | 7f83a9e | 2012-02-08 07:49:23 +0000 | [diff] [blame] | 1173 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1174 | /* if DD is not set pending work has not been completed */ |
| 1175 | if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD))) |
| 1176 | break; |
| 1177 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1178 | /* clear next_to_watch to prevent false hangs */ |
| 1179 | tx_buffer->next_to_watch = NULL; |
| 1180 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 1181 | /* update the statistics for this packet */ |
| 1182 | total_bytes += tx_buffer->bytecount; |
| 1183 | total_packets += tx_buffer->gso_segs; |
| 1184 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1185 | /* free the skb */ |
Jesper Dangaard Brouer | a3a8749 | 2016-02-08 13:15:09 +0100 | [diff] [blame] | 1186 | napi_consume_skb(tx_buffer->skb, napi_budget); |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1187 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1188 | /* unmap skb header data */ |
| 1189 | dma_unmap_single(tx_ring->dev, |
| 1190 | dma_unmap_addr(tx_buffer, dma), |
| 1191 | dma_unmap_len(tx_buffer, len), |
| 1192 | DMA_TO_DEVICE); |
| 1193 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1194 | /* clear tx_buffer data */ |
| 1195 | tx_buffer->skb = NULL; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1196 | dma_unmap_len_set(tx_buffer, len, 0); |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1197 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1198 | /* unmap remaining buffers */ |
| 1199 | while (tx_desc != eop_desc) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1200 | tx_buffer++; |
| 1201 | tx_desc++; |
| 1202 | i++; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1203 | if (unlikely(!i)) { |
| 1204 | i -= tx_ring->count; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1205 | tx_buffer = tx_ring->tx_buffer_info; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1206 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1207 | } |
| 1208 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1209 | /* unmap any remaining paged data */ |
| 1210 | if (dma_unmap_len(tx_buffer, len)) { |
| 1211 | dma_unmap_page(tx_ring->dev, |
| 1212 | dma_unmap_addr(tx_buffer, dma), |
| 1213 | dma_unmap_len(tx_buffer, len), |
| 1214 | DMA_TO_DEVICE); |
| 1215 | dma_unmap_len_set(tx_buffer, len, 0); |
| 1216 | } |
| 1217 | } |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 1218 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1219 | /* move us one more past the eop_desc for start of next pkt */ |
| 1220 | tx_buffer++; |
| 1221 | tx_desc++; |
| 1222 | i++; |
| 1223 | if (unlikely(!i)) { |
| 1224 | i -= tx_ring->count; |
| 1225 | tx_buffer = tx_ring->tx_buffer_info; |
| 1226 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
| 1227 | } |
| 1228 | |
| 1229 | /* issue prefetch for next Tx descriptor */ |
| 1230 | prefetch(tx_desc); |
| 1231 | |
| 1232 | /* update budget accounting */ |
| 1233 | budget--; |
| 1234 | } while (likely(budget)); |
| 1235 | |
| 1236 | i += tx_ring->count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1237 | tx_ring->next_to_clean = i; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1238 | u64_stats_update_begin(&tx_ring->syncp); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1239 | tx_ring->stats.bytes += total_bytes; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1240 | tx_ring->stats.packets += total_packets; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1241 | u64_stats_update_end(&tx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1242 | q_vector->tx.total_bytes += total_bytes; |
| 1243 | q_vector->tx.total_packets += total_packets; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1244 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1245 | 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] | 1246 | /* schedule immediate reset if we believe we hung */ |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1247 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1248 | e_err(drv, "Detected Tx Unit Hang\n" |
| 1249 | " Tx Queue <%d>\n" |
| 1250 | " TDH, TDT <%x>, <%x>\n" |
| 1251 | " next_to_use <%x>\n" |
| 1252 | " next_to_clean <%x>\n" |
| 1253 | "tx_buffer_info[next_to_clean]\n" |
| 1254 | " time_stamp <%lx>\n" |
| 1255 | " jiffies <%lx>\n", |
| 1256 | tx_ring->queue_index, |
| 1257 | IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)), |
| 1258 | IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)), |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1259 | tx_ring->next_to_use, i, |
| 1260 | tx_ring->tx_buffer_info[i].time_stamp, jiffies); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1261 | |
| 1262 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 1263 | |
| 1264 | e_info(probe, |
| 1265 | "tx hang %d detected on queue %d, resetting adapter\n", |
| 1266 | adapter->tx_timeout_count + 1, tx_ring->queue_index); |
| 1267 | |
| 1268 | /* schedule immediate reset if we believe we hung */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 1269 | ixgbe_tx_timeout_reset(adapter); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1270 | |
| 1271 | /* the adapter is about to reset, no point in enabling stuff */ |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 1272 | return true; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1273 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1274 | |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 1275 | netdev_tx_completed_queue(txring_txq(tx_ring), |
| 1276 | total_packets, total_bytes); |
| 1277 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 1278 | #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) |
Alexander Duyck | 30065e6 | 2011-07-15 03:05:14 +0000 | [diff] [blame] | 1279 | if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) && |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 1280 | (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 1281 | /* Make sure that anybody stopping the queue after this |
| 1282 | * sees the new next_to_clean. |
| 1283 | */ |
| 1284 | smp_mb(); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1285 | if (__netif_subqueue_stopped(tx_ring->netdev, |
| 1286 | tx_ring->queue_index) |
| 1287 | && !test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1288 | netif_wake_subqueue(tx_ring->netdev, |
| 1289 | tx_ring->queue_index); |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 1290 | ++tx_ring->tx_stats.restart_queue; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 1291 | } |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 1292 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1293 | |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 1294 | return !!budget; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1295 | } |
| 1296 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1297 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1298 | static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter, |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1299 | struct ixgbe_ring *tx_ring, |
| 1300 | int cpu) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1301 | { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 1302 | struct ixgbe_hw *hw = &adapter->hw; |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1303 | u32 txctrl = 0; |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1304 | u16 reg_offset; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1305 | |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1306 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1307 | txctrl = dca3_get_tag(tx_ring->dev, cpu); |
| 1308 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1309 | switch (hw->mac.type) { |
| 1310 | case ixgbe_mac_82598EB: |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1311 | reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1312 | break; |
| 1313 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1314 | case ixgbe_mac_X540: |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1315 | reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx); |
| 1316 | txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599; |
| 1317 | break; |
| 1318 | default: |
| 1319 | /* for unknown hardware do not write register */ |
| 1320 | return; |
| 1321 | } |
| 1322 | |
| 1323 | /* |
| 1324 | * We can enable relaxed ordering for reads, but not writes when |
| 1325 | * DCA is enabled. This is due to a known issue in some chipsets |
| 1326 | * which will cause the DCA tag to be cleared. |
| 1327 | */ |
| 1328 | txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN | |
| 1329 | IXGBE_DCA_TXCTRL_DATA_RRO_EN | |
| 1330 | IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
| 1331 | |
| 1332 | IXGBE_WRITE_REG(hw, reg_offset, txctrl); |
| 1333 | } |
| 1334 | |
| 1335 | static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter, |
| 1336 | struct ixgbe_ring *rx_ring, |
| 1337 | int cpu) |
| 1338 | { |
| 1339 | struct ixgbe_hw *hw = &adapter->hw; |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1340 | u32 rxctrl = 0; |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1341 | u8 reg_idx = rx_ring->reg_idx; |
| 1342 | |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1343 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1344 | rxctrl = dca3_get_tag(rx_ring->dev, cpu); |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1345 | |
| 1346 | switch (hw->mac.type) { |
| 1347 | case ixgbe_mac_82599EB: |
| 1348 | case ixgbe_mac_X540: |
| 1349 | rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1350 | break; |
| 1351 | default: |
| 1352 | break; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1353 | } |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1354 | |
| 1355 | /* |
| 1356 | * We can enable relaxed ordering for reads, but not writes when |
| 1357 | * DCA is enabled. This is due to a known issue in some chipsets |
| 1358 | * which will cause the DCA tag to be cleared. |
| 1359 | */ |
| 1360 | rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN | |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1361 | IXGBE_DCA_RXCTRL_DATA_DCA_EN | |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1362 | IXGBE_DCA_RXCTRL_DESC_DCA_EN; |
| 1363 | |
| 1364 | IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector) |
| 1368 | { |
| 1369 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1370 | struct ixgbe_ring *ring; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1371 | int cpu = get_cpu(); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1372 | |
| 1373 | if (q_vector->cpu == cpu) |
| 1374 | goto out_no_update; |
| 1375 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 1376 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1377 | ixgbe_update_tx_dca(adapter, ring, cpu); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1378 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 1379 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1380 | ixgbe_update_rx_dca(adapter, ring, cpu); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1381 | |
| 1382 | q_vector->cpu = cpu; |
| 1383 | out_no_update: |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1384 | put_cpu(); |
| 1385 | } |
| 1386 | |
| 1387 | static void ixgbe_setup_dca(struct ixgbe_adapter *adapter) |
| 1388 | { |
| 1389 | int i; |
| 1390 | |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 1391 | /* always use CB2 mode, difference is masked in the CB driver */ |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1392 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1393 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 1394 | IXGBE_DCA_CTRL_DCA_MODE_CB2); |
| 1395 | else |
| 1396 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 1397 | IXGBE_DCA_CTRL_DCA_DISABLE); |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 1398 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 1399 | for (i = 0; i < adapter->num_q_vectors; i++) { |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1400 | adapter->q_vector[i]->cpu = -1; |
| 1401 | ixgbe_update_dca(adapter->q_vector[i]); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1402 | } |
| 1403 | } |
| 1404 | |
| 1405 | static int __ixgbe_notify_dca(struct device *dev, void *data) |
| 1406 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 1407 | struct ixgbe_adapter *adapter = dev_get_drvdata(dev); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1408 | unsigned long event = *(unsigned long *)data; |
| 1409 | |
Don Skidmore | 2a72c31 | 2011-07-20 02:27:05 +0000 | [diff] [blame] | 1410 | if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE)) |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1411 | return 0; |
| 1412 | |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1413 | switch (event) { |
| 1414 | case DCA_PROVIDER_ADD: |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 1415 | /* if we're already enabled, don't do it again */ |
| 1416 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1417 | break; |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 1418 | if (dca_add_requester(dev) == 0) { |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 1419 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1420 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 1421 | IXGBE_DCA_CTRL_DCA_MODE_CB2); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1422 | break; |
| 1423 | } |
| 1424 | /* Fall Through since DCA is disabled. */ |
| 1425 | case DCA_PROVIDER_REMOVE: |
| 1426 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 1427 | dca_remove_requester(dev); |
| 1428 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1429 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 1430 | IXGBE_DCA_CTRL_DCA_DISABLE); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1431 | } |
| 1432 | break; |
| 1433 | } |
| 1434 | |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 1435 | return 0; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1436 | } |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1437 | |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1438 | #endif /* CONFIG_IXGBE_DCA */ |
Fan Du | 7edda4b | 2015-04-29 10:57:39 +0800 | [diff] [blame] | 1439 | |
| 1440 | #define IXGBE_RSS_L4_TYPES_MASK \ |
| 1441 | ((1ul << IXGBE_RXDADV_RSSTYPE_IPV4_TCP) | \ |
| 1442 | (1ul << IXGBE_RXDADV_RSSTYPE_IPV4_UDP) | \ |
| 1443 | (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_TCP) | \ |
| 1444 | (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_UDP)) |
| 1445 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1446 | static inline void ixgbe_rx_hash(struct ixgbe_ring *ring, |
| 1447 | union ixgbe_adv_rx_desc *rx_desc, |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1448 | struct sk_buff *skb) |
| 1449 | { |
Fan Du | 7edda4b | 2015-04-29 10:57:39 +0800 | [diff] [blame] | 1450 | u16 rss_type; |
| 1451 | |
| 1452 | if (!(ring->netdev->features & NETIF_F_RXHASH)) |
| 1453 | return; |
| 1454 | |
| 1455 | rss_type = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) & |
| 1456 | IXGBE_RXDADV_RSSTYPE_MASK; |
| 1457 | |
| 1458 | if (!rss_type) |
| 1459 | return; |
| 1460 | |
| 1461 | skb_set_hash(skb, le32_to_cpu(rx_desc->wb.lower.hi_dword.rss), |
| 1462 | (IXGBE_RSS_L4_TYPES_MASK & (1ul << rss_type)) ? |
| 1463 | PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3); |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1464 | } |
| 1465 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1466 | #ifdef IXGBE_FCOE |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1467 | /** |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1468 | * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1469 | * @ring: structure containing ring specific data |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1470 | * @rx_desc: advanced rx descriptor |
| 1471 | * |
| 1472 | * Returns : true if it is FCoE pkt |
| 1473 | */ |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1474 | static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring, |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1475 | union ixgbe_adv_rx_desc *rx_desc) |
| 1476 | { |
| 1477 | __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 1478 | |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1479 | return test_bit(__IXGBE_RX_FCOE, &ring->state) && |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1480 | ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) == |
| 1481 | (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE << |
| 1482 | IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT))); |
| 1483 | } |
| 1484 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1485 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1486 | /** |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1487 | * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1488 | * @ring: structure containing ring specific data |
| 1489 | * @rx_desc: current Rx descriptor being processed |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1490 | * @skb: skb currently being received and modified |
| 1491 | **/ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1492 | static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring, |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1493 | union ixgbe_adv_rx_desc *rx_desc, |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1494 | struct sk_buff *skb) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1495 | { |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1496 | __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 1497 | __le16 hdr_info = rx_desc->wb.lower.lo_dword.hs_rss.hdr_info; |
| 1498 | bool encap_pkt = false; |
| 1499 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1500 | skb_checksum_none_assert(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1501 | |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 1502 | /* Rx csum disabled */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1503 | if (!(ring->netdev->features & NETIF_F_RXCSUM)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1504 | return; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1505 | |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1506 | if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_VXLAN)) && |
| 1507 | (hdr_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_TUNNEL >> 16))) { |
| 1508 | encap_pkt = true; |
| 1509 | skb->encapsulation = 1; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1510 | } |
| 1511 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1512 | /* if IP and error */ |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1513 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) && |
| 1514 | ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1515 | ring->rx_stats.csum_err++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1516 | return; |
| 1517 | } |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1518 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1519 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS)) |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1520 | return; |
| 1521 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1522 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) { |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1523 | /* |
| 1524 | * 82599 errata, UDP frames with a 0 checksum can be marked as |
| 1525 | * checksum errors. |
| 1526 | */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1527 | if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) && |
| 1528 | test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state)) |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1529 | return; |
| 1530 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1531 | ring->rx_stats.csum_err++; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1532 | return; |
| 1533 | } |
| 1534 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1535 | /* It must be a TCP or UDP packet with a valid checksum */ |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1536 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1537 | if (encap_pkt) { |
| 1538 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_OUTERIPCS)) |
| 1539 | return; |
| 1540 | |
| 1541 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_OUTERIPER)) { |
Mark Rustad | d469251 | 2015-12-04 11:26:43 -0800 | [diff] [blame] | 1542 | skb->ip_summed = CHECKSUM_NONE; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1543 | return; |
| 1544 | } |
| 1545 | /* If we checked the outer header let the stack know */ |
| 1546 | skb->csum_level = 1; |
| 1547 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1548 | } |
| 1549 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1550 | static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring, |
| 1551 | struct ixgbe_rx_buffer *bi) |
| 1552 | { |
| 1553 | struct page *page = bi->page; |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1554 | dma_addr_t dma; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1555 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1556 | /* since we are recycling buffers we should seldom need to alloc */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1557 | if (likely(page)) |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1558 | return true; |
| 1559 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1560 | /* alloc new page for storage */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1561 | page = dev_alloc_pages(ixgbe_rx_pg_order(rx_ring)); |
| 1562 | if (unlikely(!page)) { |
| 1563 | rx_ring->rx_stats.alloc_rx_page_failed++; |
| 1564 | return false; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1565 | } |
| 1566 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1567 | /* map page for use */ |
| 1568 | dma = dma_map_page(rx_ring->dev, page, 0, |
| 1569 | ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1570 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1571 | /* |
| 1572 | * if mapping failed free memory back to system since |
| 1573 | * there isn't much point in holding memory we can't use |
| 1574 | */ |
| 1575 | if (dma_mapping_error(rx_ring->dev, dma)) { |
Alexander Duyck | dd411ec | 2012-04-06 04:24:50 +0000 | [diff] [blame] | 1576 | __free_pages(page, ixgbe_rx_pg_order(rx_ring)); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1577 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1578 | rx_ring->rx_stats.alloc_rx_page_failed++; |
| 1579 | return false; |
| 1580 | } |
| 1581 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1582 | bi->dma = dma; |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1583 | bi->page = page; |
Alexander Duyck | afaa945 | 2012-07-20 08:08:12 +0000 | [diff] [blame] | 1584 | bi->page_offset = 0; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1585 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1586 | return true; |
| 1587 | } |
| 1588 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1589 | /** |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1590 | * ixgbe_alloc_rx_buffers - Replace used receive buffers |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1591 | * @rx_ring: ring to place buffers on |
| 1592 | * @cleaned_count: number of buffers to replace |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1593 | **/ |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1594 | 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] | 1595 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1596 | union ixgbe_adv_rx_desc *rx_desc; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1597 | struct ixgbe_rx_buffer *bi; |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1598 | u16 i = rx_ring->next_to_use; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1599 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1600 | /* nothing to do */ |
| 1601 | if (!cleaned_count) |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1602 | return; |
| 1603 | |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1604 | rx_desc = IXGBE_RX_DESC(rx_ring, i); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1605 | bi = &rx_ring->rx_buffer_info[i]; |
| 1606 | i -= rx_ring->count; |
| 1607 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1608 | do { |
| 1609 | if (!ixgbe_alloc_mapped_page(rx_ring, bi)) |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1610 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1611 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1612 | /* |
| 1613 | * Refresh the desc even if buffer_addrs didn't change |
| 1614 | * because each write-back erases this info. |
| 1615 | */ |
| 1616 | 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] | 1617 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1618 | rx_desc++; |
| 1619 | bi++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1620 | i++; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1621 | if (unlikely(!i)) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1622 | rx_desc = IXGBE_RX_DESC(rx_ring, 0); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1623 | bi = rx_ring->rx_buffer_info; |
| 1624 | i -= rx_ring->count; |
| 1625 | } |
| 1626 | |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1627 | /* clear the status bits for the next_to_use descriptor */ |
| 1628 | rx_desc->wb.upper.status_error = 0; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1629 | |
| 1630 | cleaned_count--; |
| 1631 | } while (cleaned_count); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1632 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1633 | i += rx_ring->count; |
| 1634 | |
Alexander Duyck | ad435ec | 2014-11-14 00:56:35 +0000 | [diff] [blame] | 1635 | if (rx_ring->next_to_use != i) { |
| 1636 | rx_ring->next_to_use = i; |
| 1637 | |
| 1638 | /* update next to alloc since we have filled the ring */ |
| 1639 | rx_ring->next_to_alloc = i; |
| 1640 | |
| 1641 | /* Force memory writes to complete before letting h/w |
| 1642 | * know there are new descriptors to fetch. (Only |
| 1643 | * applicable for weak-ordered memory model archs, |
| 1644 | * such as IA-64). |
| 1645 | */ |
| 1646 | wmb(); |
| 1647 | writel(i, rx_ring->tail); |
| 1648 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1649 | } |
| 1650 | |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1651 | static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring, |
| 1652 | struct sk_buff *skb) |
| 1653 | { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1654 | u16 hdr_len = skb_headlen(skb); |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1655 | |
| 1656 | /* set gso_size to avoid messing up TCP MSS */ |
| 1657 | skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len), |
| 1658 | IXGBE_CB(skb)->append_cnt); |
Alexander Duyck | 96be80a | 2013-02-12 09:45:44 +0000 | [diff] [blame] | 1659 | skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4; |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1660 | } |
| 1661 | |
| 1662 | static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring, |
| 1663 | struct sk_buff *skb) |
| 1664 | { |
| 1665 | /* if append_cnt is 0 then frame is not RSC */ |
| 1666 | if (!IXGBE_CB(skb)->append_cnt) |
| 1667 | return; |
| 1668 | |
| 1669 | rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt; |
| 1670 | rx_ring->rx_stats.rsc_flush++; |
| 1671 | |
| 1672 | ixgbe_set_rsc_gso_size(rx_ring, skb); |
| 1673 | |
| 1674 | /* gso_size is computed using append_cnt so always clear it last */ |
| 1675 | IXGBE_CB(skb)->append_cnt = 0; |
| 1676 | } |
| 1677 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1678 | /** |
| 1679 | * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor |
| 1680 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1681 | * @rx_desc: pointer to the EOP Rx descriptor |
| 1682 | * @skb: pointer to current skb being populated |
| 1683 | * |
| 1684 | * This function checks the ring, descriptor, and packet information in |
| 1685 | * order to populate the hash, checksum, VLAN, timestamp, protocol, and |
| 1686 | * other fields within the skb. |
| 1687 | **/ |
| 1688 | static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring, |
| 1689 | union ixgbe_adv_rx_desc *rx_desc, |
| 1690 | struct sk_buff *skb) |
| 1691 | { |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1692 | struct net_device *dev = rx_ring->netdev; |
Mark Rustad | a9763f3 | 2015-10-27 09:58:07 -0700 | [diff] [blame] | 1693 | u32 flags = rx_ring->q_vector->adapter->flags; |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1694 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1695 | ixgbe_update_rsc_stats(rx_ring, skb); |
| 1696 | |
| 1697 | ixgbe_rx_hash(rx_ring, rx_desc, skb); |
| 1698 | |
| 1699 | ixgbe_rx_checksum(rx_ring, rx_desc, skb); |
| 1700 | |
Mark Rustad | a9763f3 | 2015-10-27 09:58:07 -0700 | [diff] [blame] | 1701 | if (unlikely(flags & IXGBE_FLAG_RX_HWTSTAMP_ENABLED)) |
| 1702 | ixgbe_ptp_rx_hwtstamp(rx_ring, rx_desc, skb); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 1703 | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 1704 | if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) && |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1705 | ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1706 | u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan); |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 1707 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid); |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1708 | } |
| 1709 | |
| 1710 | skb_record_rx_queue(skb, rx_ring->queue_index); |
| 1711 | |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1712 | skb->protocol = eth_type_trans(skb, dev); |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1713 | } |
| 1714 | |
| 1715 | static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector, |
| 1716 | struct sk_buff *skb) |
| 1717 | { |
Eric Dumazet | 93f93a4 | 2015-11-18 06:30:59 -0800 | [diff] [blame] | 1718 | skb_mark_napi_id(skb, &q_vector->napi); |
Jacob Keller | b464003 | 2013-10-01 04:33:54 -0700 | [diff] [blame] | 1719 | if (ixgbe_qv_busy_polling(q_vector)) |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 1720 | netif_receive_skb(skb); |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1721 | else |
Alexander Duyck | 856f606 | 2015-02-25 17:45:54 +0000 | [diff] [blame] | 1722 | napi_gro_receive(&q_vector->napi, skb); |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1723 | } |
Mallikarjuna R Chilakala | 43634e8 | 2010-02-25 23:14:37 +0000 | [diff] [blame] | 1724 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1725 | /** |
| 1726 | * ixgbe_is_non_eop - process handling of non-EOP buffers |
| 1727 | * @rx_ring: Rx ring being processed |
| 1728 | * @rx_desc: Rx descriptor for current buffer |
| 1729 | * @skb: Current socket buffer containing buffer in progress |
| 1730 | * |
| 1731 | * This function updates next to clean. If the buffer is an EOP buffer |
| 1732 | * this function exits returning false, otherwise it will place the |
| 1733 | * sk_buff in the next buffer to be chained and return true indicating |
| 1734 | * that this is in fact a non-EOP buffer. |
| 1735 | **/ |
| 1736 | static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring, |
| 1737 | union ixgbe_adv_rx_desc *rx_desc, |
| 1738 | struct sk_buff *skb) |
| 1739 | { |
| 1740 | u32 ntc = rx_ring->next_to_clean + 1; |
| 1741 | |
| 1742 | /* fetch, update, and store next to clean */ |
| 1743 | ntc = (ntc < rx_ring->count) ? ntc : 0; |
| 1744 | rx_ring->next_to_clean = ntc; |
| 1745 | |
| 1746 | prefetch(IXGBE_RX_DESC(rx_ring, ntc)); |
| 1747 | |
Alexander Duyck | 5a02cbd | 2012-07-20 08:08:51 +0000 | [diff] [blame] | 1748 | /* update RSC append count if present */ |
| 1749 | if (ring_is_rsc_enabled(rx_ring)) { |
| 1750 | __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data & |
| 1751 | cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK); |
| 1752 | |
| 1753 | if (unlikely(rsc_enabled)) { |
| 1754 | u32 rsc_cnt = le32_to_cpu(rsc_enabled); |
| 1755 | |
| 1756 | rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT; |
| 1757 | IXGBE_CB(skb)->append_cnt += rsc_cnt - 1; |
| 1758 | |
| 1759 | /* update ntc based on RSC value */ |
| 1760 | ntc = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 1761 | ntc &= IXGBE_RXDADV_NEXTP_MASK; |
| 1762 | ntc >>= IXGBE_RXDADV_NEXTP_SHIFT; |
| 1763 | } |
| 1764 | } |
| 1765 | |
| 1766 | /* 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] | 1767 | if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))) |
| 1768 | return false; |
| 1769 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1770 | /* place skb in next buffer to be received */ |
| 1771 | rx_ring->rx_buffer_info[ntc].skb = skb; |
| 1772 | rx_ring->rx_stats.non_eop_descs++; |
| 1773 | |
| 1774 | return true; |
| 1775 | } |
| 1776 | |
| 1777 | /** |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1778 | * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail |
| 1779 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1780 | * @skb: pointer to current skb being adjusted |
| 1781 | * |
| 1782 | * This function is an ixgbe specific version of __pskb_pull_tail. The |
| 1783 | * main difference between this version and the original function is that |
| 1784 | * this function can make several assumptions about the state of things |
| 1785 | * that allow for significant optimizations versus the standard function. |
| 1786 | * As a result we can do things like drop a frag and maintain an accurate |
| 1787 | * truesize for the skb. |
| 1788 | */ |
| 1789 | static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring, |
| 1790 | struct sk_buff *skb) |
| 1791 | { |
| 1792 | struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0]; |
| 1793 | unsigned char *va; |
| 1794 | unsigned int pull_len; |
| 1795 | |
| 1796 | /* |
| 1797 | * it is valid to use page_address instead of kmap since we are |
| 1798 | * working with pages allocated out of the lomem pool per |
| 1799 | * alloc_page(GFP_ATOMIC) |
| 1800 | */ |
| 1801 | va = skb_frag_address(frag); |
| 1802 | |
| 1803 | /* |
| 1804 | * we need the header to contain the greater of either ETH_HLEN or |
| 1805 | * 60 bytes if the skb->len is less than 60 for skb_pad. |
| 1806 | */ |
Alexander Duyck | 8496e33 | 2014-09-05 19:22:18 -0400 | [diff] [blame] | 1807 | pull_len = eth_get_headlen(va, IXGBE_RX_HDR_SIZE); |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1808 | |
| 1809 | /* align pull length to size of long to optimize memcpy performance */ |
| 1810 | skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long))); |
| 1811 | |
| 1812 | /* update all of the pointers */ |
| 1813 | skb_frag_size_sub(frag, pull_len); |
| 1814 | frag->page_offset += pull_len; |
| 1815 | skb->data_len -= pull_len; |
| 1816 | skb->tail += pull_len; |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1817 | } |
| 1818 | |
| 1819 | /** |
Alexander Duyck | 42073d9 | 2012-07-20 08:08:28 +0000 | [diff] [blame] | 1820 | * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB |
| 1821 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1822 | * @skb: pointer to current skb being updated |
| 1823 | * |
| 1824 | * This function provides a basic DMA sync up for the first fragment of an |
| 1825 | * skb. The reason for doing this is that the first fragment cannot be |
| 1826 | * unmapped until we have reached the end of packet descriptor for a buffer |
| 1827 | * chain. |
| 1828 | */ |
| 1829 | static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring, |
| 1830 | struct sk_buff *skb) |
| 1831 | { |
| 1832 | /* if the page was released unmap it, else just sync our portion */ |
| 1833 | if (unlikely(IXGBE_CB(skb)->page_released)) { |
| 1834 | dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma, |
| 1835 | ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE); |
| 1836 | IXGBE_CB(skb)->page_released = false; |
| 1837 | } else { |
| 1838 | struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0]; |
| 1839 | |
| 1840 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 1841 | IXGBE_CB(skb)->dma, |
| 1842 | frag->page_offset, |
| 1843 | ixgbe_rx_bufsz(rx_ring), |
| 1844 | DMA_FROM_DEVICE); |
| 1845 | } |
| 1846 | IXGBE_CB(skb)->dma = 0; |
| 1847 | } |
| 1848 | |
| 1849 | /** |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1850 | * ixgbe_cleanup_headers - Correct corrupted or empty headers |
| 1851 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1852 | * @rx_desc: pointer to the EOP Rx descriptor |
| 1853 | * @skb: pointer to current skb being fixed |
| 1854 | * |
| 1855 | * Check for corrupted packet headers caused by senders on the local L2 |
| 1856 | * embedded NIC switch not setting up their Tx Descriptors right. These |
| 1857 | * should be very rare. |
| 1858 | * |
| 1859 | * Also address the case where we are pulling data in on pages only |
| 1860 | * and as such no data is present in the skb header. |
| 1861 | * |
| 1862 | * In addition if skb is not at least 60 bytes we need to pad it so that |
| 1863 | * it is large enough to qualify as a valid Ethernet frame. |
| 1864 | * |
| 1865 | * Returns true if an error was encountered and skb was freed. |
| 1866 | **/ |
| 1867 | static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring, |
| 1868 | union ixgbe_adv_rx_desc *rx_desc, |
| 1869 | struct sk_buff *skb) |
| 1870 | { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1871 | struct net_device *netdev = rx_ring->netdev; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1872 | |
| 1873 | /* verify that the packet does not have any known errors */ |
| 1874 | if (unlikely(ixgbe_test_staterr(rx_desc, |
| 1875 | IXGBE_RXDADV_ERR_FRAME_ERR_MASK) && |
| 1876 | !(netdev->features & NETIF_F_RXALL))) { |
| 1877 | dev_kfree_skb_any(skb); |
| 1878 | return true; |
| 1879 | } |
| 1880 | |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1881 | /* place header in linear portion of buffer */ |
Alexander Duyck | cf3fe7a | 2012-07-20 08:08:39 +0000 | [diff] [blame] | 1882 | if (skb_is_nonlinear(skb)) |
| 1883 | ixgbe_pull_tail(rx_ring, skb); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1884 | |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1885 | #ifdef IXGBE_FCOE |
| 1886 | /* do not attempt to pad FCoE Frames as this will disrupt DDP */ |
| 1887 | if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) |
| 1888 | return false; |
| 1889 | |
| 1890 | #endif |
Alexander Duyck | a94d9e2 | 2014-12-03 08:17:39 -0800 | [diff] [blame] | 1891 | /* if eth_skb_pad returns an error the skb was freed */ |
| 1892 | if (eth_skb_pad(skb)) |
| 1893 | return true; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1894 | |
| 1895 | return false; |
| 1896 | } |
| 1897 | |
| 1898 | /** |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1899 | * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring |
| 1900 | * @rx_ring: rx descriptor ring to store buffers on |
| 1901 | * @old_buff: donor buffer to have page reused |
| 1902 | * |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1903 | * Synchronizes page for reuse by the adapter |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1904 | **/ |
| 1905 | static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring, |
| 1906 | struct ixgbe_rx_buffer *old_buff) |
| 1907 | { |
| 1908 | struct ixgbe_rx_buffer *new_buff; |
| 1909 | u16 nta = rx_ring->next_to_alloc; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1910 | |
| 1911 | new_buff = &rx_ring->rx_buffer_info[nta]; |
| 1912 | |
| 1913 | /* update, and store next to alloc */ |
| 1914 | nta++; |
| 1915 | rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0; |
| 1916 | |
| 1917 | /* transfer page from old buffer to new buffer */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1918 | *new_buff = *old_buff; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1919 | |
| 1920 | /* sync the buffer for use by the device */ |
| 1921 | dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma, |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1922 | new_buff->page_offset, |
| 1923 | ixgbe_rx_bufsz(rx_ring), |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1924 | DMA_FROM_DEVICE); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1925 | } |
| 1926 | |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1927 | static inline bool ixgbe_page_is_reserved(struct page *page) |
| 1928 | { |
Michal Hocko | 2f064f3 | 2015-08-21 14:11:51 -0700 | [diff] [blame] | 1929 | return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page); |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1930 | } |
| 1931 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1932 | /** |
| 1933 | * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff |
| 1934 | * @rx_ring: rx descriptor ring to transact packets on |
| 1935 | * @rx_buffer: buffer containing page to add |
| 1936 | * @rx_desc: descriptor containing length of buffer written by hardware |
| 1937 | * @skb: sk_buff to place the data into |
| 1938 | * |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1939 | * This function will add the data contained in rx_buffer->page to the skb. |
| 1940 | * This is done either through a direct copy if the data in the buffer is |
| 1941 | * less than the skb header size, otherwise it will just attach the page as |
| 1942 | * a frag to the skb. |
| 1943 | * |
| 1944 | * The function will then update the page offset if necessary and return |
| 1945 | * true if the buffer can be reused by the adapter. |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1946 | **/ |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1947 | static bool ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring, |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1948 | struct ixgbe_rx_buffer *rx_buffer, |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1949 | union ixgbe_adv_rx_desc *rx_desc, |
| 1950 | struct sk_buff *skb) |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1951 | { |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1952 | struct page *page = rx_buffer->page; |
| 1953 | unsigned int size = le16_to_cpu(rx_desc->wb.upper.length); |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1954 | #if (PAGE_SIZE < 8192) |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1955 | unsigned int truesize = ixgbe_rx_bufsz(rx_ring); |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1956 | #else |
| 1957 | unsigned int truesize = ALIGN(size, L1_CACHE_BYTES); |
| 1958 | unsigned int last_offset = ixgbe_rx_pg_size(rx_ring) - |
| 1959 | ixgbe_rx_bufsz(rx_ring); |
| 1960 | #endif |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1961 | |
Alexander Duyck | cf3fe7a | 2012-07-20 08:08:39 +0000 | [diff] [blame] | 1962 | if ((size <= IXGBE_RX_HDR_SIZE) && !skb_is_nonlinear(skb)) { |
| 1963 | unsigned char *va = page_address(page) + rx_buffer->page_offset; |
| 1964 | |
| 1965 | memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long))); |
| 1966 | |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1967 | /* page is not reserved, we can reuse buffer as-is */ |
| 1968 | if (likely(!ixgbe_page_is_reserved(page))) |
Alexander Duyck | cf3fe7a | 2012-07-20 08:08:39 +0000 | [diff] [blame] | 1969 | return true; |
| 1970 | |
| 1971 | /* this page cannot be reused so discard it */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1972 | __free_pages(page, ixgbe_rx_pg_order(rx_ring)); |
Alexander Duyck | cf3fe7a | 2012-07-20 08:08:39 +0000 | [diff] [blame] | 1973 | return false; |
| 1974 | } |
| 1975 | |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1976 | skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page, |
| 1977 | rx_buffer->page_offset, size, truesize); |
| 1978 | |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1979 | /* avoid re-using remote pages */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1980 | if (unlikely(ixgbe_page_is_reserved(page))) |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1981 | return false; |
| 1982 | |
| 1983 | #if (PAGE_SIZE < 8192) |
| 1984 | /* if we are only owner of page we can reuse it */ |
| 1985 | if (unlikely(page_count(page) != 1)) |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1986 | return false; |
| 1987 | |
| 1988 | /* flip page offset to other buffer */ |
| 1989 | rx_buffer->page_offset ^= truesize; |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1990 | #else |
| 1991 | /* move offset up to the next cache line */ |
| 1992 | rx_buffer->page_offset += truesize; |
| 1993 | |
| 1994 | if (rx_buffer->page_offset > last_offset) |
| 1995 | return false; |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1996 | #endif |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1997 | |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1998 | /* Even if we own the page, we are not allowed to use atomic_set() |
| 1999 | * This would break get_page_unless_zero() users. |
| 2000 | */ |
Joonsoo Kim | fe896d1 | 2016-03-17 14:19:26 -0700 | [diff] [blame] | 2001 | page_ref_inc(page); |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 2002 | |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 2003 | return true; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2004 | } |
| 2005 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2006 | static struct sk_buff *ixgbe_fetch_rx_buffer(struct ixgbe_ring *rx_ring, |
| 2007 | union ixgbe_adv_rx_desc *rx_desc) |
| 2008 | { |
| 2009 | struct ixgbe_rx_buffer *rx_buffer; |
| 2010 | struct sk_buff *skb; |
| 2011 | struct page *page; |
| 2012 | |
| 2013 | rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean]; |
| 2014 | page = rx_buffer->page; |
| 2015 | prefetchw(page); |
| 2016 | |
| 2017 | skb = rx_buffer->skb; |
| 2018 | |
| 2019 | if (likely(!skb)) { |
| 2020 | void *page_addr = page_address(page) + |
| 2021 | rx_buffer->page_offset; |
| 2022 | |
| 2023 | /* prefetch first cache line of first page */ |
| 2024 | prefetch(page_addr); |
| 2025 | #if L1_CACHE_BYTES < 128 |
| 2026 | prefetch(page_addr + L1_CACHE_BYTES); |
| 2027 | #endif |
| 2028 | |
| 2029 | /* allocate a skb to store the frags */ |
Alexander Duyck | 67fd893 | 2014-12-09 19:40:56 -0800 | [diff] [blame] | 2030 | skb = napi_alloc_skb(&rx_ring->q_vector->napi, |
| 2031 | IXGBE_RX_HDR_SIZE); |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2032 | if (unlikely(!skb)) { |
| 2033 | rx_ring->rx_stats.alloc_rx_buff_failed++; |
| 2034 | return NULL; |
| 2035 | } |
| 2036 | |
| 2037 | /* |
| 2038 | * we will be copying header into skb->data in |
| 2039 | * pskb_may_pull so it is in our interest to prefetch |
| 2040 | * it now to avoid a possible cache miss |
| 2041 | */ |
| 2042 | prefetchw(skb->data); |
| 2043 | |
| 2044 | /* |
| 2045 | * Delay unmapping of the first packet. It carries the |
| 2046 | * header information, HW may still access the header |
| 2047 | * after the writeback. Only unmap it when EOP is |
| 2048 | * reached |
| 2049 | */ |
| 2050 | if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))) |
| 2051 | goto dma_sync; |
| 2052 | |
| 2053 | IXGBE_CB(skb)->dma = rx_buffer->dma; |
| 2054 | } else { |
| 2055 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)) |
| 2056 | ixgbe_dma_sync_frag(rx_ring, skb); |
| 2057 | |
| 2058 | dma_sync: |
| 2059 | /* we are reusing so sync this buffer for CPU use */ |
| 2060 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 2061 | rx_buffer->dma, |
| 2062 | rx_buffer->page_offset, |
| 2063 | ixgbe_rx_bufsz(rx_ring), |
| 2064 | DMA_FROM_DEVICE); |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 2065 | |
| 2066 | rx_buffer->skb = NULL; |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2067 | } |
| 2068 | |
| 2069 | /* pull page into skb */ |
| 2070 | if (ixgbe_add_rx_frag(rx_ring, rx_buffer, rx_desc, skb)) { |
| 2071 | /* hand second half of page back to the ring */ |
| 2072 | ixgbe_reuse_rx_page(rx_ring, rx_buffer); |
| 2073 | } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) { |
| 2074 | /* the page has been released from the ring */ |
| 2075 | IXGBE_CB(skb)->page_released = true; |
| 2076 | } else { |
| 2077 | /* we are not reusing the buffer so unmap it */ |
| 2078 | dma_unmap_page(rx_ring->dev, rx_buffer->dma, |
| 2079 | ixgbe_rx_pg_size(rx_ring), |
| 2080 | DMA_FROM_DEVICE); |
| 2081 | } |
| 2082 | |
| 2083 | /* clear contents of buffer_info */ |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2084 | rx_buffer->page = NULL; |
| 2085 | |
| 2086 | return skb; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2087 | } |
| 2088 | |
| 2089 | /** |
| 2090 | * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf |
| 2091 | * @q_vector: structure containing interrupt and ring information |
| 2092 | * @rx_ring: rx descriptor ring to transact packets on |
| 2093 | * @budget: Total limit on number of packets to process |
| 2094 | * |
| 2095 | * This function provides a "bounce buffer" approach to Rx interrupt |
| 2096 | * processing. The advantage to this is that on systems that have |
| 2097 | * expensive overhead for IOMMU access this provides a means of avoiding |
| 2098 | * it by maintaining the mapping of the page to the syste. |
| 2099 | * |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2100 | * Returns amount of work completed |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2101 | **/ |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2102 | static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2103 | struct ixgbe_ring *rx_ring, |
Alexander Duyck | f4de00e | 2012-09-25 00:29:37 +0000 | [diff] [blame] | 2104 | const int budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2105 | { |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 2106 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 2107 | #ifdef IXGBE_FCOE |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2108 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Mark Rustad | 4ffdf91 | 2012-07-18 06:05:50 +0000 | [diff] [blame] | 2109 | int ddp_bytes; |
| 2110 | unsigned int mss = 0; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 2111 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2112 | u16 cleaned_count = ixgbe_desc_unused(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2113 | |
Eric W. Biederman | fdabfc8a | 2014-03-14 18:00:41 -0700 | [diff] [blame] | 2114 | while (likely(total_rx_packets < budget)) { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2115 | union ixgbe_adv_rx_desc *rx_desc; |
| 2116 | struct sk_buff *skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2117 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2118 | /* return some buffers to hardware, one at a time is too slow */ |
| 2119 | if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) { |
| 2120 | ixgbe_alloc_rx_buffers(rx_ring, cleaned_count); |
| 2121 | cleaned_count = 0; |
| 2122 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2123 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2124 | rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2125 | |
Alexander Duyck | 124b74c | 2014-12-11 15:02:28 -0800 | [diff] [blame] | 2126 | if (!rx_desc->wb.upper.status_error) |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2127 | break; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 2128 | |
Alexander Duyck | 124b74c | 2014-12-11 15:02:28 -0800 | [diff] [blame] | 2129 | /* This memory barrier is needed to keep us from reading |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2130 | * any other fields out of the rx_desc until we know the |
Alexander Duyck | 124b74c | 2014-12-11 15:02:28 -0800 | [diff] [blame] | 2131 | * descriptor has been written back |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2132 | */ |
Alexander Duyck | 124b74c | 2014-12-11 15:02:28 -0800 | [diff] [blame] | 2133 | dma_rmb(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2134 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2135 | /* retrieve a buffer from the ring */ |
| 2136 | skb = ixgbe_fetch_rx_buffer(rx_ring, rx_desc); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2137 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2138 | /* exit if we failed to retrieve a buffer */ |
| 2139 | if (!skb) |
| 2140 | break; |
Alexander Duyck | 4c1975d | 2012-01-31 02:59:23 +0000 | [diff] [blame] | 2141 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2142 | cleaned_count++; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2143 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2144 | /* place incomplete frames back on ring for completion */ |
| 2145 | if (ixgbe_is_non_eop(rx_ring, rx_desc, skb)) |
| 2146 | continue; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2147 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2148 | /* verify the packet layout is correct */ |
| 2149 | if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb)) |
| 2150 | continue; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 2151 | |
| 2152 | /* probably a little skewed due to removing CRC */ |
| 2153 | total_rx_bytes += skb->len; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 2154 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 2155 | /* populate checksum, timestamp, VLAN, and protocol */ |
| 2156 | ixgbe_process_skb_fields(rx_ring, rx_desc, skb); |
| 2157 | |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 2158 | #ifdef IXGBE_FCOE |
| 2159 | /* if ddp, not passing to ULD unless for FCP_RSP or error */ |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 2160 | if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) { |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 2161 | ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb); |
Mark Rustad | 4ffdf91 | 2012-07-18 06:05:50 +0000 | [diff] [blame] | 2162 | /* include DDPed FCoE data */ |
| 2163 | if (ddp_bytes > 0) { |
| 2164 | if (!mss) { |
| 2165 | mss = rx_ring->netdev->mtu - |
| 2166 | sizeof(struct fcoe_hdr) - |
| 2167 | sizeof(struct fc_frame_header) - |
| 2168 | sizeof(struct fcoe_crc_eof); |
| 2169 | if (mss > 512) |
| 2170 | mss &= ~511; |
| 2171 | } |
| 2172 | total_rx_bytes += ddp_bytes; |
| 2173 | total_rx_packets += DIV_ROUND_UP(ddp_bytes, |
| 2174 | mss); |
| 2175 | } |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 2176 | if (!ddp_bytes) { |
| 2177 | dev_kfree_skb_any(skb); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2178 | continue; |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 2179 | } |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 2180 | } |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2181 | |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 2182 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 2183 | ixgbe_rx_skb(q_vector, skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2184 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2185 | /* update budget accounting */ |
Alexander Duyck | f4de00e | 2012-09-25 00:29:37 +0000 | [diff] [blame] | 2186 | total_rx_packets++; |
Eric W. Biederman | fdabfc8a | 2014-03-14 18:00:41 -0700 | [diff] [blame] | 2187 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2188 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 2189 | u64_stats_update_begin(&rx_ring->syncp); |
| 2190 | rx_ring->stats.packets += total_rx_packets; |
| 2191 | rx_ring->stats.bytes += total_rx_bytes; |
| 2192 | u64_stats_update_end(&rx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2193 | q_vector->rx.total_packets += total_rx_packets; |
| 2194 | q_vector->rx.total_bytes += total_rx_bytes; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2195 | |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2196 | return total_rx_packets; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2197 | } |
| 2198 | |
Cong Wang | e0d1095 | 2013-08-01 11:10:25 +0800 | [diff] [blame] | 2199 | #ifdef CONFIG_NET_RX_BUSY_POLL |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2200 | /* must be called with local_bh_disable()d */ |
| 2201 | static int ixgbe_low_latency_recv(struct napi_struct *napi) |
| 2202 | { |
| 2203 | struct ixgbe_q_vector *q_vector = |
| 2204 | container_of(napi, struct ixgbe_q_vector, napi); |
| 2205 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 2206 | struct ixgbe_ring *ring; |
| 2207 | int found = 0; |
| 2208 | |
| 2209 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2210 | return LL_FLUSH_FAILED; |
| 2211 | |
| 2212 | if (!ixgbe_qv_lock_poll(q_vector)) |
| 2213 | return LL_FLUSH_BUSY; |
| 2214 | |
| 2215 | ixgbe_for_each_ring(ring, q_vector->rx) { |
| 2216 | found = ixgbe_clean_rx_irq(q_vector, ring, 4); |
Jacob Keller | b464003 | 2013-10-01 04:33:54 -0700 | [diff] [blame] | 2217 | #ifdef BP_EXTENDED_STATS |
Eliezer Tamir | 7e15b90 | 2013-06-10 11:40:31 +0300 | [diff] [blame] | 2218 | if (found) |
| 2219 | ring->stats.cleaned += found; |
| 2220 | else |
| 2221 | ring->stats.misses++; |
| 2222 | #endif |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2223 | if (found) |
| 2224 | break; |
| 2225 | } |
| 2226 | |
| 2227 | ixgbe_qv_unlock_poll(q_vector); |
| 2228 | |
| 2229 | return found; |
| 2230 | } |
Cong Wang | e0d1095 | 2013-08-01 11:10:25 +0800 | [diff] [blame] | 2231 | #endif /* CONFIG_NET_RX_BUSY_POLL */ |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2232 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2233 | /** |
| 2234 | * ixgbe_configure_msix - Configure MSI-X hardware |
| 2235 | * @adapter: board private structure |
| 2236 | * |
| 2237 | * ixgbe_configure_msix sets up the hardware to properly generate MSI-X |
| 2238 | * interrupts. |
| 2239 | **/ |
| 2240 | static void ixgbe_configure_msix(struct ixgbe_adapter *adapter) |
| 2241 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2242 | struct ixgbe_q_vector *q_vector; |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2243 | int v_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2244 | u32 mask; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2245 | |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 2246 | /* Populate MSIX to EITR Select */ |
| 2247 | if (adapter->num_vfs > 32) { |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame^] | 2248 | u32 eitrsel = BIT(adapter->num_vfs - 32) - 1; |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 2249 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel); |
| 2250 | } |
| 2251 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 2252 | /* |
| 2253 | * Populate the IVAR table and set the ITR values to the |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2254 | * corresponding register. |
| 2255 | */ |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2256 | for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) { |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2257 | struct ixgbe_ring *ring; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2258 | q_vector = adapter->q_vector[v_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2259 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 2260 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2261 | ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2262 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 2263 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2264 | ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2265 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2266 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2267 | } |
| 2268 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2269 | switch (adapter->hw.mac.type) { |
| 2270 | case ixgbe_mac_82598EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2271 | ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2272 | v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2273 | break; |
| 2274 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2275 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2276 | case ixgbe_mac_X550: |
| 2277 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2278 | case ixgbe_mac_x550em_a: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2279 | ixgbe_set_ivar(adapter, -1, 1, v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2280 | break; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2281 | default: |
| 2282 | break; |
| 2283 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2284 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2285 | |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 2286 | /* set up to autoclear timer, and the vectors */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2287 | mask = IXGBE_EIMS_ENABLE_MASK; |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2288 | mask &= ~(IXGBE_EIMS_OTHER | |
| 2289 | IXGBE_EIMS_MAILBOX | |
| 2290 | IXGBE_EIMS_LSC); |
| 2291 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2292 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2293 | } |
| 2294 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2295 | enum latency_range { |
| 2296 | lowest_latency = 0, |
| 2297 | low_latency = 1, |
| 2298 | bulk_latency = 2, |
| 2299 | latency_invalid = 255 |
| 2300 | }; |
| 2301 | |
| 2302 | /** |
| 2303 | * ixgbe_update_itr - update the dynamic ITR value based on statistics |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2304 | * @q_vector: structure containing interrupt and ring information |
| 2305 | * @ring_container: structure containing ring performance data |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2306 | * |
| 2307 | * Stores a new ITR value based on packets and byte |
| 2308 | * counts during the last interrupt. The advantage of per interrupt |
| 2309 | * computation is faster updates and more accurate ITR for the current |
| 2310 | * traffic pattern. Constants in this function were computed |
| 2311 | * based on theoretical maximum wire speed and thresholds were set based |
| 2312 | * on testing data as well as attempting to minimize response time |
| 2313 | * while increasing bulk throughput. |
| 2314 | * this functionality is controlled by the InterruptThrottleRate module |
| 2315 | * parameter (see ixgbe_param.c) |
| 2316 | **/ |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2317 | static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector, |
| 2318 | struct ixgbe_ring_container *ring_container) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2319 | { |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2320 | int bytes = ring_container->total_bytes; |
| 2321 | int packets = ring_container->total_packets; |
| 2322 | u32 timepassed_us; |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2323 | u64 bytes_perint; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2324 | u8 itr_setting = ring_container->itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2325 | |
| 2326 | if (packets == 0) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2327 | return; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2328 | |
| 2329 | /* simple throttlerate management |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2330 | * 0-10MB/s lowest (100000 ints/s) |
| 2331 | * 10-20MB/s low (20000 ints/s) |
Alexander Duyck | 8ac34f1 | 2015-07-30 15:19:28 -0700 | [diff] [blame] | 2332 | * 20-1249MB/s bulk (12000 ints/s) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2333 | */ |
| 2334 | /* what was last interrupt timeslice? */ |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2335 | timepassed_us = q_vector->itr >> 2; |
Don Skidmore | bdbeefe | 2013-03-02 07:17:37 +0000 | [diff] [blame] | 2336 | if (timepassed_us == 0) |
| 2337 | return; |
| 2338 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2339 | bytes_perint = bytes / timepassed_us; /* bytes/usec */ |
| 2340 | |
| 2341 | switch (itr_setting) { |
| 2342 | case lowest_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2343 | if (bytes_perint > 10) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2344 | itr_setting = low_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2345 | break; |
| 2346 | case low_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2347 | if (bytes_perint > 20) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2348 | itr_setting = bulk_latency; |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2349 | else if (bytes_perint <= 10) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2350 | itr_setting = lowest_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2351 | break; |
| 2352 | case bulk_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2353 | if (bytes_perint <= 20) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2354 | itr_setting = low_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2355 | break; |
| 2356 | } |
| 2357 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2358 | /* clear work counters since we have the values we need */ |
| 2359 | ring_container->total_bytes = 0; |
| 2360 | ring_container->total_packets = 0; |
| 2361 | |
| 2362 | /* write updated itr to ring container */ |
| 2363 | ring_container->itr = itr_setting; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2364 | } |
| 2365 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2366 | /** |
| 2367 | * ixgbe_write_eitr - write EITR register in hardware specific way |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2368 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2369 | * |
| 2370 | * This function is made to be called by ethtool and by the driver |
| 2371 | * when it needs to update EITR registers at runtime. Hardware |
| 2372 | * specific quirks/differences are taken care of here. |
| 2373 | */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2374 | void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector) |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2375 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2376 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2377 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2378 | int v_idx = q_vector->v_idx; |
Alexander Duyck | 5d967eb | 2012-02-08 07:49:43 +0000 | [diff] [blame] | 2379 | u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2380 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2381 | switch (adapter->hw.mac.type) { |
| 2382 | case ixgbe_mac_82598EB: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2383 | /* must write high and low 16 bits to reset counter */ |
| 2384 | itr_reg |= (itr_reg << 16); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2385 | break; |
| 2386 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2387 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2388 | case ixgbe_mac_X550: |
| 2389 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2390 | case ixgbe_mac_x550em_a: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2391 | /* |
| 2392 | * set the WDIS bit to not clear the timer bits and cause an |
| 2393 | * immediate assertion of the interrupt |
| 2394 | */ |
| 2395 | itr_reg |= IXGBE_EITR_CNT_WDIS; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2396 | break; |
| 2397 | default: |
| 2398 | break; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2399 | } |
| 2400 | IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg); |
| 2401 | } |
| 2402 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2403 | static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2404 | { |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2405 | u32 new_itr = q_vector->itr; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2406 | u8 current_itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2407 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2408 | ixgbe_update_itr(q_vector, &q_vector->tx); |
| 2409 | ixgbe_update_itr(q_vector, &q_vector->rx); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2410 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2411 | current_itr = max(q_vector->rx.itr, q_vector->tx.itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2412 | |
| 2413 | switch (current_itr) { |
| 2414 | /* counts and packets in update_itr are dependent on these numbers */ |
| 2415 | case lowest_latency: |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2416 | new_itr = IXGBE_100K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2417 | break; |
| 2418 | case low_latency: |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2419 | new_itr = IXGBE_20K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2420 | break; |
| 2421 | case bulk_latency: |
Alexander Duyck | 8ac34f1 | 2015-07-30 15:19:28 -0700 | [diff] [blame] | 2422 | new_itr = IXGBE_12K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2423 | break; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2424 | default: |
| 2425 | break; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2426 | } |
| 2427 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2428 | if (new_itr != q_vector->itr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2429 | /* do an exponential smoothing */ |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2430 | new_itr = (10 * new_itr * q_vector->itr) / |
| 2431 | ((9 * new_itr) + q_vector->itr); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2432 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2433 | /* save the algorithm value here */ |
Alexander Duyck | 5d967eb | 2012-02-08 07:49:43 +0000 | [diff] [blame] | 2434 | q_vector->itr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2435 | |
| 2436 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2437 | } |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2438 | } |
| 2439 | |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2440 | /** |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2441 | * ixgbe_check_overtemp_subtask - check for over temperature |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2442 | * @adapter: pointer to adapter |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2443 | **/ |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2444 | static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter) |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2445 | { |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2446 | struct ixgbe_hw *hw = &adapter->hw; |
| 2447 | u32 eicr = adapter->interrupt_event; |
| 2448 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2449 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2450 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2451 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2452 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) && |
| 2453 | !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT)) |
| 2454 | return; |
| 2455 | |
| 2456 | adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2457 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2458 | switch (hw->device_id) { |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2459 | case IXGBE_DEV_ID_82599_T3_LOM: |
| 2460 | /* |
| 2461 | * Since the warning interrupt is for both ports |
| 2462 | * we don't have to check if: |
| 2463 | * - This interrupt wasn't for our port. |
| 2464 | * - We may have missed the interrupt so always have to |
| 2465 | * check if we got a LSC |
| 2466 | */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2467 | if (!(eicr & IXGBE_EICR_GPI_SDP0_8259X) && |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2468 | !(eicr & IXGBE_EICR_LSC)) |
| 2469 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2470 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2471 | if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) { |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 2472 | u32 speed; |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2473 | bool link_up = false; |
| 2474 | |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 2475 | hw->mac.ops.check_link(hw, &speed, &link_up, false); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2476 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2477 | if (link_up) |
| 2478 | return; |
| 2479 | } |
| 2480 | |
| 2481 | /* Check if this is not due to overtemp */ |
| 2482 | if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP) |
| 2483 | return; |
| 2484 | |
| 2485 | break; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2486 | default: |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 2487 | if (adapter->hw.mac.type >= ixgbe_mac_X540) |
| 2488 | return; |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2489 | if (!(eicr & IXGBE_EICR_GPI_SDP0(hw))) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2490 | return; |
| 2491 | break; |
| 2492 | } |
Don Skidmore | f44e751 | 2015-06-09 16:36:23 -0700 | [diff] [blame] | 2493 | e_crit(drv, "%s\n", ixgbe_overheat_msg); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2494 | |
| 2495 | adapter->interrupt_event = 0; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2496 | } |
| 2497 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2498 | static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr) |
| 2499 | { |
| 2500 | struct ixgbe_hw *hw = &adapter->hw; |
| 2501 | |
| 2502 | if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) && |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2503 | (eicr & IXGBE_EICR_GPI_SDP1(hw))) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2504 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2505 | /* write to clear the interrupt */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2506 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw)); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2507 | } |
| 2508 | } |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2509 | |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2510 | static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 2511 | { |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2512 | struct ixgbe_hw *hw = &adapter->hw; |
| 2513 | |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2514 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)) |
| 2515 | return; |
| 2516 | |
| 2517 | switch (adapter->hw.mac.type) { |
| 2518 | case ixgbe_mac_82599EB: |
| 2519 | /* |
| 2520 | * Need to check link state so complete overtemp check |
| 2521 | * on service task |
| 2522 | */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2523 | if (((eicr & IXGBE_EICR_GPI_SDP0(hw)) || |
| 2524 | (eicr & IXGBE_EICR_LSC)) && |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2525 | (!test_bit(__IXGBE_DOWN, &adapter->state))) { |
| 2526 | adapter->interrupt_event = eicr; |
| 2527 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2528 | ixgbe_service_event_schedule(adapter); |
| 2529 | return; |
| 2530 | } |
| 2531 | return; |
| 2532 | case ixgbe_mac_X540: |
| 2533 | if (!(eicr & IXGBE_EICR_TS)) |
| 2534 | return; |
| 2535 | break; |
| 2536 | default: |
| 2537 | return; |
| 2538 | } |
| 2539 | |
Don Skidmore | f44e751 | 2015-06-09 16:36:23 -0700 | [diff] [blame] | 2540 | e_crit(drv, "%s\n", ixgbe_overheat_msg); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2541 | } |
| 2542 | |
Don Skidmore | 45788d2 | 2015-06-09 16:59:04 -0700 | [diff] [blame] | 2543 | static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw) |
| 2544 | { |
| 2545 | switch (hw->mac.type) { |
| 2546 | case ixgbe_mac_82598EB: |
| 2547 | if (hw->phy.type == ixgbe_phy_nl) |
| 2548 | return true; |
| 2549 | return false; |
| 2550 | case ixgbe_mac_82599EB: |
| 2551 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2552 | case ixgbe_mac_x550em_a: |
Don Skidmore | 45788d2 | 2015-06-09 16:59:04 -0700 | [diff] [blame] | 2553 | switch (hw->mac.ops.get_media_type(hw)) { |
| 2554 | case ixgbe_media_type_fiber: |
| 2555 | case ixgbe_media_type_fiber_qsfp: |
| 2556 | return true; |
| 2557 | default: |
| 2558 | return false; |
| 2559 | } |
| 2560 | default: |
| 2561 | return false; |
| 2562 | } |
| 2563 | } |
| 2564 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2565 | static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 2566 | { |
| 2567 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 4ccc650 | 2015-09-02 13:47:54 -0700 | [diff] [blame] | 2568 | u32 eicr_mask = IXGBE_EICR_GPI_SDP2(hw); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2569 | |
Don Skidmore | 4ccc650 | 2015-09-02 13:47:54 -0700 | [diff] [blame] | 2570 | if (!ixgbe_is_sfp(hw)) |
| 2571 | return; |
| 2572 | |
| 2573 | /* Later MAC's use different SDP */ |
| 2574 | if (hw->mac.type >= ixgbe_mac_X540) |
| 2575 | eicr_mask = IXGBE_EICR_GPI_SDP0_X540; |
| 2576 | |
| 2577 | if (eicr & eicr_mask) { |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2578 | /* Clear the interrupt */ |
Don Skidmore | 4ccc650 | 2015-09-02 13:47:54 -0700 | [diff] [blame] | 2579 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr_mask); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2580 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2581 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
Mark Rustad | 58e7cd2 | 2015-08-08 16:18:48 -0700 | [diff] [blame] | 2582 | adapter->sfp_poll_time = 0; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2583 | ixgbe_service_event_schedule(adapter); |
| 2584 | } |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2585 | } |
| 2586 | |
Don Skidmore | 4ccc650 | 2015-09-02 13:47:54 -0700 | [diff] [blame] | 2587 | if (adapter->hw.mac.type == ixgbe_mac_82599EB && |
| 2588 | (eicr & IXGBE_EICR_GPI_SDP1(hw))) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2589 | /* Clear the interrupt */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2590 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw)); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2591 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2592 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 2593 | ixgbe_service_event_schedule(adapter); |
| 2594 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2595 | } |
| 2596 | } |
| 2597 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2598 | static void ixgbe_check_lsc(struct ixgbe_adapter *adapter) |
| 2599 | { |
| 2600 | struct ixgbe_hw *hw = &adapter->hw; |
| 2601 | |
| 2602 | adapter->lsc_int++; |
| 2603 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 2604 | adapter->link_check_timeout = jiffies; |
| 2605 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2606 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC); |
Nelson, Shannon | 8a0717f | 2009-11-12 18:47:11 +0000 | [diff] [blame] | 2607 | IXGBE_WRITE_FLUSH(hw); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 2608 | ixgbe_service_event_schedule(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2609 | } |
| 2610 | } |
| 2611 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2612 | static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter, |
| 2613 | u64 qmask) |
| 2614 | { |
| 2615 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2616 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2617 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2618 | switch (hw->mac.type) { |
| 2619 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2620 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2621 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask); |
| 2622 | break; |
| 2623 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2624 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2625 | case ixgbe_mac_X550: |
| 2626 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2627 | case ixgbe_mac_x550em_a: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2628 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2629 | if (mask) |
| 2630 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2631 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2632 | if (mask) |
| 2633 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask); |
| 2634 | break; |
| 2635 | default: |
| 2636 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2637 | } |
| 2638 | /* skip the flush */ |
| 2639 | } |
| 2640 | |
| 2641 | static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2642 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2643 | { |
| 2644 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2645 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2646 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2647 | switch (hw->mac.type) { |
| 2648 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2649 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2650 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask); |
| 2651 | break; |
| 2652 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2653 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2654 | case ixgbe_mac_X550: |
| 2655 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2656 | case ixgbe_mac_x550em_a: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2657 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2658 | if (mask) |
| 2659 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2660 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2661 | if (mask) |
| 2662 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask); |
| 2663 | break; |
| 2664 | default: |
| 2665 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2666 | } |
| 2667 | /* skip the flush */ |
| 2668 | } |
| 2669 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2670 | /** |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2671 | * ixgbe_irq_enable - Enable default interrupt generation settings |
| 2672 | * @adapter: board private structure |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2673 | **/ |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2674 | static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues, |
| 2675 | bool flush) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2676 | { |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2677 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2678 | u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE); |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 2679 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2680 | /* don't reenable LSC while waiting for link */ |
| 2681 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 2682 | mask &= ~IXGBE_EIMS_LSC; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2683 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2684 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2685 | switch (adapter->hw.mac.type) { |
| 2686 | case ixgbe_mac_82599EB: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2687 | mask |= IXGBE_EIMS_GPI_SDP0(hw); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2688 | break; |
| 2689 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2690 | case ixgbe_mac_X550: |
| 2691 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2692 | case ixgbe_mac_x550em_a: |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2693 | mask |= IXGBE_EIMS_TS; |
| 2694 | break; |
| 2695 | default: |
| 2696 | break; |
| 2697 | } |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2698 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2699 | mask |= IXGBE_EIMS_GPI_SDP1(hw); |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2700 | switch (adapter->hw.mac.type) { |
| 2701 | case ixgbe_mac_82599EB: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2702 | mask |= IXGBE_EIMS_GPI_SDP1(hw); |
| 2703 | mask |= IXGBE_EIMS_GPI_SDP2(hw); |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2704 | /* fall through */ |
Don Skidmore | 858bc08 | 2011-08-04 09:28:30 +0000 | [diff] [blame] | 2705 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2706 | case ixgbe_mac_X550: |
| 2707 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2708 | case ixgbe_mac_x550em_a: |
| 2709 | if (adapter->hw.device_id == IXGBE_DEV_ID_X550EM_X_SFP || |
Mark Rustad | 2d40cd1 | 2016-04-01 12:18:35 -0700 | [diff] [blame] | 2710 | adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP || |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2711 | adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP_N) |
Mark Rustad | cbd45ec | 2015-08-08 16:17:51 -0700 | [diff] [blame] | 2712 | mask |= IXGBE_EIMS_GPI_SDP0(&adapter->hw); |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 2713 | if (adapter->hw.phy.type == ixgbe_phy_x550em_ext_t) |
| 2714 | mask |= IXGBE_EICR_GPI_SDP0_X540; |
Don Skidmore | 858bc08 | 2011-08-04 09:28:30 +0000 | [diff] [blame] | 2715 | mask |= IXGBE_EIMS_ECC; |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2716 | mask |= IXGBE_EIMS_MAILBOX; |
| 2717 | break; |
| 2718 | default: |
| 2719 | break; |
| 2720 | } |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2721 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2722 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) && |
| 2723 | !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 2724 | mask |= IXGBE_EIMS_FLOW_DIR; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2725 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2726 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
| 2727 | if (queues) |
| 2728 | ixgbe_irq_enable_queues(adapter, ~0); |
| 2729 | if (flush) |
| 2730 | IXGBE_WRITE_FLUSH(&adapter->hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2731 | } |
| 2732 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2733 | static irqreturn_t ixgbe_msix_other(int irq, void *data) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2734 | { |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2735 | struct ixgbe_adapter *adapter = data; |
| 2736 | struct ixgbe_hw *hw = &adapter->hw; |
| 2737 | u32 eicr; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2738 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2739 | /* |
| 2740 | * Workaround for Silicon errata. Use clear-by-write instead |
| 2741 | * of clear-by-read. Reading with EICS will return the |
| 2742 | * interrupt causes without clearing, which later be done |
| 2743 | * with the write to EICR. |
| 2744 | */ |
| 2745 | eicr = IXGBE_READ_REG(hw, IXGBE_EICS); |
Jacob Keller | d87d830 | 2013-03-02 07:51:42 +0000 | [diff] [blame] | 2746 | |
| 2747 | /* The lower 16bits of the EICR register are for the queue interrupts |
Joe Perches | dbedd44 | 2015-03-06 20:49:12 -0800 | [diff] [blame] | 2748 | * 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] | 2749 | * the bits are high when ixgbe_msix_other is called. There is a race |
| 2750 | * condition otherwise which results in possible performance loss |
| 2751 | * especially if the ixgbe_msix_other interrupt is triggering |
| 2752 | * consistently (as it would when PPS is turned on for the X540 device) |
| 2753 | */ |
| 2754 | eicr &= 0xFFFF0000; |
| 2755 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2756 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2757 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2758 | if (eicr & IXGBE_EICR_LSC) |
| 2759 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2760 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2761 | if (eicr & IXGBE_EICR_MAILBOX) |
| 2762 | ixgbe_msg_task(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2763 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2764 | switch (hw->mac.type) { |
| 2765 | case ixgbe_mac_82599EB: |
| 2766 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2767 | case ixgbe_mac_X550: |
| 2768 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2769 | case ixgbe_mac_x550em_a: |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 2770 | if (hw->phy.type == ixgbe_phy_x550em_ext_t && |
| 2771 | (eicr & IXGBE_EICR_GPI_SDP0_X540)) { |
| 2772 | adapter->flags2 |= IXGBE_FLAG2_PHY_INTERRUPT; |
| 2773 | ixgbe_service_event_schedule(adapter); |
| 2774 | IXGBE_WRITE_REG(hw, IXGBE_EICR, |
| 2775 | IXGBE_EICR_GPI_SDP0_X540); |
| 2776 | } |
Don Skidmore | d773ce2 | 2014-02-25 17:58:53 -0800 | [diff] [blame] | 2777 | if (eicr & IXGBE_EICR_ECC) { |
| 2778 | e_info(link, "Received ECC Err, initiating reset\n"); |
| 2779 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; |
| 2780 | ixgbe_service_event_schedule(adapter); |
| 2781 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC); |
| 2782 | } |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2783 | /* Handle Flow Director Full threshold interrupt */ |
| 2784 | if (eicr & IXGBE_EICR_FLOW_DIR) { |
| 2785 | int reinit_count = 0; |
| 2786 | int i; |
| 2787 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2788 | struct ixgbe_ring *ring = adapter->tx_ring[i]; |
| 2789 | if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE, |
| 2790 | &ring->state)) |
| 2791 | reinit_count++; |
| 2792 | } |
| 2793 | if (reinit_count) { |
| 2794 | /* no more flow director interrupts until after init */ |
| 2795 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR); |
| 2796 | adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 2797 | ixgbe_service_event_schedule(adapter); |
| 2798 | } |
| 2799 | } |
| 2800 | ixgbe_check_sfp_event(adapter, eicr); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2801 | ixgbe_check_overtemp_event(adapter, eicr); |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2802 | break; |
| 2803 | default: |
| 2804 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2805 | } |
| 2806 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2807 | ixgbe_check_fan_failure(adapter, eicr); |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2808 | |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2809 | if (unlikely(eicr & IXGBE_EICR_TIMESYNC)) |
Mark Rustad | a9763f3 | 2015-10-27 09:58:07 -0700 | [diff] [blame] | 2810 | ixgbe_ptp_check_pps_event(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2811 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2812 | /* re-enable the original interrupt state, no lsc, no queues */ |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2813 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2814 | ixgbe_irq_enable(adapter, false, false); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2815 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2816 | return IRQ_HANDLED; |
| 2817 | } |
| 2818 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2819 | static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2820 | { |
| 2821 | struct ixgbe_q_vector *q_vector = data; |
| 2822 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2823 | /* EIAM disabled interrupts (on this vector) for us */ |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2824 | |
| 2825 | if (q_vector->rx.ring || q_vector->tx.ring) |
Alexander Duyck | ef2662b | 2015-09-29 15:19:43 -0700 | [diff] [blame] | 2826 | napi_schedule_irqoff(&q_vector->napi); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2827 | |
| 2828 | return IRQ_HANDLED; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2829 | } |
| 2830 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2831 | /** |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2832 | * ixgbe_poll - NAPI Rx polling callback |
| 2833 | * @napi: structure for representing this polling device |
| 2834 | * @budget: how many packets driver is allowed to clean |
| 2835 | * |
| 2836 | * This function is used for legacy and MSI, NAPI mode |
| 2837 | **/ |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 2838 | int ixgbe_poll(struct napi_struct *napi, int budget) |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2839 | { |
| 2840 | struct ixgbe_q_vector *q_vector = |
| 2841 | container_of(napi, struct ixgbe_q_vector, napi); |
| 2842 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 2843 | struct ixgbe_ring *ring; |
Jesse Brandeburg | 32b3e08 | 2015-09-24 16:35:47 -0700 | [diff] [blame] | 2844 | int per_ring_budget, work_done = 0; |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2845 | bool clean_complete = true; |
| 2846 | |
| 2847 | #ifdef CONFIG_IXGBE_DCA |
| 2848 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 2849 | ixgbe_update_dca(q_vector); |
| 2850 | #endif |
| 2851 | |
Alexander Duyck | 8220bbc | 2016-03-07 09:30:09 -0800 | [diff] [blame] | 2852 | ixgbe_for_each_ring(ring, q_vector->tx) { |
| 2853 | if (!ixgbe_clean_tx_irq(q_vector, ring, budget)) |
| 2854 | clean_complete = false; |
| 2855 | } |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2856 | |
Alexander Duyck | 5d6002b | 2015-09-22 14:35:41 -0700 | [diff] [blame] | 2857 | /* Exit if we are called by netpoll or busy polling is active */ |
| 2858 | if ((budget <= 0) || !ixgbe_qv_lock_napi(q_vector)) |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2859 | return budget; |
| 2860 | |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2861 | /* attempt to distribute budget to each queue fairly, but don't allow |
| 2862 | * the budget to go below 1 because we'll exit polling */ |
| 2863 | if (q_vector->rx.count > 1) |
| 2864 | per_ring_budget = max(budget/q_vector->rx.count, 1); |
| 2865 | else |
| 2866 | per_ring_budget = budget; |
| 2867 | |
Jesse Brandeburg | 32b3e08 | 2015-09-24 16:35:47 -0700 | [diff] [blame] | 2868 | ixgbe_for_each_ring(ring, q_vector->rx) { |
| 2869 | int cleaned = ixgbe_clean_rx_irq(q_vector, ring, |
| 2870 | per_ring_budget); |
| 2871 | |
| 2872 | work_done += cleaned; |
Alexander Duyck | 8220bbc | 2016-03-07 09:30:09 -0800 | [diff] [blame] | 2873 | if (cleaned >= per_ring_budget) |
| 2874 | clean_complete = false; |
Jesse Brandeburg | 32b3e08 | 2015-09-24 16:35:47 -0700 | [diff] [blame] | 2875 | } |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2876 | |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2877 | ixgbe_qv_unlock_napi(q_vector); |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2878 | /* If all work not completed, return budget and keep polling */ |
| 2879 | if (!clean_complete) |
| 2880 | return budget; |
| 2881 | |
| 2882 | /* all work done, exit the polling mode */ |
Jesse Brandeburg | 32b3e08 | 2015-09-24 16:35:47 -0700 | [diff] [blame] | 2883 | napi_complete_done(napi, work_done); |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2884 | if (adapter->rx_itr_setting & 1) |
| 2885 | ixgbe_set_itr(q_vector); |
| 2886 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame^] | 2887 | ixgbe_irq_enable_queues(adapter, BIT_ULL(q_vector->v_idx)); |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2888 | |
| 2889 | return 0; |
| 2890 | } |
| 2891 | |
| 2892 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2893 | * ixgbe_request_msix_irqs - Initialize MSI-X interrupts |
| 2894 | * @adapter: board private structure |
| 2895 | * |
| 2896 | * ixgbe_request_msix_irqs allocates MSI-X vectors and requests |
| 2897 | * interrupts from the kernel. |
| 2898 | **/ |
| 2899 | static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter) |
| 2900 | { |
| 2901 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2902 | int vector, err; |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2903 | int ri = 0, ti = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2904 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2905 | for (vector = 0; vector < adapter->num_q_vectors; vector++) { |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2906 | struct ixgbe_q_vector *q_vector = adapter->q_vector[vector]; |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2907 | struct msix_entry *entry = &adapter->msix_entries[vector]; |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 2908 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2909 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 2910 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2911 | "%s-%s-%d", netdev->name, "TxRx", ri++); |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2912 | ti++; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2913 | } else if (q_vector->rx.ring) { |
| 2914 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2915 | "%s-%s-%d", netdev->name, "rx", ri++); |
| 2916 | } else if (q_vector->tx.ring) { |
| 2917 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2918 | "%s-%s-%d", netdev->name, "tx", ti++); |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2919 | } else { |
| 2920 | /* skip this unused q_vector */ |
| 2921 | continue; |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2922 | } |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2923 | err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0, |
| 2924 | q_vector->name, q_vector); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2925 | if (err) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2926 | e_err(probe, "request_irq failed for MSIX interrupt " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 2927 | "Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2928 | goto free_queue_irqs; |
| 2929 | } |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2930 | /* If Flow Director is enabled, set interrupt affinity */ |
| 2931 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 2932 | /* assign the mask for this irq */ |
| 2933 | irq_set_affinity_hint(entry->vector, |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2934 | &q_vector->affinity_mask); |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2935 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2936 | } |
| 2937 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2938 | err = request_irq(adapter->msix_entries[vector].vector, |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2939 | ixgbe_msix_other, 0, netdev->name, adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2940 | if (err) { |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2941 | e_err(probe, "request_irq for msix_other failed: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2942 | goto free_queue_irqs; |
| 2943 | } |
| 2944 | |
| 2945 | return 0; |
| 2946 | |
| 2947 | free_queue_irqs: |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2948 | while (vector) { |
| 2949 | vector--; |
| 2950 | irq_set_affinity_hint(adapter->msix_entries[vector].vector, |
| 2951 | NULL); |
| 2952 | free_irq(adapter->msix_entries[vector].vector, |
| 2953 | adapter->q_vector[vector]); |
| 2954 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2955 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 2956 | pci_disable_msix(adapter->pdev); |
| 2957 | kfree(adapter->msix_entries); |
| 2958 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2959 | return err; |
| 2960 | } |
| 2961 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 2962 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2963 | * ixgbe_intr - legacy mode Interrupt Handler |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2964 | * @irq: interrupt number |
| 2965 | * @data: pointer to a network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2966 | **/ |
| 2967 | static irqreturn_t ixgbe_intr(int irq, void *data) |
| 2968 | { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2969 | struct ixgbe_adapter *adapter = data; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2970 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2971 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2972 | u32 eicr; |
| 2973 | |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 2974 | /* |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 2975 | * Workaround for silicon errata #26 on 82598. Mask the interrupt |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 2976 | * before the read of EICR. |
| 2977 | */ |
| 2978 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); |
| 2979 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2980 | /* 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] | 2981 | * therefore no explicit interrupt disable is necessary */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2982 | eicr = IXGBE_READ_REG(hw, IXGBE_EICR); |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2983 | if (!eicr) { |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2984 | /* |
| 2985 | * shared interrupt alert! |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2986 | * make sure interrupts are enabled because the read will |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2987 | * have disabled interrupts due to EIAM |
| 2988 | * finish the workaround of silicon errata on 82598. Unmask |
| 2989 | * the interrupt that we masked before the EICR read. |
| 2990 | */ |
| 2991 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2992 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2993 | return IRQ_NONE; /* Not our interrupt */ |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2994 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2995 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2996 | if (eicr & IXGBE_EICR_LSC) |
| 2997 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2998 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2999 | switch (hw->mac.type) { |
| 3000 | case ixgbe_mac_82599EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3001 | ixgbe_check_sfp_event(adapter, eicr); |
Don Skidmore | 0ccb974 | 2011-08-04 02:07:48 +0000 | [diff] [blame] | 3002 | /* Fall through */ |
| 3003 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 3004 | case ixgbe_mac_X550: |
| 3005 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 3006 | case ixgbe_mac_x550em_a: |
Don Skidmore | d773ce2 | 2014-02-25 17:58:53 -0800 | [diff] [blame] | 3007 | if (eicr & IXGBE_EICR_ECC) { |
| 3008 | e_info(link, "Received ECC Err, initiating reset\n"); |
| 3009 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; |
| 3010 | ixgbe_service_event_schedule(adapter); |
| 3011 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC); |
| 3012 | } |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 3013 | ixgbe_check_overtemp_event(adapter, eicr); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3014 | break; |
| 3015 | default: |
| 3016 | break; |
| 3017 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3018 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 3019 | ixgbe_check_fan_failure(adapter, eicr); |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 3020 | if (unlikely(eicr & IXGBE_EICR_TIMESYNC)) |
Mark Rustad | a9763f3 | 2015-10-27 09:58:07 -0700 | [diff] [blame] | 3021 | ixgbe_ptp_check_pps_event(adapter); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 3022 | |
Alexander Duyck | b9f6ed2 | 2012-02-08 07:49:54 +0000 | [diff] [blame] | 3023 | /* would disable interrupts here but EIAM disabled it */ |
Alexander Duyck | ef2662b | 2015-09-29 15:19:43 -0700 | [diff] [blame] | 3024 | napi_schedule_irqoff(&q_vector->napi); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3025 | |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 3026 | /* |
| 3027 | * re-enable link(maybe) and non-queue interrupts, no flush. |
| 3028 | * ixgbe_poll will re-enable the queue interrupts |
| 3029 | */ |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 3030 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 3031 | ixgbe_irq_enable(adapter, false, false); |
| 3032 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3033 | return IRQ_HANDLED; |
| 3034 | } |
| 3035 | |
| 3036 | /** |
| 3037 | * ixgbe_request_irq - initialize interrupts |
| 3038 | * @adapter: board private structure |
| 3039 | * |
| 3040 | * Attempts to configure interrupts using the best available |
| 3041 | * capabilities of the hardware and kernel. |
| 3042 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3043 | static int ixgbe_request_irq(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3044 | { |
| 3045 | struct net_device *netdev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3046 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3047 | |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 3048 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3049 | err = ixgbe_request_msix_irqs(adapter); |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 3050 | else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 3051 | err = request_irq(adapter->pdev->irq, ixgbe_intr, 0, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 3052 | netdev->name, adapter); |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 3053 | else |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 3054 | err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 3055 | netdev->name, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3056 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 3057 | if (err) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 3058 | e_err(probe, "request_irq failed, Error %d\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3059 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3060 | return err; |
| 3061 | } |
| 3062 | |
| 3063 | static void ixgbe_free_irq(struct ixgbe_adapter *adapter) |
| 3064 | { |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3065 | int vector; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3066 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3067 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 3068 | free_irq(adapter->pdev->irq, adapter); |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3069 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3070 | } |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3071 | |
| 3072 | for (vector = 0; vector < adapter->num_q_vectors; vector++) { |
| 3073 | struct ixgbe_q_vector *q_vector = adapter->q_vector[vector]; |
| 3074 | struct msix_entry *entry = &adapter->msix_entries[vector]; |
| 3075 | |
| 3076 | /* free only the irqs that were actually requested */ |
| 3077 | if (!q_vector->rx.ring && !q_vector->tx.ring) |
| 3078 | continue; |
| 3079 | |
| 3080 | /* clear the affinity_mask in the IRQ descriptor */ |
| 3081 | irq_set_affinity_hint(entry->vector, NULL); |
| 3082 | |
| 3083 | free_irq(entry->vector, q_vector); |
| 3084 | } |
| 3085 | |
| 3086 | free_irq(adapter->msix_entries[vector++].vector, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3087 | } |
| 3088 | |
| 3089 | /** |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3090 | * ixgbe_irq_disable - Mask off interrupt generation on the NIC |
| 3091 | * @adapter: board private structure |
| 3092 | **/ |
| 3093 | static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter) |
| 3094 | { |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3095 | switch (adapter->hw.mac.type) { |
| 3096 | case ixgbe_mac_82598EB: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 3097 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3098 | break; |
| 3099 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3100 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 3101 | case ixgbe_mac_X550: |
| 3102 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 3103 | case ixgbe_mac_x550em_a: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 3104 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000); |
| 3105 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3106 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3107 | break; |
| 3108 | default: |
| 3109 | break; |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3110 | } |
| 3111 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 3112 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3113 | int vector; |
| 3114 | |
| 3115 | for (vector = 0; vector < adapter->num_q_vectors; vector++) |
| 3116 | synchronize_irq(adapter->msix_entries[vector].vector); |
| 3117 | |
| 3118 | synchronize_irq(adapter->msix_entries[vector++].vector); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3119 | } else { |
| 3120 | synchronize_irq(adapter->pdev->irq); |
| 3121 | } |
| 3122 | } |
| 3123 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3124 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3125 | * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts |
| 3126 | * |
| 3127 | **/ |
| 3128 | static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter) |
| 3129 | { |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 3130 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3131 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 3132 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3133 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3134 | ixgbe_set_ivar(adapter, 0, 0, 0); |
| 3135 | ixgbe_set_ivar(adapter, 1, 0, 0); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3136 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 3137 | e_info(hw, "Legacy interrupt IVAR setup done\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3138 | } |
| 3139 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3140 | /** |
| 3141 | * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset |
| 3142 | * @adapter: board private structure |
| 3143 | * @ring: structure containing ring specific data |
| 3144 | * |
| 3145 | * Configure the Tx descriptor ring after a reset. |
| 3146 | **/ |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 3147 | void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter, |
| 3148 | struct ixgbe_ring *ring) |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3149 | { |
| 3150 | struct ixgbe_hw *hw = &adapter->hw; |
| 3151 | u64 tdba = ring->dma; |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3152 | int wait_loop = 10; |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3153 | u32 txdctl = IXGBE_TXDCTL_ENABLE; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3154 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3155 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3156 | /* disable queue to avoid issues while updating state */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3157 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3158 | IXGBE_WRITE_FLUSH(hw); |
| 3159 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3160 | IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3161 | (tdba & DMA_BIT_MASK(32))); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3162 | IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32)); |
| 3163 | IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx), |
| 3164 | ring->count * sizeof(union ixgbe_adv_tx_desc)); |
| 3165 | IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0); |
| 3166 | IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 3167 | ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3168 | |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3169 | /* |
| 3170 | * set WTHRESH to encourage burst writeback, it should not be set |
Emil Tantilov | 67da097 | 2013-01-25 06:19:20 +0000 | [diff] [blame] | 3171 | * higher than 1 when: |
| 3172 | * - ITR is 0 as it could cause false TX hangs |
| 3173 | * - ITR is set to > 100k int/sec and BQL is enabled |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3174 | * |
| 3175 | * In order to avoid issues WTHRESH + PTHRESH should always be equal |
| 3176 | * to or less than the number of on chip descriptors, which is |
| 3177 | * currently 40. |
| 3178 | */ |
Emil Tantilov | 67da097 | 2013-01-25 06:19:20 +0000 | [diff] [blame] | 3179 | if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR)) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame^] | 3180 | txdctl |= 1u << 16; /* WTHRESH = 1 */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3181 | else |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame^] | 3182 | txdctl |= 8u << 16; /* WTHRESH = 8 */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3183 | |
Alexander Duyck | e954b37 | 2012-02-08 07:49:38 +0000 | [diff] [blame] | 3184 | /* |
| 3185 | * Setting PTHRESH to 32 both improves performance |
| 3186 | * and avoids a TX hang with DFP enabled |
| 3187 | */ |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame^] | 3188 | txdctl |= (1u << 8) | /* HTHRESH = 1 */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3189 | 32; /* PTHRESH = 32 */ |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3190 | |
| 3191 | /* reinitialize flowdirector state */ |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 3192 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 3193 | ring->atr_sample_rate = adapter->atr_sample_rate; |
| 3194 | ring->atr_count = 0; |
| 3195 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state); |
| 3196 | } else { |
| 3197 | ring->atr_sample_rate = 0; |
| 3198 | } |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3199 | |
Alexander Duyck | fd786b7 | 2013-01-12 06:33:31 +0000 | [diff] [blame] | 3200 | /* initialize XPS */ |
| 3201 | if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) { |
| 3202 | struct ixgbe_q_vector *q_vector = ring->q_vector; |
| 3203 | |
| 3204 | if (q_vector) |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 3205 | netif_set_xps_queue(ring->netdev, |
Alexander Duyck | fd786b7 | 2013-01-12 06:33:31 +0000 | [diff] [blame] | 3206 | &q_vector->affinity_mask, |
| 3207 | ring->queue_index); |
| 3208 | } |
| 3209 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 3210 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state); |
| 3211 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3212 | /* enable queue */ |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3213 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl); |
| 3214 | |
| 3215 | /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 3216 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 3217 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 3218 | return; |
| 3219 | |
| 3220 | /* poll to verify queue is enabled */ |
| 3221 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 3222 | usleep_range(1000, 2000); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3223 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx)); |
| 3224 | } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE)); |
| 3225 | if (!wait_loop) |
| 3226 | e_err(drv, "Could not enable Tx Queue %d\n", reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3227 | } |
| 3228 | |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 3229 | static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter) |
| 3230 | { |
| 3231 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3232 | u32 rttdcs, mtqc; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3233 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 3234 | |
| 3235 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3236 | return; |
| 3237 | |
| 3238 | /* disable the arbiter while setting MTQC */ |
| 3239 | rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS); |
| 3240 | rttdcs |= IXGBE_RTTDCS_ARBDIS; |
| 3241 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 3242 | |
| 3243 | /* set transmit pool layout */ |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3244 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 3245 | mtqc = IXGBE_MTQC_VT_ENA; |
| 3246 | if (tcs > 4) |
| 3247 | mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ; |
| 3248 | else if (tcs > 1) |
| 3249 | mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ; |
| 3250 | else if (adapter->ring_feature[RING_F_RSS].indices == 4) |
| 3251 | mtqc |= IXGBE_MTQC_32VF; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3252 | else |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3253 | mtqc |= IXGBE_MTQC_64VF; |
| 3254 | } else { |
| 3255 | if (tcs > 4) |
| 3256 | mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ; |
| 3257 | else if (tcs > 1) |
| 3258 | mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ; |
| 3259 | else |
| 3260 | mtqc = IXGBE_MTQC_64Q_1PB; |
| 3261 | } |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3262 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3263 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3264 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3265 | /* Enable Security TX Buffer IFG for multiple pb */ |
| 3266 | if (tcs) { |
| 3267 | u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG); |
| 3268 | sectx |= IXGBE_SECTX_DCB; |
| 3269 | IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx); |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 3270 | } |
| 3271 | |
| 3272 | /* re-enable the arbiter */ |
| 3273 | rttdcs &= ~IXGBE_RTTDCS_ARBDIS; |
| 3274 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 3275 | } |
| 3276 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3277 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3278 | * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3279 | * @adapter: board private structure |
| 3280 | * |
| 3281 | * Configure the Tx unit of the MAC after a reset. |
| 3282 | **/ |
| 3283 | static void ixgbe_configure_tx(struct ixgbe_adapter *adapter) |
| 3284 | { |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3285 | struct ixgbe_hw *hw = &adapter->hw; |
| 3286 | u32 dmatxctl; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3287 | u32 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3288 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3289 | ixgbe_setup_mtqc(adapter); |
| 3290 | |
| 3291 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 3292 | /* DMATXCTL.EN must be before Tx queues are enabled */ |
| 3293 | dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); |
| 3294 | dmatxctl |= IXGBE_DMATXCTL_TE; |
| 3295 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl); |
| 3296 | } |
| 3297 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3298 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3299 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 3300 | ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3301 | } |
| 3302 | |
Alexander Duyck | 3ebe8fd | 2012-04-25 04:36:38 +0000 | [diff] [blame] | 3303 | static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter, |
| 3304 | struct ixgbe_ring *ring) |
| 3305 | { |
| 3306 | struct ixgbe_hw *hw = &adapter->hw; |
| 3307 | u8 reg_idx = ring->reg_idx; |
| 3308 | u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx)); |
| 3309 | |
| 3310 | srrctl |= IXGBE_SRRCTL_DROP_EN; |
| 3311 | |
| 3312 | IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl); |
| 3313 | } |
| 3314 | |
| 3315 | static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter, |
| 3316 | struct ixgbe_ring *ring) |
| 3317 | { |
| 3318 | struct ixgbe_hw *hw = &adapter->hw; |
| 3319 | u8 reg_idx = ring->reg_idx; |
| 3320 | u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx)); |
| 3321 | |
| 3322 | srrctl &= ~IXGBE_SRRCTL_DROP_EN; |
| 3323 | |
| 3324 | IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl); |
| 3325 | } |
| 3326 | |
| 3327 | #ifdef CONFIG_IXGBE_DCB |
| 3328 | void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter) |
| 3329 | #else |
| 3330 | static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter) |
| 3331 | #endif |
| 3332 | { |
| 3333 | int i; |
| 3334 | bool pfc_en = adapter->dcb_cfg.pfc_mode_enable; |
| 3335 | |
| 3336 | if (adapter->ixgbe_ieee_pfc) |
| 3337 | pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en); |
| 3338 | |
| 3339 | /* |
| 3340 | * We should set the drop enable bit if: |
| 3341 | * SR-IOV is enabled |
| 3342 | * or |
| 3343 | * Number of Rx queues > 1 and flow control is disabled |
| 3344 | * |
| 3345 | * This allows us to avoid head of line blocking for security |
| 3346 | * and performance reasons. |
| 3347 | */ |
| 3348 | if (adapter->num_vfs || (adapter->num_rx_queues > 1 && |
| 3349 | !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) { |
| 3350 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3351 | ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]); |
| 3352 | } else { |
| 3353 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3354 | ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]); |
| 3355 | } |
| 3356 | } |
| 3357 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3358 | #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3359 | |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 3360 | static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3361 | struct ixgbe_ring *rx_ring) |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3362 | { |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3363 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3364 | u32 srrctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3365 | u8 reg_idx = rx_ring->reg_idx; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3366 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3367 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 3368 | u16 mask = adapter->ring_feature[RING_F_RSS].mask; |
| 3369 | |
| 3370 | /* |
| 3371 | * if VMDq is not active we must program one srrctl register |
| 3372 | * per RSS queue since we have enabled RDRXCTL.MVMEN |
| 3373 | */ |
| 3374 | reg_idx &= mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3375 | } |
| 3376 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3377 | /* configure header buffer length, needed for RSC */ |
| 3378 | srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3379 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3380 | /* configure the packet buffer length */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 3381 | srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3382 | |
| 3383 | /* configure descriptor type */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 3384 | srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3385 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3386 | IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3387 | } |
| 3388 | |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3389 | /** |
Jean Sacren | a897a2a | 2015-09-19 05:08:44 -0600 | [diff] [blame] | 3390 | * ixgbe_rss_indir_tbl_entries - Return RSS indirection table entries |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3391 | * @adapter: device handle |
| 3392 | * |
| 3393 | * - 82598/82599/X540: 128 |
| 3394 | * - X550(non-SRIOV mode): 512 |
| 3395 | * - X550(SRIOV mode): 64 |
| 3396 | */ |
Vlad Zolotarov | 7f276ef | 2015-03-30 21:18:58 +0300 | [diff] [blame] | 3397 | u32 ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3398 | { |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3399 | if (adapter->hw.mac.type < ixgbe_mac_X550) |
| 3400 | return 128; |
| 3401 | else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 3402 | return 64; |
| 3403 | else |
| 3404 | return 512; |
| 3405 | } |
| 3406 | |
| 3407 | /** |
Jean Sacren | a897a2a | 2015-09-19 05:08:44 -0600 | [diff] [blame] | 3408 | * ixgbe_store_reta - Write the RETA table to HW |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3409 | * @adapter: device handle |
| 3410 | * |
| 3411 | * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW. |
| 3412 | */ |
Tom Barbette | 1c7cf07 | 2015-06-26 15:40:18 +0200 | [diff] [blame] | 3413 | void ixgbe_store_reta(struct ixgbe_adapter *adapter) |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3414 | { |
| 3415 | u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter); |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3416 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3417 | u32 reta = 0; |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3418 | u32 indices_multi; |
| 3419 | u8 *indir_tbl = adapter->rss_indir_tbl; |
John Fastabend | 86b4db3 | 2011-04-26 07:26:19 +0000 | [diff] [blame] | 3420 | |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3421 | /* Fill out the redirection table as follows: |
| 3422 | * - 82598: 8 bit wide entries containing pair of 4 bit RSS |
| 3423 | * indices. |
| 3424 | * - 82599/X540: 8 bit wide entries containing 4 bit RSS index |
| 3425 | * - X550: 8 bit wide entries containing 6 bit RSS index |
| 3426 | */ |
| 3427 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 3428 | indices_multi = 0x11; |
| 3429 | else |
| 3430 | indices_multi = 0x1; |
| 3431 | |
| 3432 | /* Write redirection table to HW */ |
| 3433 | for (i = 0; i < reta_entries; i++) { |
| 3434 | reta |= indices_multi * indir_tbl[i] << (i & 0x3) * 8; |
| 3435 | if ((i & 3) == 3) { |
| 3436 | if (i < 128) |
| 3437 | IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); |
| 3438 | else |
| 3439 | IXGBE_WRITE_REG(hw, IXGBE_ERETA((i >> 2) - 32), |
| 3440 | reta); |
| 3441 | reta = 0; |
| 3442 | } |
| 3443 | } |
| 3444 | } |
| 3445 | |
| 3446 | /** |
Jean Sacren | a897a2a | 2015-09-19 05:08:44 -0600 | [diff] [blame] | 3447 | * 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] | 3448 | * @adapter: device handle |
| 3449 | * |
| 3450 | * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW. |
| 3451 | */ |
| 3452 | static void ixgbe_store_vfreta(struct ixgbe_adapter *adapter) |
| 3453 | { |
| 3454 | u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter); |
| 3455 | struct ixgbe_hw *hw = &adapter->hw; |
| 3456 | u32 vfreta = 0; |
| 3457 | unsigned int pf_pool = adapter->num_vfs; |
| 3458 | |
| 3459 | /* Write redirection table to HW */ |
| 3460 | for (i = 0; i < reta_entries; i++) { |
| 3461 | vfreta |= (u32)adapter->rss_indir_tbl[i] << (i & 0x3) * 8; |
| 3462 | if ((i & 3) == 3) { |
| 3463 | IXGBE_WRITE_REG(hw, IXGBE_PFVFRETA(i >> 2, pf_pool), |
| 3464 | vfreta); |
| 3465 | vfreta = 0; |
| 3466 | } |
| 3467 | } |
| 3468 | } |
| 3469 | |
| 3470 | static void ixgbe_setup_reta(struct ixgbe_adapter *adapter) |
| 3471 | { |
| 3472 | struct ixgbe_hw *hw = &adapter->hw; |
| 3473 | u32 i, j; |
| 3474 | u32 reta_entries = ixgbe_rss_indir_tbl_entries(adapter); |
| 3475 | u16 rss_i = adapter->ring_feature[RING_F_RSS].indices; |
| 3476 | |
| 3477 | /* Program table for at least 2 queues w/ SR-IOV so that VFs can |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3478 | * make full use of any rings they may have. We will use the |
| 3479 | * PSRTYPE register to control how many rings we use within the PF. |
| 3480 | */ |
| 3481 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 2)) |
| 3482 | rss_i = 2; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3483 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3484 | /* Fill out hash function seeds */ |
| 3485 | for (i = 0; i < 10; i++) |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3486 | IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), adapter->rss_key[i]); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3487 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3488 | /* Fill out redirection table */ |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3489 | memset(adapter->rss_indir_tbl, 0, sizeof(adapter->rss_indir_tbl)); |
| 3490 | |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3491 | for (i = 0, j = 0; i < reta_entries; i++, j++) { |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3492 | if (j == rss_i) |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3493 | j = 0; |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3494 | |
| 3495 | adapter->rss_indir_tbl[i] = j; |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3496 | } |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3497 | |
| 3498 | ixgbe_store_reta(adapter); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3499 | } |
| 3500 | |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3501 | static void ixgbe_setup_vfreta(struct ixgbe_adapter *adapter) |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3502 | { |
| 3503 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3504 | u16 rss_i = adapter->ring_feature[RING_F_RSS].indices; |
| 3505 | unsigned int pf_pool = adapter->num_vfs; |
| 3506 | int i, j; |
| 3507 | |
| 3508 | /* Fill out hash function seeds */ |
| 3509 | for (i = 0; i < 10; i++) |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3510 | IXGBE_WRITE_REG(hw, IXGBE_PFVFRSSRK(i, pf_pool), |
| 3511 | adapter->rss_key[i]); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3512 | |
| 3513 | /* Fill out the redirection table */ |
| 3514 | for (i = 0, j = 0; i < 64; i++, j++) { |
| 3515 | if (j == rss_i) |
| 3516 | j = 0; |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3517 | |
| 3518 | adapter->rss_indir_tbl[i] = j; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3519 | } |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3520 | |
| 3521 | ixgbe_store_vfreta(adapter); |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3522 | } |
| 3523 | |
| 3524 | static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter) |
| 3525 | { |
| 3526 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3527 | u32 mrqc = 0, rss_field = 0, vfmrqc = 0; |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3528 | u32 rxcsum; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3529 | |
| 3530 | /* Disable indicating checksum in descriptor, enables RSS hash */ |
| 3531 | rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); |
| 3532 | rxcsum |= IXGBE_RXCSUM_PCSD; |
| 3533 | IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); |
| 3534 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3535 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 3536 | if (adapter->ring_feature[RING_F_RSS].mask) |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3537 | mrqc = IXGBE_MRQC_RSSEN; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3538 | } else { |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3539 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3540 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3541 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 3542 | if (tcs > 4) |
| 3543 | mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */ |
| 3544 | else if (tcs > 1) |
| 3545 | mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */ |
| 3546 | else if (adapter->ring_feature[RING_F_RSS].indices == 4) |
| 3547 | mrqc = IXGBE_MRQC_VMDQRSS32EN; |
| 3548 | else |
| 3549 | mrqc = IXGBE_MRQC_VMDQRSS64EN; |
| 3550 | } else { |
| 3551 | if (tcs > 4) |
| 3552 | mrqc = IXGBE_MRQC_RTRSS8TCEN; |
| 3553 | else if (tcs > 1) |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3554 | mrqc = IXGBE_MRQC_RTRSS4TCEN; |
| 3555 | else |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3556 | mrqc = IXGBE_MRQC_RSSEN; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3557 | } |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3558 | } |
| 3559 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3560 | /* Perform hash on these packet types */ |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3561 | rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4 | |
| 3562 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP | |
| 3563 | IXGBE_MRQC_RSS_FIELD_IPV6 | |
| 3564 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3565 | |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 3566 | if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP) |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3567 | rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP; |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 3568 | if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP) |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3569 | rss_field |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP; |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 3570 | |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3571 | netdev_rss_key_fill(adapter->rss_key, sizeof(adapter->rss_key)); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3572 | if ((hw->mac.type >= ixgbe_mac_X550) && |
| 3573 | (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) { |
| 3574 | unsigned int pf_pool = adapter->num_vfs; |
| 3575 | |
| 3576 | /* Enable VF RSS mode */ |
| 3577 | mrqc |= IXGBE_MRQC_MULTIPLE_RSS; |
| 3578 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
| 3579 | |
| 3580 | /* Setup RSS through the VF registers */ |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3581 | ixgbe_setup_vfreta(adapter); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3582 | vfmrqc = IXGBE_MRQC_RSSEN; |
| 3583 | vfmrqc |= rss_field; |
| 3584 | IXGBE_WRITE_REG(hw, IXGBE_PFVFMRQC(pf_pool), vfmrqc); |
| 3585 | } else { |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3586 | ixgbe_setup_reta(adapter); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3587 | mrqc |= rss_field; |
| 3588 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
| 3589 | } |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3590 | } |
| 3591 | |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3592 | /** |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3593 | * ixgbe_configure_rscctl - enable RSC for the indicated ring |
| 3594 | * @adapter: address of board private structure |
| 3595 | * @index: index of ring to set |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3596 | **/ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 3597 | static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3598 | struct ixgbe_ring *ring) |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3599 | { |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3600 | struct ixgbe_hw *hw = &adapter->hw; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3601 | u32 rscctrl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3602 | u8 reg_idx = ring->reg_idx; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3603 | |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3604 | if (!ring_is_rsc_enabled(ring)) |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3605 | return; |
| 3606 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3607 | rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx)); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3608 | rscctrl |= IXGBE_RSCCTL_RSCEN; |
| 3609 | /* |
| 3610 | * we must limit the number of descriptors so that the |
| 3611 | * total size of max desc * buf_len is not greater |
Alexander Duyck | 642c680 | 2011-11-10 09:09:17 +0000 | [diff] [blame] | 3612 | * than 65536 |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3613 | */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 3614 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3615 | IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3616 | } |
| 3617 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3618 | #define IXGBE_MAX_RX_DESC_POLL 10 |
| 3619 | static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter, |
| 3620 | struct ixgbe_ring *ring) |
| 3621 | { |
| 3622 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3623 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 3624 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3625 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3626 | |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 3627 | if (ixgbe_removed(hw->hw_addr)) |
| 3628 | return; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3629 | /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 3630 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 3631 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 3632 | return; |
| 3633 | |
| 3634 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 3635 | usleep_range(1000, 2000); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3636 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 3637 | } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 3638 | |
| 3639 | if (!wait_loop) { |
| 3640 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within " |
| 3641 | "the polling period\n", reg_idx); |
| 3642 | } |
| 3643 | } |
| 3644 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 3645 | void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter, |
| 3646 | struct ixgbe_ring *ring) |
| 3647 | { |
| 3648 | struct ixgbe_hw *hw = &adapter->hw; |
| 3649 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 3650 | u32 rxdctl; |
| 3651 | u8 reg_idx = ring->reg_idx; |
| 3652 | |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 3653 | if (ixgbe_removed(hw->hw_addr)) |
| 3654 | return; |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 3655 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 3656 | rxdctl &= ~IXGBE_RXDCTL_ENABLE; |
| 3657 | |
| 3658 | /* write value back with RXDCTL.ENABLE bit cleared */ |
| 3659 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 3660 | |
| 3661 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 3662 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 3663 | return; |
| 3664 | |
| 3665 | /* the hardware may take up to 100us to really disable the rx queue */ |
| 3666 | do { |
| 3667 | udelay(10); |
| 3668 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 3669 | } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 3670 | |
| 3671 | if (!wait_loop) { |
| 3672 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within " |
| 3673 | "the polling period\n", reg_idx); |
| 3674 | } |
| 3675 | } |
| 3676 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 3677 | void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter, |
| 3678 | struct ixgbe_ring *ring) |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3679 | { |
| 3680 | struct ixgbe_hw *hw = &adapter->hw; |
| 3681 | u64 rdba = ring->dma; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3682 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3683 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3684 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3685 | /* disable queue to avoid issues while updating state */ |
| 3686 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 3687 | ixgbe_disable_rx_queue(adapter, ring); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3688 | |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3689 | IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32))); |
| 3690 | IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32)); |
| 3691 | IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx), |
| 3692 | ring->count * sizeof(union ixgbe_adv_rx_desc)); |
Neerav Parikh | 8b75451 | 2015-12-08 22:13:58 -0800 | [diff] [blame] | 3693 | /* Force flushing of IXGBE_RDLEN to prevent MDD */ |
| 3694 | IXGBE_WRITE_FLUSH(hw); |
| 3695 | |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3696 | IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0); |
| 3697 | IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 3698 | ring->tail = adapter->io_addr + IXGBE_RDT(reg_idx); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3699 | |
| 3700 | ixgbe_configure_srrctl(adapter, ring); |
| 3701 | ixgbe_configure_rscctl(adapter, ring); |
| 3702 | |
| 3703 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 3704 | /* |
| 3705 | * enable cache line friendly hardware writes: |
| 3706 | * PTHRESH=32 descriptors (half the internal cache), |
| 3707 | * this also removes ugly rx_no_buffer_count increment |
| 3708 | * HTHRESH=4 descriptors (to minimize latency on fetch) |
| 3709 | * WTHRESH=8 burst writeback up to two cache lines |
| 3710 | */ |
| 3711 | rxdctl &= ~0x3FFFFF; |
| 3712 | rxdctl |= 0x080420; |
| 3713 | } |
| 3714 | |
| 3715 | /* enable receive descriptor ring */ |
| 3716 | rxdctl |= IXGBE_RXDCTL_ENABLE; |
| 3717 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 3718 | |
| 3719 | ixgbe_rx_desc_queue_enable(adapter, ring); |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 3720 | ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring)); |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3721 | } |
| 3722 | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3723 | static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter) |
| 3724 | { |
| 3725 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 3726 | int rss_i = adapter->ring_feature[RING_F_RSS].indices; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 3727 | u16 pool; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3728 | |
| 3729 | /* PSRTYPE must be initialized in non 82598 adapters */ |
| 3730 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3731 | IXGBE_PSRTYPE_UDPHDR | |
| 3732 | IXGBE_PSRTYPE_IPV4HDR | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3733 | IXGBE_PSRTYPE_L2HDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3734 | IXGBE_PSRTYPE_IPV6HDR; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3735 | |
| 3736 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3737 | return; |
| 3738 | |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 3739 | if (rss_i > 3) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame^] | 3740 | psrtype |= 2u << 29; |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 3741 | else if (rss_i > 1) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame^] | 3742 | psrtype |= 1u << 29; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3743 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 3744 | for_each_set_bit(pool, &adapter->fwd_bitmask, 32) |
| 3745 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype); |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3746 | } |
| 3747 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3748 | static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter) |
| 3749 | { |
| 3750 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3751 | u32 reg_offset, vf_shift; |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3752 | u32 gcr_ext, vmdctl; |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 3753 | int i; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3754 | |
| 3755 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 3756 | return; |
| 3757 | |
| 3758 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL); |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3759 | vmdctl |= IXGBE_VMD_CTL_VMDQ_EN; |
| 3760 | vmdctl &= ~IXGBE_VT_CTL_POOL_MASK; |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3761 | vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT; |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3762 | vmdctl |= IXGBE_VT_CTL_REPLEN; |
| 3763 | IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3764 | |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3765 | vf_shift = VMDQ_P(0) % 32; |
| 3766 | reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3767 | |
| 3768 | /* Enable only the PF's pool for Tx/Rx */ |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3769 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (~0) << vf_shift); |
| 3770 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1); |
| 3771 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (~0) << vf_shift); |
| 3772 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1); |
Don Skidmore | aa2bacb | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 3773 | if (adapter->bridge_mode == BRIDGE_MODE_VEB) |
Greg Rose | 9b73598 | 2012-11-08 02:41:35 +0000 | [diff] [blame] | 3774 | IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3775 | |
| 3776 | /* 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] | 3777 | hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0)); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3778 | |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 3779 | /* clear VLAN promisc flag so VFTA will be updated if necessary */ |
| 3780 | adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC; |
| 3781 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3782 | /* |
| 3783 | * Set up VF register offsets for selected VT Mode, |
| 3784 | * i.e. 32 or 64 VFs for SR-IOV |
| 3785 | */ |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 3786 | switch (adapter->ring_feature[RING_F_VMDQ].mask) { |
| 3787 | case IXGBE_82599_VMDQ_8Q_MASK: |
| 3788 | gcr_ext = IXGBE_GCR_EXT_VT_MODE_16; |
| 3789 | break; |
| 3790 | case IXGBE_82599_VMDQ_4Q_MASK: |
| 3791 | gcr_ext = IXGBE_GCR_EXT_VT_MODE_32; |
| 3792 | break; |
| 3793 | default: |
| 3794 | gcr_ext = IXGBE_GCR_EXT_VT_MODE_64; |
| 3795 | break; |
| 3796 | } |
| 3797 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3798 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext); |
| 3799 | |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 3800 | for (i = 0; i < adapter->num_vfs; i++) { |
Emil Tantilov | 77f192a | 2016-03-18 16:11:14 -0700 | [diff] [blame] | 3801 | /* configure spoof checking */ |
| 3802 | ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, |
| 3803 | adapter->vfinfo[i].spoofchk_enabled); |
Vlad Zolotarov | e65ce0d | 2015-03-30 21:35:24 +0300 | [diff] [blame] | 3804 | |
| 3805 | /* Enable/Disable RSS query feature */ |
| 3806 | ixgbe_ndo_set_vf_rss_query_en(adapter->netdev, i, |
| 3807 | adapter->vfinfo[i].rss_query_enabled); |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 3808 | } |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3809 | } |
| 3810 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3811 | static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3812 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3813 | struct ixgbe_hw *hw = &adapter->hw; |
| 3814 | struct net_device *netdev = adapter->netdev; |
| 3815 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3816 | struct ixgbe_ring *rx_ring; |
| 3817 | int i; |
| 3818 | u32 mhadd, hlreg0; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3819 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3820 | #ifdef IXGBE_FCOE |
| 3821 | /* adjust max frame to be able to do baby jumbo for FCoE */ |
| 3822 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 3823 | (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE)) |
| 3824 | max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 3825 | |
| 3826 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 3827 | |
| 3828 | /* adjust max frame to be at least the size of a standard frame */ |
| 3829 | if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN)) |
| 3830 | max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN); |
| 3831 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3832 | mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD); |
| 3833 | if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) { |
| 3834 | mhadd &= ~IXGBE_MHADD_MFS_MASK; |
| 3835 | mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT; |
| 3836 | |
| 3837 | IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3838 | } |
| 3839 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3840 | hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3841 | /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */ |
| 3842 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3843 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0); |
| 3844 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3845 | /* |
| 3846 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3847 | * the Base and Length of the Rx Descriptor Ring |
| 3848 | */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3849 | for (i = 0; i < adapter->num_rx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3850 | rx_ring = adapter->rx_ring[i]; |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3851 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
| 3852 | set_ring_rsc_enabled(rx_ring); |
| 3853 | else |
| 3854 | clear_ring_rsc_enabled(rx_ring); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3855 | } |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3856 | } |
| 3857 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3858 | static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter) |
| 3859 | { |
| 3860 | struct ixgbe_hw *hw = &adapter->hw; |
| 3861 | u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 3862 | |
| 3863 | switch (hw->mac.type) { |
| 3864 | case ixgbe_mac_82598EB: |
| 3865 | /* |
| 3866 | * For VMDq support of different descriptor types or |
| 3867 | * buffer sizes through the use of multiple SRRCTL |
| 3868 | * registers, RDRXCTL.MVMEN must be set to 1 |
| 3869 | * |
| 3870 | * also, the manual doesn't mention it clearly but DCA hints |
| 3871 | * will only use queue 0's tags unless this bit is set. Side |
| 3872 | * effects of setting this bit are only that SRRCTL must be |
| 3873 | * fully programmed [0..15] |
| 3874 | */ |
| 3875 | rdrxctl |= IXGBE_RDRXCTL_MVMEN; |
| 3876 | break; |
Mark Rustad | 052a1a7 | 2015-08-08 16:19:04 -0700 | [diff] [blame] | 3877 | case ixgbe_mac_X550: |
| 3878 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 3879 | case ixgbe_mac_x550em_a: |
Mark Rustad | f961dda | 2015-08-08 16:19:09 -0700 | [diff] [blame] | 3880 | if (adapter->num_vfs) |
| 3881 | rdrxctl |= IXGBE_RDRXCTL_PSP; |
| 3882 | /* fall through for older HW */ |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3883 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3884 | case ixgbe_mac_X540: |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3885 | /* Disable RSC for ACK packets */ |
| 3886 | IXGBE_WRITE_REG(hw, IXGBE_RSCDBU, |
| 3887 | (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU))); |
| 3888 | rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE; |
| 3889 | /* hardware requires some bits to be set by default */ |
| 3890 | rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX); |
| 3891 | rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP; |
| 3892 | break; |
| 3893 | default: |
| 3894 | /* We should do nothing since we don't know this hardware */ |
| 3895 | return; |
| 3896 | } |
| 3897 | |
| 3898 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
| 3899 | } |
| 3900 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3901 | /** |
| 3902 | * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset |
| 3903 | * @adapter: board private structure |
| 3904 | * |
| 3905 | * Configure the Rx unit of the MAC after a reset. |
| 3906 | **/ |
| 3907 | static void ixgbe_configure_rx(struct ixgbe_adapter *adapter) |
| 3908 | { |
| 3909 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3910 | int i; |
Jacob Keller | 6dcc28b | 2013-07-17 02:53:23 +0000 | [diff] [blame] | 3911 | u32 rxctrl, rfctl; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3912 | |
| 3913 | /* disable receives while setting up the descriptors */ |
Don Skidmore | 1f9ac57 | 2015-03-13 13:54:30 -0700 | [diff] [blame] | 3914 | hw->mac.ops.disable_rx(hw); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3915 | |
| 3916 | ixgbe_setup_psrtype(adapter); |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3917 | ixgbe_setup_rdrxctl(adapter); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3918 | |
Jacob Keller | 6dcc28b | 2013-07-17 02:53:23 +0000 | [diff] [blame] | 3919 | /* RSC Setup */ |
| 3920 | rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL); |
| 3921 | rfctl &= ~IXGBE_RFCTL_RSC_DIS; |
| 3922 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) |
| 3923 | rfctl |= IXGBE_RFCTL_RSC_DIS; |
| 3924 | IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl); |
| 3925 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3926 | /* Program registers for the distribution of queues */ |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3927 | ixgbe_setup_mrqc(adapter); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3928 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3929 | /* set_rx_buffer_len must be called before ring initialization */ |
| 3930 | ixgbe_set_rx_buffer_len(adapter); |
| 3931 | |
| 3932 | /* |
| 3933 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3934 | * the Base and Length of the Rx Descriptor Ring |
| 3935 | */ |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3936 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3937 | ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3938 | |
Don Skidmore | 1f9ac57 | 2015-03-13 13:54:30 -0700 | [diff] [blame] | 3939 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3940 | /* disable drop enable for 82598 parts */ |
| 3941 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3942 | rxctrl |= IXGBE_RXCTRL_DMBYPS; |
| 3943 | |
| 3944 | /* enable all receives */ |
| 3945 | rxctrl |= IXGBE_RXCTRL_RXEN; |
| 3946 | hw->mac.ops.enable_rx_dma(hw, rxctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3947 | } |
| 3948 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 3949 | static int ixgbe_vlan_rx_add_vid(struct net_device *netdev, |
| 3950 | __be16 proto, u16 vid) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3951 | { |
| 3952 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3953 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3954 | |
| 3955 | /* add VID to filter table */ |
Alexander Duyck | 18be4fc | 2016-01-06 22:48:44 -0800 | [diff] [blame] | 3956 | if (!vid || !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)) |
| 3957 | hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true, !!vid); |
| 3958 | |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3959 | set_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 3960 | |
| 3961 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3962 | } |
| 3963 | |
Alexander Duyck | e1d0a2a | 2015-11-02 17:10:19 -0800 | [diff] [blame] | 3964 | static int ixgbe_find_vlvf_entry(struct ixgbe_hw *hw, u32 vlan) |
| 3965 | { |
| 3966 | u32 vlvf; |
| 3967 | int idx; |
| 3968 | |
| 3969 | /* short cut the special case */ |
| 3970 | if (vlan == 0) |
| 3971 | return 0; |
| 3972 | |
| 3973 | /* Search for the vlan id in the VLVF entries */ |
| 3974 | for (idx = IXGBE_VLVF_ENTRIES; --idx;) { |
| 3975 | vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(idx)); |
| 3976 | if ((vlvf & VLAN_VID_MASK) == vlan) |
| 3977 | break; |
| 3978 | } |
| 3979 | |
| 3980 | return idx; |
| 3981 | } |
| 3982 | |
| 3983 | void ixgbe_update_pf_promisc_vlvf(struct ixgbe_adapter *adapter, u32 vid) |
| 3984 | { |
| 3985 | struct ixgbe_hw *hw = &adapter->hw; |
| 3986 | u32 bits, word; |
| 3987 | int idx; |
| 3988 | |
| 3989 | idx = ixgbe_find_vlvf_entry(hw, vid); |
| 3990 | if (!idx) |
| 3991 | return; |
| 3992 | |
| 3993 | /* See if any other pools are set for this VLAN filter |
| 3994 | * entry other than the PF. |
| 3995 | */ |
| 3996 | word = idx * 2 + (VMDQ_P(0) / 32); |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame^] | 3997 | bits = ~BIT(VMDQ_P(0) % 32); |
Alexander Duyck | e1d0a2a | 2015-11-02 17:10:19 -0800 | [diff] [blame] | 3998 | bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word)); |
| 3999 | |
| 4000 | /* Disable the filter so this falls into the default pool. */ |
| 4001 | if (!bits && !IXGBE_READ_REG(hw, IXGBE_VLVFB(word ^ 1))) { |
| 4002 | if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)) |
| 4003 | IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), 0); |
| 4004 | IXGBE_WRITE_REG(hw, IXGBE_VLVF(idx), 0); |
| 4005 | } |
| 4006 | } |
| 4007 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 4008 | static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev, |
| 4009 | __be16 proto, u16 vid) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4010 | { |
| 4011 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4012 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4013 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4014 | /* remove VID from filter table */ |
Alexander Duyck | 18be4fc | 2016-01-06 22:48:44 -0800 | [diff] [blame] | 4015 | if (vid && !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)) |
Alexander Duyck | e1d0a2a | 2015-11-02 17:10:19 -0800 | [diff] [blame] | 4016 | hw->mac.ops.set_vfta(hw, vid, VMDQ_P(0), false, true); |
| 4017 | |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4018 | clear_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 4019 | |
| 4020 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4021 | } |
| 4022 | |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4023 | /** |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4024 | * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping |
| 4025 | * @adapter: driver data |
| 4026 | */ |
| 4027 | static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter) |
| 4028 | { |
| 4029 | struct ixgbe_hw *hw = &adapter->hw; |
| 4030 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4031 | int i, j; |
| 4032 | |
| 4033 | switch (hw->mac.type) { |
| 4034 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4035 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 4036 | vlnctrl &= ~IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4037 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4038 | break; |
| 4039 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4040 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 4041 | case ixgbe_mac_X550: |
| 4042 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 4043 | case ixgbe_mac_x550em_a: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4044 | for (i = 0; i < adapter->num_rx_queues; i++) { |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4045 | struct ixgbe_ring *ring = adapter->rx_ring[i]; |
| 4046 | |
| 4047 | if (ring->l2_accel_priv) |
| 4048 | continue; |
| 4049 | j = ring->reg_idx; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4050 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 4051 | vlnctrl &= ~IXGBE_RXDCTL_VME; |
| 4052 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 4053 | } |
| 4054 | break; |
| 4055 | default: |
| 4056 | break; |
| 4057 | } |
| 4058 | } |
| 4059 | |
| 4060 | /** |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4061 | * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4062 | * @adapter: driver data |
| 4063 | */ |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4064 | static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4065 | { |
| 4066 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4067 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4068 | int i, j; |
| 4069 | |
| 4070 | switch (hw->mac.type) { |
| 4071 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4072 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 4073 | vlnctrl |= IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4074 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4075 | break; |
| 4076 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4077 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 4078 | case ixgbe_mac_X550: |
| 4079 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 4080 | case ixgbe_mac_x550em_a: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4081 | for (i = 0; i < adapter->num_rx_queues; i++) { |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4082 | struct ixgbe_ring *ring = adapter->rx_ring[i]; |
| 4083 | |
| 4084 | if (ring->l2_accel_priv) |
| 4085 | continue; |
| 4086 | j = ring->reg_idx; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4087 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 4088 | vlnctrl |= IXGBE_RXDCTL_VME; |
| 4089 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 4090 | } |
| 4091 | break; |
| 4092 | default: |
| 4093 | break; |
| 4094 | } |
| 4095 | } |
| 4096 | |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4097 | static void ixgbe_vlan_promisc_enable(struct ixgbe_adapter *adapter) |
| 4098 | { |
| 4099 | struct ixgbe_hw *hw = &adapter->hw; |
| 4100 | u32 vlnctrl, i; |
| 4101 | |
| 4102 | switch (hw->mac.type) { |
| 4103 | case ixgbe_mac_82599EB: |
| 4104 | case ixgbe_mac_X540: |
| 4105 | case ixgbe_mac_X550: |
| 4106 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 4107 | case ixgbe_mac_x550em_a: |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4108 | default: |
| 4109 | if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) |
| 4110 | break; |
| 4111 | /* fall through */ |
| 4112 | case ixgbe_mac_82598EB: |
| 4113 | /* legacy case, we can just disable VLAN filtering */ |
| 4114 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 4115 | vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN); |
| 4116 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4117 | return; |
| 4118 | } |
| 4119 | |
| 4120 | /* We are already in VLAN promisc, nothing to do */ |
| 4121 | if (adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC) |
| 4122 | return; |
| 4123 | |
| 4124 | /* Set flag so we don't redo unnecessary work */ |
| 4125 | adapter->flags2 |= IXGBE_FLAG2_VLAN_PROMISC; |
| 4126 | |
| 4127 | /* Add PF to all active pools */ |
| 4128 | for (i = IXGBE_VLVF_ENTRIES; --i;) { |
| 4129 | u32 reg_offset = IXGBE_VLVFB(i * 2 + VMDQ_P(0) / 32); |
| 4130 | u32 vlvfb = IXGBE_READ_REG(hw, reg_offset); |
| 4131 | |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame^] | 4132 | vlvfb |= BIT(VMDQ_P(0) % 32); |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4133 | IXGBE_WRITE_REG(hw, reg_offset, vlvfb); |
| 4134 | } |
| 4135 | |
| 4136 | /* Set all bits in the VLAN filter table array */ |
| 4137 | for (i = hw->mac.vft_size; i--;) |
| 4138 | IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), ~0U); |
| 4139 | } |
| 4140 | |
| 4141 | #define VFTA_BLOCK_SIZE 8 |
| 4142 | static void ixgbe_scrub_vfta(struct ixgbe_adapter *adapter, u32 vfta_offset) |
| 4143 | { |
| 4144 | struct ixgbe_hw *hw = &adapter->hw; |
| 4145 | u32 vfta[VFTA_BLOCK_SIZE] = { 0 }; |
| 4146 | u32 vid_start = vfta_offset * 32; |
| 4147 | u32 vid_end = vid_start + (VFTA_BLOCK_SIZE * 32); |
| 4148 | u32 i, vid, word, bits; |
| 4149 | |
| 4150 | for (i = IXGBE_VLVF_ENTRIES; --i;) { |
| 4151 | u32 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(i)); |
| 4152 | |
| 4153 | /* pull VLAN ID from VLVF */ |
| 4154 | vid = vlvf & VLAN_VID_MASK; |
| 4155 | |
| 4156 | /* only concern outselves with a certain range */ |
| 4157 | if (vid < vid_start || vid >= vid_end) |
| 4158 | continue; |
| 4159 | |
| 4160 | if (vlvf) { |
| 4161 | /* record VLAN ID in VFTA */ |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame^] | 4162 | vfta[(vid - vid_start) / 32] |= BIT(vid % 32); |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4163 | |
| 4164 | /* if PF is part of this then continue */ |
| 4165 | if (test_bit(vid, adapter->active_vlans)) |
| 4166 | continue; |
| 4167 | } |
| 4168 | |
| 4169 | /* remove PF from the pool */ |
| 4170 | word = i * 2 + VMDQ_P(0) / 32; |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame^] | 4171 | bits = ~BIT(VMDQ_P(0) % 32); |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4172 | bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word)); |
| 4173 | IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), bits); |
| 4174 | } |
| 4175 | |
| 4176 | /* extract values from active_vlans and write back to VFTA */ |
| 4177 | for (i = VFTA_BLOCK_SIZE; i--;) { |
| 4178 | vid = (vfta_offset + i) * 32; |
| 4179 | word = vid / BITS_PER_LONG; |
| 4180 | bits = vid % BITS_PER_LONG; |
| 4181 | |
| 4182 | vfta[i] |= adapter->active_vlans[word] >> bits; |
| 4183 | |
| 4184 | IXGBE_WRITE_REG(hw, IXGBE_VFTA(vfta_offset + i), vfta[i]); |
| 4185 | } |
| 4186 | } |
| 4187 | |
| 4188 | static void ixgbe_vlan_promisc_disable(struct ixgbe_adapter *adapter) |
| 4189 | { |
| 4190 | struct ixgbe_hw *hw = &adapter->hw; |
| 4191 | u32 vlnctrl, i; |
| 4192 | |
| 4193 | switch (hw->mac.type) { |
| 4194 | case ixgbe_mac_82599EB: |
| 4195 | case ixgbe_mac_X540: |
| 4196 | case ixgbe_mac_X550: |
| 4197 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 4198 | case ixgbe_mac_x550em_a: |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4199 | default: |
| 4200 | if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) |
| 4201 | break; |
| 4202 | /* fall through */ |
| 4203 | case ixgbe_mac_82598EB: |
| 4204 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 4205 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 4206 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
| 4207 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4208 | return; |
| 4209 | } |
| 4210 | |
| 4211 | /* We are not in VLAN promisc, nothing to do */ |
| 4212 | if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)) |
| 4213 | return; |
| 4214 | |
| 4215 | /* Set flag so we don't redo unnecessary work */ |
| 4216 | adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC; |
| 4217 | |
| 4218 | for (i = 0; i < hw->mac.vft_size; i += VFTA_BLOCK_SIZE) |
| 4219 | ixgbe_scrub_vfta(adapter, i); |
| 4220 | } |
| 4221 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4222 | static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter) |
| 4223 | { |
Alexander Duyck | 06bb1c3 | 2016-01-06 22:48:50 -0800 | [diff] [blame] | 4224 | u16 vid = 1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4225 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 4226 | ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4227 | |
Alexander Duyck | 06bb1c3 | 2016-01-06 22:48:50 -0800 | [diff] [blame] | 4228 | for_each_set_bit_from(vid, adapter->active_vlans, VLAN_N_VID) |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 4229 | ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4230 | } |
| 4231 | |
| 4232 | /** |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4233 | * ixgbe_write_mc_addr_list - write multicast addresses to MTA |
| 4234 | * @netdev: network interface device structure |
| 4235 | * |
| 4236 | * Writes multicast address list to the MTA hash table. |
| 4237 | * Returns: -ENOMEM on failure |
| 4238 | * 0 on no addresses written |
| 4239 | * X on writing X addresses to MTA |
| 4240 | **/ |
| 4241 | static int ixgbe_write_mc_addr_list(struct net_device *netdev) |
| 4242 | { |
| 4243 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4244 | struct ixgbe_hw *hw = &adapter->hw; |
| 4245 | |
| 4246 | if (!netif_running(netdev)) |
| 4247 | return 0; |
| 4248 | |
| 4249 | if (hw->mac.ops.update_mc_addr_list) |
| 4250 | hw->mac.ops.update_mc_addr_list(hw, netdev); |
| 4251 | else |
| 4252 | return -ENOMEM; |
| 4253 | |
| 4254 | #ifdef CONFIG_PCI_IOV |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4255 | ixgbe_restore_vf_multicasts(adapter); |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4256 | #endif |
| 4257 | |
| 4258 | return netdev_mc_count(netdev); |
| 4259 | } |
| 4260 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4261 | #ifdef CONFIG_PCI_IOV |
| 4262 | void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter) |
| 4263 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4264 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4265 | struct ixgbe_hw *hw = &adapter->hw; |
| 4266 | int i; |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4267 | |
| 4268 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4269 | mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED; |
| 4270 | |
| 4271 | if (mac_table->state & IXGBE_MAC_STATE_IN_USE) |
| 4272 | hw->mac.ops.set_rar(hw, i, |
| 4273 | mac_table->addr, |
| 4274 | mac_table->pool, |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4275 | IXGBE_RAH_AV); |
| 4276 | else |
| 4277 | hw->mac.ops.clear_rar(hw, i); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4278 | } |
| 4279 | } |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4280 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4281 | #endif |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4282 | static void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter) |
| 4283 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4284 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4285 | struct ixgbe_hw *hw = &adapter->hw; |
| 4286 | int i; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4287 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4288 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4289 | if (!(mac_table->state & IXGBE_MAC_STATE_MODIFIED)) |
| 4290 | continue; |
| 4291 | |
| 4292 | mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED; |
| 4293 | |
| 4294 | if (mac_table->state & IXGBE_MAC_STATE_IN_USE) |
| 4295 | hw->mac.ops.set_rar(hw, i, |
| 4296 | mac_table->addr, |
| 4297 | mac_table->pool, |
| 4298 | IXGBE_RAH_AV); |
| 4299 | else |
| 4300 | hw->mac.ops.clear_rar(hw, i); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4301 | } |
| 4302 | } |
| 4303 | |
| 4304 | static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter) |
| 4305 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4306 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4307 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4308 | int i; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4309 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4310 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4311 | mac_table->state |= IXGBE_MAC_STATE_MODIFIED; |
| 4312 | mac_table->state &= ~IXGBE_MAC_STATE_IN_USE; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4313 | } |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4314 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4315 | ixgbe_sync_mac_table(adapter); |
| 4316 | } |
| 4317 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4318 | static int ixgbe_available_rars(struct ixgbe_adapter *adapter, u16 pool) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4319 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4320 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4321 | struct ixgbe_hw *hw = &adapter->hw; |
| 4322 | int i, count = 0; |
| 4323 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4324 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4325 | /* do not count default RAR as available */ |
| 4326 | if (mac_table->state & IXGBE_MAC_STATE_DEFAULT) |
| 4327 | continue; |
| 4328 | |
| 4329 | /* only count unused and addresses that belong to us */ |
| 4330 | if (mac_table->state & IXGBE_MAC_STATE_IN_USE) { |
| 4331 | if (mac_table->pool != pool) |
| 4332 | continue; |
| 4333 | } |
| 4334 | |
| 4335 | count++; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4336 | } |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4337 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4338 | return count; |
| 4339 | } |
| 4340 | |
| 4341 | /* this function destroys the first RAR entry */ |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4342 | static void ixgbe_mac_set_default_filter(struct ixgbe_adapter *adapter) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4343 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4344 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4345 | struct ixgbe_hw *hw = &adapter->hw; |
| 4346 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4347 | memcpy(&mac_table->addr, hw->mac.addr, ETH_ALEN); |
| 4348 | mac_table->pool = VMDQ_P(0); |
| 4349 | |
| 4350 | mac_table->state = IXGBE_MAC_STATE_DEFAULT | IXGBE_MAC_STATE_IN_USE; |
| 4351 | |
| 4352 | 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] | 4353 | IXGBE_RAH_AV); |
| 4354 | } |
| 4355 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4356 | int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter, |
| 4357 | const u8 *addr, u16 pool) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4358 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4359 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4360 | struct ixgbe_hw *hw = &adapter->hw; |
| 4361 | int i; |
| 4362 | |
| 4363 | if (is_zero_ether_addr(addr)) |
| 4364 | return -EINVAL; |
| 4365 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4366 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4367 | if (mac_table->state & IXGBE_MAC_STATE_IN_USE) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4368 | continue; |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4369 | |
| 4370 | ether_addr_copy(mac_table->addr, addr); |
| 4371 | mac_table->pool = pool; |
| 4372 | |
| 4373 | mac_table->state |= IXGBE_MAC_STATE_MODIFIED | |
| 4374 | IXGBE_MAC_STATE_IN_USE; |
| 4375 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4376 | ixgbe_sync_mac_table(adapter); |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4377 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4378 | return i; |
| 4379 | } |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4380 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4381 | return -ENOMEM; |
| 4382 | } |
| 4383 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4384 | int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter, |
| 4385 | const u8 *addr, u16 pool) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4386 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4387 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4388 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4389 | int i; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4390 | |
| 4391 | if (is_zero_ether_addr(addr)) |
| 4392 | return -EINVAL; |
| 4393 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4394 | /* search table for addr, if found clear IN_USE flag and sync */ |
| 4395 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4396 | /* we can only delete an entry if it is in use */ |
| 4397 | if (!(mac_table->state & IXGBE_MAC_STATE_IN_USE)) |
| 4398 | continue; |
| 4399 | /* we only care about entries that belong to the given pool */ |
| 4400 | if (mac_table->pool != pool) |
| 4401 | continue; |
| 4402 | /* we only care about a specific MAC address */ |
| 4403 | if (!ether_addr_equal(addr, mac_table->addr)) |
| 4404 | continue; |
| 4405 | |
| 4406 | mac_table->state |= IXGBE_MAC_STATE_MODIFIED; |
| 4407 | mac_table->state &= ~IXGBE_MAC_STATE_IN_USE; |
| 4408 | |
| 4409 | ixgbe_sync_mac_table(adapter); |
| 4410 | |
| 4411 | return 0; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4412 | } |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4413 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4414 | return -ENOMEM; |
| 4415 | } |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4416 | /** |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4417 | * ixgbe_write_uc_addr_list - write unicast addresses to RAR table |
| 4418 | * @netdev: network interface device structure |
| 4419 | * |
| 4420 | * Writes unicast address list to the RAR table. |
| 4421 | * Returns: -ENOMEM on failure/insufficient address space |
| 4422 | * 0 on no addresses written |
| 4423 | * X on writing X addresses to the RAR table |
| 4424 | **/ |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4425 | 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] | 4426 | { |
| 4427 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4428 | int count = 0; |
| 4429 | |
| 4430 | /* return ENOMEM indicating insufficient memory for addresses */ |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4431 | if (netdev_uc_count(netdev) > ixgbe_available_rars(adapter, vfn)) |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4432 | return -ENOMEM; |
| 4433 | |
John Fastabend | 9544746 | 2012-05-31 12:42:26 +0000 | [diff] [blame] | 4434 | if (!netdev_uc_empty(netdev)) { |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4435 | struct netdev_hw_addr *ha; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4436 | netdev_for_each_uc_addr(ha, netdev) { |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4437 | ixgbe_del_mac_filter(adapter, ha->addr, vfn); |
| 4438 | ixgbe_add_mac_filter(adapter, ha->addr, vfn); |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4439 | count++; |
| 4440 | } |
| 4441 | } |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4442 | return count; |
| 4443 | } |
| 4444 | |
Alexander Duyck | 0f079d2 | 2015-10-22 16:26:36 -0700 | [diff] [blame] | 4445 | static int ixgbe_uc_sync(struct net_device *netdev, const unsigned char *addr) |
| 4446 | { |
| 4447 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4448 | int ret; |
| 4449 | |
| 4450 | ret = ixgbe_add_mac_filter(adapter, addr, VMDQ_P(0)); |
| 4451 | |
| 4452 | return min_t(int, ret, 0); |
| 4453 | } |
| 4454 | |
| 4455 | static int ixgbe_uc_unsync(struct net_device *netdev, const unsigned char *addr) |
| 4456 | { |
| 4457 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4458 | |
| 4459 | ixgbe_del_mac_filter(adapter, addr, VMDQ_P(0)); |
| 4460 | |
| 4461 | return 0; |
| 4462 | } |
| 4463 | |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4464 | /** |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 4465 | * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4466 | * @netdev: network interface device structure |
| 4467 | * |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 4468 | * The set_rx_method entry point is called whenever the unicast/multicast |
| 4469 | * address list or the network interface flags are updated. This routine is |
| 4470 | * responsible for configuring the hardware for proper unicast, multicast and |
| 4471 | * promiscuous mode. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4472 | **/ |
Greg Rose | 7f87047 | 2010-01-09 02:25:29 +0000 | [diff] [blame] | 4473 | void ixgbe_set_rx_mode(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4474 | { |
| 4475 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4476 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4477 | u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE; |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 4478 | netdev_features_t features = netdev->features; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4479 | int count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4480 | |
| 4481 | /* Check for Promiscuous and All Multicast modes */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4482 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 4483 | |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 4484 | /* set all bits that we expect to always be set */ |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 4485 | fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */ |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 4486 | fctrl |= IXGBE_FCTRL_BAM; |
| 4487 | fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */ |
| 4488 | fctrl |= IXGBE_FCTRL_PMCF; |
| 4489 | |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4490 | /* clear the bits we are changing the status of */ |
| 4491 | fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4492 | if (netdev->flags & IFF_PROMISC) { |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 4493 | hw->addr_ctrl.user_set_promisc = true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4494 | fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4495 | vmolr |= IXGBE_VMOLR_MPE; |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 4496 | features &= ~NETIF_F_HW_VLAN_CTAG_FILTER; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4497 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 4498 | if (netdev->flags & IFF_ALLMULTI) { |
| 4499 | fctrl |= IXGBE_FCTRL_MPE; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4500 | vmolr |= IXGBE_VMOLR_MPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 4501 | } |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 4502 | hw->addr_ctrl.user_set_promisc = false; |
John Fastabend | 9dcb373 | 2012-04-15 06:44:25 +0000 | [diff] [blame] | 4503 | } |
| 4504 | |
| 4505 | /* |
| 4506 | * Write addresses to available RAR registers, if there is not |
| 4507 | * sufficient space to store all the addresses then enable |
| 4508 | * unicast promiscuous mode |
| 4509 | */ |
Alexander Duyck | 0f079d2 | 2015-10-22 16:26:36 -0700 | [diff] [blame] | 4510 | if (__dev_uc_sync(netdev, ixgbe_uc_sync, ixgbe_uc_unsync)) { |
John Fastabend | 9dcb373 | 2012-04-15 06:44:25 +0000 | [diff] [blame] | 4511 | fctrl |= IXGBE_FCTRL_UPE; |
| 4512 | vmolr |= IXGBE_VMOLR_ROPE; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4513 | } |
| 4514 | |
Emil Tantilov | cf78959 | 2013-10-26 08:13:20 +0000 | [diff] [blame] | 4515 | /* Write addresses to the MTA, if the attempt fails |
| 4516 | * then we should just turn on promiscuous mode so |
| 4517 | * that we can at least receive multicast traffic |
| 4518 | */ |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4519 | count = ixgbe_write_mc_addr_list(netdev); |
| 4520 | if (count < 0) { |
| 4521 | fctrl |= IXGBE_FCTRL_MPE; |
| 4522 | vmolr |= IXGBE_VMOLR_MPE; |
| 4523 | } else if (count) { |
| 4524 | vmolr |= IXGBE_VMOLR_ROMPE; |
| 4525 | } |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 4526 | |
| 4527 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 4528 | vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) & |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4529 | ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE | |
| 4530 | IXGBE_VMOLR_ROPE); |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 4531 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4532 | } |
| 4533 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 4534 | /* This is useful for sniffing bad packets. */ |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 4535 | if (features & NETIF_F_RXALL) { |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 4536 | /* UPE and MPE will be handled by normal PROMISC logic |
| 4537 | * in e1000e_set_rx_mode */ |
| 4538 | fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */ |
| 4539 | IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */ |
| 4540 | IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */ |
| 4541 | |
| 4542 | fctrl &= ~(IXGBE_FCTRL_DPF); |
| 4543 | /* NOTE: VLAN filtering is disabled by setting PROMISC */ |
| 4544 | } |
| 4545 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4546 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4547 | |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 4548 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4549 | ixgbe_vlan_strip_enable(adapter); |
| 4550 | else |
| 4551 | ixgbe_vlan_strip_disable(adapter); |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 4552 | |
| 4553 | if (features & NETIF_F_HW_VLAN_CTAG_FILTER) |
| 4554 | ixgbe_vlan_promisc_disable(adapter); |
| 4555 | else |
| 4556 | ixgbe_vlan_promisc_enable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4557 | } |
| 4558 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4559 | static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter) |
| 4560 | { |
| 4561 | int q_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4562 | |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 4563 | for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) { |
| 4564 | ixgbe_qv_init_lock(adapter->q_vector[q_idx]); |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 4565 | napi_enable(&adapter->q_vector[q_idx]->napi); |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 4566 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4567 | } |
| 4568 | |
| 4569 | static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter) |
| 4570 | { |
| 4571 | int q_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4572 | |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 4573 | for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) { |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 4574 | napi_disable(&adapter->q_vector[q_idx]->napi); |
Jacob Keller | 27d9ce4 | 2013-09-21 05:05:44 +0000 | [diff] [blame] | 4575 | while (!ixgbe_qv_disable(adapter->q_vector[q_idx])) { |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 4576 | pr_info("QV %d locked\n", q_idx); |
Jacob Keller | 27d9ce4 | 2013-09-21 05:05:44 +0000 | [diff] [blame] | 4577 | usleep_range(1000, 20000); |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 4578 | } |
| 4579 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4580 | } |
| 4581 | |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 4582 | static void ixgbe_clear_vxlan_port(struct ixgbe_adapter *adapter) |
| 4583 | { |
| 4584 | switch (adapter->hw.mac.type) { |
| 4585 | case ixgbe_mac_X550: |
| 4586 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 4587 | case ixgbe_mac_x550em_a: |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 4588 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_VXLANCTRL, 0); |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 4589 | adapter->vxlan_port = 0; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 4590 | break; |
| 4591 | default: |
| 4592 | break; |
| 4593 | } |
| 4594 | } |
| 4595 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 4596 | #ifdef CONFIG_IXGBE_DCB |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4597 | /** |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4598 | * ixgbe_configure_dcb - Configure DCB hardware |
| 4599 | * @adapter: ixgbe adapter struct |
| 4600 | * |
| 4601 | * This is called by the driver on open to configure the DCB hardware. |
| 4602 | * This is also called by the gennetlink interface when reconfiguring |
| 4603 | * the DCB state. |
| 4604 | */ |
| 4605 | static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter) |
| 4606 | { |
| 4607 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 9806307 | 2010-10-28 00:59:57 +0000 | [diff] [blame] | 4608 | int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4609 | |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 4610 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) { |
| 4611 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4612 | netif_set_gso_max_size(adapter->netdev, 65536); |
| 4613 | return; |
| 4614 | } |
| 4615 | |
| 4616 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4617 | netif_set_gso_max_size(adapter->netdev, 32768); |
| 4618 | |
John Fastabend | b120818 | 2011-10-15 05:00:10 +0000 | [diff] [blame] | 4619 | #ifdef IXGBE_FCOE |
| 4620 | if (adapter->netdev->features & NETIF_F_FCOE_MTU) |
| 4621 | max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE); |
| 4622 | #endif |
| 4623 | |
Alexander Duyck | 01fa7d9 | 2010-11-16 19:26:53 -0800 | [diff] [blame] | 4624 | /* reconfigure the hardware */ |
John Fastabend | 6f70f6a | 2011-04-26 07:26:25 +0000 | [diff] [blame] | 4625 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) { |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 4626 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 4627 | DCB_TX_CONFIG); |
| 4628 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 4629 | DCB_RX_CONFIG); |
| 4630 | ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg); |
John Fastabend | b120818 | 2011-10-15 05:00:10 +0000 | [diff] [blame] | 4631 | } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) { |
| 4632 | ixgbe_dcb_hw_ets(&adapter->hw, |
| 4633 | adapter->ixgbe_ieee_ets, |
| 4634 | max_frame); |
| 4635 | ixgbe_dcb_hw_pfc_config(&adapter->hw, |
| 4636 | adapter->ixgbe_ieee_pfc->pfc_en, |
| 4637 | adapter->ixgbe_ieee_ets->prio_tc); |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 4638 | } |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 4639 | |
| 4640 | /* Enable RSS Hash per TC */ |
| 4641 | if (hw->mac.type != ixgbe_mac_82598EB) { |
Alexander Duyck | 4ae6373 | 2012-06-22 06:46:33 +0000 | [diff] [blame] | 4642 | u32 msb = 0; |
| 4643 | u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1; |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 4644 | |
Alexander Duyck | d411a93 | 2012-06-30 00:14:01 +0000 | [diff] [blame] | 4645 | while (rss_i) { |
| 4646 | msb++; |
| 4647 | rss_i >>= 1; |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 4648 | } |
Alexander Duyck | d411a93 | 2012-06-30 00:14:01 +0000 | [diff] [blame] | 4649 | |
Alexander Duyck | 4ae6373 | 2012-06-22 06:46:33 +0000 | [diff] [blame] | 4650 | /* write msb to all 8 TCs in one write */ |
| 4651 | IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111); |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 4652 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4653 | } |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4654 | #endif |
| 4655 | |
| 4656 | /* Additional bittime to account for IXGBE framing */ |
| 4657 | #define IXGBE_ETH_FRAMING 20 |
| 4658 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4659 | /** |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4660 | * ixgbe_hpbthresh - calculate high water mark for flow control |
| 4661 | * |
| 4662 | * @adapter: board private structure to calculate for |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4663 | * @pb: packet buffer to calculate |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4664 | */ |
| 4665 | static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb) |
| 4666 | { |
| 4667 | struct ixgbe_hw *hw = &adapter->hw; |
| 4668 | struct net_device *dev = adapter->netdev; |
| 4669 | int link, tc, kb, marker; |
| 4670 | u32 dv_id, rx_pba; |
| 4671 | |
| 4672 | /* Calculate max LAN frame size */ |
| 4673 | tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING; |
| 4674 | |
| 4675 | #ifdef IXGBE_FCOE |
| 4676 | /* FCoE traffic class uses FCOE jumbo frames */ |
Alexander Duyck | 800bd60 | 2012-06-02 00:11:02 +0000 | [diff] [blame] | 4677 | if ((dev->features & NETIF_F_FCOE_MTU) && |
| 4678 | (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) && |
| 4679 | (pb == ixgbe_fcoe_get_tc(adapter))) |
| 4680 | tc = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4681 | #endif |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4682 | |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4683 | /* Calculate delay value for device */ |
| 4684 | switch (hw->mac.type) { |
| 4685 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 4686 | case ixgbe_mac_X550: |
| 4687 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 4688 | case ixgbe_mac_x550em_a: |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4689 | dv_id = IXGBE_DV_X540(link, tc); |
| 4690 | break; |
| 4691 | default: |
| 4692 | dv_id = IXGBE_DV(link, tc); |
| 4693 | break; |
| 4694 | } |
| 4695 | |
| 4696 | /* Loopback switch introduces additional latency */ |
| 4697 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 4698 | dv_id += IXGBE_B2BT(tc); |
| 4699 | |
| 4700 | /* Delay value is calculated in bit times convert to KB */ |
| 4701 | kb = IXGBE_BT2KB(dv_id); |
| 4702 | rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10; |
| 4703 | |
| 4704 | marker = rx_pba - kb; |
| 4705 | |
| 4706 | /* It is possible that the packet buffer is not large enough |
| 4707 | * to provide required headroom. In this case throw an error |
| 4708 | * to user and a do the best we can. |
| 4709 | */ |
| 4710 | if (marker < 0) { |
| 4711 | e_warn(drv, "Packet Buffer(%i) can not provide enough" |
| 4712 | "headroom to support flow control." |
| 4713 | "Decrease MTU or number of traffic classes\n", pb); |
| 4714 | marker = tc + 1; |
| 4715 | } |
| 4716 | |
| 4717 | return marker; |
| 4718 | } |
| 4719 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4720 | /** |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4721 | * ixgbe_lpbthresh - calculate low water mark for for flow control |
| 4722 | * |
| 4723 | * @adapter: board private structure to calculate for |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4724 | * @pb: packet buffer to calculate |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4725 | */ |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4726 | static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb) |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4727 | { |
| 4728 | struct ixgbe_hw *hw = &adapter->hw; |
| 4729 | struct net_device *dev = adapter->netdev; |
| 4730 | int tc; |
| 4731 | u32 dv_id; |
| 4732 | |
| 4733 | /* Calculate max LAN frame size */ |
| 4734 | tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN; |
| 4735 | |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4736 | #ifdef IXGBE_FCOE |
| 4737 | /* FCoE traffic class uses FCOE jumbo frames */ |
| 4738 | if ((dev->features & NETIF_F_FCOE_MTU) && |
| 4739 | (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) && |
| 4740 | (pb == netdev_get_prio_tc_map(dev, adapter->fcoe.up))) |
| 4741 | tc = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 4742 | #endif |
| 4743 | |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4744 | /* Calculate delay value for device */ |
| 4745 | switch (hw->mac.type) { |
| 4746 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 4747 | case ixgbe_mac_X550: |
| 4748 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 4749 | case ixgbe_mac_x550em_a: |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4750 | dv_id = IXGBE_LOW_DV_X540(tc); |
| 4751 | break; |
| 4752 | default: |
| 4753 | dv_id = IXGBE_LOW_DV(tc); |
| 4754 | break; |
| 4755 | } |
| 4756 | |
| 4757 | /* Delay value is calculated in bit times convert to KB */ |
| 4758 | return IXGBE_BT2KB(dv_id); |
| 4759 | } |
| 4760 | |
| 4761 | /* |
| 4762 | * ixgbe_pbthresh_setup - calculate and setup high low water marks |
| 4763 | */ |
| 4764 | static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter) |
| 4765 | { |
| 4766 | struct ixgbe_hw *hw = &adapter->hw; |
| 4767 | int num_tc = netdev_get_num_tc(adapter->netdev); |
| 4768 | int i; |
| 4769 | |
| 4770 | if (!num_tc) |
| 4771 | num_tc = 1; |
| 4772 | |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4773 | for (i = 0; i < num_tc; i++) { |
| 4774 | hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i); |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4775 | hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i); |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4776 | |
| 4777 | /* Low water marks must not be larger than high water marks */ |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4778 | if (hw->fc.low_water[i] > hw->fc.high_water[i]) |
| 4779 | hw->fc.low_water[i] = 0; |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4780 | } |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 4781 | |
| 4782 | for (; i < MAX_TRAFFIC_CLASS; i++) |
| 4783 | hw->fc.high_water[i] = 0; |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4784 | } |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4785 | |
| 4786 | static void ixgbe_configure_pb(struct ixgbe_adapter *adapter) |
| 4787 | { |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4788 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 4789 | int hdrm; |
| 4790 | u8 tc = netdev_get_num_tc(adapter->netdev); |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4791 | |
| 4792 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 4793 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 4794 | hdrm = 32 << adapter->fdir_pballoc; |
| 4795 | else |
| 4796 | hdrm = 0; |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4797 | |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 4798 | hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL); |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4799 | ixgbe_pbthresh_setup(adapter); |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4800 | } |
| 4801 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4802 | static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter) |
| 4803 | { |
| 4804 | struct ixgbe_hw *hw = &adapter->hw; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 4805 | struct hlist_node *node2; |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4806 | struct ixgbe_fdir_filter *filter; |
| 4807 | |
| 4808 | spin_lock(&adapter->fdir_perfect_lock); |
| 4809 | |
| 4810 | if (!hlist_empty(&adapter->fdir_filter_list)) |
| 4811 | ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask); |
| 4812 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 4813 | hlist_for_each_entry_safe(filter, node2, |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4814 | &adapter->fdir_filter_list, fdir_node) { |
| 4815 | ixgbe_fdir_write_perfect_filter_82599(hw, |
Alexander Duyck | 1f4d518 | 2011-05-14 01:16:02 +0000 | [diff] [blame] | 4816 | &filter->filter, |
| 4817 | filter->sw_idx, |
| 4818 | (filter->action == IXGBE_FDIR_DROP_QUEUE) ? |
| 4819 | IXGBE_FDIR_DROP_QUEUE : |
| 4820 | adapter->rx_ring[filter->action]->reg_idx); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4821 | } |
| 4822 | |
| 4823 | spin_unlock(&adapter->fdir_perfect_lock); |
| 4824 | } |
| 4825 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4826 | static void ixgbe_macvlan_set_rx_mode(struct net_device *dev, unsigned int pool, |
| 4827 | struct ixgbe_adapter *adapter) |
| 4828 | { |
| 4829 | struct ixgbe_hw *hw = &adapter->hw; |
| 4830 | u32 vmolr; |
| 4831 | |
| 4832 | /* No unicast promiscuous support for VMDQ devices. */ |
| 4833 | vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(pool)); |
| 4834 | vmolr |= (IXGBE_VMOLR_ROMPE | IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE); |
| 4835 | |
| 4836 | /* clear the affected bit */ |
| 4837 | vmolr &= ~IXGBE_VMOLR_MPE; |
| 4838 | |
| 4839 | if (dev->flags & IFF_ALLMULTI) { |
| 4840 | vmolr |= IXGBE_VMOLR_MPE; |
| 4841 | } else { |
| 4842 | vmolr |= IXGBE_VMOLR_ROMPE; |
| 4843 | hw->mac.ops.update_mc_addr_list(hw, dev); |
| 4844 | } |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4845 | ixgbe_write_uc_addr_list(adapter->netdev, pool); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4846 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(pool), vmolr); |
| 4847 | } |
| 4848 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4849 | static void ixgbe_fwd_psrtype(struct ixgbe_fwd_adapter *vadapter) |
| 4850 | { |
| 4851 | struct ixgbe_adapter *adapter = vadapter->real_adapter; |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 4852 | int rss_i = adapter->num_rx_queues_per_pool; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4853 | struct ixgbe_hw *hw = &adapter->hw; |
| 4854 | u16 pool = vadapter->pool; |
| 4855 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
| 4856 | IXGBE_PSRTYPE_UDPHDR | |
| 4857 | IXGBE_PSRTYPE_IPV4HDR | |
| 4858 | IXGBE_PSRTYPE_L2HDR | |
| 4859 | IXGBE_PSRTYPE_IPV6HDR; |
| 4860 | |
| 4861 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4862 | return; |
| 4863 | |
| 4864 | if (rss_i > 3) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame^] | 4865 | psrtype |= 2u << 29; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4866 | else if (rss_i > 1) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame^] | 4867 | psrtype |= 1u << 29; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4868 | |
| 4869 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype); |
| 4870 | } |
| 4871 | |
| 4872 | /** |
| 4873 | * ixgbe_clean_rx_ring - Free Rx Buffers per Queue |
| 4874 | * @rx_ring: ring to free buffers from |
| 4875 | **/ |
| 4876 | static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring) |
| 4877 | { |
| 4878 | struct device *dev = rx_ring->dev; |
| 4879 | unsigned long size; |
| 4880 | u16 i; |
| 4881 | |
| 4882 | /* ring already cleared, nothing to do */ |
| 4883 | if (!rx_ring->rx_buffer_info) |
| 4884 | return; |
| 4885 | |
| 4886 | /* Free all the Rx ring sk_buffs */ |
| 4887 | for (i = 0; i < rx_ring->count; i++) { |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 4888 | struct ixgbe_rx_buffer *rx_buffer = &rx_ring->rx_buffer_info[i]; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4889 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4890 | if (rx_buffer->skb) { |
| 4891 | struct sk_buff *skb = rx_buffer->skb; |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 4892 | if (IXGBE_CB(skb)->page_released) |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4893 | dma_unmap_page(dev, |
| 4894 | IXGBE_CB(skb)->dma, |
| 4895 | ixgbe_rx_bufsz(rx_ring), |
| 4896 | DMA_FROM_DEVICE); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4897 | dev_kfree_skb(skb); |
Junwei Zhang | 4d2fcfb | 2014-10-22 15:29:03 +0000 | [diff] [blame] | 4898 | rx_buffer->skb = NULL; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4899 | } |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 4900 | |
| 4901 | if (!rx_buffer->page) |
| 4902 | continue; |
| 4903 | |
| 4904 | dma_unmap_page(dev, rx_buffer->dma, |
| 4905 | ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE); |
| 4906 | __free_pages(rx_buffer->page, ixgbe_rx_pg_order(rx_ring)); |
| 4907 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4908 | rx_buffer->page = NULL; |
| 4909 | } |
| 4910 | |
| 4911 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 4912 | memset(rx_ring->rx_buffer_info, 0, size); |
| 4913 | |
| 4914 | /* Zero out the descriptor ring */ |
| 4915 | memset(rx_ring->desc, 0, rx_ring->size); |
| 4916 | |
| 4917 | rx_ring->next_to_alloc = 0; |
| 4918 | rx_ring->next_to_clean = 0; |
| 4919 | rx_ring->next_to_use = 0; |
| 4920 | } |
| 4921 | |
| 4922 | static void ixgbe_disable_fwd_ring(struct ixgbe_fwd_adapter *vadapter, |
| 4923 | struct ixgbe_ring *rx_ring) |
| 4924 | { |
| 4925 | struct ixgbe_adapter *adapter = vadapter->real_adapter; |
| 4926 | int index = rx_ring->queue_index + vadapter->rx_base_queue; |
| 4927 | |
| 4928 | /* shutdown specific queue receive and wait for dma to settle */ |
| 4929 | ixgbe_disable_rx_queue(adapter, rx_ring); |
| 4930 | usleep_range(10000, 20000); |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame^] | 4931 | ixgbe_irq_disable_queues(adapter, BIT_ULL(index)); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4932 | ixgbe_clean_rx_ring(rx_ring); |
| 4933 | rx_ring->l2_accel_priv = NULL; |
| 4934 | } |
| 4935 | |
John Fastabend | ae72c8d | 2013-11-09 07:11:26 +0000 | [diff] [blame] | 4936 | static int ixgbe_fwd_ring_down(struct net_device *vdev, |
| 4937 | struct ixgbe_fwd_adapter *accel) |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4938 | { |
| 4939 | struct ixgbe_adapter *adapter = accel->real_adapter; |
| 4940 | unsigned int rxbase = accel->rx_base_queue; |
| 4941 | unsigned int txbase = accel->tx_base_queue; |
| 4942 | int i; |
| 4943 | |
| 4944 | netif_tx_stop_all_queues(vdev); |
| 4945 | |
| 4946 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 4947 | ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]); |
| 4948 | adapter->rx_ring[rxbase + i]->netdev = adapter->netdev; |
| 4949 | } |
| 4950 | |
| 4951 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 4952 | adapter->tx_ring[txbase + i]->l2_accel_priv = NULL; |
| 4953 | adapter->tx_ring[txbase + i]->netdev = adapter->netdev; |
| 4954 | } |
| 4955 | |
| 4956 | |
| 4957 | return 0; |
| 4958 | } |
| 4959 | |
| 4960 | static int ixgbe_fwd_ring_up(struct net_device *vdev, |
| 4961 | struct ixgbe_fwd_adapter *accel) |
| 4962 | { |
| 4963 | struct ixgbe_adapter *adapter = accel->real_adapter; |
| 4964 | unsigned int rxbase, txbase, queues; |
| 4965 | int i, baseq, err = 0; |
| 4966 | |
| 4967 | if (!test_bit(accel->pool, &adapter->fwd_bitmask)) |
| 4968 | return 0; |
| 4969 | |
| 4970 | baseq = accel->pool * adapter->num_rx_queues_per_pool; |
| 4971 | netdev_dbg(vdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n", |
| 4972 | accel->pool, adapter->num_rx_pools, |
| 4973 | baseq, baseq + adapter->num_rx_queues_per_pool, |
| 4974 | adapter->fwd_bitmask); |
| 4975 | |
| 4976 | accel->netdev = vdev; |
| 4977 | accel->rx_base_queue = rxbase = baseq; |
| 4978 | accel->tx_base_queue = txbase = baseq; |
| 4979 | |
| 4980 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) |
| 4981 | ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]); |
| 4982 | |
| 4983 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 4984 | adapter->rx_ring[rxbase + i]->netdev = vdev; |
| 4985 | adapter->rx_ring[rxbase + i]->l2_accel_priv = accel; |
| 4986 | ixgbe_configure_rx_ring(adapter, adapter->rx_ring[rxbase + i]); |
| 4987 | } |
| 4988 | |
| 4989 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 4990 | adapter->tx_ring[txbase + i]->netdev = vdev; |
| 4991 | adapter->tx_ring[txbase + i]->l2_accel_priv = accel; |
| 4992 | } |
| 4993 | |
| 4994 | queues = min_t(unsigned int, |
| 4995 | adapter->num_rx_queues_per_pool, vdev->num_tx_queues); |
| 4996 | err = netif_set_real_num_tx_queues(vdev, queues); |
| 4997 | if (err) |
| 4998 | goto fwd_queue_err; |
| 4999 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5000 | err = netif_set_real_num_rx_queues(vdev, queues); |
| 5001 | if (err) |
| 5002 | goto fwd_queue_err; |
| 5003 | |
| 5004 | if (is_valid_ether_addr(vdev->dev_addr)) |
| 5005 | ixgbe_add_mac_filter(adapter, vdev->dev_addr, accel->pool); |
| 5006 | |
| 5007 | ixgbe_fwd_psrtype(accel); |
| 5008 | ixgbe_macvlan_set_rx_mode(vdev, accel->pool, adapter); |
| 5009 | return err; |
| 5010 | fwd_queue_err: |
| 5011 | ixgbe_fwd_ring_down(vdev, accel); |
| 5012 | return err; |
| 5013 | } |
| 5014 | |
| 5015 | static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter) |
| 5016 | { |
| 5017 | struct net_device *upper; |
| 5018 | struct list_head *iter; |
| 5019 | int err; |
| 5020 | |
| 5021 | netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) { |
| 5022 | if (netif_is_macvlan(upper)) { |
| 5023 | struct macvlan_dev *dfwd = netdev_priv(upper); |
| 5024 | struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv; |
| 5025 | |
| 5026 | if (dfwd->fwd_priv) { |
| 5027 | err = ixgbe_fwd_ring_up(upper, vadapter); |
| 5028 | if (err) |
| 5029 | continue; |
| 5030 | } |
| 5031 | } |
| 5032 | } |
| 5033 | } |
| 5034 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5035 | static void ixgbe_configure(struct ixgbe_adapter *adapter) |
| 5036 | { |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 5037 | struct ixgbe_hw *hw = &adapter->hw; |
| 5038 | |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 5039 | ixgbe_configure_pb(adapter); |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5040 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 5041 | ixgbe_configure_dcb(adapter); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5042 | #endif |
Alexander Duyck | b35d4d4 | 2012-05-23 05:39:25 +0000 | [diff] [blame] | 5043 | /* |
| 5044 | * We must restore virtualization before VLANs or else |
| 5045 | * the VLVF registers will not be populated |
| 5046 | */ |
| 5047 | ixgbe_configure_virtualization(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5048 | |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 5049 | ixgbe_set_rx_mode(adapter->netdev); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 5050 | ixgbe_restore_vlan(adapter); |
| 5051 | |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 5052 | switch (hw->mac.type) { |
| 5053 | case ixgbe_mac_82599EB: |
| 5054 | case ixgbe_mac_X540: |
| 5055 | hw->mac.ops.disable_rx_buff(hw); |
| 5056 | break; |
| 5057 | default: |
| 5058 | break; |
| 5059 | } |
| 5060 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5061 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 5062 | ixgbe_init_fdir_signature_82599(&adapter->hw, |
| 5063 | adapter->fdir_pballoc); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5064 | } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) { |
| 5065 | ixgbe_init_fdir_perfect_82599(&adapter->hw, |
| 5066 | adapter->fdir_pballoc); |
| 5067 | ixgbe_fdir_filter_restore(adapter); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5068 | } |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 5069 | |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 5070 | switch (hw->mac.type) { |
| 5071 | case ixgbe_mac_82599EB: |
| 5072 | case ixgbe_mac_X540: |
| 5073 | hw->mac.ops.enable_rx_buff(hw); |
| 5074 | break; |
| 5075 | default: |
| 5076 | break; |
| 5077 | } |
| 5078 | |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 5079 | #ifdef CONFIG_IXGBE_DCA |
| 5080 | /* configure DCA */ |
| 5081 | if (adapter->flags & IXGBE_FLAG_DCA_CAPABLE) |
| 5082 | ixgbe_setup_dca(adapter); |
| 5083 | #endif /* CONFIG_IXGBE_DCA */ |
| 5084 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 5085 | #ifdef IXGBE_FCOE |
| 5086 | /* configure FCoE L2 filters, redirection table, and Rx control */ |
| 5087 | ixgbe_configure_fcoe(adapter); |
| 5088 | |
| 5089 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5090 | ixgbe_configure_tx(adapter); |
| 5091 | ixgbe_configure_rx(adapter); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5092 | ixgbe_configure_dfwd(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5093 | } |
| 5094 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5095 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5096 | * ixgbe_sfp_link_config - set up SFP+ link |
| 5097 | * @adapter: pointer to private adapter struct |
| 5098 | **/ |
| 5099 | static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter) |
| 5100 | { |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5101 | /* |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 5102 | * We are assuming the worst case scenario here, and that |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5103 | * is that an SFP was inserted/removed after the reset |
| 5104 | * but before SFP detection was enabled. As such the best |
| 5105 | * solution is to just start searching as soon as we start |
| 5106 | */ |
| 5107 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 5108 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5109 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5110 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
Mark Rustad | 58e7cd2 | 2015-08-08 16:18:48 -0700 | [diff] [blame] | 5111 | adapter->sfp_poll_time = 0; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5112 | } |
| 5113 | |
| 5114 | /** |
| 5115 | * ixgbe_non_sfp_link_config - set up non-SFP+ link |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5116 | * @hw: pointer to private hardware struct |
| 5117 | * |
| 5118 | * Returns 0 on success, negative on failure |
| 5119 | **/ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5120 | 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] | 5121 | { |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 5122 | u32 speed; |
| 5123 | bool autoneg, link_up = false; |
Mark Rustad | a1e869d | 2015-04-10 10:36:36 -0700 | [diff] [blame] | 5124 | int ret = IXGBE_ERR_LINK_SETUP; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5125 | |
| 5126 | if (hw->mac.ops.check_link) |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 5127 | 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] | 5128 | |
| 5129 | if (ret) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 5130 | return ret; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5131 | |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 5132 | speed = hw->phy.autoneg_advertised; |
| 5133 | if ((!speed) && (hw->mac.ops.get_link_capabilities)) |
| 5134 | ret = hw->mac.ops.get_link_capabilities(hw, &speed, |
| 5135 | &autoneg); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5136 | if (ret) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 5137 | return ret; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5138 | |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 5139 | if (hw->mac.ops.setup_link) |
Josh Hay | fd0326f | 2012-12-15 03:28:30 +0000 | [diff] [blame] | 5140 | ret = hw->mac.ops.setup_link(hw, speed, link_up); |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 5141 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5142 | return ret; |
| 5143 | } |
| 5144 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5145 | static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5146 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5147 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5148 | u32 gpie = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5149 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 5150 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5151 | gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT | |
| 5152 | IXGBE_GPIE_OCD; |
| 5153 | gpie |= IXGBE_GPIE_EIAME; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 5154 | /* |
| 5155 | * use EIAM to auto-mask when MSI-X interrupt is asserted |
| 5156 | * this saves a register write for every interrupt |
| 5157 | */ |
| 5158 | switch (hw->mac.type) { |
| 5159 | case ixgbe_mac_82598EB: |
| 5160 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
| 5161 | break; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 5162 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5163 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5164 | case ixgbe_mac_X550: |
| 5165 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 5166 | case ixgbe_mac_x550em_a: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5167 | default: |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 5168 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF); |
| 5169 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF); |
| 5170 | break; |
| 5171 | } |
| 5172 | } else { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5173 | /* legacy interrupts, use EIAM to auto-mask when reading EICR, |
| 5174 | * specifically only auto mask tx and rx interrupts */ |
| 5175 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5176 | } |
| 5177 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5178 | /* XXX: to interrupt immediately for EICS writes, enable this */ |
| 5179 | /* gpie |= IXGBE_GPIE_EIMEN; */ |
| 5180 | |
| 5181 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 5182 | gpie &= ~IXGBE_GPIE_VTMODE_MASK; |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 5183 | |
| 5184 | switch (adapter->ring_feature[RING_F_VMDQ].mask) { |
| 5185 | case IXGBE_82599_VMDQ_8Q_MASK: |
| 5186 | gpie |= IXGBE_GPIE_VTMODE_16; |
| 5187 | break; |
| 5188 | case IXGBE_82599_VMDQ_4Q_MASK: |
| 5189 | gpie |= IXGBE_GPIE_VTMODE_32; |
| 5190 | break; |
| 5191 | default: |
| 5192 | gpie |= IXGBE_GPIE_VTMODE_64; |
| 5193 | break; |
| 5194 | } |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 5195 | } |
| 5196 | |
Alexander Duyck | 5fdd31f | 2011-07-21 00:40:45 +0000 | [diff] [blame] | 5197 | /* Enable Thermal over heat sensor interrupt */ |
Don Skidmore | f3df98e | 2011-08-17 10:15:21 +0000 | [diff] [blame] | 5198 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) { |
| 5199 | switch (adapter->hw.mac.type) { |
| 5200 | case ixgbe_mac_82599EB: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 5201 | gpie |= IXGBE_SDP0_GPIEN_8259X; |
Don Skidmore | f3df98e | 2011-08-17 10:15:21 +0000 | [diff] [blame] | 5202 | break; |
Don Skidmore | f3df98e | 2011-08-17 10:15:21 +0000 | [diff] [blame] | 5203 | default: |
| 5204 | break; |
| 5205 | } |
| 5206 | } |
Alexander Duyck | 5fdd31f | 2011-07-21 00:40:45 +0000 | [diff] [blame] | 5207 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5208 | /* Enable fan failure interrupt */ |
| 5209 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 5210 | gpie |= IXGBE_SDP1_GPIEN(hw); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 5211 | |
Don Skidmore | a023bbd | 2015-06-24 16:38:53 -0400 | [diff] [blame] | 5212 | switch (hw->mac.type) { |
| 5213 | case ixgbe_mac_82599EB: |
| 5214 | gpie |= IXGBE_SDP1_GPIEN_8259X | IXGBE_SDP2_GPIEN_8259X; |
| 5215 | break; |
| 5216 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 5217 | case ixgbe_mac_x550em_a: |
Don Skidmore | a023bbd | 2015-06-24 16:38:53 -0400 | [diff] [blame] | 5218 | gpie |= IXGBE_SDP0_GPIEN_X540; |
| 5219 | break; |
| 5220 | default: |
| 5221 | break; |
Don Skidmore | 2698b20 | 2011-04-13 07:01:52 +0000 | [diff] [blame] | 5222 | } |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5223 | |
| 5224 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 5225 | } |
| 5226 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 5227 | static void ixgbe_up_complete(struct ixgbe_adapter *adapter) |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5228 | { |
| 5229 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5230 | int err; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5231 | u32 ctrl_ext; |
| 5232 | |
| 5233 | ixgbe_get_hw_control(adapter); |
| 5234 | ixgbe_setup_gpie(adapter); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5235 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5236 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 5237 | ixgbe_configure_msix(adapter); |
| 5238 | else |
| 5239 | ixgbe_configure_msi_and_legacy(adapter); |
| 5240 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 5241 | /* enable the optics for 82599 SFP+ fiber */ |
| 5242 | if (hw->mac.ops.enable_tx_laser) |
Peter Waskiewicz | 61fac74 | 2010-04-27 00:38:15 +0000 | [diff] [blame] | 5243 | hw->mac.ops.enable_tx_laser(hw); |
| 5244 | |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 5245 | if (hw->phy.ops.set_phy_power) |
| 5246 | hw->phy.ops.set_phy_power(hw, true); |
| 5247 | |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 5248 | smp_mb__before_atomic(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5249 | clear_bit(__IXGBE_DOWN, &adapter->state); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5250 | ixgbe_napi_enable_all(adapter); |
| 5251 | |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 5252 | if (ixgbe_is_sfp(hw)) { |
| 5253 | ixgbe_sfp_link_config(adapter); |
| 5254 | } else { |
| 5255 | err = ixgbe_non_sfp_link_config(hw); |
| 5256 | if (err) |
| 5257 | e_err(probe, "link_config FAILED %d\n", err); |
| 5258 | } |
| 5259 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5260 | /* clear any pending interrupts, may auto mask */ |
| 5261 | IXGBE_READ_REG(hw, IXGBE_EICR); |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 5262 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5263 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5264 | /* |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5265 | * If this adapter has a fan, check to see if we had a failure |
| 5266 | * before we enabled the interrupt. |
| 5267 | */ |
| 5268 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 5269 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 5270 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5271 | e_crit(drv, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5272 | } |
| 5273 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5274 | /* bring the link up in the watchdog, this could race with our first |
| 5275 | * link up interrupt but shouldn't be a problem */ |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5276 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 5277 | adapter->link_check_timeout = jiffies; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5278 | mod_timer(&adapter->service_timer, jiffies); |
Greg Rose | c920569 | 2010-01-22 22:46:22 +0000 | [diff] [blame] | 5279 | |
| 5280 | /* Set PF Reset Done bit so PF/VF Mail Ops can work */ |
| 5281 | ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); |
| 5282 | ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD; |
| 5283 | IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5284 | } |
| 5285 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5286 | void ixgbe_reinit_locked(struct ixgbe_adapter *adapter) |
| 5287 | { |
| 5288 | WARN_ON(in_interrupt()); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5289 | /* put off any impending NetWatchDogTimeout */ |
| 5290 | adapter->netdev->trans_start = jiffies; |
| 5291 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5292 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 5293 | usleep_range(1000, 2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5294 | ixgbe_down(adapter); |
Greg Rose | 5809a1a | 2010-03-24 09:36:08 +0000 | [diff] [blame] | 5295 | /* |
| 5296 | * If SR-IOV enabled then wait a bit before bringing the adapter |
| 5297 | * back up to give the VFs time to respond to the reset. The |
| 5298 | * two second wait is based upon the watchdog timer cycle in |
| 5299 | * the VF driver. |
| 5300 | */ |
| 5301 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 5302 | msleep(2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5303 | ixgbe_up(adapter); |
| 5304 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
| 5305 | } |
| 5306 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 5307 | void ixgbe_up(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5308 | { |
| 5309 | /* hardware has been reset, we need to reload some things */ |
| 5310 | ixgbe_configure(adapter); |
| 5311 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 5312 | ixgbe_up_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5313 | } |
| 5314 | |
| 5315 | void ixgbe_reset(struct ixgbe_adapter *adapter) |
| 5316 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5317 | struct ixgbe_hw *hw = &adapter->hw; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 5318 | struct net_device *netdev = adapter->netdev; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 5319 | int err; |
| 5320 | |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 5321 | if (ixgbe_removed(hw->hw_addr)) |
| 5322 | return; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5323 | /* lock SFP init bit to prevent race conditions with the watchdog */ |
| 5324 | while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 5325 | usleep_range(1000, 2000); |
| 5326 | |
| 5327 | /* clear all SFP and link config related flags while holding SFP_INIT */ |
| 5328 | adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP | |
| 5329 | IXGBE_FLAG2_SFP_NEEDS_RESET); |
| 5330 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 5331 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 5332 | err = hw->mac.ops.init_hw(hw); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5333 | switch (err) { |
| 5334 | case 0: |
| 5335 | case IXGBE_ERR_SFP_NOT_PRESENT: |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5336 | case IXGBE_ERR_SFP_NOT_SUPPORTED: |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5337 | break; |
| 5338 | case IXGBE_ERR_MASTER_REQUESTS_PENDING: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5339 | e_dev_err("master disable timed out\n"); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5340 | break; |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 5341 | case IXGBE_ERR_EEPROM_VERSION: |
| 5342 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5343 | e_dev_warn("This device is a pre-production adapter/LOM. " |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 5344 | "Please be aware there may be issues associated with " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5345 | "your hardware. If you are experiencing problems " |
| 5346 | "please contact your Intel or hardware " |
| 5347 | "representative who provided you with this " |
| 5348 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 5349 | break; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5350 | default: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5351 | e_dev_err("Hardware Error: %d\n", err); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5352 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5353 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5354 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
Alexander Duyck | 0f079d2 | 2015-10-22 16:26:36 -0700 | [diff] [blame] | 5355 | |
| 5356 | /* flush entries out of MAC table */ |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 5357 | ixgbe_flush_sw_mac_table(adapter); |
Alexander Duyck | 0f079d2 | 2015-10-22 16:26:36 -0700 | [diff] [blame] | 5358 | __dev_uc_unsync(netdev, NULL); |
| 5359 | |
| 5360 | /* do not flush user set addresses */ |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 5361 | ixgbe_mac_set_default_filter(adapter); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 5362 | |
| 5363 | /* update SAN MAC vmdq pool selection */ |
| 5364 | if (hw->mac.san_mac_rar_index) |
| 5365 | hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0)); |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 5366 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 5367 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 5368 | ixgbe_ptp_reset(adapter); |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 5369 | |
| 5370 | if (hw->phy.ops.set_phy_power) { |
| 5371 | if (!netif_running(adapter->netdev) && !adapter->wol) |
| 5372 | hw->phy.ops.set_phy_power(hw, false); |
| 5373 | else |
| 5374 | hw->phy.ops.set_phy_power(hw, true); |
| 5375 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5376 | } |
| 5377 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5378 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5379 | * ixgbe_clean_tx_ring - Free Tx Buffers |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5380 | * @tx_ring: ring to be cleaned |
| 5381 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5382 | static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5383 | { |
| 5384 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 5385 | unsigned long size; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5386 | u16 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5387 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 5388 | /* ring already cleared, nothing to do */ |
| 5389 | if (!tx_ring->tx_buffer_info) |
| 5390 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5391 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 5392 | /* Free all the Tx ring sk_buffs */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5393 | for (i = 0; i < tx_ring->count; i++) { |
| 5394 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5395 | ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5396 | } |
| 5397 | |
John Fastabend | dad8a3b | 2012-04-23 12:22:39 +0000 | [diff] [blame] | 5398 | netdev_tx_reset_queue(txring_txq(tx_ring)); |
| 5399 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5400 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 5401 | memset(tx_ring->tx_buffer_info, 0, size); |
| 5402 | |
| 5403 | /* Zero out the descriptor ring */ |
| 5404 | memset(tx_ring->desc, 0, tx_ring->size); |
| 5405 | |
| 5406 | tx_ring->next_to_use = 0; |
| 5407 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5408 | } |
| 5409 | |
| 5410 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5411 | * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues |
| 5412 | * @adapter: board private structure |
| 5413 | **/ |
| 5414 | static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter) |
| 5415 | { |
| 5416 | int i; |
| 5417 | |
| 5418 | for (i = 0; i < adapter->num_rx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5419 | ixgbe_clean_rx_ring(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5420 | } |
| 5421 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5422 | /** |
| 5423 | * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues |
| 5424 | * @adapter: board private structure |
| 5425 | **/ |
| 5426 | static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter) |
| 5427 | { |
| 5428 | int i; |
| 5429 | |
| 5430 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5431 | ixgbe_clean_tx_ring(adapter->tx_ring[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5432 | } |
| 5433 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5434 | static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter) |
| 5435 | { |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 5436 | struct hlist_node *node2; |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5437 | struct ixgbe_fdir_filter *filter; |
| 5438 | |
| 5439 | spin_lock(&adapter->fdir_perfect_lock); |
| 5440 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 5441 | hlist_for_each_entry_safe(filter, node2, |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5442 | &adapter->fdir_filter_list, fdir_node) { |
| 5443 | hlist_del(&filter->fdir_node); |
| 5444 | kfree(filter); |
| 5445 | } |
| 5446 | adapter->fdir_filter_count = 0; |
| 5447 | |
| 5448 | spin_unlock(&adapter->fdir_perfect_lock); |
| 5449 | } |
| 5450 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5451 | void ixgbe_down(struct ixgbe_adapter *adapter) |
| 5452 | { |
| 5453 | struct net_device *netdev = adapter->netdev; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5454 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5455 | struct net_device *upper; |
| 5456 | struct list_head *iter; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 5457 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5458 | |
| 5459 | /* signal that we are down to the interrupt handler */ |
Mark Rustad | c3049c8 | 2014-01-14 18:53:12 -0800 | [diff] [blame] | 5460 | if (test_and_set_bit(__IXGBE_DOWN, &adapter->state)) |
| 5461 | return; /* do nothing if already down */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5462 | |
| 5463 | /* disable receives */ |
Don Skidmore | 1f9ac57 | 2015-03-13 13:54:30 -0700 | [diff] [blame] | 5464 | hw->mac.ops.disable_rx(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5465 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 5466 | /* disable all enabled rx queues */ |
| 5467 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 5468 | /* this call also flushes the previous write */ |
| 5469 | ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]); |
| 5470 | |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 5471 | usleep_range(10000, 20000); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5472 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5473 | netif_tx_stop_all_queues(netdev); |
| 5474 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5475 | /* call carrier off first to avoid false dev_watchdog timeouts */ |
John Fastabend | c0dfb90 | 2010-04-27 02:13:39 +0000 | [diff] [blame] | 5476 | netif_carrier_off(netdev); |
| 5477 | netif_tx_disable(netdev); |
| 5478 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5479 | /* disable any upper devices */ |
| 5480 | netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) { |
| 5481 | if (netif_is_macvlan(upper)) { |
| 5482 | struct macvlan_dev *vlan = netdev_priv(upper); |
| 5483 | |
| 5484 | if (vlan->fwd_priv) { |
| 5485 | netif_tx_stop_all_queues(upper); |
| 5486 | netif_carrier_off(upper); |
| 5487 | netif_tx_disable(upper); |
| 5488 | } |
| 5489 | } |
| 5490 | } |
| 5491 | |
John Fastabend | c0dfb90 | 2010-04-27 02:13:39 +0000 | [diff] [blame] | 5492 | ixgbe_irq_disable(adapter); |
| 5493 | |
| 5494 | ixgbe_napi_disable_all(adapter); |
| 5495 | |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 5496 | adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT | |
| 5497 | IXGBE_FLAG2_RESET_REQUESTED); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5498 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 5499 | |
| 5500 | del_timer_sync(&adapter->service_timer); |
| 5501 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 5502 | if (adapter->num_vfs) { |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 5503 | /* Clear EITR Select mapping */ |
| 5504 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0); |
| 5505 | |
| 5506 | /* Mark all the VFs as inactive */ |
| 5507 | for (i = 0 ; i < adapter->num_vfs; i++) |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 5508 | adapter->vfinfo[i].clear_to_send = false; |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 5509 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 5510 | /* 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] | 5511 | ixgbe_ping_all_vfs(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5512 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5513 | /* Disable all VFTE/VFRE TX/RX */ |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 5514 | ixgbe_disable_tx_rx(adapter); |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 5515 | } |
| 5516 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5517 | /* disable transmits in the hardware now that interrupts are off */ |
| 5518 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 5519 | u8 reg_idx = adapter->tx_ring[i]->reg_idx; |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 5520 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5521 | } |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 5522 | |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5523 | /* Disable the Tx DMA engine on 82599 and later MAC */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5524 | switch (hw->mac.type) { |
| 5525 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5526 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5527 | case ixgbe_mac_X550: |
| 5528 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 5529 | case ixgbe_mac_x550em_a: |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 5530 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 5531 | (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) & |
| 5532 | ~IXGBE_DMATXCTL_TE)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5533 | break; |
| 5534 | default: |
| 5535 | break; |
| 5536 | } |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5537 | |
Paul Larson | 6f4a0e4 | 2008-06-24 17:00:56 -0700 | [diff] [blame] | 5538 | if (!pci_channel_offline(adapter->pdev)) |
| 5539 | ixgbe_reset(adapter); |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 5540 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 5541 | /* power down the optics for 82599 SFP+ fiber */ |
| 5542 | if (hw->mac.ops.disable_tx_laser) |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 5543 | hw->mac.ops.disable_tx_laser(hw); |
| 5544 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5545 | ixgbe_clean_all_tx_rings(adapter); |
| 5546 | ixgbe_clean_all_rx_rings(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5547 | } |
| 5548 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5549 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5550 | * ixgbe_tx_timeout - Respond to a Tx Hang |
| 5551 | * @netdev: network interface device structure |
| 5552 | **/ |
| 5553 | static void ixgbe_tx_timeout(struct net_device *netdev) |
| 5554 | { |
| 5555 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5556 | |
| 5557 | /* Do the reset outside of interrupt context */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 5558 | ixgbe_tx_timeout_reset(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5559 | } |
| 5560 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 5561 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5562 | * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter) |
| 5563 | * @adapter: board private structure to initialize |
| 5564 | * |
| 5565 | * ixgbe_sw_init initializes the Adapter private data structure. |
| 5566 | * Fields are initialized based on PCI device information and |
| 5567 | * OS network device settings (MTU size). |
| 5568 | **/ |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 5569 | static int ixgbe_sw_init(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5570 | { |
| 5571 | struct ixgbe_hw *hw = &adapter->hw; |
| 5572 | struct pci_dev *pdev = adapter->pdev; |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 5573 | unsigned int rss, fdir; |
Jacob Keller | cb6d0f5 | 2012-12-04 06:03:14 +0000 | [diff] [blame] | 5574 | u32 fwsm; |
Don Skidmore | 4319a79 | 2016-04-12 19:25:10 -0400 | [diff] [blame] | 5575 | u16 device_caps; |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5576 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5577 | int j; |
| 5578 | struct tc_configuration *tc; |
| 5579 | #endif |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5580 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5581 | /* PCI config space info */ |
| 5582 | |
| 5583 | hw->vendor_id = pdev->vendor; |
| 5584 | hw->device_id = pdev->device; |
| 5585 | hw->revision_id = pdev->revision; |
| 5586 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 5587 | hw->subsystem_device_id = pdev->subsystem_device; |
| 5588 | |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5589 | /* Set common capability flags and settings */ |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 5590 | rss = min_t(int, ixgbe_max_rss_indices(adapter), num_online_cpus()); |
Alexander Duyck | c087663 | 2012-05-10 00:01:46 +0000 | [diff] [blame] | 5591 | adapter->ring_feature[RING_F_RSS].limit = rss; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5592 | adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5593 | adapter->max_q_vectors = MAX_Q_VECTORS_82599; |
| 5594 | adapter->atr_sample_rate = 20; |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 5595 | fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus()); |
| 5596 | adapter->ring_feature[RING_F_FDIR].limit = fdir; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5597 | adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K; |
| 5598 | #ifdef CONFIG_IXGBE_DCA |
| 5599 | adapter->flags |= IXGBE_FLAG_DCA_CAPABLE; |
| 5600 | #endif |
| 5601 | #ifdef IXGBE_FCOE |
| 5602 | adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE; |
| 5603 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 5604 | #ifdef CONFIG_IXGBE_DCB |
| 5605 | /* Default traffic class to use for FCoE */ |
| 5606 | adapter->fcoe.up = IXGBE_FCOE_DEFTC; |
| 5607 | #endif /* CONFIG_IXGBE_DCB */ |
| 5608 | #endif /* IXGBE_FCOE */ |
| 5609 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 5610 | /* initialize static ixgbe jump table entries */ |
| 5611 | adapter->jump_tables[0] = ixgbe_ipv4_fields; |
| 5612 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 5613 | adapter->mac_table = kzalloc(sizeof(struct ixgbe_mac_addr) * |
| 5614 | hw->mac.num_rar_entries, |
| 5615 | GFP_ATOMIC); |
Alexander Duyck | 530fd82 | 2015-11-02 17:09:29 -0800 | [diff] [blame] | 5616 | if (!adapter->mac_table) |
| 5617 | return -ENOMEM; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 5618 | |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5619 | /* Set MAC specific capability flags and exceptions */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5620 | switch (hw->mac.type) { |
| 5621 | case ixgbe_mac_82598EB: |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5622 | adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5623 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5624 | if (hw->device_id == IXGBE_DEV_ID_82598AT) |
| 5625 | adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5626 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 5627 | adapter->max_q_vectors = MAX_Q_VECTORS_82598; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 5628 | adapter->ring_feature[RING_F_FDIR].limit = 0; |
| 5629 | adapter->atr_sample_rate = 0; |
| 5630 | adapter->fdir_pballoc = 0; |
| 5631 | #ifdef IXGBE_FCOE |
| 5632 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
| 5633 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 5634 | #ifdef CONFIG_IXGBE_DCB |
| 5635 | adapter->fcoe.up = 0; |
| 5636 | #endif /* IXGBE_DCB */ |
| 5637 | #endif /* IXGBE_FCOE */ |
| 5638 | break; |
| 5639 | case ixgbe_mac_82599EB: |
| 5640 | if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM) |
| 5641 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5642 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5643 | case ixgbe_mac_X540: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 5644 | fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw)); |
Jacob Keller | cb6d0f5 | 2012-12-04 06:03:14 +0000 | [diff] [blame] | 5645 | if (fwsm & IXGBE_FWSM_TS_ENABLED) |
| 5646 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5647 | break; |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5648 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 5649 | case ixgbe_mac_x550em_a: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5650 | case ixgbe_mac_X550: |
| 5651 | #ifdef CONFIG_IXGBE_DCA |
| 5652 | adapter->flags &= ~IXGBE_FLAG_DCA_CAPABLE; |
| 5653 | #endif |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 5654 | #ifdef CONFIG_IXGBE_VXLAN |
| 5655 | adapter->flags |= IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE; |
| 5656 | #endif |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5657 | break; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5658 | default: |
| 5659 | break; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5660 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5661 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 5662 | #ifdef IXGBE_FCOE |
| 5663 | /* FCoE support exists, always init the FCoE lock */ |
| 5664 | spin_lock_init(&adapter->fcoe.lock); |
| 5665 | |
| 5666 | #endif |
Alexander Duyck | 1fc5f03 | 2011-06-02 04:28:39 +0000 | [diff] [blame] | 5667 | /* n-tuple support exists, always init our spinlock */ |
| 5668 | spin_lock_init(&adapter->fdir_perfect_lock); |
| 5669 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5670 | #ifdef CONFIG_IXGBE_DCB |
John Fastabend | 4de2a02 | 2011-09-27 03:52:01 +0000 | [diff] [blame] | 5671 | switch (hw->mac.type) { |
| 5672 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5673 | case ixgbe_mac_X550: |
| 5674 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 5675 | case ixgbe_mac_x550em_a: |
John Fastabend | 4de2a02 | 2011-09-27 03:52:01 +0000 | [diff] [blame] | 5676 | adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS; |
| 5677 | adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS; |
| 5678 | break; |
| 5679 | default: |
| 5680 | adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS; |
| 5681 | adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS; |
| 5682 | break; |
| 5683 | } |
| 5684 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5685 | /* Configure DCB traffic classes */ |
| 5686 | for (j = 0; j < MAX_TRAFFIC_CLASS; j++) { |
| 5687 | tc = &adapter->dcb_cfg.tc_config[j]; |
| 5688 | tc->path[DCB_TX_CONFIG].bwg_id = 0; |
| 5689 | tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1); |
| 5690 | tc->path[DCB_RX_CONFIG].bwg_id = 0; |
| 5691 | tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1); |
| 5692 | tc->dcb_pfc = pfc_disabled; |
| 5693 | } |
John Fastabend | 4de2a02 | 2011-09-27 03:52:01 +0000 | [diff] [blame] | 5694 | |
| 5695 | /* Initialize default user to priority mapping, UPx->TC0 */ |
| 5696 | tc = &adapter->dcb_cfg.tc_config[0]; |
| 5697 | tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF; |
| 5698 | tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF; |
| 5699 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5700 | adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100; |
| 5701 | adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100; |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 5702 | adapter->dcb_cfg.pfc_mode_enable = false; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5703 | adapter->dcb_set_bitmap = 0x00; |
John Fastabend | 3032309 | 2011-03-01 05:25:35 +0000 | [diff] [blame] | 5704 | adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE; |
John Fastabend | f525c6d2 | 2012-04-18 22:42:27 +0000 | [diff] [blame] | 5705 | memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg, |
| 5706 | sizeof(adapter->temp_dcb_cfg)); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5707 | |
| 5708 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5709 | |
| 5710 | /* default flow control settings */ |
Don Skidmore | cd7664f | 2009-03-31 21:33:44 +0000 | [diff] [blame] | 5711 | hw->fc.requested_mode = ixgbe_fc_full; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 5712 | hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */ |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5713 | ixgbe_pbthresh_setup(adapter); |
Jesse Brandeburg | 2b9ade9 | 2008-08-26 04:27:10 -0700 | [diff] [blame] | 5714 | hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE; |
| 5715 | hw->fc.send_xon = true; |
Don Skidmore | 73d80953d | 2013-07-31 02:19:24 +0000 | [diff] [blame] | 5716 | hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5717 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 5718 | #ifdef CONFIG_PCI_IOV |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 5719 | if (max_vfs > 0) |
| 5720 | 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] | 5721 | |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 5722 | /* assign number of SR-IOV VFs */ |
| 5723 | if (hw->mac.type != ixgbe_mac_82598EB) { |
ethan.zhao | dcc23e3 | 2014-01-16 19:41:04 -0800 | [diff] [blame] | 5724 | if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) { |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 5725 | adapter->num_vfs = 0; |
| 5726 | e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n"); |
| 5727 | } else { |
| 5728 | adapter->num_vfs = max_vfs; |
| 5729 | } |
| 5730 | } |
| 5731 | #endif /* CONFIG_PCI_IOV */ |
| 5732 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5733 | /* enable itr by default in dynamic mode */ |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 5734 | adapter->rx_itr_setting = 1; |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 5735 | adapter->tx_itr_setting = 1; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5736 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5737 | /* set default ring sizes */ |
| 5738 | adapter->tx_ring_count = IXGBE_DEFAULT_TXD; |
| 5739 | adapter->rx_ring_count = IXGBE_DEFAULT_RXD; |
| 5740 | |
Don Skidmore | 4319a79 | 2016-04-12 19:25:10 -0400 | [diff] [blame] | 5741 | /* Cache bit indicating need for crosstalk fix */ |
| 5742 | switch (hw->mac.type) { |
| 5743 | case ixgbe_mac_82599EB: |
| 5744 | case ixgbe_mac_X550EM_x: |
| 5745 | case ixgbe_mac_x550em_a: |
| 5746 | hw->mac.ops.get_device_caps(hw, &device_caps); |
| 5747 | if (device_caps & IXGBE_DEVICE_CAPS_NO_CROSSTALK_WR) |
| 5748 | adapter->need_crosstalk_fix = false; |
| 5749 | else |
| 5750 | adapter->need_crosstalk_fix = true; |
| 5751 | break; |
| 5752 | default: |
| 5753 | adapter->need_crosstalk_fix = false; |
| 5754 | break; |
| 5755 | } |
| 5756 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 5757 | /* set default work limits */ |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 5758 | adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 5759 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5760 | /* initialize eeprom parameters */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5761 | if (ixgbe_init_eeprom_params_generic(hw)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5762 | e_dev_err("EEPROM initialization failed\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5763 | return -EIO; |
| 5764 | } |
| 5765 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5766 | /* PF holds first pool slot */ |
| 5767 | set_bit(0, &adapter->fwd_bitmask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5768 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 5769 | |
| 5770 | return 0; |
| 5771 | } |
| 5772 | |
| 5773 | /** |
| 5774 | * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5775 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5776 | * |
| 5777 | * Return 0 on success, negative on failure |
| 5778 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5779 | int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5780 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5781 | struct device *dev = tx_ring->dev; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5782 | int orig_node = dev_to_node(dev); |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5783 | int ring_node = -1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5784 | int size; |
| 5785 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5786 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5787 | |
| 5788 | if (tx_ring->q_vector) |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5789 | ring_node = tx_ring->q_vector->numa_node; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5790 | |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5791 | tx_ring->tx_buffer_info = vzalloc_node(size, ring_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5792 | if (!tx_ring->tx_buffer_info) |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5793 | tx_ring->tx_buffer_info = vzalloc(size); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5794 | if (!tx_ring->tx_buffer_info) |
| 5795 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5796 | |
John Stultz | 827da44 | 2013-10-07 15:51:58 -0700 | [diff] [blame] | 5797 | u64_stats_init(&tx_ring->syncp); |
| 5798 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5799 | /* round up to nearest 4K */ |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 5800 | tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5801 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5802 | |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5803 | set_dev_node(dev, ring_node); |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5804 | tx_ring->desc = dma_alloc_coherent(dev, |
| 5805 | tx_ring->size, |
| 5806 | &tx_ring->dma, |
| 5807 | GFP_KERNEL); |
| 5808 | set_dev_node(dev, orig_node); |
| 5809 | if (!tx_ring->desc) |
| 5810 | tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size, |
| 5811 | &tx_ring->dma, GFP_KERNEL); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5812 | if (!tx_ring->desc) |
| 5813 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5814 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5815 | tx_ring->next_to_use = 0; |
| 5816 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5817 | return 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5818 | |
| 5819 | err: |
| 5820 | vfree(tx_ring->tx_buffer_info); |
| 5821 | tx_ring->tx_buffer_info = NULL; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5822 | 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] | 5823 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5824 | } |
| 5825 | |
| 5826 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5827 | * ixgbe_setup_all_tx_resources - allocate all queues Tx resources |
| 5828 | * @adapter: board private structure |
| 5829 | * |
| 5830 | * If this function returns with an error, then it's possible one or |
| 5831 | * more of the rings is populated (while the rest are not). It is the |
| 5832 | * callers duty to clean those orphaned rings. |
| 5833 | * |
| 5834 | * Return 0 on success, negative on failure |
| 5835 | **/ |
| 5836 | static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) |
| 5837 | { |
| 5838 | int i, err = 0; |
| 5839 | |
| 5840 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5841 | err = ixgbe_setup_tx_resources(adapter->tx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5842 | if (!err) |
| 5843 | continue; |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5844 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5845 | e_err(probe, "Allocation for Tx Queue %u failed\n", i); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5846 | goto err_setup_tx; |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5847 | } |
| 5848 | |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5849 | return 0; |
| 5850 | err_setup_tx: |
| 5851 | /* rewind the index freeing the rings as we go */ |
| 5852 | while (i--) |
| 5853 | ixgbe_free_tx_resources(adapter->tx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5854 | return err; |
| 5855 | } |
| 5856 | |
| 5857 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5858 | * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5859 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5860 | * |
| 5861 | * Returns 0 on success, negative on failure |
| 5862 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5863 | int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5864 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5865 | struct device *dev = rx_ring->dev; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5866 | int orig_node = dev_to_node(dev); |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5867 | int ring_node = -1; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5868 | int size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5869 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5870 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5871 | |
| 5872 | if (rx_ring->q_vector) |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5873 | ring_node = rx_ring->q_vector->numa_node; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5874 | |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5875 | rx_ring->rx_buffer_info = vzalloc_node(size, ring_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5876 | if (!rx_ring->rx_buffer_info) |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5877 | rx_ring->rx_buffer_info = vzalloc(size); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5878 | if (!rx_ring->rx_buffer_info) |
| 5879 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5880 | |
John Stultz | 827da44 | 2013-10-07 15:51:58 -0700 | [diff] [blame] | 5881 | u64_stats_init(&rx_ring->syncp); |
| 5882 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5883 | /* Round up to nearest 4K */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5884 | rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); |
| 5885 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5886 | |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 5887 | set_dev_node(dev, ring_node); |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5888 | rx_ring->desc = dma_alloc_coherent(dev, |
| 5889 | rx_ring->size, |
| 5890 | &rx_ring->dma, |
| 5891 | GFP_KERNEL); |
| 5892 | set_dev_node(dev, orig_node); |
| 5893 | if (!rx_ring->desc) |
| 5894 | rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size, |
| 5895 | &rx_ring->dma, GFP_KERNEL); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5896 | if (!rx_ring->desc) |
| 5897 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5898 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5899 | rx_ring->next_to_clean = 0; |
| 5900 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5901 | |
| 5902 | return 0; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5903 | err: |
| 5904 | vfree(rx_ring->rx_buffer_info); |
| 5905 | rx_ring->rx_buffer_info = NULL; |
| 5906 | 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] | 5907 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5908 | } |
| 5909 | |
| 5910 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5911 | * ixgbe_setup_all_rx_resources - allocate all queues Rx resources |
| 5912 | * @adapter: board private structure |
| 5913 | * |
| 5914 | * If this function returns with an error, then it's possible one or |
| 5915 | * more of the rings is populated (while the rest are not). It is the |
| 5916 | * callers duty to clean those orphaned rings. |
| 5917 | * |
| 5918 | * Return 0 on success, negative on failure |
| 5919 | **/ |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5920 | static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) |
| 5921 | { |
| 5922 | int i, err = 0; |
| 5923 | |
| 5924 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5925 | err = ixgbe_setup_rx_resources(adapter->rx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5926 | if (!err) |
| 5927 | continue; |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5928 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5929 | e_err(probe, "Allocation for Rx Queue %u failed\n", i); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5930 | goto err_setup_rx; |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5931 | } |
| 5932 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 5933 | #ifdef IXGBE_FCOE |
| 5934 | err = ixgbe_setup_fcoe_ddp_resources(adapter); |
| 5935 | if (!err) |
| 5936 | #endif |
| 5937 | return 0; |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5938 | err_setup_rx: |
| 5939 | /* rewind the index freeing the rings as we go */ |
| 5940 | while (i--) |
| 5941 | ixgbe_free_rx_resources(adapter->rx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5942 | return err; |
| 5943 | } |
| 5944 | |
| 5945 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5946 | * ixgbe_free_tx_resources - Free Tx Resources per Queue |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5947 | * @tx_ring: Tx descriptor ring for a specific queue |
| 5948 | * |
| 5949 | * Free all transmit software resources |
| 5950 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5951 | void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5952 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5953 | ixgbe_clean_tx_ring(tx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5954 | |
| 5955 | vfree(tx_ring->tx_buffer_info); |
| 5956 | tx_ring->tx_buffer_info = NULL; |
| 5957 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5958 | /* if not set, then don't free */ |
| 5959 | if (!tx_ring->desc) |
| 5960 | return; |
| 5961 | |
| 5962 | dma_free_coherent(tx_ring->dev, tx_ring->size, |
| 5963 | tx_ring->desc, tx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5964 | |
| 5965 | tx_ring->desc = NULL; |
| 5966 | } |
| 5967 | |
| 5968 | /** |
| 5969 | * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues |
| 5970 | * @adapter: board private structure |
| 5971 | * |
| 5972 | * Free all transmit software resources |
| 5973 | **/ |
| 5974 | static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter) |
| 5975 | { |
| 5976 | int i; |
| 5977 | |
| 5978 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5979 | if (adapter->tx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5980 | ixgbe_free_tx_resources(adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5981 | } |
| 5982 | |
| 5983 | /** |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5984 | * ixgbe_free_rx_resources - Free Rx Resources |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5985 | * @rx_ring: ring to clean the resources from |
| 5986 | * |
| 5987 | * Free all receive software resources |
| 5988 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5989 | void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5990 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5991 | ixgbe_clean_rx_ring(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5992 | |
| 5993 | vfree(rx_ring->rx_buffer_info); |
| 5994 | rx_ring->rx_buffer_info = NULL; |
| 5995 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5996 | /* if not set, then don't free */ |
| 5997 | if (!rx_ring->desc) |
| 5998 | return; |
| 5999 | |
| 6000 | dma_free_coherent(rx_ring->dev, rx_ring->size, |
| 6001 | rx_ring->desc, rx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6002 | |
| 6003 | rx_ring->desc = NULL; |
| 6004 | } |
| 6005 | |
| 6006 | /** |
| 6007 | * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues |
| 6008 | * @adapter: board private structure |
| 6009 | * |
| 6010 | * Free all receive software resources |
| 6011 | **/ |
| 6012 | static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter) |
| 6013 | { |
| 6014 | int i; |
| 6015 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 6016 | #ifdef IXGBE_FCOE |
| 6017 | ixgbe_free_fcoe_ddp_resources(adapter); |
| 6018 | |
| 6019 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6020 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 6021 | if (adapter->rx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6022 | ixgbe_free_rx_resources(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6023 | } |
| 6024 | |
| 6025 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6026 | * ixgbe_change_mtu - Change the Maximum Transfer Unit |
| 6027 | * @netdev: network interface device structure |
| 6028 | * @new_mtu: new value for maximum frame size |
| 6029 | * |
| 6030 | * Returns 0 on success, negative on failure |
| 6031 | **/ |
| 6032 | static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu) |
| 6033 | { |
| 6034 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 6035 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 6036 | |
Jesse Brandeburg | 42c783c | 2008-09-11 19:56:28 -0700 | [diff] [blame] | 6037 | /* MTU < 68 is an error and causes problems on some kernels */ |
Alexander Duyck | 655309e | 2012-02-08 07:50:35 +0000 | [diff] [blame] | 6038 | if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) |
| 6039 | return -EINVAL; |
| 6040 | |
| 6041 | /* |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 6042 | * For 82599EB we cannot allow legacy VFs to enable their receive |
| 6043 | * paths when MTU greater than 1500 is configured. So display a |
| 6044 | * warning that legacy VFs will be disabled. |
Alexander Duyck | 655309e | 2012-02-08 07:50:35 +0000 | [diff] [blame] | 6045 | */ |
| 6046 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && |
| 6047 | (adapter->hw.mac.type == ixgbe_mac_82599EB) && |
Alexander Duyck | c560451 | 2013-01-09 08:50:42 +0000 | [diff] [blame] | 6048 | (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN))) |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 6049 | e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6050 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 6051 | 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] | 6052 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6053 | /* must set new MTU before calling down or up */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6054 | netdev->mtu = new_mtu; |
| 6055 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 6056 | if (netif_running(netdev)) |
| 6057 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6058 | |
| 6059 | return 0; |
| 6060 | } |
| 6061 | |
| 6062 | /** |
| 6063 | * ixgbe_open - Called when a network interface is made active |
| 6064 | * @netdev: network interface device structure |
| 6065 | * |
| 6066 | * Returns 0 on success, negative value on failure |
| 6067 | * |
| 6068 | * The open entry point is called when a network interface is made |
| 6069 | * active by the system (IFF_UP). At this point all resources needed |
| 6070 | * for transmit and receive operations are allocated, the interrupt |
| 6071 | * handler is registered with the OS, the watchdog timer is started, |
| 6072 | * and the stack is notified that the interface is ready. |
| 6073 | **/ |
Stefan Assmann | 6c211fe1 | 2016-02-03 09:20:48 +0100 | [diff] [blame] | 6074 | int ixgbe_open(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6075 | { |
| 6076 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 6077 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 6078 | int err, queues; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6079 | |
Auke Kok | 4bebfaa | 2008-02-11 09:26:01 -0800 | [diff] [blame] | 6080 | /* disallow open during test */ |
| 6081 | if (test_bit(__IXGBE_TESTING, &adapter->state)) |
| 6082 | return -EBUSY; |
| 6083 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 6084 | netif_carrier_off(netdev); |
| 6085 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6086 | /* allocate transmit descriptors */ |
| 6087 | err = ixgbe_setup_all_tx_resources(adapter); |
| 6088 | if (err) |
| 6089 | goto err_setup_tx; |
| 6090 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6091 | /* allocate receive descriptors */ |
| 6092 | err = ixgbe_setup_all_rx_resources(adapter); |
| 6093 | if (err) |
| 6094 | goto err_setup_rx; |
| 6095 | |
| 6096 | ixgbe_configure(adapter); |
| 6097 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6098 | err = ixgbe_request_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6099 | if (err) |
| 6100 | goto err_req_irq; |
| 6101 | |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6102 | /* Notify the stack of the actual queue counts. */ |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 6103 | if (adapter->num_rx_pools > 1) |
| 6104 | queues = adapter->num_rx_queues_per_pool; |
| 6105 | else |
| 6106 | queues = adapter->num_tx_queues; |
| 6107 | |
| 6108 | err = netif_set_real_num_tx_queues(netdev, queues); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6109 | if (err) |
| 6110 | goto err_set_queues; |
| 6111 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 6112 | if (adapter->num_rx_pools > 1 && |
| 6113 | adapter->num_rx_queues > IXGBE_MAX_L2A_QUEUES) |
| 6114 | queues = IXGBE_MAX_L2A_QUEUES; |
| 6115 | else |
| 6116 | queues = adapter->num_rx_queues; |
| 6117 | err = netif_set_real_num_rx_queues(netdev, queues); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6118 | if (err) |
| 6119 | goto err_set_queues; |
| 6120 | |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6121 | ixgbe_ptp_init(adapter); |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6122 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 6123 | ixgbe_up_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6124 | |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 6125 | ixgbe_clear_vxlan_port(adapter); |
| 6126 | #ifdef CONFIG_IXGBE_VXLAN |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 6127 | vxlan_get_rx_port(netdev); |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 6128 | #endif |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 6129 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6130 | return 0; |
| 6131 | |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6132 | err_set_queues: |
| 6133 | ixgbe_free_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6134 | err_req_irq: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 6135 | ixgbe_free_all_rx_resources(adapter); |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 6136 | if (hw->phy.ops.set_phy_power && !adapter->wol) |
| 6137 | hw->phy.ops.set_phy_power(&adapter->hw, false); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6138 | err_setup_rx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 6139 | ixgbe_free_all_tx_resources(adapter); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6140 | err_setup_tx: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6141 | ixgbe_reset(adapter); |
| 6142 | |
| 6143 | return err; |
| 6144 | } |
| 6145 | |
Jacob Keller | a0cccce | 2014-05-16 05:12:29 +0000 | [diff] [blame] | 6146 | static void ixgbe_close_suspend(struct ixgbe_adapter *adapter) |
| 6147 | { |
| 6148 | ixgbe_ptp_suspend(adapter); |
| 6149 | |
Don Skidmore | 6ac7439 | 2015-06-17 17:34:31 -0400 | [diff] [blame] | 6150 | if (adapter->hw.phy.ops.enter_lplu) { |
| 6151 | adapter->hw.phy.reset_disable = true; |
| 6152 | ixgbe_down(adapter); |
| 6153 | adapter->hw.phy.ops.enter_lplu(&adapter->hw); |
| 6154 | adapter->hw.phy.reset_disable = false; |
| 6155 | } else { |
| 6156 | ixgbe_down(adapter); |
| 6157 | } |
| 6158 | |
Jacob Keller | a0cccce | 2014-05-16 05:12:29 +0000 | [diff] [blame] | 6159 | ixgbe_free_irq(adapter); |
| 6160 | |
| 6161 | ixgbe_free_all_tx_resources(adapter); |
| 6162 | ixgbe_free_all_rx_resources(adapter); |
| 6163 | } |
| 6164 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6165 | /** |
| 6166 | * ixgbe_close - Disables a network interface |
| 6167 | * @netdev: network interface device structure |
| 6168 | * |
| 6169 | * Returns 0, this is not allowed to fail |
| 6170 | * |
| 6171 | * The close entry point is called when an interface is de-activated |
| 6172 | * by the OS. The hardware is still under the drivers control, but |
| 6173 | * needs to be disabled. A global MAC reset is issued to stop the |
| 6174 | * hardware, and all transmit and receive resources are freed. |
| 6175 | **/ |
Stefan Assmann | 6c211fe1 | 2016-02-03 09:20:48 +0100 | [diff] [blame] | 6176 | int ixgbe_close(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6177 | { |
| 6178 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6179 | |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6180 | ixgbe_ptp_stop(adapter); |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6181 | |
Jacob Keller | a0cccce | 2014-05-16 05:12:29 +0000 | [diff] [blame] | 6182 | ixgbe_close_suspend(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6183 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 6184 | ixgbe_fdir_filter_exit(adapter); |
| 6185 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 6186 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6187 | |
| 6188 | return 0; |
| 6189 | } |
| 6190 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6191 | #ifdef CONFIG_PM |
| 6192 | static int ixgbe_resume(struct pci_dev *pdev) |
| 6193 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 6194 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 6195 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6196 | u32 err; |
| 6197 | |
Mark Rustad | 0391bbe | 2014-02-28 15:48:55 -0800 | [diff] [blame] | 6198 | adapter->hw.hw_addr = adapter->io_addr; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6199 | pci_set_power_state(pdev, PCI_D0); |
| 6200 | pci_restore_state(pdev); |
Don Skidmore | 656ab81 | 2009-12-23 21:19:19 -0800 | [diff] [blame] | 6201 | /* |
| 6202 | * pci_restore_state clears dev->state_saved so call |
| 6203 | * pci_save_state to restore it. |
| 6204 | */ |
| 6205 | pci_save_state(pdev); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 6206 | |
| 6207 | err = pci_enable_device_mem(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6208 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 6209 | e_dev_err("Cannot enable PCI device from suspend\n"); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6210 | return err; |
| 6211 | } |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 6212 | smp_mb__before_atomic(); |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 6213 | clear_bit(__IXGBE_DISABLED, &adapter->state); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6214 | pci_set_master(pdev); |
| 6215 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 6216 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6217 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6218 | ixgbe_reset(adapter); |
| 6219 | |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 6220 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
| 6221 | |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6222 | rtnl_lock(); |
| 6223 | err = ixgbe_init_interrupt_scheme(adapter); |
| 6224 | if (!err && netif_running(netdev)) |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 6225 | err = ixgbe_open(netdev); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6226 | |
| 6227 | rtnl_unlock(); |
| 6228 | |
| 6229 | if (err) |
| 6230 | return err; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6231 | |
| 6232 | netif_device_attach(netdev); |
| 6233 | |
| 6234 | return 0; |
| 6235 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6236 | #endif /* CONFIG_PM */ |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6237 | |
| 6238 | static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6239 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 6240 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 6241 | struct net_device *netdev = adapter->netdev; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6242 | struct ixgbe_hw *hw = &adapter->hw; |
| 6243 | u32 ctrl, fctrl; |
| 6244 | u32 wufc = adapter->wol; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6245 | #ifdef CONFIG_PM |
| 6246 | int retval = 0; |
| 6247 | #endif |
| 6248 | |
| 6249 | netif_device_detach(netdev); |
| 6250 | |
akepner | 499ab5c | 2013-03-13 14:54:58 +0000 | [diff] [blame] | 6251 | rtnl_lock(); |
Jacob Keller | a0cccce | 2014-05-16 05:12:29 +0000 | [diff] [blame] | 6252 | if (netif_running(netdev)) |
| 6253 | ixgbe_close_suspend(adapter); |
akepner | 499ab5c | 2013-03-13 14:54:58 +0000 | [diff] [blame] | 6254 | rtnl_unlock(); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6255 | |
Alexander Duyck | 5f5ae6f | 2010-11-16 19:26:52 -0800 | [diff] [blame] | 6256 | ixgbe_clear_interrupt_scheme(adapter); |
| 6257 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6258 | #ifdef CONFIG_PM |
| 6259 | retval = pci_save_state(pdev); |
| 6260 | if (retval) |
| 6261 | return retval; |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 6262 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6263 | #endif |
Jacob Keller | f4f1040 | 2013-06-25 07:59:23 +0000 | [diff] [blame] | 6264 | if (hw->mac.ops.stop_link_on_d3) |
| 6265 | hw->mac.ops.stop_link_on_d3(hw); |
| 6266 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6267 | if (wufc) { |
| 6268 | ixgbe_set_rx_mode(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6269 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 6270 | /* enable the optics for 82599 SFP+ fiber as we can WoL */ |
| 6271 | if (hw->mac.ops.enable_tx_laser) |
Don Skidmore | c509e75 | 2012-04-05 08:12:05 +0000 | [diff] [blame] | 6272 | hw->mac.ops.enable_tx_laser(hw); |
| 6273 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6274 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 6275 | if (wufc & IXGBE_WUFC_MC) { |
| 6276 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 6277 | fctrl |= IXGBE_FCTRL_MPE; |
| 6278 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
| 6279 | } |
| 6280 | |
| 6281 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 6282 | ctrl |= IXGBE_CTRL_GIO_DIS; |
| 6283 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); |
| 6284 | |
| 6285 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc); |
| 6286 | } else { |
| 6287 | IXGBE_WRITE_REG(hw, IXGBE_WUC, 0); |
| 6288 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0); |
| 6289 | } |
| 6290 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6291 | switch (hw->mac.type) { |
| 6292 | case ixgbe_mac_82598EB: |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 6293 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6294 | break; |
| 6295 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 6296 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6297 | case ixgbe_mac_X550: |
| 6298 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 6299 | case ixgbe_mac_x550em_a: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6300 | pci_wake_from_d3(pdev, !!wufc); |
| 6301 | break; |
| 6302 | default: |
| 6303 | break; |
| 6304 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6305 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6306 | *enable_wake = !!wufc; |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 6307 | if (hw->phy.ops.set_phy_power && !*enable_wake) |
| 6308 | hw->phy.ops.set_phy_power(hw, false); |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6309 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6310 | ixgbe_release_hw_control(adapter); |
| 6311 | |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 6312 | if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state)) |
| 6313 | pci_disable_device(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6314 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6315 | return 0; |
| 6316 | } |
| 6317 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6318 | #ifdef CONFIG_PM |
| 6319 | static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state) |
| 6320 | { |
| 6321 | int retval; |
| 6322 | bool wake; |
| 6323 | |
| 6324 | retval = __ixgbe_shutdown(pdev, &wake); |
| 6325 | if (retval) |
| 6326 | return retval; |
| 6327 | |
| 6328 | if (wake) { |
| 6329 | pci_prepare_to_sleep(pdev); |
| 6330 | } else { |
| 6331 | pci_wake_from_d3(pdev, false); |
| 6332 | pci_set_power_state(pdev, PCI_D3hot); |
| 6333 | } |
| 6334 | |
| 6335 | return 0; |
| 6336 | } |
| 6337 | #endif /* CONFIG_PM */ |
| 6338 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6339 | static void ixgbe_shutdown(struct pci_dev *pdev) |
| 6340 | { |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6341 | bool wake; |
| 6342 | |
| 6343 | __ixgbe_shutdown(pdev, &wake); |
| 6344 | |
| 6345 | if (system_state == SYSTEM_POWER_OFF) { |
| 6346 | pci_wake_from_d3(pdev, wake); |
| 6347 | pci_set_power_state(pdev, PCI_D3hot); |
| 6348 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6349 | } |
| 6350 | |
| 6351 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6352 | * ixgbe_update_stats - Update the board statistics counters. |
| 6353 | * @adapter: board private structure |
| 6354 | **/ |
| 6355 | void ixgbe_update_stats(struct ixgbe_adapter *adapter) |
| 6356 | { |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 6357 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6358 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6359 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6360 | u64 total_mpc = 0; |
| 6361 | u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6362 | u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0; |
| 6363 | u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 6364 | u64 bytes = 0, packets = 0, hw_csum_rx_error = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6365 | |
Don Skidmore | d08935c | 2010-06-11 13:20:29 +0000 | [diff] [blame] | 6366 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 6367 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 6368 | return; |
| 6369 | |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 6370 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 6371 | u64 rsc_count = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 6372 | u64 rsc_flush = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 6373 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6374 | rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count; |
| 6375 | rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 6376 | } |
| 6377 | adapter->rsc_total_count = rsc_count; |
| 6378 | adapter->rsc_total_flush = rsc_flush; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 6379 | } |
| 6380 | |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6381 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 6382 | struct ixgbe_ring *rx_ring = adapter->rx_ring[i]; |
| 6383 | non_eop_descs += rx_ring->rx_stats.non_eop_descs; |
| 6384 | alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed; |
| 6385 | alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 6386 | hw_csum_rx_error += rx_ring->rx_stats.csum_err; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6387 | bytes += rx_ring->stats.bytes; |
| 6388 | packets += rx_ring->stats.packets; |
| 6389 | } |
Mallikarjuna R Chilakala | eb985f0 | 2009-12-15 11:56:59 +0000 | [diff] [blame] | 6390 | adapter->non_eop_descs = non_eop_descs; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6391 | adapter->alloc_rx_page_failed = alloc_rx_page_failed; |
| 6392 | adapter->alloc_rx_buff_failed = alloc_rx_buff_failed; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 6393 | adapter->hw_csum_rx_error = hw_csum_rx_error; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6394 | netdev->stats.rx_bytes = bytes; |
| 6395 | netdev->stats.rx_packets = packets; |
| 6396 | |
| 6397 | bytes = 0; |
| 6398 | packets = 0; |
| 6399 | /* gather some stats to the adapter struct that are per queue */ |
| 6400 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 6401 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 6402 | restart_queue += tx_ring->tx_stats.restart_queue; |
| 6403 | tx_busy += tx_ring->tx_stats.tx_busy; |
| 6404 | bytes += tx_ring->stats.bytes; |
| 6405 | packets += tx_ring->stats.packets; |
| 6406 | } |
| 6407 | adapter->restart_queue = restart_queue; |
| 6408 | adapter->tx_busy = tx_busy; |
| 6409 | netdev->stats.tx_bytes = bytes; |
| 6410 | netdev->stats.tx_packets = packets; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 6411 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6412 | hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS); |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6413 | |
| 6414 | /* 8 register reads */ |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6415 | for (i = 0; i < 8; i++) { |
| 6416 | /* for packet buffers not used, the register should read 0 */ |
| 6417 | mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i)); |
| 6418 | missed_rx += mpc; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6419 | hwstats->mpc[i] += mpc; |
| 6420 | total_mpc += hwstats->mpc[i]; |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6421 | hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i)); |
| 6422 | hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6423 | switch (hw->mac.type) { |
| 6424 | case ixgbe_mac_82598EB: |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6425 | hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i)); |
| 6426 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i)); |
| 6427 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i)); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6428 | hwstats->pxonrxc[i] += |
| 6429 | IXGBE_READ_REG(hw, IXGBE_PXONRXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6430 | break; |
| 6431 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 6432 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6433 | case ixgbe_mac_X550: |
| 6434 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 6435 | case ixgbe_mac_x550em_a: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6436 | hwstats->pxonrxc[i] += |
| 6437 | IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6438 | break; |
| 6439 | default: |
| 6440 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6441 | } |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6442 | } |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6443 | |
| 6444 | /*16 register reads */ |
| 6445 | for (i = 0; i < 16; i++) { |
| 6446 | hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i)); |
| 6447 | hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i)); |
| 6448 | if ((hw->mac.type == ixgbe_mac_82599EB) || |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6449 | (hw->mac.type == ixgbe_mac_X540) || |
| 6450 | (hw->mac.type == ixgbe_mac_X550) || |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 6451 | (hw->mac.type == ixgbe_mac_X550EM_x) || |
| 6452 | (hw->mac.type == ixgbe_mac_x550em_a)) { |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6453 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i)); |
| 6454 | IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */ |
| 6455 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i)); |
| 6456 | IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */ |
| 6457 | } |
| 6458 | } |
| 6459 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6460 | hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6461 | /* work around hardware counting issue */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6462 | hwstats->gprc -= missed_rx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6463 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 6464 | ixgbe_update_xoff_received(adapter); |
| 6465 | |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6466 | /* 82598 hardware only has a 32 bit counter in the high register */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6467 | switch (hw->mac.type) { |
| 6468 | case ixgbe_mac_82598EB: |
| 6469 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6470 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH); |
| 6471 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH); |
| 6472 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH); |
| 6473 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 6474 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6475 | case ixgbe_mac_X550: |
| 6476 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 6477 | case ixgbe_mac_x550em_a: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6478 | /* OS2BMC stats are X540 and later */ |
Emil Tantilov | 58f6bcf | 2011-04-21 08:43:43 +0000 | [diff] [blame] | 6479 | hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC); |
| 6480 | hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC); |
| 6481 | hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC); |
| 6482 | hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC); |
| 6483 | case ixgbe_mac_82599EB: |
Alexander Duyck | a4d4f62 | 2012-03-28 08:03:32 +0000 | [diff] [blame] | 6484 | for (i = 0; i < 16; i++) |
| 6485 | adapter->hw_rx_no_dma_resources += |
| 6486 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6487 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6488 | IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6489 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6490 | IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6491 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6492 | IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6493 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6494 | hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH); |
| 6495 | hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS); |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 6496 | #ifdef IXGBE_FCOE |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6497 | hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC); |
| 6498 | hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC); |
| 6499 | hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC); |
| 6500 | hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC); |
| 6501 | hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC); |
| 6502 | hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC); |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 6503 | /* Add up per cpu counters for total ddp aloc fail */ |
Alexander Duyck | 5a1ee27 | 2012-05-05 17:14:28 +0000 | [diff] [blame] | 6504 | if (adapter->fcoe.ddp_pool) { |
| 6505 | struct ixgbe_fcoe *fcoe = &adapter->fcoe; |
| 6506 | struct ixgbe_fcoe_ddp_pool *ddp_pool; |
| 6507 | unsigned int cpu; |
| 6508 | u64 noddp = 0, noddp_ext_buff = 0; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 6509 | for_each_possible_cpu(cpu) { |
Alexander Duyck | 5a1ee27 | 2012-05-05 17:14:28 +0000 | [diff] [blame] | 6510 | ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu); |
| 6511 | noddp += ddp_pool->noddp; |
| 6512 | noddp_ext_buff += ddp_pool->noddp_ext_buff; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 6513 | } |
Alexander Duyck | 5a1ee27 | 2012-05-05 17:14:28 +0000 | [diff] [blame] | 6514 | hwstats->fcoe_noddp = noddp; |
| 6515 | hwstats->fcoe_noddp_ext_buff = noddp_ext_buff; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 6516 | } |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 6517 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6518 | break; |
| 6519 | default: |
| 6520 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6521 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6522 | bprc = IXGBE_READ_REG(hw, IXGBE_BPRC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6523 | hwstats->bprc += bprc; |
| 6524 | hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6525 | if (hw->mac.type == ixgbe_mac_82598EB) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6526 | hwstats->mprc -= bprc; |
| 6527 | hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC); |
| 6528 | hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64); |
| 6529 | hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127); |
| 6530 | hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255); |
| 6531 | hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511); |
| 6532 | hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023); |
| 6533 | hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522); |
| 6534 | hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6535 | lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6536 | hwstats->lxontxc += lxon; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6537 | lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6538 | hwstats->lxofftxc += lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6539 | hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC); |
| 6540 | hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6541 | /* |
| 6542 | * 82598 errata - tx of flow control packets is included in tx counters |
| 6543 | */ |
| 6544 | xon_off_tot = lxon + lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6545 | hwstats->gptc -= xon_off_tot; |
| 6546 | hwstats->mptc -= xon_off_tot; |
| 6547 | hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN)); |
| 6548 | hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 6549 | hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC); |
| 6550 | hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC); |
| 6551 | hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR); |
| 6552 | hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64); |
| 6553 | hwstats->ptc64 -= xon_off_tot; |
| 6554 | hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127); |
| 6555 | hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255); |
| 6556 | hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511); |
| 6557 | hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023); |
| 6558 | hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522); |
| 6559 | hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6560 | |
| 6561 | /* Fill out the OS statistics structure */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6562 | netdev->stats.multicast = hwstats->mprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6563 | |
| 6564 | /* Rx Errors */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6565 | netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 6566 | netdev->stats.rx_dropped = 0; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6567 | netdev->stats.rx_length_errors = hwstats->rlec; |
| 6568 | netdev->stats.rx_crc_errors = hwstats->crcerrs; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 6569 | netdev->stats.rx_missed_errors = total_mpc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6570 | } |
| 6571 | |
| 6572 | /** |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6573 | * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6574 | * @adapter: pointer to the device adapter structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6575 | **/ |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6576 | static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6577 | { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6578 | struct ixgbe_hw *hw = &adapter->hw; |
| 6579 | int i; |
| 6580 | |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6581 | if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 6582 | return; |
| 6583 | |
| 6584 | adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 6585 | |
| 6586 | /* if interface is down do nothing */ |
| 6587 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 6588 | return; |
| 6589 | |
| 6590 | /* do nothing if we are not using signature filters */ |
| 6591 | if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) |
| 6592 | return; |
| 6593 | |
| 6594 | adapter->fdir_overflow++; |
| 6595 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6596 | if (ixgbe_reinit_fdir_tables_82599(hw) == 0) { |
| 6597 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 6598 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 6599 | &(adapter->tx_ring[i]->state)); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6600 | /* re-enable flow director interrupts */ |
| 6601 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6602 | } else { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 6603 | e_err(probe, "failed to finish FDIR re-initialization, " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 6604 | "ignored adding FDIR ATR filters\n"); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6605 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6606 | } |
| 6607 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6608 | /** |
| 6609 | * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6610 | * @adapter: pointer to the device adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6611 | * |
| 6612 | * This function serves two purposes. First it strobes the interrupt lines |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 6613 | * in order to make certain interrupts are occurring. Secondly it sets the |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6614 | * 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] | 6615 | * determine if a hang has occurred. |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6616 | */ |
| 6617 | static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter) |
| 6618 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6619 | struct ixgbe_hw *hw = &adapter->hw; |
| 6620 | u64 eics = 0; |
| 6621 | int i; |
| 6622 | |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 6623 | /* If we're down, removing or resetting, just bail */ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6624 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 6625 | test_bit(__IXGBE_REMOVING, &adapter->state) || |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6626 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 6627 | return; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6628 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6629 | /* Force detection of hung controller */ |
| 6630 | if (netif_carrier_ok(adapter->netdev)) { |
| 6631 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 6632 | set_check_for_tx_hang(adapter->tx_ring[i]); |
| 6633 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6634 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 6635 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6636 | /* |
| 6637 | * for legacy and MSI interrupts don't set any bits |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 6638 | * that are enabled for EIAM, because this operation |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6639 | * would set *both* EIMS and EICS for any bit in EIAM |
| 6640 | */ |
| 6641 | IXGBE_WRITE_REG(hw, IXGBE_EICS, |
| 6642 | (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER)); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6643 | } else { |
| 6644 | /* get one bit for every active tx/rx interrupt vector */ |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 6645 | for (i = 0; i < adapter->num_q_vectors; i++) { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6646 | struct ixgbe_q_vector *qv = adapter->q_vector[i]; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 6647 | if (qv->rx.ring || qv->tx.ring) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame^] | 6648 | eics |= BIT_ULL(i); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6649 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6650 | } |
| 6651 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6652 | /* Cause software interrupt to ensure rings are cleaned */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6653 | ixgbe_irq_rearm_queues(adapter, eics); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6654 | } |
| 6655 | |
| 6656 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6657 | * ixgbe_watchdog_update_link - update the link status |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6658 | * @adapter: pointer to the device adapter structure |
| 6659 | * @link_speed: pointer to a u32 to store the link_speed |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6660 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6661 | static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter) |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6662 | { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6663 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6664 | u32 link_speed = adapter->link_speed; |
| 6665 | bool link_up = adapter->link_up; |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 6666 | bool pfc_en = adapter->dcb_cfg.pfc_mode_enable; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6667 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6668 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) |
| 6669 | return; |
| 6670 | |
| 6671 | if (hw->mac.ops.check_link) { |
| 6672 | 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] | 6673 | } else { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6674 | /* always assume link is up, if no check link function */ |
| 6675 | link_speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 6676 | link_up = true; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6677 | } |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 6678 | |
Don Skidmore | 4319a79 | 2016-04-12 19:25:10 -0400 | [diff] [blame] | 6679 | /* If Crosstalk fix enabled do the sanity check of making sure |
| 6680 | * the SFP+ cage is empty. |
| 6681 | */ |
| 6682 | if (adapter->need_crosstalk_fix) { |
| 6683 | u32 sfp_cage_full; |
| 6684 | |
| 6685 | sfp_cage_full = IXGBE_READ_REG(hw, IXGBE_ESDP) & |
| 6686 | IXGBE_ESDP_SDP2; |
| 6687 | if (ixgbe_is_sfp(hw) && link_up && !sfp_cage_full) |
| 6688 | link_up = false; |
| 6689 | } |
| 6690 | |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 6691 | if (adapter->ixgbe_ieee_pfc) |
| 6692 | pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en); |
| 6693 | |
Alexander Duyck | 3ebe8fd | 2012-04-25 04:36:38 +0000 | [diff] [blame] | 6694 | if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) { |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 6695 | hw->mac.ops.fc_enable(hw); |
Alexander Duyck | 3ebe8fd | 2012-04-25 04:36:38 +0000 | [diff] [blame] | 6696 | ixgbe_set_rx_drop_en(adapter); |
| 6697 | } |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6698 | |
| 6699 | if (link_up || |
| 6700 | time_after(jiffies, (adapter->link_check_timeout + |
| 6701 | IXGBE_TRY_LINK_TIMEOUT))) { |
| 6702 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 6703 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC); |
| 6704 | IXGBE_WRITE_FLUSH(hw); |
| 6705 | } |
| 6706 | |
| 6707 | adapter->link_up = link_up; |
| 6708 | adapter->link_speed = link_speed; |
| 6709 | } |
| 6710 | |
Alexander Duyck | 107d301 | 2012-10-02 00:17:03 +0000 | [diff] [blame] | 6711 | static void ixgbe_update_default_up(struct ixgbe_adapter *adapter) |
| 6712 | { |
| 6713 | #ifdef CONFIG_IXGBE_DCB |
| 6714 | struct net_device *netdev = adapter->netdev; |
| 6715 | struct dcb_app app = { |
| 6716 | .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE, |
| 6717 | .protocol = 0, |
| 6718 | }; |
| 6719 | u8 up = 0; |
| 6720 | |
| 6721 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE) |
| 6722 | up = dcb_ieee_getapp_mask(netdev, &app); |
| 6723 | |
| 6724 | adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0; |
| 6725 | #endif |
| 6726 | } |
| 6727 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6728 | /** |
| 6729 | * ixgbe_watchdog_link_is_up - update netif_carrier status and |
| 6730 | * print link up message |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6731 | * @adapter: pointer to the device adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6732 | **/ |
| 6733 | static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter) |
| 6734 | { |
| 6735 | struct net_device *netdev = adapter->netdev; |
| 6736 | struct ixgbe_hw *hw = &adapter->hw; |
Emil Tantilov | cdc04dc | 2014-03-20 03:47:53 +0000 | [diff] [blame] | 6737 | struct net_device *upper; |
| 6738 | struct list_head *iter; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6739 | u32 link_speed = adapter->link_speed; |
Mark Rustad | 454adb0 | 2015-07-10 14:19:22 -0700 | [diff] [blame] | 6740 | const char *speed_str; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6741 | bool flow_rx, flow_tx; |
| 6742 | |
| 6743 | /* only continue if link was previously down */ |
| 6744 | if (netif_carrier_ok(netdev)) |
| 6745 | return; |
| 6746 | |
| 6747 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 6748 | |
| 6749 | switch (hw->mac.type) { |
| 6750 | case ixgbe_mac_82598EB: { |
| 6751 | u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 6752 | u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS); |
| 6753 | flow_rx = !!(frctl & IXGBE_FCTRL_RFCE); |
| 6754 | flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X); |
| 6755 | } |
| 6756 | break; |
| 6757 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6758 | case ixgbe_mac_X550: |
| 6759 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 6760 | case ixgbe_mac_x550em_a: |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6761 | case ixgbe_mac_82599EB: { |
| 6762 | u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN); |
| 6763 | u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG); |
| 6764 | flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE); |
| 6765 | flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X); |
| 6766 | } |
| 6767 | break; |
| 6768 | default: |
| 6769 | flow_tx = false; |
| 6770 | flow_rx = false; |
| 6771 | break; |
| 6772 | } |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 6773 | |
Jacob Keller | 6cb562d | 2012-12-05 07:24:41 +0000 | [diff] [blame] | 6774 | adapter->last_rx_ptp_check = jiffies; |
| 6775 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 6776 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6777 | ixgbe_ptp_start_cyclecounter(adapter); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 6778 | |
Mark Rustad | 454adb0 | 2015-07-10 14:19:22 -0700 | [diff] [blame] | 6779 | switch (link_speed) { |
| 6780 | case IXGBE_LINK_SPEED_10GB_FULL: |
| 6781 | speed_str = "10 Gbps"; |
| 6782 | break; |
| 6783 | case IXGBE_LINK_SPEED_2_5GB_FULL: |
| 6784 | speed_str = "2.5 Gbps"; |
| 6785 | break; |
| 6786 | case IXGBE_LINK_SPEED_1GB_FULL: |
| 6787 | speed_str = "1 Gbps"; |
| 6788 | break; |
| 6789 | case IXGBE_LINK_SPEED_100_FULL: |
| 6790 | speed_str = "100 Mbps"; |
| 6791 | break; |
| 6792 | default: |
| 6793 | speed_str = "unknown speed"; |
| 6794 | break; |
| 6795 | } |
| 6796 | 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] | 6797 | ((flow_rx && flow_tx) ? "RX/TX" : |
| 6798 | (flow_rx ? "RX" : |
| 6799 | (flow_tx ? "TX" : "None")))); |
| 6800 | |
| 6801 | netif_carrier_on(netdev); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6802 | ixgbe_check_vf_rate_limit(adapter); |
Alexander Duyck | befa2af | 2012-05-05 05:30:38 +0000 | [diff] [blame] | 6803 | |
Emil Tantilov | cdc04dc | 2014-03-20 03:47:53 +0000 | [diff] [blame] | 6804 | /* enable transmits */ |
| 6805 | netif_tx_wake_all_queues(adapter->netdev); |
| 6806 | |
| 6807 | /* enable any upper devices */ |
| 6808 | rtnl_lock(); |
| 6809 | netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) { |
| 6810 | if (netif_is_macvlan(upper)) { |
| 6811 | struct macvlan_dev *vlan = netdev_priv(upper); |
| 6812 | |
| 6813 | if (vlan->fwd_priv) |
| 6814 | netif_tx_wake_all_queues(upper); |
| 6815 | } |
| 6816 | } |
| 6817 | rtnl_unlock(); |
| 6818 | |
Alexander Duyck | 107d301 | 2012-10-02 00:17:03 +0000 | [diff] [blame] | 6819 | /* update the default user priority for VFs */ |
| 6820 | ixgbe_update_default_up(adapter); |
| 6821 | |
Alexander Duyck | befa2af | 2012-05-05 05:30:38 +0000 | [diff] [blame] | 6822 | /* ping all the active vfs to let them know link has changed */ |
| 6823 | ixgbe_ping_all_vfs(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6824 | } |
| 6825 | |
| 6826 | /** |
| 6827 | * ixgbe_watchdog_link_is_down - update netif_carrier status and |
| 6828 | * print link down message |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6829 | * @adapter: pointer to the adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6830 | **/ |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 6831 | static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6832 | { |
| 6833 | struct net_device *netdev = adapter->netdev; |
| 6834 | struct ixgbe_hw *hw = &adapter->hw; |
| 6835 | |
| 6836 | adapter->link_up = false; |
| 6837 | adapter->link_speed = 0; |
| 6838 | |
| 6839 | /* only continue if link was up previously */ |
| 6840 | if (!netif_carrier_ok(netdev)) |
| 6841 | return; |
| 6842 | |
| 6843 | /* poll for SFP+ cable when link is down */ |
| 6844 | if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB) |
| 6845 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 6846 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 6847 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6848 | ixgbe_ptp_start_cyclecounter(adapter); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 6849 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6850 | e_info(drv, "NIC Link is Down\n"); |
| 6851 | netif_carrier_off(netdev); |
Alexander Duyck | befa2af | 2012-05-05 05:30:38 +0000 | [diff] [blame] | 6852 | |
| 6853 | /* ping all the active vfs to let them know link has changed */ |
| 6854 | ixgbe_ping_all_vfs(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6855 | } |
| 6856 | |
Emil Tantilov | 07923c1 | 2014-08-12 07:12:08 +0000 | [diff] [blame] | 6857 | static bool ixgbe_ring_tx_pending(struct ixgbe_adapter *adapter) |
| 6858 | { |
| 6859 | int i; |
| 6860 | |
| 6861 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 6862 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 6863 | |
| 6864 | if (tx_ring->next_to_use != tx_ring->next_to_clean) |
| 6865 | return true; |
| 6866 | } |
| 6867 | |
| 6868 | return false; |
| 6869 | } |
| 6870 | |
| 6871 | static bool ixgbe_vf_tx_pending(struct ixgbe_adapter *adapter) |
| 6872 | { |
| 6873 | struct ixgbe_hw *hw = &adapter->hw; |
| 6874 | struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ]; |
| 6875 | u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask); |
| 6876 | |
| 6877 | int i, j; |
| 6878 | |
| 6879 | if (!adapter->num_vfs) |
| 6880 | return false; |
| 6881 | |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6882 | /* resetting the PF is only needed for MAC before X550 */ |
| 6883 | if (hw->mac.type >= ixgbe_mac_X550) |
| 6884 | return false; |
| 6885 | |
Emil Tantilov | 07923c1 | 2014-08-12 07:12:08 +0000 | [diff] [blame] | 6886 | for (i = 0; i < adapter->num_vfs; i++) { |
| 6887 | for (j = 0; j < q_per_pool; j++) { |
| 6888 | u32 h, t; |
| 6889 | |
| 6890 | h = IXGBE_READ_REG(hw, IXGBE_PVFTDHN(q_per_pool, i, j)); |
| 6891 | t = IXGBE_READ_REG(hw, IXGBE_PVFTDTN(q_per_pool, i, j)); |
| 6892 | |
| 6893 | if (h != t) |
| 6894 | return true; |
| 6895 | } |
| 6896 | } |
| 6897 | |
| 6898 | return false; |
| 6899 | } |
| 6900 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6901 | /** |
| 6902 | * ixgbe_watchdog_flush_tx - flush queues on link down |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6903 | * @adapter: pointer to the device adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6904 | **/ |
| 6905 | static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter) |
| 6906 | { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6907 | if (!netif_carrier_ok(adapter->netdev)) { |
Emil Tantilov | 07923c1 | 2014-08-12 07:12:08 +0000 | [diff] [blame] | 6908 | if (ixgbe_ring_tx_pending(adapter) || |
| 6909 | ixgbe_vf_tx_pending(adapter)) { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6910 | /* We've lost link, so the controller stops DMA, |
| 6911 | * but we've got queued Tx work that's never going |
| 6912 | * to get done, so reset controller to flush Tx. |
| 6913 | * (Do the reset outside of interrupt context). |
| 6914 | */ |
Jacob Keller | 12ff3f3 | 2012-12-01 07:57:17 +0000 | [diff] [blame] | 6915 | e_warn(drv, "initiating reset to clear Tx work after link loss\n"); |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6916 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6917 | } |
| 6918 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6919 | } |
| 6920 | |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 6921 | #ifdef CONFIG_PCI_IOV |
| 6922 | static inline void ixgbe_issue_vf_flr(struct ixgbe_adapter *adapter, |
| 6923 | struct pci_dev *vfdev) |
| 6924 | { |
| 6925 | if (!pci_wait_for_pending_transaction(vfdev)) |
| 6926 | e_dev_warn("Issuing VFLR with pending transactions\n"); |
| 6927 | |
| 6928 | e_dev_err("Issuing VFLR for VF %s\n", pci_name(vfdev)); |
| 6929 | pcie_capability_set_word(vfdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_BCR_FLR); |
| 6930 | |
| 6931 | msleep(100); |
| 6932 | } |
| 6933 | |
| 6934 | static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter) |
| 6935 | { |
| 6936 | struct ixgbe_hw *hw = &adapter->hw; |
| 6937 | struct pci_dev *pdev = adapter->pdev; |
Mark Rustad | 988d130 | 2015-10-30 15:29:34 -0700 | [diff] [blame] | 6938 | unsigned int vf; |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 6939 | u32 gpc; |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 6940 | |
| 6941 | if (!(netif_carrier_ok(adapter->netdev))) |
| 6942 | return; |
| 6943 | |
| 6944 | gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC); |
| 6945 | if (gpc) /* If incrementing then no need for the check below */ |
| 6946 | return; |
| 6947 | /* Check to see if a bad DMA write target from an errant or |
| 6948 | * malicious VF has caused a PCIe error. If so then we can |
| 6949 | * issue a VFLR to the offending VF(s) and then resume without |
| 6950 | * requesting a full slot reset. |
| 6951 | */ |
| 6952 | |
| 6953 | if (!pdev) |
| 6954 | return; |
| 6955 | |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 6956 | /* check status reg for all VFs owned by this PF */ |
Mark Rustad | 988d130 | 2015-10-30 15:29:34 -0700 | [diff] [blame] | 6957 | for (vf = 0; vf < adapter->num_vfs; ++vf) { |
| 6958 | struct pci_dev *vfdev = adapter->vfinfo[vf].vfdev; |
| 6959 | u16 status_reg; |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 6960 | |
Mark Rustad | 988d130 | 2015-10-30 15:29:34 -0700 | [diff] [blame] | 6961 | if (!vfdev) |
| 6962 | continue; |
| 6963 | pci_read_config_word(vfdev, PCI_STATUS, &status_reg); |
| 6964 | if (status_reg != IXGBE_FAILED_READ_CFG_WORD && |
| 6965 | status_reg & PCI_STATUS_REC_MASTER_ABORT) |
| 6966 | ixgbe_issue_vf_flr(adapter, vfdev); |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 6967 | } |
| 6968 | } |
| 6969 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6970 | static void ixgbe_spoof_check(struct ixgbe_adapter *adapter) |
| 6971 | { |
| 6972 | u32 ssvpc; |
| 6973 | |
Greg Rose | 0584d99 | 2012-08-08 00:00:58 +0000 | [diff] [blame] | 6974 | /* Do not perform spoof check for 82598 or if not in IOV mode */ |
| 6975 | if (adapter->hw.mac.type == ixgbe_mac_82598EB || |
| 6976 | adapter->num_vfs == 0) |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6977 | return; |
| 6978 | |
| 6979 | ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC); |
| 6980 | |
| 6981 | /* |
| 6982 | * ssvpc register is cleared on read, if zero then no |
| 6983 | * spoofed packets in the last interval. |
| 6984 | */ |
| 6985 | if (!ssvpc) |
| 6986 | return; |
| 6987 | |
Emil Tantilov | d6ea075 | 2012-08-08 06:28:37 +0000 | [diff] [blame] | 6988 | e_warn(drv, "%u Spoofed packets detected\n", ssvpc); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6989 | } |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 6990 | #else |
| 6991 | static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused *adapter) |
| 6992 | { |
| 6993 | } |
| 6994 | |
| 6995 | static void |
| 6996 | ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused *adapter) |
| 6997 | { |
| 6998 | } |
| 6999 | #endif /* CONFIG_PCI_IOV */ |
| 7000 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 7001 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7002 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7003 | * ixgbe_watchdog_subtask - check and bring link up |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7004 | * @adapter: pointer to the device adapter structure |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 7005 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7006 | static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 7007 | { |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 7008 | /* if interface is down, removing or resetting, do nothing */ |
Emil Tantilov | 7edebf9 | 2011-08-27 07:18:37 +0000 | [diff] [blame] | 7009 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 7010 | test_bit(__IXGBE_REMOVING, &adapter->state) || |
Emil Tantilov | 7edebf9 | 2011-08-27 07:18:37 +0000 | [diff] [blame] | 7011 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7012 | return; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 7013 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7014 | ixgbe_watchdog_update_link(adapter); |
John Fastabend | 10eec95 | 2010-02-03 14:23:32 +0000 | [diff] [blame] | 7015 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7016 | if (adapter->link_up) |
| 7017 | ixgbe_watchdog_link_is_up(adapter); |
| 7018 | else |
| 7019 | ixgbe_watchdog_link_is_down(adapter); |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 7020 | |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7021 | ixgbe_check_for_bad_vf(adapter); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 7022 | ixgbe_spoof_check(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7023 | ixgbe_update_stats(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7024 | |
| 7025 | ixgbe_watchdog_flush_tx(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7026 | } |
| 7027 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7028 | /** |
| 7029 | * ixgbe_sfp_detection_subtask - poll for SFP+ cable |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7030 | * @adapter: the ixgbe adapter structure |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7031 | **/ |
| 7032 | static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter) |
| 7033 | { |
| 7034 | struct ixgbe_hw *hw = &adapter->hw; |
| 7035 | s32 err; |
| 7036 | |
Don Skidmore | 4319a79 | 2016-04-12 19:25:10 -0400 | [diff] [blame] | 7037 | /* If crosstalk fix enabled verify the SFP+ cage is full */ |
| 7038 | if (adapter->need_crosstalk_fix) { |
| 7039 | u32 sfp_cage_full; |
| 7040 | |
| 7041 | sfp_cage_full = IXGBE_READ_REG(hw, IXGBE_ESDP) & |
| 7042 | IXGBE_ESDP_SDP2; |
| 7043 | if (!sfp_cage_full) |
| 7044 | return; |
| 7045 | } |
| 7046 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7047 | /* not searching for SFP so there is nothing to do here */ |
| 7048 | if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) && |
| 7049 | !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 7050 | return; |
| 7051 | |
Mark Rustad | 58e7cd2 | 2015-08-08 16:18:48 -0700 | [diff] [blame] | 7052 | if (adapter->sfp_poll_time && |
| 7053 | time_after(adapter->sfp_poll_time, jiffies)) |
| 7054 | return; /* If not yet time to poll for SFP */ |
| 7055 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7056 | /* someone else is in init, wait until next service event */ |
| 7057 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 7058 | return; |
| 7059 | |
Mark Rustad | 58e7cd2 | 2015-08-08 16:18:48 -0700 | [diff] [blame] | 7060 | adapter->sfp_poll_time = jiffies + IXGBE_SFP_POLL_JIFFIES - 1; |
| 7061 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7062 | err = hw->phy.ops.identify_sfp(hw); |
| 7063 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 7064 | goto sfp_out; |
| 7065 | |
| 7066 | if (err == IXGBE_ERR_SFP_NOT_PRESENT) { |
| 7067 | /* If no cable is present, then we need to reset |
| 7068 | * the next time we find a good cable. */ |
| 7069 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 7070 | } |
| 7071 | |
| 7072 | /* exit on error */ |
| 7073 | if (err) |
| 7074 | goto sfp_out; |
| 7075 | |
| 7076 | /* exit if reset not needed */ |
| 7077 | if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 7078 | goto sfp_out; |
| 7079 | |
| 7080 | adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 7081 | |
| 7082 | /* |
| 7083 | * A module may be identified correctly, but the EEPROM may not have |
| 7084 | * support for that module. setup_sfp() will fail in that case, so |
| 7085 | * we should not allow that module to load. |
| 7086 | */ |
| 7087 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 7088 | err = hw->phy.ops.reset(hw); |
| 7089 | else |
| 7090 | err = hw->mac.ops.setup_sfp(hw); |
| 7091 | |
| 7092 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 7093 | goto sfp_out; |
| 7094 | |
| 7095 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 7096 | e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type); |
| 7097 | |
| 7098 | sfp_out: |
| 7099 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 7100 | |
| 7101 | if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) && |
| 7102 | (adapter->netdev->reg_state == NETREG_REGISTERED)) { |
| 7103 | e_dev_err("failed to initialize because an unsupported " |
| 7104 | "SFP+ module type was detected.\n"); |
| 7105 | e_dev_err("Reload the driver after installing a " |
| 7106 | "supported module.\n"); |
| 7107 | unregister_netdev(adapter->netdev); |
| 7108 | } |
| 7109 | } |
| 7110 | |
| 7111 | /** |
| 7112 | * ixgbe_sfp_link_config_subtask - set up link SFP after module install |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7113 | * @adapter: the ixgbe adapter structure |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7114 | **/ |
| 7115 | static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter) |
| 7116 | { |
| 7117 | struct ixgbe_hw *hw = &adapter->hw; |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 7118 | u32 speed; |
| 7119 | bool autoneg = false; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7120 | |
| 7121 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG)) |
| 7122 | return; |
| 7123 | |
| 7124 | /* someone else is in init, wait until next service event */ |
| 7125 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 7126 | return; |
| 7127 | |
| 7128 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 7129 | |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 7130 | speed = hw->phy.autoneg_advertised; |
Emil Tantilov | ed33ff6 | 2013-08-30 07:55:24 +0000 | [diff] [blame] | 7131 | if ((!speed) && (hw->mac.ops.get_link_capabilities)) { |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 7132 | hw->mac.ops.get_link_capabilities(hw, &speed, &autoneg); |
Emil Tantilov | ed33ff6 | 2013-08-30 07:55:24 +0000 | [diff] [blame] | 7133 | |
| 7134 | /* setup the highest link when no autoneg */ |
| 7135 | if (!autoneg) { |
| 7136 | if (speed & IXGBE_LINK_SPEED_10GB_FULL) |
| 7137 | speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 7138 | } |
| 7139 | } |
| 7140 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7141 | if (hw->mac.ops.setup_link) |
Josh Hay | fd0326f | 2012-12-15 03:28:30 +0000 | [diff] [blame] | 7142 | hw->mac.ops.setup_link(hw, speed, true); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7143 | |
| 7144 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 7145 | adapter->link_check_timeout = jiffies; |
| 7146 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 7147 | } |
| 7148 | |
| 7149 | /** |
| 7150 | * ixgbe_service_timer - Timer Call-back |
| 7151 | * @data: pointer to adapter cast into an unsigned long |
| 7152 | **/ |
| 7153 | static void ixgbe_service_timer(unsigned long data) |
| 7154 | { |
| 7155 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
| 7156 | unsigned long next_event_offset; |
| 7157 | |
| 7158 | /* poll faster when waiting for link */ |
| 7159 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 7160 | next_event_offset = HZ / 10; |
| 7161 | else |
| 7162 | next_event_offset = HZ * 2; |
| 7163 | |
| 7164 | /* Reset the timer */ |
| 7165 | mod_timer(&adapter->service_timer, next_event_offset + jiffies); |
| 7166 | |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7167 | ixgbe_service_event_schedule(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7168 | } |
| 7169 | |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 7170 | static void ixgbe_phy_interrupt_subtask(struct ixgbe_adapter *adapter) |
| 7171 | { |
| 7172 | struct ixgbe_hw *hw = &adapter->hw; |
| 7173 | u32 status; |
| 7174 | |
| 7175 | if (!(adapter->flags2 & IXGBE_FLAG2_PHY_INTERRUPT)) |
| 7176 | return; |
| 7177 | |
| 7178 | adapter->flags2 &= ~IXGBE_FLAG2_PHY_INTERRUPT; |
| 7179 | |
| 7180 | if (!hw->phy.ops.handle_lasi) |
| 7181 | return; |
| 7182 | |
| 7183 | status = hw->phy.ops.handle_lasi(&adapter->hw); |
| 7184 | if (status != IXGBE_ERR_OVERTEMP) |
| 7185 | return; |
| 7186 | |
| 7187 | e_crit(drv, "%s\n", ixgbe_overheat_msg); |
| 7188 | } |
| 7189 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7190 | static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter) |
| 7191 | { |
| 7192 | if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED)) |
| 7193 | return; |
| 7194 | |
| 7195 | adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED; |
| 7196 | |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 7197 | /* If we're already down, removing or resetting, just bail */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7198 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 7199 | test_bit(__IXGBE_REMOVING, &adapter->state) || |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7200 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 7201 | return; |
| 7202 | |
| 7203 | ixgbe_dump(adapter); |
| 7204 | netdev_err(adapter->netdev, "Reset adapter\n"); |
| 7205 | adapter->tx_timeout_count++; |
| 7206 | |
John Fastabend | 8f4c5c9 | 2014-01-16 02:30:05 -0800 | [diff] [blame] | 7207 | rtnl_lock(); |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7208 | ixgbe_reinit_locked(adapter); |
John Fastabend | 8f4c5c9 | 2014-01-16 02:30:05 -0800 | [diff] [blame] | 7209 | rtnl_unlock(); |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7210 | } |
| 7211 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7212 | /** |
| 7213 | * ixgbe_service_task - manages and runs subtasks |
| 7214 | * @work: pointer to work_struct containing our data |
| 7215 | **/ |
| 7216 | static void ixgbe_service_task(struct work_struct *work) |
| 7217 | { |
| 7218 | struct ixgbe_adapter *adapter = container_of(work, |
| 7219 | struct ixgbe_adapter, |
| 7220 | service_task); |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 7221 | if (ixgbe_removed(adapter->hw.hw_addr)) { |
| 7222 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 7223 | rtnl_lock(); |
| 7224 | ixgbe_down(adapter); |
| 7225 | rtnl_unlock(); |
| 7226 | } |
| 7227 | ixgbe_service_event_complete(adapter); |
| 7228 | return; |
| 7229 | } |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7230 | #ifdef CONFIG_IXGBE_VXLAN |
Hannes Frederic Sowa | b1f99a7 | 2016-04-18 21:19:45 +0200 | [diff] [blame] | 7231 | rtnl_lock(); |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7232 | if (adapter->flags2 & IXGBE_FLAG2_VXLAN_REREG_NEEDED) { |
| 7233 | adapter->flags2 &= ~IXGBE_FLAG2_VXLAN_REREG_NEEDED; |
| 7234 | vxlan_get_rx_port(adapter->netdev); |
| 7235 | } |
Hannes Frederic Sowa | b1f99a7 | 2016-04-18 21:19:45 +0200 | [diff] [blame] | 7236 | rtnl_unlock(); |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7237 | #endif /* CONFIG_IXGBE_VXLAN */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7238 | ixgbe_reset_subtask(adapter); |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 7239 | ixgbe_phy_interrupt_subtask(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7240 | ixgbe_sfp_detection_subtask(adapter); |
| 7241 | ixgbe_sfp_link_config_subtask(adapter); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 7242 | ixgbe_check_overtemp_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7243 | ixgbe_watchdog_subtask(adapter); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 7244 | ixgbe_fdir_reinit_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7245 | ixgbe_check_hang_subtask(adapter); |
Jacob Keller | 891dc08 | 2012-12-05 07:24:46 +0000 | [diff] [blame] | 7246 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 7247 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) { |
Jacob Keller | 891dc08 | 2012-12-05 07:24:46 +0000 | [diff] [blame] | 7248 | ixgbe_ptp_overflow_check(adapter); |
| 7249 | ixgbe_ptp_rx_hang(adapter); |
| 7250 | } |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7251 | |
| 7252 | ixgbe_service_event_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7253 | } |
| 7254 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7255 | static int ixgbe_tso(struct ixgbe_ring *tx_ring, |
| 7256 | struct ixgbe_tx_buffer *first, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7257 | u8 *hdr_len) |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7258 | { |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7259 | struct sk_buff *skb = first->skb; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7260 | u32 vlan_macip_lens, type_tucmd; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 7261 | u32 mss_l4len_idx, l4len; |
Francois Romieu | 2049e1f | 2014-03-30 03:14:27 +0000 | [diff] [blame] | 7262 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7263 | |
Alexander Duyck | 8f4fbb9 | 2012-10-30 06:01:40 +0000 | [diff] [blame] | 7264 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 7265 | return 0; |
| 7266 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7267 | if (!skb_is_gso(skb)) |
| 7268 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7269 | |
Francois Romieu | 2049e1f | 2014-03-30 03:14:27 +0000 | [diff] [blame] | 7270 | err = skb_cow_head(skb, 0); |
| 7271 | if (err < 0) |
| 7272 | return err; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 7273 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7274 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
| 7275 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 7276 | |
Joe Perches | a1108ff | 2014-03-13 05:19:25 +0000 | [diff] [blame] | 7277 | if (first->protocol == htons(ETH_P_IP)) { |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7278 | struct iphdr *iph = ip_hdr(skb); |
| 7279 | iph->tot_len = 0; |
| 7280 | iph->check = 0; |
| 7281 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 7282 | iph->daddr, 0, |
| 7283 | IPPROTO_TCP, |
| 7284 | 0); |
| 7285 | type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7286 | first->tx_flags |= IXGBE_TX_FLAGS_TSO | |
| 7287 | IXGBE_TX_FLAGS_CSUM | |
| 7288 | IXGBE_TX_FLAGS_IPV4; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7289 | } else if (skb_is_gso_v6(skb)) { |
| 7290 | ipv6_hdr(skb)->payload_len = 0; |
| 7291 | tcp_hdr(skb)->check = |
| 7292 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 7293 | &ipv6_hdr(skb)->daddr, |
| 7294 | 0, IPPROTO_TCP, 0); |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7295 | first->tx_flags |= IXGBE_TX_FLAGS_TSO | |
| 7296 | IXGBE_TX_FLAGS_CSUM; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7297 | } |
| 7298 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 7299 | /* compute header lengths */ |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7300 | l4len = tcp_hdrlen(skb); |
| 7301 | *hdr_len = skb_transport_offset(skb) + l4len; |
| 7302 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 7303 | /* update gso size and bytecount with header size */ |
| 7304 | first->gso_segs = skb_shinfo(skb)->gso_segs; |
| 7305 | first->bytecount += (first->gso_segs - 1) * *hdr_len; |
| 7306 | |
Alexander Duyck | c44f5f5 | 2012-10-30 06:01:45 +0000 | [diff] [blame] | 7307 | /* mss_l4len_id: use 0 as index for TSO */ |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7308 | mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT; |
| 7309 | mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7310 | |
| 7311 | /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */ |
| 7312 | vlan_macip_lens = skb_network_header_len(skb); |
| 7313 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7314 | vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7315 | |
| 7316 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7317 | mss_l4len_idx); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7318 | |
| 7319 | return 1; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 7320 | } |
| 7321 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7322 | static inline bool ixgbe_ipv6_csum_is_sctp(struct sk_buff *skb) |
| 7323 | { |
| 7324 | unsigned int offset = 0; |
| 7325 | |
| 7326 | ipv6_find_hdr(skb, &offset, IPPROTO_SCTP, NULL, NULL); |
| 7327 | |
| 7328 | return offset == skb_checksum_start_offset(skb); |
| 7329 | } |
| 7330 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7331 | static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring, |
| 7332 | struct ixgbe_tx_buffer *first) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7333 | { |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7334 | struct sk_buff *skb = first->skb; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7335 | u32 vlan_macip_lens = 0; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7336 | u32 type_tucmd = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7337 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7338 | if (skb->ip_summed != CHECKSUM_PARTIAL) { |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7339 | csum_failed: |
| 7340 | if (!(first->tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | |
| 7341 | IXGBE_TX_FLAGS_CC))) |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7342 | return; |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7343 | goto no_csum; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7344 | } |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 7345 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7346 | switch (skb->csum_offset) { |
| 7347 | case offsetof(struct tcphdr, check): |
| 7348 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 7349 | /* fall through */ |
| 7350 | case offsetof(struct udphdr, check): |
| 7351 | break; |
| 7352 | case offsetof(struct sctphdr, checksum): |
| 7353 | /* validate that this is actually an SCTP request */ |
| 7354 | if (((first->protocol == htons(ETH_P_IP)) && |
| 7355 | (ip_hdr(skb)->protocol == IPPROTO_SCTP)) || |
| 7356 | ((first->protocol == htons(ETH_P_IPV6)) && |
| 7357 | ixgbe_ipv6_csum_is_sctp(skb))) { |
| 7358 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
| 7359 | break; |
| 7360 | } |
| 7361 | /* fall through */ |
| 7362 | default: |
| 7363 | skb_checksum_help(skb); |
| 7364 | goto csum_failed; |
| 7365 | } |
| 7366 | |
| 7367 | /* update TX checksum flag */ |
| 7368 | first->tx_flags |= IXGBE_TX_FLAGS_CSUM; |
| 7369 | vlan_macip_lens = skb_checksum_start_offset(skb) - |
| 7370 | skb_network_offset(skb); |
Mark Rustad | 36a92d7 | 2015-11-18 09:21:28 -0800 | [diff] [blame] | 7371 | no_csum: |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7372 | /* vlan_macip_lens: MACLEN, VLAN tag */ |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7373 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7374 | vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7375 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7376 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, 0); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7377 | } |
| 7378 | |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7379 | #define IXGBE_SET_FLAG(_input, _flag, _result) \ |
| 7380 | ((_flag <= _result) ? \ |
| 7381 | ((u32)(_input & _flag) * (_result / _flag)) : \ |
| 7382 | ((u32)(_input & _flag) / (_flag / _result))) |
| 7383 | |
| 7384 | 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] | 7385 | { |
| 7386 | /* set type for advanced descriptor with frame checksum insertion */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7387 | u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA | |
| 7388 | IXGBE_ADVTXD_DCMD_DEXT | |
| 7389 | IXGBE_ADVTXD_DCMD_IFCS; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7390 | |
| 7391 | /* set HW vlan bit if vlan is present */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7392 | cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN, |
| 7393 | IXGBE_ADVTXD_DCMD_VLE); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7394 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7395 | /* set segmentation enable bits for TSO/FSO */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7396 | cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO, |
| 7397 | IXGBE_ADVTXD_DCMD_TSE); |
| 7398 | |
| 7399 | /* set timestamp bit if present */ |
| 7400 | cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP, |
| 7401 | IXGBE_ADVTXD_MAC_TSTAMP); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7402 | |
Alexander Duyck | 62748b7 | 2012-07-20 08:09:01 +0000 | [diff] [blame] | 7403 | /* insert frame checksum */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7404 | 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] | 7405 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7406 | return cmd_type; |
| 7407 | } |
| 7408 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7409 | static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc, |
| 7410 | u32 tx_flags, unsigned int paylen) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7411 | { |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7412 | u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7413 | |
| 7414 | /* enable L4 checksum for TSO and TX checksum offload */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7415 | olinfo_status |= IXGBE_SET_FLAG(tx_flags, |
| 7416 | IXGBE_TX_FLAGS_CSUM, |
| 7417 | IXGBE_ADVTXD_POPTS_TXSM); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7418 | |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 7419 | /* enble IPv4 checksum for TSO */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7420 | olinfo_status |= IXGBE_SET_FLAG(tx_flags, |
| 7421 | IXGBE_TX_FLAGS_IPV4, |
| 7422 | IXGBE_ADVTXD_POPTS_IXSM); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7423 | |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 7424 | /* |
| 7425 | * Check Context must be set if Tx switch is enabled, which it |
| 7426 | * always is for case where virtual functions are running |
| 7427 | */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7428 | olinfo_status |= IXGBE_SET_FLAG(tx_flags, |
| 7429 | IXGBE_TX_FLAGS_CC, |
| 7430 | IXGBE_ADVTXD_CC); |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 7431 | |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7432 | tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7433 | } |
| 7434 | |
Daniel Borkmann | 2367a17 | 2014-08-26 19:34:18 +0200 | [diff] [blame] | 7435 | static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size) |
| 7436 | { |
| 7437 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 7438 | |
| 7439 | /* Herbert's original patch had: |
| 7440 | * smp_mb__after_netif_stop_queue(); |
| 7441 | * but since that doesn't exist yet, just open code it. |
| 7442 | */ |
| 7443 | smp_mb(); |
| 7444 | |
| 7445 | /* We need to check again in a case another CPU has just |
| 7446 | * made room available. |
| 7447 | */ |
| 7448 | if (likely(ixgbe_desc_unused(tx_ring) < size)) |
| 7449 | return -EBUSY; |
| 7450 | |
| 7451 | /* A reprieve! - use start_queue because it doesn't call schedule */ |
| 7452 | netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 7453 | ++tx_ring->tx_stats.restart_queue; |
| 7454 | return 0; |
| 7455 | } |
| 7456 | |
| 7457 | static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size) |
| 7458 | { |
| 7459 | if (likely(ixgbe_desc_unused(tx_ring) >= size)) |
| 7460 | return 0; |
| 7461 | |
| 7462 | return __ixgbe_maybe_stop_tx(tx_ring, size); |
| 7463 | } |
| 7464 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7465 | #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \ |
| 7466 | IXGBE_TXD_CMD_RS) |
| 7467 | |
| 7468 | static void ixgbe_tx_map(struct ixgbe_ring *tx_ring, |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7469 | struct ixgbe_tx_buffer *first, |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7470 | const u8 hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7471 | { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7472 | struct sk_buff *skb = first->skb; |
| 7473 | struct ixgbe_tx_buffer *tx_buffer; |
| 7474 | union ixgbe_adv_tx_desc *tx_desc; |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7475 | struct skb_frag_struct *frag; |
| 7476 | dma_addr_t dma; |
| 7477 | unsigned int data_len, size; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7478 | u32 tx_flags = first->tx_flags; |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7479 | u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7480 | u16 i = tx_ring->next_to_use; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7481 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7482 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
| 7483 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7484 | ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len); |
| 7485 | |
| 7486 | size = skb_headlen(skb); |
| 7487 | data_len = skb->data_len; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7488 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7489 | #ifdef IXGBE_FCOE |
| 7490 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7491 | if (data_len < sizeof(struct fcoe_crc_eof)) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7492 | size -= sizeof(struct fcoe_crc_eof) - data_len; |
| 7493 | data_len = 0; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7494 | } else { |
| 7495 | data_len -= sizeof(struct fcoe_crc_eof); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 7496 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7497 | } |
| 7498 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7499 | #endif |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7500 | 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] | 7501 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7502 | tx_buffer = first; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7503 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7504 | for (frag = &skb_shinfo(skb)->frags[0];; frag++) { |
| 7505 | if (dma_mapping_error(tx_ring->dev, dma)) |
| 7506 | goto dma_error; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7507 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7508 | /* record length, and DMA address */ |
| 7509 | dma_unmap_len_set(tx_buffer, len, size); |
| 7510 | dma_unmap_addr_set(tx_buffer, dma, dma); |
| 7511 | |
| 7512 | tx_desc->read.buffer_addr = cpu_to_le64(dma); |
| 7513 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7514 | while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7515 | tx_desc->read.cmd_type_len = |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7516 | cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7517 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7518 | i++; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7519 | tx_desc++; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7520 | if (i == tx_ring->count) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 7521 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7522 | i = 0; |
| 7523 | } |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7524 | tx_desc->read.olinfo_status = 0; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7525 | |
| 7526 | dma += IXGBE_MAX_DATA_PER_TXD; |
| 7527 | size -= IXGBE_MAX_DATA_PER_TXD; |
| 7528 | |
| 7529 | tx_desc->read.buffer_addr = cpu_to_le64(dma); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7530 | } |
| 7531 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7532 | if (likely(!data_len)) |
| 7533 | break; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7534 | |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7535 | tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7536 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7537 | i++; |
| 7538 | tx_desc++; |
| 7539 | if (i == tx_ring->count) { |
| 7540 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
| 7541 | i = 0; |
| 7542 | } |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7543 | tx_desc->read.olinfo_status = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7544 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7545 | #ifdef IXGBE_FCOE |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 7546 | size = min_t(unsigned int, data_len, skb_frag_size(frag)); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7547 | #else |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 7548 | size = skb_frag_size(frag); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7549 | #endif |
| 7550 | data_len -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7551 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7552 | dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size, |
| 7553 | DMA_TO_DEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7554 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7555 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7556 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 7557 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7558 | /* write last descriptor with RS and EOP bits */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7559 | cmd_type |= size | IXGBE_TXD_CMD; |
| 7560 | tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7561 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 7562 | netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount); |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 7563 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7564 | /* set the timestamp */ |
| 7565 | first->time_stamp = jiffies; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7566 | |
| 7567 | /* |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7568 | * Force memory writes to complete before letting h/w know there |
| 7569 | * are new descriptors to fetch. (Only applicable for weak-ordered |
| 7570 | * memory model archs, such as IA-64). |
| 7571 | * |
| 7572 | * We also need this memory barrier to make certain all of the |
| 7573 | * status bits have been updated before next_to_watch is written. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7574 | */ |
| 7575 | wmb(); |
| 7576 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7577 | /* set next_to_watch value indicating a packet is present */ |
| 7578 | first->next_to_watch = tx_desc; |
| 7579 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7580 | i++; |
| 7581 | if (i == tx_ring->count) |
| 7582 | i = 0; |
| 7583 | |
| 7584 | tx_ring->next_to_use = i; |
| 7585 | |
Daniel Borkmann | 2367a17 | 2014-08-26 19:34:18 +0200 | [diff] [blame] | 7586 | ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED); |
| 7587 | |
| 7588 | if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) { |
Alexander Duyck | ad435ec | 2014-11-14 00:56:35 +0000 | [diff] [blame] | 7589 | writel(i, tx_ring->tail); |
| 7590 | |
| 7591 | /* we need this if more than one processor can write to our tail |
| 7592 | * at a time, it synchronizes IO on IA64/Altix systems |
| 7593 | */ |
| 7594 | mmiowb(); |
Daniel Borkmann | 9c938cd | 2014-08-24 15:42:16 +0200 | [diff] [blame] | 7595 | } |
Daniel Borkmann | 2367a17 | 2014-08-26 19:34:18 +0200 | [diff] [blame] | 7596 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7597 | return; |
| 7598 | dma_error: |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7599 | dev_err(tx_ring->dev, "TX DMA map failed\n"); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7600 | |
| 7601 | /* clear dma mappings for failed tx_buffer_info map */ |
| 7602 | for (;;) { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7603 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
| 7604 | ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer); |
| 7605 | if (tx_buffer == first) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7606 | break; |
| 7607 | if (i == 0) |
| 7608 | i = tx_ring->count; |
| 7609 | i--; |
| 7610 | } |
| 7611 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7612 | tx_ring->next_to_use = i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7613 | } |
| 7614 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7615 | static void ixgbe_atr(struct ixgbe_ring *ring, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7616 | struct ixgbe_tx_buffer *first) |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7617 | { |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7618 | struct ixgbe_q_vector *q_vector = ring->q_vector; |
| 7619 | union ixgbe_atr_hash_dword input = { .dword = 0 }; |
| 7620 | union ixgbe_atr_hash_dword common = { .dword = 0 }; |
| 7621 | union { |
| 7622 | unsigned char *network; |
| 7623 | struct iphdr *ipv4; |
| 7624 | struct ipv6hdr *ipv6; |
| 7625 | } hdr; |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 7626 | struct tcphdr *th; |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7627 | unsigned int hlen; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7628 | struct sk_buff *skb; |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 7629 | __be16 vlan_id; |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7630 | int l4_proto; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7631 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7632 | /* if ring doesn't have a interrupt vector, cannot perform ATR */ |
| 7633 | if (!q_vector) |
Guillaume Gaudonville | d3ead24 | 2010-06-29 18:29:00 +0000 | [diff] [blame] | 7634 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7635 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7636 | /* do nothing if sampling is disabled */ |
| 7637 | if (!ring->atr_sample_rate) |
| 7638 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7639 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7640 | ring->atr_count++; |
| 7641 | |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7642 | /* currently only IPv4/IPv6 with TCP is supported */ |
| 7643 | if ((first->protocol != htons(ETH_P_IP)) && |
| 7644 | (first->protocol != htons(ETH_P_IPV6))) |
| 7645 | return; |
| 7646 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7647 | /* snag network header to get L4 type and address */ |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7648 | skb = first->skb; |
| 7649 | hdr.network = skb_network_header(skb); |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7650 | #ifdef CONFIG_IXGBE_VXLAN |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 7651 | if (skb->encapsulation && |
| 7652 | first->protocol == htons(ETH_P_IP) && |
| 7653 | hdr.ipv4->protocol != IPPROTO_UDP) { |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7654 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7655 | |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 7656 | /* verify the port is recognized as VXLAN */ |
| 7657 | if (adapter->vxlan_port && |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7658 | udp_hdr(skb)->dest == adapter->vxlan_port) |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 7659 | hdr.network = skb_inner_network_header(skb); |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7660 | } |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 7661 | #endif /* CONFIG_IXGBE_VXLAN */ |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7662 | |
| 7663 | /* Currently only IPv4/IPv6 with TCP is supported */ |
| 7664 | switch (hdr.ipv4->version) { |
| 7665 | case IPVERSION: |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7666 | /* access ihl as u8 to avoid unaligned access on ia64 */ |
| 7667 | hlen = (hdr.network[0] & 0x0F) << 2; |
| 7668 | l4_proto = hdr.ipv4->protocol; |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7669 | break; |
| 7670 | case 6: |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7671 | hlen = hdr.network - skb->data; |
| 7672 | l4_proto = ipv6_find_hdr(skb, &hlen, IPPROTO_TCP, NULL, NULL); |
| 7673 | hlen -= hdr.network - skb->data; |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7674 | break; |
| 7675 | default: |
| 7676 | return; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7677 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7678 | |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 7679 | if (l4_proto != IPPROTO_TCP) |
| 7680 | return; |
| 7681 | |
| 7682 | th = (struct tcphdr *)(hdr.network + hlen); |
| 7683 | |
| 7684 | /* skip this packet since the socket is closing */ |
| 7685 | if (th->fin) |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7686 | return; |
| 7687 | |
| 7688 | /* sample on all syn packets or once every atr sample count */ |
| 7689 | if (!th->syn && (ring->atr_count < ring->atr_sample_rate)) |
| 7690 | return; |
| 7691 | |
| 7692 | /* reset sample count */ |
| 7693 | ring->atr_count = 0; |
| 7694 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7695 | vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT); |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7696 | |
| 7697 | /* |
| 7698 | * src and dst are inverted, think how the receiver sees them |
| 7699 | * |
| 7700 | * The input is broken into two sections, a non-compressed section |
| 7701 | * containing vm_pool, vlan_id, and flow_type. The rest of the data |
| 7702 | * is XORed together and stored in the compressed dword. |
| 7703 | */ |
| 7704 | input.formatted.vlan_id = vlan_id; |
| 7705 | |
| 7706 | /* |
| 7707 | * since src port and flex bytes occupy the same word XOR them together |
| 7708 | * and write the value to source port portion of compressed dword |
| 7709 | */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7710 | 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] | 7711 | common.port.src ^= th->dest ^ htons(ETH_P_8021Q); |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7712 | else |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7713 | common.port.src ^= th->dest ^ first->protocol; |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7714 | common.port.dst ^= th->source; |
| 7715 | |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7716 | switch (hdr.ipv4->version) { |
| 7717 | case IPVERSION: |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7718 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4; |
| 7719 | common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr; |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7720 | break; |
| 7721 | case 6: |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7722 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6; |
| 7723 | common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^ |
| 7724 | hdr.ipv6->saddr.s6_addr32[1] ^ |
| 7725 | hdr.ipv6->saddr.s6_addr32[2] ^ |
| 7726 | hdr.ipv6->saddr.s6_addr32[3] ^ |
| 7727 | hdr.ipv6->daddr.s6_addr32[0] ^ |
| 7728 | hdr.ipv6->daddr.s6_addr32[1] ^ |
| 7729 | hdr.ipv6->daddr.s6_addr32[2] ^ |
| 7730 | hdr.ipv6->daddr.s6_addr32[3]; |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 7731 | break; |
| 7732 | default: |
| 7733 | break; |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7734 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7735 | |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 7736 | if (hdr.network != skb_network_header(skb)) |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7737 | input.formatted.flow_type |= IXGBE_ATR_L4TYPE_TUNNEL_MASK; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7738 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7739 | /* 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] | 7740 | ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw, |
| 7741 | input, common, ring->queue_index); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7742 | } |
| 7743 | |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 7744 | 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] | 7745 | void *accel_priv, select_queue_fallback_t fallback) |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 7746 | { |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 7747 | struct ixgbe_fwd_adapter *fwd_adapter = accel_priv; |
| 7748 | #ifdef IXGBE_FCOE |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 7749 | struct ixgbe_adapter *adapter; |
| 7750 | struct ixgbe_ring_feature *f; |
| 7751 | int txq; |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 7752 | #endif |
| 7753 | |
| 7754 | if (fwd_adapter) |
| 7755 | return skb->queue_mapping + fwd_adapter->tx_base_queue; |
| 7756 | |
| 7757 | #ifdef IXGBE_FCOE |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 7758 | |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 7759 | /* |
| 7760 | * only execute the code below if protocol is FCoE |
| 7761 | * or FIP and we have FCoE enabled on the adapter |
| 7762 | */ |
| 7763 | switch (vlan_get_protocol(skb)) { |
Joe Perches | a1108ff | 2014-03-13 05:19:25 +0000 | [diff] [blame] | 7764 | case htons(ETH_P_FCOE): |
| 7765 | case htons(ETH_P_FIP): |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 7766 | adapter = netdev_priv(dev); |
Alexander Duyck | c087663 | 2012-05-10 00:01:46 +0000 | [diff] [blame] | 7767 | |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 7768 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 7769 | break; |
| 7770 | default: |
Daniel Borkmann | 99932d4 | 2014-02-16 15:55:20 +0100 | [diff] [blame] | 7771 | return fallback(dev, skb); |
Krishna Kumar | fdd3d63 | 2010-02-03 13:13:10 +0000 | [diff] [blame] | 7772 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7773 | |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 7774 | f = &adapter->ring_feature[RING_F_FCOE]; |
| 7775 | |
| 7776 | txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) : |
| 7777 | smp_processor_id(); |
| 7778 | |
| 7779 | while (txq >= f->indices) |
| 7780 | txq -= f->indices; |
| 7781 | |
| 7782 | return txq + f->offset; |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 7783 | #else |
Daniel Borkmann | 99932d4 | 2014-02-16 15:55:20 +0100 | [diff] [blame] | 7784 | return fallback(dev, skb); |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 7785 | #endif |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 7786 | } |
| 7787 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 7788 | netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb, |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 7789 | struct ixgbe_adapter *adapter, |
| 7790 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7791 | { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7792 | struct ixgbe_tx_buffer *first; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 7793 | int tso; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7794 | u32 tx_flags = 0; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7795 | unsigned short f; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7796 | u16 count = TXD_USE_COUNT(skb_headlen(skb)); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7797 | __be16 protocol = skb->protocol; |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 7798 | u8 hdr_len = 0; |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 7799 | |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7800 | /* |
| 7801 | * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD, |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 7802 | * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD, |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7803 | * + 2 desc gap to keep tail from touching head, |
| 7804 | * + 1 desc for context descriptor, |
| 7805 | * otherwise try next time |
| 7806 | */ |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7807 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) |
| 7808 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size); |
Alexander Duyck | 7f66162 | 2013-02-09 01:19:55 +0000 | [diff] [blame] | 7809 | |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7810 | if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) { |
| 7811 | tx_ring->tx_stats.tx_busy++; |
| 7812 | return NETDEV_TX_BUSY; |
| 7813 | } |
| 7814 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7815 | /* record the location of the first descriptor for this packet */ |
| 7816 | first = &tx_ring->tx_buffer_info[tx_ring->next_to_use]; |
| 7817 | first->skb = skb; |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 7818 | first->bytecount = skb->len; |
| 7819 | first->gso_segs = 1; |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7820 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7821 | /* 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] | 7822 | if (skb_vlan_tag_present(skb)) { |
| 7823 | tx_flags |= skb_vlan_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7824 | tx_flags |= IXGBE_TX_FLAGS_HW_VLAN; |
| 7825 | /* 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] | 7826 | } else if (protocol == htons(ETH_P_8021Q)) { |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7827 | struct vlan_hdr *vhdr, _vhdr; |
| 7828 | vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr); |
| 7829 | if (!vhdr) |
| 7830 | goto out_drop; |
| 7831 | |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 7832 | tx_flags |= ntohs(vhdr->h_vlan_TCI) << |
| 7833 | IXGBE_TX_FLAGS_VLAN_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7834 | tx_flags |= IXGBE_TX_FLAGS_SW_VLAN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7835 | } |
Toshiaki Makita | 0213668 | 2015-01-29 20:37:09 +0900 | [diff] [blame] | 7836 | protocol = vlan_get_protocol(skb); |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7837 | |
Mark Rustad | d523493 | 2014-08-09 07:02:09 +0000 | [diff] [blame] | 7838 | if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && |
| 7839 | adapter->ptp_clock && |
| 7840 | !test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS, |
| 7841 | &adapter->state)) { |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7842 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; |
| 7843 | tx_flags |= IXGBE_TX_FLAGS_TSTAMP; |
Jacob Keller | 891dc08 | 2012-12-05 07:24:46 +0000 | [diff] [blame] | 7844 | |
| 7845 | /* schedule check for Tx timestamp */ |
| 7846 | adapter->ptp_tx_skb = skb_get(skb); |
| 7847 | adapter->ptp_tx_start = jiffies; |
| 7848 | schedule_work(&adapter->ptp_tx_work); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7849 | } |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7850 | |
Jakub Kicinski | ff29a86 | 2014-03-15 14:55:16 +0000 | [diff] [blame] | 7851 | skb_tx_timestamp(skb); |
| 7852 | |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 7853 | #ifdef CONFIG_PCI_IOV |
| 7854 | /* |
| 7855 | * Use the l2switch_enable flag - would be false if the DMA |
| 7856 | * Tx switch had been disabled. |
| 7857 | */ |
| 7858 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7859 | tx_flags |= IXGBE_TX_FLAGS_CC; |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 7860 | |
| 7861 | #endif |
John Fastabend | 32701dc | 2011-09-27 03:51:56 +0000 | [diff] [blame] | 7862 | /* 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] | 7863 | if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && |
Alexander Duyck | 09dca47 | 2011-07-20 00:09:10 +0000 | [diff] [blame] | 7864 | ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) || |
| 7865 | (skb->priority != TC_PRIO_CONTROL))) { |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7866 | tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK; |
John Fastabend | 32701dc | 2011-09-27 03:51:56 +0000 | [diff] [blame] | 7867 | tx_flags |= (skb->priority & 0x7) << |
| 7868 | IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7869 | if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) { |
| 7870 | struct vlan_ethhdr *vhdr; |
Francois Romieu | 2049e1f | 2014-03-30 03:14:27 +0000 | [diff] [blame] | 7871 | |
| 7872 | if (skb_cow_head(skb, 0)) |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7873 | goto out_drop; |
| 7874 | vhdr = (struct vlan_ethhdr *)skb->data; |
| 7875 | vhdr->h_vlan_TCI = htons(tx_flags >> |
| 7876 | IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 7877 | } else { |
| 7878 | tx_flags |= IXGBE_TX_FLAGS_HW_VLAN; |
| 7879 | } |
| 7880 | } |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7881 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7882 | /* record initial flags and protocol */ |
| 7883 | first->tx_flags = tx_flags; |
| 7884 | first->protocol = protocol; |
| 7885 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7886 | #ifdef IXGBE_FCOE |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7887 | /* setup tx offload for FCoE */ |
Joe Perches | a1108ff | 2014-03-13 05:19:25 +0000 | [diff] [blame] | 7888 | if ((protocol == htons(ETH_P_FCOE)) && |
Alexander Duyck | a58915c | 2012-05-25 06:38:18 +0000 | [diff] [blame] | 7889 | (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) { |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7890 | tso = ixgbe_fso(tx_ring, first, &hdr_len); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7891 | if (tso < 0) |
| 7892 | goto out_drop; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7893 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7894 | goto xmit_fcoe; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 7895 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7896 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7897 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7898 | tso = ixgbe_tso(tx_ring, first, &hdr_len); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7899 | if (tso < 0) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7900 | goto out_drop; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7901 | else if (!tso) |
| 7902 | ixgbe_tx_csum(tx_ring, first); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7903 | |
| 7904 | /* add the ATR filter if ATR is on */ |
| 7905 | if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state)) |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7906 | ixgbe_atr(tx_ring, first); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7907 | |
| 7908 | #ifdef IXGBE_FCOE |
| 7909 | xmit_fcoe: |
| 7910 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7911 | ixgbe_tx_map(tx_ring, first, hdr_len); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7912 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7913 | return NETDEV_TX_OK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7914 | |
| 7915 | out_drop: |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7916 | dev_kfree_skb_any(first->skb); |
| 7917 | first->skb = NULL; |
| 7918 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7919 | return NETDEV_TX_OK; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7920 | } |
| 7921 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 7922 | static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb, |
| 7923 | struct net_device *netdev, |
| 7924 | struct ixgbe_ring *ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7925 | { |
| 7926 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7927 | struct ixgbe_ring *tx_ring; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7928 | |
Alexander Duyck | a50c29d | 2012-02-08 07:50:40 +0000 | [diff] [blame] | 7929 | /* |
| 7930 | * The minimum packet size for olinfo paylen is 17 so pad the skb |
| 7931 | * in order to meet this minimum size requirement. |
| 7932 | */ |
Alexander Duyck | a94d9e2 | 2014-12-03 08:17:39 -0800 | [diff] [blame] | 7933 | if (skb_put_padto(skb, 17)) |
| 7934 | return NETDEV_TX_OK; |
Alexander Duyck | a50c29d | 2012-02-08 07:50:40 +0000 | [diff] [blame] | 7935 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 7936 | tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping]; |
| 7937 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7938 | return ixgbe_xmit_frame_ring(skb, adapter, tx_ring); |
| 7939 | } |
| 7940 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 7941 | static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, |
| 7942 | struct net_device *netdev) |
| 7943 | { |
| 7944 | return __ixgbe_xmit_frame(skb, netdev, NULL); |
| 7945 | } |
| 7946 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7947 | /** |
| 7948 | * ixgbe_set_mac - Change the Ethernet Address of the NIC |
| 7949 | * @netdev: network interface device structure |
| 7950 | * @p: pointer to an address structure |
| 7951 | * |
| 7952 | * Returns 0 on success, negative on failure |
| 7953 | **/ |
| 7954 | static int ixgbe_set_mac(struct net_device *netdev, void *p) |
| 7955 | { |
| 7956 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7957 | struct ixgbe_hw *hw = &adapter->hw; |
| 7958 | struct sockaddr *addr = p; |
| 7959 | |
| 7960 | if (!is_valid_ether_addr(addr->sa_data)) |
| 7961 | return -EADDRNOTAVAIL; |
| 7962 | |
| 7963 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7964 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7965 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 7966 | ixgbe_mac_set_default_filter(adapter); |
| 7967 | |
| 7968 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7969 | } |
| 7970 | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7971 | static int |
| 7972 | ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr) |
| 7973 | { |
| 7974 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7975 | struct ixgbe_hw *hw = &adapter->hw; |
| 7976 | u16 value; |
| 7977 | int rc; |
| 7978 | |
| 7979 | if (prtad != hw->phy.mdio.prtad) |
| 7980 | return -EINVAL; |
| 7981 | rc = hw->phy.ops.read_reg(hw, addr, devad, &value); |
| 7982 | if (!rc) |
| 7983 | rc = value; |
| 7984 | return rc; |
| 7985 | } |
| 7986 | |
| 7987 | static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad, |
| 7988 | u16 addr, u16 value) |
| 7989 | { |
| 7990 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7991 | struct ixgbe_hw *hw = &adapter->hw; |
| 7992 | |
| 7993 | if (prtad != hw->phy.mdio.prtad) |
| 7994 | return -EINVAL; |
| 7995 | return hw->phy.ops.write_reg(hw, addr, devad, value); |
| 7996 | } |
| 7997 | |
| 7998 | static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd) |
| 7999 | { |
| 8000 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8001 | |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 8002 | switch (cmd) { |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 8003 | case SIOCSHWTSTAMP: |
Jacob Keller | 93501d4 | 2014-02-28 15:48:58 -0800 | [diff] [blame] | 8004 | return ixgbe_ptp_set_ts_config(adapter, req); |
| 8005 | case SIOCGHWTSTAMP: |
| 8006 | return ixgbe_ptp_get_ts_config(adapter, req); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 8007 | default: |
| 8008 | return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd); |
| 8009 | } |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 8010 | } |
| 8011 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8012 | /** |
| 8013 | * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 8014 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8015 | * @netdev: network interface device structure |
| 8016 | * |
| 8017 | * Returns non-zero on failure |
| 8018 | **/ |
| 8019 | static int ixgbe_add_sanmac_netdev(struct net_device *dev) |
| 8020 | { |
| 8021 | int err = 0; |
| 8022 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 8023 | struct ixgbe_hw *hw = &adapter->hw; |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8024 | |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 8025 | if (is_valid_ether_addr(hw->mac.san_addr)) { |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8026 | rtnl_lock(); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 8027 | 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] | 8028 | rtnl_unlock(); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 8029 | |
| 8030 | /* update SAN MAC vmdq pool selection */ |
| 8031 | hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0)); |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8032 | } |
| 8033 | return err; |
| 8034 | } |
| 8035 | |
| 8036 | /** |
| 8037 | * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 8038 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8039 | * @netdev: network interface device structure |
| 8040 | * |
| 8041 | * Returns non-zero on failure |
| 8042 | **/ |
| 8043 | static int ixgbe_del_sanmac_netdev(struct net_device *dev) |
| 8044 | { |
| 8045 | int err = 0; |
| 8046 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 8047 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 8048 | |
| 8049 | if (is_valid_ether_addr(mac->san_addr)) { |
| 8050 | rtnl_lock(); |
| 8051 | err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 8052 | rtnl_unlock(); |
| 8053 | } |
| 8054 | return err; |
| 8055 | } |
| 8056 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8057 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 8058 | /* |
| 8059 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 8060 | * without having to re-enable interrupts. It's not called while |
| 8061 | * the interrupt routine is executing. |
| 8062 | */ |
| 8063 | static void ixgbe_netpoll(struct net_device *netdev) |
| 8064 | { |
| 8065 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 8066 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8067 | |
Alexander Duyck | 1a647bd | 2010-01-13 01:49:13 +0000 | [diff] [blame] | 8068 | /* if interface is down do nothing */ |
| 8069 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 8070 | return; |
| 8071 | |
Alexander Duyck | 856f606 | 2015-02-25 17:45:54 +0000 | [diff] [blame] | 8072 | /* loop through and schedule all active queues */ |
| 8073 | for (i = 0; i < adapter->num_q_vectors; i++) |
| 8074 | ixgbe_msix_clean_rings(0, adapter->q_vector[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8075 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8076 | |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 8077 | #endif |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8078 | static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev, |
| 8079 | struct rtnl_link_stats64 *stats) |
| 8080 | { |
| 8081 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8082 | int i; |
| 8083 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8084 | rcu_read_lock(); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8085 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8086 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8087 | u64 bytes, packets; |
| 8088 | unsigned int start; |
| 8089 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8090 | if (ring) { |
| 8091 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 8092 | start = u64_stats_fetch_begin_irq(&ring->syncp); |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8093 | packets = ring->stats.packets; |
| 8094 | bytes = ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 8095 | } while (u64_stats_fetch_retry_irq(&ring->syncp, start)); |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8096 | stats->rx_packets += packets; |
| 8097 | stats->rx_bytes += bytes; |
| 8098 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8099 | } |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 8100 | |
| 8101 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 8102 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]); |
| 8103 | u64 bytes, packets; |
| 8104 | unsigned int start; |
| 8105 | |
| 8106 | if (ring) { |
| 8107 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 8108 | start = u64_stats_fetch_begin_irq(&ring->syncp); |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 8109 | packets = ring->stats.packets; |
| 8110 | bytes = ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 8111 | } while (u64_stats_fetch_retry_irq(&ring->syncp, start)); |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 8112 | stats->tx_packets += packets; |
| 8113 | stats->tx_bytes += bytes; |
| 8114 | } |
| 8115 | } |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8116 | rcu_read_unlock(); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8117 | /* following stats updated by ixgbe_watchdog_task() */ |
| 8118 | stats->multicast = netdev->stats.multicast; |
| 8119 | stats->rx_errors = netdev->stats.rx_errors; |
| 8120 | stats->rx_length_errors = netdev->stats.rx_length_errors; |
| 8121 | stats->rx_crc_errors = netdev->stats.rx_crc_errors; |
| 8122 | stats->rx_missed_errors = netdev->stats.rx_missed_errors; |
| 8123 | return stats; |
| 8124 | } |
| 8125 | |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 8126 | #ifdef CONFIG_IXGBE_DCB |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 8127 | /** |
| 8128 | * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid. |
| 8129 | * @adapter: pointer to ixgbe_adapter |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8130 | * @tc: number of traffic classes currently enabled |
| 8131 | * |
| 8132 | * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm |
| 8133 | * 802.1Q priority maps to a packet buffer that exists. |
| 8134 | */ |
| 8135 | static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc) |
| 8136 | { |
| 8137 | struct ixgbe_hw *hw = &adapter->hw; |
| 8138 | u32 reg, rsave; |
| 8139 | int i; |
| 8140 | |
| 8141 | /* 82598 have a static priority to TC mapping that can not |
| 8142 | * be changed so no validation is needed. |
| 8143 | */ |
| 8144 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 8145 | return; |
| 8146 | |
| 8147 | reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC); |
| 8148 | rsave = reg; |
| 8149 | |
| 8150 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 8151 | u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT); |
| 8152 | |
| 8153 | /* If up2tc is out of bounds default to zero */ |
| 8154 | if (up2tc > tc) |
| 8155 | reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT); |
| 8156 | } |
| 8157 | |
| 8158 | if (reg != rsave) |
| 8159 | IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg); |
| 8160 | |
| 8161 | return; |
| 8162 | } |
| 8163 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 8164 | /** |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 8165 | * ixgbe_set_prio_tc_map - Configure netdev prio tc map |
| 8166 | * @adapter: Pointer to adapter struct |
| 8167 | * |
| 8168 | * Populate the netdev user priority to tc map |
| 8169 | */ |
| 8170 | static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter) |
| 8171 | { |
| 8172 | struct net_device *dev = adapter->netdev; |
| 8173 | struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg; |
| 8174 | struct ieee_ets *ets = adapter->ixgbe_ieee_ets; |
| 8175 | u8 prio; |
| 8176 | |
| 8177 | for (prio = 0; prio < MAX_USER_PRIORITY; prio++) { |
| 8178 | u8 tc = 0; |
| 8179 | |
| 8180 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) |
| 8181 | tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio); |
| 8182 | else if (ets) |
| 8183 | tc = ets->prio_tc[prio]; |
| 8184 | |
| 8185 | netdev_set_prio_tc_map(dev, prio, tc); |
| 8186 | } |
| 8187 | } |
| 8188 | |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 8189 | #endif /* CONFIG_IXGBE_DCB */ |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 8190 | /** |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 8191 | * ixgbe_setup_tc - configure net_device for multiple traffic classes |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8192 | * |
| 8193 | * @netdev: net device to configure |
| 8194 | * @tc: number of traffic classes to enable |
| 8195 | */ |
| 8196 | int ixgbe_setup_tc(struct net_device *dev, u8 tc) |
| 8197 | { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8198 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 8199 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8200 | bool pools; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8201 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8202 | /* Hardware supports up to 8 traffic classes */ |
Emil Tantilov | 7e3f5c8 | 2015-07-09 12:28:59 -0700 | [diff] [blame] | 8203 | if (tc > adapter->dcb_cfg.num_tcs.pg_tcs) |
| 8204 | return -EINVAL; |
| 8205 | |
| 8206 | if (hw->mac.type == ixgbe_mac_82598EB && tc && tc < MAX_TRAFFIC_CLASS) |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8207 | return -EINVAL; |
| 8208 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8209 | pools = (find_first_zero_bit(&adapter->fwd_bitmask, 32) > 1); |
| 8210 | if (tc && pools && adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS) |
| 8211 | return -EBUSY; |
| 8212 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8213 | /* Hardware has to reinitialize queues and interrupts to |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 8214 | * match packet buffer alignment. Unfortunately, the |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8215 | * hardware is not flexible enough to do this dynamically. |
| 8216 | */ |
| 8217 | if (netif_running(dev)) |
| 8218 | ixgbe_close(dev); |
Alexander Duyck | bf4d67d | 2015-10-20 13:28:17 -0700 | [diff] [blame] | 8219 | else |
| 8220 | ixgbe_reset(adapter); |
| 8221 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8222 | ixgbe_clear_interrupt_scheme(adapter); |
| 8223 | |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 8224 | #ifdef CONFIG_IXGBE_DCB |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8225 | if (tc) { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8226 | netdev_set_num_tc(dev, tc); |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 8227 | ixgbe_set_prio_tc_map(adapter); |
| 8228 | |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8229 | adapter->flags |= IXGBE_FLAG_DCB_ENABLED; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8230 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 8231 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 8232 | adapter->last_lfc_mode = adapter->hw.fc.requested_mode; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8233 | adapter->hw.fc.requested_mode = ixgbe_fc_none; |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 8234 | } |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8235 | } else { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8236 | netdev_reset_tc(dev); |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 8237 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 8238 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 8239 | adapter->hw.fc.requested_mode = adapter->last_lfc_mode; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8240 | |
| 8241 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8242 | |
| 8243 | adapter->temp_dcb_cfg.pfc_mode_enable = false; |
| 8244 | adapter->dcb_cfg.pfc_mode_enable = false; |
| 8245 | } |
| 8246 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8247 | ixgbe_validate_rtr(adapter, tc); |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 8248 | |
| 8249 | #endif /* CONFIG_IXGBE_DCB */ |
| 8250 | ixgbe_init_interrupt_scheme(adapter); |
| 8251 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8252 | if (netif_running(dev)) |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 8253 | return ixgbe_open(dev); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8254 | |
| 8255 | return 0; |
| 8256 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8257 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8258 | static int ixgbe_delete_clsu32(struct ixgbe_adapter *adapter, |
| 8259 | struct tc_cls_u32_offload *cls) |
| 8260 | { |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8261 | u32 uhtid = TC_U32_USERHTID(cls->knode.handle); |
| 8262 | u32 loc; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8263 | int err; |
| 8264 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8265 | if ((uhtid != 0x800) && (uhtid >= IXGBE_MAX_LINK_HANDLE)) |
| 8266 | return -EINVAL; |
| 8267 | |
| 8268 | loc = cls->knode.handle & 0xfffff; |
| 8269 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8270 | spin_lock(&adapter->fdir_perfect_lock); |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8271 | err = ixgbe_update_ethtool_fdir_entry(adapter, NULL, loc); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8272 | spin_unlock(&adapter->fdir_perfect_lock); |
| 8273 | return err; |
| 8274 | } |
| 8275 | |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8276 | static int ixgbe_configure_clsu32_add_hnode(struct ixgbe_adapter *adapter, |
| 8277 | __be16 protocol, |
| 8278 | struct tc_cls_u32_offload *cls) |
| 8279 | { |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8280 | u32 uhtid = TC_U32_USERHTID(cls->hnode.handle); |
| 8281 | |
| 8282 | if (uhtid >= IXGBE_MAX_LINK_HANDLE) |
| 8283 | return -EINVAL; |
| 8284 | |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8285 | /* This ixgbe devices do not support hash tables at the moment |
| 8286 | * so abort when given hash tables. |
| 8287 | */ |
| 8288 | if (cls->hnode.divisor > 0) |
| 8289 | return -EINVAL; |
| 8290 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8291 | set_bit(uhtid - 1, &adapter->tables); |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8292 | return 0; |
| 8293 | } |
| 8294 | |
| 8295 | static int ixgbe_configure_clsu32_del_hnode(struct ixgbe_adapter *adapter, |
| 8296 | struct tc_cls_u32_offload *cls) |
| 8297 | { |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8298 | u32 uhtid = TC_U32_USERHTID(cls->hnode.handle); |
| 8299 | |
| 8300 | if (uhtid >= IXGBE_MAX_LINK_HANDLE) |
| 8301 | return -EINVAL; |
| 8302 | |
| 8303 | clear_bit(uhtid - 1, &adapter->tables); |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8304 | return 0; |
| 8305 | } |
| 8306 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8307 | static int ixgbe_configure_clsu32(struct ixgbe_adapter *adapter, |
| 8308 | __be16 protocol, |
| 8309 | struct tc_cls_u32_offload *cls) |
| 8310 | { |
| 8311 | u32 loc = cls->knode.handle & 0xfffff; |
| 8312 | struct ixgbe_hw *hw = &adapter->hw; |
| 8313 | struct ixgbe_mat_field *field_ptr; |
| 8314 | struct ixgbe_fdir_filter *input; |
| 8315 | union ixgbe_atr_input mask; |
| 8316 | #ifdef CONFIG_NET_CLS_ACT |
| 8317 | const struct tc_action *a; |
| 8318 | #endif |
| 8319 | int i, err = 0; |
| 8320 | u8 queue; |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8321 | u32 uhtid, link_uhtid; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8322 | |
| 8323 | memset(&mask, 0, sizeof(union ixgbe_atr_input)); |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8324 | uhtid = TC_U32_USERHTID(cls->knode.handle); |
| 8325 | link_uhtid = TC_U32_USERHTID(cls->knode.link_handle); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8326 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8327 | /* At the moment cls_u32 jumps to network layer and skips past |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8328 | * L2 headers. The canonical method to match L2 frames is to use |
| 8329 | * negative values. However this is error prone at best but really |
| 8330 | * 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] | 8331 | * 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] | 8332 | * headers when needed. |
| 8333 | */ |
| 8334 | if (protocol != htons(ETH_P_IP)) |
| 8335 | return -EINVAL; |
| 8336 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8337 | if (link_uhtid) { |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8338 | struct ixgbe_nexthdr *nexthdr = ixgbe_ipv4_jumps; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8339 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8340 | if (link_uhtid >= IXGBE_MAX_LINK_HANDLE) |
| 8341 | return -EINVAL; |
| 8342 | |
| 8343 | if (!test_bit(link_uhtid - 1, &adapter->tables)) |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8344 | return -EINVAL; |
| 8345 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8346 | for (i = 0; nexthdr[i].jump; i++) { |
Amritha Nambiar | 4ae7834 | 2016-03-09 18:32:16 -0500 | [diff] [blame] | 8347 | if (nexthdr[i].o != cls->knode.sel->offoff || |
| 8348 | nexthdr[i].s != cls->knode.sel->offshift || |
| 8349 | nexthdr[i].m != cls->knode.sel->offmask || |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8350 | /* do not support multiple key jumps its just mad */ |
| 8351 | cls->knode.sel->nkeys > 1) |
| 8352 | return -EINVAL; |
| 8353 | |
Amritha Nambiar | 4ae7834 | 2016-03-09 18:32:16 -0500 | [diff] [blame] | 8354 | if (nexthdr[i].off == cls->knode.sel->keys[0].off && |
| 8355 | nexthdr[i].val == cls->knode.sel->keys[0].val && |
| 8356 | nexthdr[i].mask == cls->knode.sel->keys[0].mask) { |
| 8357 | adapter->jump_tables[link_uhtid] = |
| 8358 | nexthdr[i].jump; |
| 8359 | break; |
| 8360 | } |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8361 | } |
| 8362 | return 0; |
| 8363 | } |
| 8364 | |
| 8365 | if (loc >= ((1024 << adapter->fdir_pballoc) - 2)) { |
| 8366 | e_err(drv, "Location out of range\n"); |
| 8367 | return -EINVAL; |
| 8368 | } |
| 8369 | |
| 8370 | /* cls u32 is a graph starting at root node 0x800. The driver tracks |
| 8371 | * links and also the fields used to advance the parser across each |
| 8372 | * link (e.g. nexthdr/eat parameters from 'tc'). This way we can map |
| 8373 | * the u32 graph onto the hardware parse graph denoted in ixgbe_model.h |
| 8374 | * To add support for new nodes update ixgbe_model.h parse structures |
| 8375 | * this function _should_ be generic try not to hardcode values here. |
| 8376 | */ |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8377 | if (uhtid == 0x800) { |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8378 | field_ptr = adapter->jump_tables[0]; |
| 8379 | } else { |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8380 | if (uhtid >= IXGBE_MAX_LINK_HANDLE) |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8381 | return -EINVAL; |
| 8382 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8383 | field_ptr = adapter->jump_tables[uhtid]; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8384 | } |
| 8385 | |
| 8386 | if (!field_ptr) |
| 8387 | return -EINVAL; |
| 8388 | |
| 8389 | input = kzalloc(sizeof(*input), GFP_KERNEL); |
| 8390 | if (!input) |
| 8391 | return -ENOMEM; |
| 8392 | |
| 8393 | for (i = 0; i < cls->knode.sel->nkeys; i++) { |
| 8394 | int off = cls->knode.sel->keys[i].off; |
| 8395 | __be32 val = cls->knode.sel->keys[i].val; |
| 8396 | __be32 m = cls->knode.sel->keys[i].mask; |
| 8397 | bool found_entry = false; |
| 8398 | int j; |
| 8399 | |
| 8400 | for (j = 0; field_ptr[j].val; j++) { |
Sridhar Samudrala | ebd83ad | 2016-03-07 09:41:48 -0800 | [diff] [blame] | 8401 | if (field_ptr[j].off == off) { |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8402 | field_ptr[j].val(input, &mask, val, m); |
| 8403 | input->filter.formatted.flow_type |= |
| 8404 | field_ptr[j].type; |
| 8405 | found_entry = true; |
| 8406 | break; |
| 8407 | } |
| 8408 | } |
| 8409 | |
| 8410 | if (!found_entry) |
| 8411 | goto err_out; |
| 8412 | } |
| 8413 | |
| 8414 | mask.formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK | |
| 8415 | IXGBE_ATR_L4TYPE_MASK; |
| 8416 | |
| 8417 | if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4) |
| 8418 | mask.formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK; |
| 8419 | |
| 8420 | #ifdef CONFIG_NET_CLS_ACT |
| 8421 | if (list_empty(&cls->knode.exts->actions)) |
| 8422 | goto err_out; |
| 8423 | |
| 8424 | list_for_each_entry(a, &cls->knode.exts->actions, list) { |
| 8425 | if (!is_tcf_gact_shot(a)) |
| 8426 | goto err_out; |
| 8427 | } |
| 8428 | #endif |
| 8429 | |
| 8430 | input->action = IXGBE_FDIR_DROP_QUEUE; |
| 8431 | queue = IXGBE_FDIR_DROP_QUEUE; |
| 8432 | input->sw_idx = loc; |
| 8433 | |
| 8434 | spin_lock(&adapter->fdir_perfect_lock); |
| 8435 | |
| 8436 | if (hlist_empty(&adapter->fdir_filter_list)) { |
| 8437 | memcpy(&adapter->fdir_mask, &mask, sizeof(mask)); |
| 8438 | err = ixgbe_fdir_set_input_mask_82599(hw, &mask); |
| 8439 | if (err) |
| 8440 | goto err_out_w_lock; |
| 8441 | } else if (memcmp(&adapter->fdir_mask, &mask, sizeof(mask))) { |
| 8442 | err = -EINVAL; |
| 8443 | goto err_out_w_lock; |
| 8444 | } |
| 8445 | |
| 8446 | ixgbe_atr_compute_perfect_hash_82599(&input->filter, &mask); |
| 8447 | err = ixgbe_fdir_write_perfect_filter_82599(hw, &input->filter, |
| 8448 | input->sw_idx, queue); |
| 8449 | if (!err) |
| 8450 | ixgbe_update_ethtool_fdir_entry(adapter, input, input->sw_idx); |
| 8451 | spin_unlock(&adapter->fdir_perfect_lock); |
| 8452 | |
| 8453 | return err; |
| 8454 | err_out_w_lock: |
| 8455 | spin_unlock(&adapter->fdir_perfect_lock); |
| 8456 | err_out: |
| 8457 | kfree(input); |
| 8458 | return -EINVAL; |
| 8459 | } |
| 8460 | |
Emil Tantilov | 6e2a60b | 2016-02-17 15:55:06 -0800 | [diff] [blame] | 8461 | static int __ixgbe_setup_tc(struct net_device *dev, u32 handle, __be16 proto, |
| 8462 | struct tc_to_netdev *tc) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 8463 | { |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8464 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 8465 | |
| 8466 | if (TC_H_MAJ(handle) == TC_H_MAJ(TC_H_INGRESS) && |
| 8467 | tc->type == TC_SETUP_CLSU32) { |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8468 | switch (tc->cls_u32->command) { |
| 8469 | case TC_CLSU32_NEW_KNODE: |
| 8470 | case TC_CLSU32_REPLACE_KNODE: |
| 8471 | return ixgbe_configure_clsu32(adapter, |
| 8472 | proto, tc->cls_u32); |
| 8473 | case TC_CLSU32_DELETE_KNODE: |
| 8474 | return ixgbe_delete_clsu32(adapter, tc->cls_u32); |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8475 | case TC_CLSU32_NEW_HNODE: |
| 8476 | case TC_CLSU32_REPLACE_HNODE: |
| 8477 | return ixgbe_configure_clsu32_add_hnode(adapter, proto, |
| 8478 | tc->cls_u32); |
| 8479 | case TC_CLSU32_DELETE_HNODE: |
| 8480 | return ixgbe_configure_clsu32_del_hnode(adapter, |
| 8481 | tc->cls_u32); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8482 | default: |
| 8483 | return -EINVAL; |
| 8484 | } |
| 8485 | } |
| 8486 | |
John Fastabend | 5eb4dce | 2016-02-29 11:26:13 -0800 | [diff] [blame] | 8487 | if (tc->type != TC_SETUP_MQPRIO) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 8488 | return -EINVAL; |
| 8489 | |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 8490 | return ixgbe_setup_tc(dev, tc->tc); |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 8491 | } |
| 8492 | |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 8493 | #ifdef CONFIG_PCI_IOV |
| 8494 | void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter) |
| 8495 | { |
| 8496 | struct net_device *netdev = adapter->netdev; |
| 8497 | |
| 8498 | rtnl_lock(); |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 8499 | ixgbe_setup_tc(netdev, netdev_get_num_tc(netdev)); |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 8500 | rtnl_unlock(); |
| 8501 | } |
| 8502 | |
| 8503 | #endif |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8504 | void ixgbe_do_reset(struct net_device *netdev) |
| 8505 | { |
| 8506 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8507 | |
| 8508 | if (netif_running(netdev)) |
| 8509 | ixgbe_reinit_locked(adapter); |
| 8510 | else |
| 8511 | ixgbe_reset(adapter); |
| 8512 | } |
| 8513 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 8514 | static netdev_features_t ixgbe_fix_features(struct net_device *netdev, |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8515 | netdev_features_t features) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8516 | { |
| 8517 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8518 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8519 | /* If Rx checksum is disabled, then RSC/LRO should also be disabled */ |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8520 | if (!(features & NETIF_F_RXCSUM)) |
| 8521 | features &= ~NETIF_F_LRO; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8522 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8523 | /* Turn off LRO if not RSC capable */ |
| 8524 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) |
| 8525 | features &= ~NETIF_F_LRO; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 8526 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8527 | return features; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8528 | } |
| 8529 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 8530 | static int ixgbe_set_features(struct net_device *netdev, |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8531 | netdev_features_t features) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8532 | { |
| 8533 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8534 | netdev_features_t changed = netdev->features ^ features; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8535 | bool need_reset = false; |
| 8536 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8537 | /* Make sure RSC matches LRO, reset if change */ |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8538 | if (!(features & NETIF_F_LRO)) { |
| 8539 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8540 | need_reset = true; |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8541 | adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED; |
| 8542 | } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) && |
| 8543 | !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) { |
| 8544 | if (adapter->rx_itr_setting == 1 || |
| 8545 | adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) { |
| 8546 | adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED; |
| 8547 | need_reset = true; |
| 8548 | } else if ((changed ^ features) & NETIF_F_LRO) { |
| 8549 | e_info(probe, "rx-usecs set too low, " |
| 8550 | "disabling RSC\n"); |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8551 | } |
| 8552 | } |
| 8553 | |
| 8554 | /* |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8555 | * Check if Flow Director n-tuple support or hw_tc support was |
| 8556 | * enabled or disabled. If the state changed, we need to reset. |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8557 | */ |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8558 | if ((features & NETIF_F_NTUPLE) || (features & NETIF_F_HW_TC)) { |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8559 | /* turn off ATR, enable perfect filters and reset */ |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 8560 | if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) |
| 8561 | need_reset = true; |
| 8562 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8563 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 8564 | adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8565 | } else { |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 8566 | /* turn off perfect filters, enable ATR and reset */ |
| 8567 | if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 8568 | need_reset = true; |
| 8569 | |
| 8570 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 8571 | |
| 8572 | /* We cannot enable ATR if SR-IOV is enabled */ |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8573 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED || |
| 8574 | /* We cannot enable ATR if we have 2 or more tcs */ |
| 8575 | (netdev_get_num_tc(netdev) > 1) || |
| 8576 | /* We cannot enable ATR if RSS is disabled */ |
| 8577 | (adapter->ring_feature[RING_F_RSS].limit <= 1) || |
| 8578 | /* A sample rate of 0 indicates ATR disabled */ |
| 8579 | (!adapter->atr_sample_rate)) |
| 8580 | ; /* do nothing not supported */ |
| 8581 | else /* otherwise supported and set the flag */ |
| 8582 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8583 | } |
| 8584 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 8585 | if (changed & NETIF_F_RXALL) |
| 8586 | need_reset = true; |
| 8587 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 8588 | netdev->features = features; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8589 | |
| 8590 | #ifdef CONFIG_IXGBE_VXLAN |
| 8591 | if ((adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) { |
| 8592 | if (features & NETIF_F_RXCSUM) |
| 8593 | adapter->flags2 |= IXGBE_FLAG2_VXLAN_REREG_NEEDED; |
| 8594 | else |
| 8595 | ixgbe_clear_vxlan_port(adapter); |
| 8596 | } |
| 8597 | #endif /* CONFIG_IXGBE_VXLAN */ |
| 8598 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8599 | if (need_reset) |
| 8600 | ixgbe_do_reset(netdev); |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 8601 | else if (changed & (NETIF_F_HW_VLAN_CTAG_RX | |
| 8602 | NETIF_F_HW_VLAN_CTAG_FILTER)) |
| 8603 | ixgbe_set_rx_mode(netdev); |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8604 | |
| 8605 | return 0; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8606 | } |
| 8607 | |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8608 | #ifdef CONFIG_IXGBE_VXLAN |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8609 | /** |
| 8610 | * ixgbe_add_vxlan_port - Get notifications about VXLAN ports that come up |
| 8611 | * @dev: The port's netdev |
| 8612 | * @sa_family: Socket Family that VXLAN is notifiying us about |
| 8613 | * @port: New UDP port number that VXLAN started listening to |
| 8614 | **/ |
| 8615 | static void ixgbe_add_vxlan_port(struct net_device *dev, sa_family_t sa_family, |
| 8616 | __be16 port) |
| 8617 | { |
| 8618 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 8619 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8620 | |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8621 | if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) |
| 8622 | return; |
| 8623 | |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8624 | if (sa_family == AF_INET6) |
| 8625 | return; |
| 8626 | |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 8627 | if (adapter->vxlan_port == port) |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8628 | return; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8629 | |
| 8630 | if (adapter->vxlan_port) { |
| 8631 | netdev_info(dev, |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8632 | "Hit Max num of VXLAN ports, not adding port %d\n", |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 8633 | ntohs(port)); |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8634 | return; |
| 8635 | } |
| 8636 | |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 8637 | adapter->vxlan_port = port; |
| 8638 | IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, ntohs(port)); |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8639 | } |
| 8640 | |
| 8641 | /** |
| 8642 | * ixgbe_del_vxlan_port - Get notifications about VXLAN ports that go away |
| 8643 | * @dev: The port's netdev |
| 8644 | * @sa_family: Socket Family that VXLAN is notifying us about |
| 8645 | * @port: UDP port number that VXLAN stopped listening to |
| 8646 | **/ |
| 8647 | static void ixgbe_del_vxlan_port(struct net_device *dev, sa_family_t sa_family, |
| 8648 | __be16 port) |
| 8649 | { |
| 8650 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8651 | |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8652 | if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) |
| 8653 | return; |
| 8654 | |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8655 | if (sa_family == AF_INET6) |
| 8656 | return; |
| 8657 | |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 8658 | if (adapter->vxlan_port != port) { |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8659 | netdev_info(dev, "Port %d was not found, not deleting\n", |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 8660 | ntohs(port)); |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8661 | return; |
| 8662 | } |
| 8663 | |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8664 | ixgbe_clear_vxlan_port(adapter); |
| 8665 | adapter->flags2 |= IXGBE_FLAG2_VXLAN_REREG_NEEDED; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8666 | } |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8667 | #endif /* CONFIG_IXGBE_VXLAN */ |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8668 | |
stephen hemminger | edc7d57 | 2012-10-01 12:32:33 +0000 | [diff] [blame] | 8669 | static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 8670 | struct net_device *dev, |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 8671 | const unsigned char *addr, u16 vid, |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 8672 | u16 flags) |
| 8673 | { |
Alexander Duyck | bcfd343 | 2014-07-17 02:11:22 +0000 | [diff] [blame] | 8674 | /* guarantee we can provide a unique filter for the unicast address */ |
Ben Hutchings | 46acc46 | 2012-11-01 09:11:11 +0000 | [diff] [blame] | 8675 | if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) { |
Alexander Duyck | 2f9be16 | 2015-10-22 16:26:42 -0700 | [diff] [blame] | 8676 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 8677 | u16 pool = VMDQ_P(0); |
| 8678 | |
| 8679 | if (netdev_uc_count(dev) >= ixgbe_available_rars(adapter, pool)) |
Alexander Duyck | bcfd343 | 2014-07-17 02:11:22 +0000 | [diff] [blame] | 8680 | return -ENOMEM; |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 8681 | } |
| 8682 | |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 8683 | return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags); |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 8684 | } |
| 8685 | |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 8686 | /** |
| 8687 | * ixgbe_configure_bridge_mode - set various bridge modes |
| 8688 | * @adapter - the private structure |
| 8689 | * @mode - requested bridge mode |
| 8690 | * |
| 8691 | * Configure some settings require for various bridge modes. |
| 8692 | **/ |
| 8693 | static int ixgbe_configure_bridge_mode(struct ixgbe_adapter *adapter, |
| 8694 | __u16 mode) |
| 8695 | { |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 8696 | struct ixgbe_hw *hw = &adapter->hw; |
| 8697 | unsigned int p, num_pools; |
| 8698 | u32 vmdctl; |
| 8699 | |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 8700 | switch (mode) { |
| 8701 | case BRIDGE_MODE_VEPA: |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 8702 | /* disable Tx loopback, rely on switch hairpin mode */ |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 8703 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, 0); |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 8704 | |
| 8705 | /* must enable Rx switching replication to allow multicast |
| 8706 | * packet reception on all VFs, and to enable source address |
| 8707 | * pruning. |
| 8708 | */ |
| 8709 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL); |
| 8710 | vmdctl |= IXGBE_VT_CTL_REPLEN; |
| 8711 | IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl); |
| 8712 | |
| 8713 | /* enable Rx source address pruning. Note, this requires |
| 8714 | * replication to be enabled or else it does nothing. |
| 8715 | */ |
| 8716 | num_pools = adapter->num_vfs + adapter->num_rx_pools; |
| 8717 | for (p = 0; p < num_pools; p++) { |
| 8718 | if (hw->mac.ops.set_source_address_pruning) |
| 8719 | hw->mac.ops.set_source_address_pruning(hw, |
| 8720 | true, |
| 8721 | p); |
| 8722 | } |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 8723 | break; |
| 8724 | case BRIDGE_MODE_VEB: |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 8725 | /* enable Tx loopback for internal VF/PF communication */ |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 8726 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, |
| 8727 | IXGBE_PFDTXGSWC_VT_LBEN); |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 8728 | |
| 8729 | /* disable Rx switching replication unless we have SR-IOV |
| 8730 | * virtual functions |
| 8731 | */ |
| 8732 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL); |
| 8733 | if (!adapter->num_vfs) |
| 8734 | vmdctl &= ~IXGBE_VT_CTL_REPLEN; |
| 8735 | IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl); |
| 8736 | |
| 8737 | /* disable Rx source address pruning, since we don't expect to |
| 8738 | * be receiving external loopback of our transmitted frames. |
| 8739 | */ |
| 8740 | num_pools = adapter->num_vfs + adapter->num_rx_pools; |
| 8741 | for (p = 0; p < num_pools; p++) { |
| 8742 | if (hw->mac.ops.set_source_address_pruning) |
| 8743 | hw->mac.ops.set_source_address_pruning(hw, |
| 8744 | false, |
| 8745 | p); |
| 8746 | } |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 8747 | break; |
| 8748 | default: |
| 8749 | return -EINVAL; |
| 8750 | } |
| 8751 | |
| 8752 | adapter->bridge_mode = mode; |
| 8753 | |
| 8754 | e_info(drv, "enabling bridge mode: %s\n", |
| 8755 | mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
| 8756 | |
| 8757 | return 0; |
| 8758 | } |
| 8759 | |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8760 | static int ixgbe_ndo_bridge_setlink(struct net_device *dev, |
Roopa Prabhu | add511b | 2015-01-29 22:40:12 -0800 | [diff] [blame] | 8761 | struct nlmsghdr *nlh, u16 flags) |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8762 | { |
| 8763 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 8764 | struct nlattr *attr, *br_spec; |
| 8765 | int rem; |
| 8766 | |
| 8767 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 8768 | return -EOPNOTSUPP; |
| 8769 | |
| 8770 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
Thomas Graf | 4ea85e8 | 2014-11-26 13:42:18 +0100 | [diff] [blame] | 8771 | if (!br_spec) |
| 8772 | return -EINVAL; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8773 | |
| 8774 | nla_for_each_nested(attr, br_spec, rem) { |
Mark Rustad | a1e869d | 2015-04-10 10:36:36 -0700 | [diff] [blame] | 8775 | int status; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8776 | __u16 mode; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8777 | |
| 8778 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 8779 | continue; |
| 8780 | |
Thomas Graf | b7c1a31 | 2014-11-26 13:42:17 +0100 | [diff] [blame] | 8781 | if (nla_len(attr) < sizeof(mode)) |
| 8782 | return -EINVAL; |
| 8783 | |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8784 | mode = nla_get_u16(attr); |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 8785 | status = ixgbe_configure_bridge_mode(adapter, mode); |
| 8786 | if (status) |
| 8787 | return status; |
Don Skidmore | aa2bacb | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 8788 | |
| 8789 | break; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8790 | } |
| 8791 | |
| 8792 | return 0; |
| 8793 | } |
| 8794 | |
| 8795 | 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] | 8796 | struct net_device *dev, |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 8797 | u32 filter_mask, int nlflags) |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8798 | { |
| 8799 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8800 | |
| 8801 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 8802 | return 0; |
| 8803 | |
Don Skidmore | aa2bacb | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 8804 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, |
Scott Feldman | 7d4f8d8 | 2015-06-22 00:27:17 -0700 | [diff] [blame] | 8805 | adapter->bridge_mode, 0, 0, nlflags, |
| 8806 | filter_mask, NULL); |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8807 | } |
| 8808 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8809 | static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev) |
| 8810 | { |
| 8811 | struct ixgbe_fwd_adapter *fwd_adapter = NULL; |
| 8812 | struct ixgbe_adapter *adapter = netdev_priv(pdev); |
Jacob Keller | aac2f1b | 2014-08-21 06:17:59 +0000 | [diff] [blame] | 8813 | int used_pools = adapter->num_vfs + adapter->num_rx_pools; |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 8814 | unsigned int limit; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8815 | int pool, err; |
| 8816 | |
Jacob Keller | aac2f1b | 2014-08-21 06:17:59 +0000 | [diff] [blame] | 8817 | /* Hardware has a limited number of available pools. Each VF, and the |
| 8818 | * PF require a pool. Check to ensure we don't attempt to use more |
| 8819 | * then the available number of pools. |
| 8820 | */ |
| 8821 | if (used_pools >= IXGBE_MAX_VF_FUNCTIONS) |
| 8822 | return ERR_PTR(-EINVAL); |
| 8823 | |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 8824 | #ifdef CONFIG_RPS |
| 8825 | if (vdev->num_rx_queues != vdev->num_tx_queues) { |
| 8826 | netdev_info(pdev, "%s: Only supports a single queue count for TX and RX\n", |
| 8827 | vdev->name); |
| 8828 | return ERR_PTR(-EINVAL); |
| 8829 | } |
| 8830 | #endif |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8831 | /* Check for hardware restriction on number of rx/tx queues */ |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 8832 | if (vdev->num_tx_queues > IXGBE_MAX_L2A_QUEUES || |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8833 | vdev->num_tx_queues == IXGBE_BAD_L2A_QUEUE) { |
| 8834 | netdev_info(pdev, |
| 8835 | "%s: Supports RX/TX Queue counts 1,2, and 4\n", |
| 8836 | pdev->name); |
| 8837 | return ERR_PTR(-EINVAL); |
| 8838 | } |
| 8839 | |
| 8840 | if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && |
| 8841 | adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS - 1) || |
| 8842 | (adapter->num_rx_pools > IXGBE_MAX_MACVLANS)) |
| 8843 | return ERR_PTR(-EBUSY); |
| 8844 | |
Maninder Singh | bc52f95 | 2015-06-19 09:37:55 +0530 | [diff] [blame] | 8845 | fwd_adapter = kzalloc(sizeof(*fwd_adapter), GFP_KERNEL); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8846 | if (!fwd_adapter) |
| 8847 | return ERR_PTR(-ENOMEM); |
| 8848 | |
| 8849 | pool = find_first_zero_bit(&adapter->fwd_bitmask, 32); |
| 8850 | adapter->num_rx_pools++; |
| 8851 | set_bit(pool, &adapter->fwd_bitmask); |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 8852 | limit = find_last_bit(&adapter->fwd_bitmask, 32); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8853 | |
| 8854 | /* Enable VMDq flag so device will be set in VM mode */ |
| 8855 | adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED | IXGBE_FLAG_SRIOV_ENABLED; |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 8856 | adapter->ring_feature[RING_F_VMDQ].limit = limit + 1; |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 8857 | adapter->ring_feature[RING_F_RSS].limit = vdev->num_tx_queues; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8858 | |
| 8859 | /* Force reinit of ring allocation with VMDQ enabled */ |
| 8860 | err = ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev)); |
| 8861 | if (err) |
| 8862 | goto fwd_add_err; |
| 8863 | fwd_adapter->pool = pool; |
| 8864 | fwd_adapter->real_adapter = adapter; |
| 8865 | err = ixgbe_fwd_ring_up(vdev, fwd_adapter); |
| 8866 | if (err) |
| 8867 | goto fwd_add_err; |
| 8868 | netif_tx_start_all_queues(vdev); |
| 8869 | return fwd_adapter; |
| 8870 | fwd_add_err: |
| 8871 | /* unwind counter and free adapter struct */ |
| 8872 | netdev_info(pdev, |
| 8873 | "%s: dfwd hardware acceleration failed\n", vdev->name); |
| 8874 | clear_bit(pool, &adapter->fwd_bitmask); |
| 8875 | adapter->num_rx_pools--; |
| 8876 | kfree(fwd_adapter); |
| 8877 | return ERR_PTR(err); |
| 8878 | } |
| 8879 | |
| 8880 | static void ixgbe_fwd_del(struct net_device *pdev, void *priv) |
| 8881 | { |
| 8882 | struct ixgbe_fwd_adapter *fwd_adapter = priv; |
| 8883 | struct ixgbe_adapter *adapter = fwd_adapter->real_adapter; |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 8884 | unsigned int limit; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8885 | |
| 8886 | clear_bit(fwd_adapter->pool, &adapter->fwd_bitmask); |
| 8887 | adapter->num_rx_pools--; |
| 8888 | |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame] | 8889 | limit = find_last_bit(&adapter->fwd_bitmask, 32); |
| 8890 | adapter->ring_feature[RING_F_VMDQ].limit = limit + 1; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8891 | ixgbe_fwd_ring_down(fwd_adapter->netdev, fwd_adapter); |
| 8892 | ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev)); |
| 8893 | netdev_dbg(pdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n", |
| 8894 | fwd_adapter->pool, adapter->num_rx_pools, |
| 8895 | fwd_adapter->rx_base_queue, |
| 8896 | fwd_adapter->rx_base_queue + adapter->num_rx_queues_per_pool, |
| 8897 | adapter->fwd_bitmask); |
| 8898 | kfree(fwd_adapter); |
| 8899 | } |
| 8900 | |
Mark Rustad | f467bc0 | 2015-06-15 11:33:20 -0700 | [diff] [blame] | 8901 | #define IXGBE_MAX_TUNNEL_HDR_LEN 80 |
| 8902 | static netdev_features_t |
| 8903 | ixgbe_features_check(struct sk_buff *skb, struct net_device *dev, |
| 8904 | netdev_features_t features) |
| 8905 | { |
| 8906 | if (!skb->encapsulation) |
| 8907 | return features; |
| 8908 | |
| 8909 | if (unlikely(skb_inner_mac_header(skb) - skb_transport_header(skb) > |
| 8910 | IXGBE_MAX_TUNNEL_HDR_LEN)) |
Tom Herbert | a188222 | 2015-12-14 11:19:43 -0800 | [diff] [blame] | 8911 | return features & ~NETIF_F_CSUM_MASK; |
Mark Rustad | f467bc0 | 2015-06-15 11:33:20 -0700 | [diff] [blame] | 8912 | |
| 8913 | return features; |
| 8914 | } |
| 8915 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 8916 | static const struct net_device_ops ixgbe_netdev_ops = { |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 8917 | .ndo_open = ixgbe_open, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 8918 | .ndo_stop = ixgbe_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 8919 | .ndo_start_xmit = ixgbe_xmit_frame, |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 8920 | .ndo_select_queue = ixgbe_select_queue, |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 8921 | .ndo_set_rx_mode = ixgbe_set_rx_mode, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 8922 | .ndo_validate_addr = eth_validate_addr, |
| 8923 | .ndo_set_mac_address = ixgbe_set_mac, |
| 8924 | .ndo_change_mtu = ixgbe_change_mtu, |
| 8925 | .ndo_tx_timeout = ixgbe_tx_timeout, |
Rostislav Pehlivanov | c04f90e | 2016-01-27 18:33:30 +0000 | [diff] [blame] | 8926 | .ndo_set_tx_maxrate = ixgbe_tx_maxrate, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 8927 | .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid, |
| 8928 | .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid, |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 8929 | .ndo_do_ioctl = ixgbe_ioctl, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 8930 | .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac, |
| 8931 | .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan, |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 8932 | .ndo_set_vf_rate = ixgbe_ndo_set_vf_bw, |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 8933 | .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk, |
Vlad Zolotarov | e65ce0d | 2015-03-30 21:35:24 +0300 | [diff] [blame] | 8934 | .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] | 8935 | .ndo_set_vf_trust = ixgbe_ndo_set_vf_trust, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 8936 | .ndo_get_vf_config = ixgbe_ndo_get_vf_config, |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8937 | .ndo_get_stats64 = ixgbe_get_stats64, |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 8938 | .ndo_setup_tc = __ixgbe_setup_tc, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 8939 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 8940 | .ndo_poll_controller = ixgbe_netpoll, |
| 8941 | #endif |
Cong Wang | e0d1095 | 2013-08-01 11:10:25 +0800 | [diff] [blame] | 8942 | #ifdef CONFIG_NET_RX_BUSY_POLL |
Eliezer Tamir | 8b80cda | 2013-07-10 17:13:26 +0300 | [diff] [blame] | 8943 | .ndo_busy_poll = ixgbe_low_latency_recv, |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 8944 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 8945 | #ifdef IXGBE_FCOE |
| 8946 | .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get, |
Yi Zou | 68a683c | 2011-02-01 07:22:16 +0000 | [diff] [blame] | 8947 | .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 8948 | .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put, |
Yi Zou | 8450ff8 | 2009-08-31 12:32:14 +0000 | [diff] [blame] | 8949 | .ndo_fcoe_enable = ixgbe_fcoe_enable, |
| 8950 | .ndo_fcoe_disable = ixgbe_fcoe_disable, |
Yi Zou | 61a1fa1 | 2009-10-28 18:24:56 +0000 | [diff] [blame] | 8951 | .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn, |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 8952 | .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 8953 | #endif /* IXGBE_FCOE */ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8954 | .ndo_set_features = ixgbe_set_features, |
| 8955 | .ndo_fix_features = ixgbe_fix_features, |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 8956 | .ndo_fdb_add = ixgbe_ndo_fdb_add, |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 8957 | .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink, |
| 8958 | .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink, |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8959 | .ndo_dfwd_add_station = ixgbe_fwd_add, |
| 8960 | .ndo_dfwd_del_station = ixgbe_fwd_del, |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8961 | #ifdef CONFIG_IXGBE_VXLAN |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 8962 | .ndo_add_vxlan_port = ixgbe_add_vxlan_port, |
| 8963 | .ndo_del_vxlan_port = ixgbe_del_vxlan_port, |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8964 | #endif /* CONFIG_IXGBE_VXLAN */ |
Mark Rustad | f467bc0 | 2015-06-15 11:33:20 -0700 | [diff] [blame] | 8965 | .ndo_features_check = ixgbe_features_check, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 8966 | }; |
| 8967 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 8968 | /** |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 8969 | * ixgbe_enumerate_functions - Get the number of ports this device has |
| 8970 | * @adapter: adapter structure |
| 8971 | * |
| 8972 | * This function enumerates the phsyical functions co-located on a single slot, |
| 8973 | * in order to determine how many ports a device has. This is most useful in |
| 8974 | * determining the required GT/s of PCIe bandwidth necessary for optimal |
| 8975 | * performance. |
| 8976 | **/ |
| 8977 | static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter) |
| 8978 | { |
Jacob Keller | caafb95 | 2014-07-19 07:17:17 +0000 | [diff] [blame] | 8979 | struct pci_dev *entry, *pdev = adapter->pdev; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 8980 | int physfns = 0; |
| 8981 | |
Jacob Keller | f1f9657 | 2013-08-31 02:45:38 +0000 | [diff] [blame] | 8982 | /* Some cards can not use the generic count PCIe functions method, |
| 8983 | * because they are behind a parent switch, so we hardcode these with |
| 8984 | * the correct number of functions. |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 8985 | */ |
Jacob Keller | 8818970 | 2014-07-19 07:17:16 +0000 | [diff] [blame] | 8986 | if (ixgbe_pcie_from_parent(&adapter->hw)) |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 8987 | physfns = 4; |
Jacob Keller | 8818970 | 2014-07-19 07:17:16 +0000 | [diff] [blame] | 8988 | |
| 8989 | list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) { |
| 8990 | /* don't count virtual functions */ |
Jacob Keller | caafb95 | 2014-07-19 07:17:17 +0000 | [diff] [blame] | 8991 | if (entry->is_virtfn) |
| 8992 | continue; |
| 8993 | |
| 8994 | /* When the devices on the bus don't all match our device ID, |
| 8995 | * we can't reliably determine the correct number of |
| 8996 | * functions. This can occur if a function has been direct |
| 8997 | * attached to a virtual machine using VT-d, for example. In |
| 8998 | * this case, simply return -1 to indicate this. |
| 8999 | */ |
| 9000 | if ((entry->vendor != pdev->vendor) || |
| 9001 | (entry->device != pdev->device)) |
| 9002 | return -1; |
| 9003 | |
| 9004 | physfns++; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 9005 | } |
| 9006 | |
| 9007 | return physfns; |
| 9008 | } |
| 9009 | |
| 9010 | /** |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9011 | * ixgbe_wol_supported - Check whether device supports WoL |
| 9012 | * @hw: hw specific details |
| 9013 | * @device_id: the device ID |
| 9014 | * @subdev_id: the subsystem device ID |
| 9015 | * |
| 9016 | * This function is used by probe and ethtool to determine |
| 9017 | * which devices have WoL support |
| 9018 | * |
| 9019 | **/ |
| 9020 | int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id, |
| 9021 | u16 subdevice_id) |
| 9022 | { |
| 9023 | struct ixgbe_hw *hw = &adapter->hw; |
| 9024 | u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK; |
| 9025 | int is_wol_supported = 0; |
| 9026 | |
| 9027 | switch (device_id) { |
| 9028 | case IXGBE_DEV_ID_82599_SFP: |
| 9029 | /* Only these subdevices could supports WOL */ |
| 9030 | switch (subdevice_id) { |
Mark Rustad | 8755744 | 2014-02-25 17:58:55 -0800 | [diff] [blame] | 9031 | case IXGBE_SUBDEV_ID_82599_SFP_WOL0: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9032 | case IXGBE_SUBDEV_ID_82599_560FLR: |
| 9033 | /* only support first port */ |
| 9034 | if (hw->bus.func != 0) |
| 9035 | break; |
Emil Tantilov | 5700ff2 | 2013-04-18 08:18:55 +0000 | [diff] [blame] | 9036 | case IXGBE_SUBDEV_ID_82599_SP_560FLR: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9037 | case IXGBE_SUBDEV_ID_82599_SFP: |
Don Skidmore | b6dfd93 | 2012-07-11 07:17:42 +0000 | [diff] [blame] | 9038 | case IXGBE_SUBDEV_ID_82599_RNDC: |
Emil Tantilov | f8a06c2 | 2012-08-16 08:13:07 +0000 | [diff] [blame] | 9039 | case IXGBE_SUBDEV_ID_82599_ECNA_DP: |
Jacob Keller | 979fe5f | 2013-04-03 04:41:37 +0000 | [diff] [blame] | 9040 | case IXGBE_SUBDEV_ID_82599_LOM_SFP: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9041 | is_wol_supported = 1; |
| 9042 | break; |
| 9043 | } |
| 9044 | break; |
Don Skidmore | 5daebbb | 2013-04-05 05:49:34 +0000 | [diff] [blame] | 9045 | case IXGBE_DEV_ID_82599EN_SFP: |
| 9046 | /* Only this subdevice supports WOL */ |
| 9047 | switch (subdevice_id) { |
| 9048 | case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1: |
| 9049 | is_wol_supported = 1; |
| 9050 | break; |
| 9051 | } |
| 9052 | break; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9053 | case IXGBE_DEV_ID_82599_COMBO_BACKPLANE: |
| 9054 | /* All except this subdevice support WOL */ |
| 9055 | if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ) |
| 9056 | is_wol_supported = 1; |
| 9057 | break; |
| 9058 | case IXGBE_DEV_ID_82599_KX4: |
| 9059 | is_wol_supported = 1; |
| 9060 | break; |
| 9061 | case IXGBE_DEV_ID_X540T: |
joshua.a.hay@intel.com | df376f0 | 2012-09-21 00:08:21 +0000 | [diff] [blame] | 9062 | case IXGBE_DEV_ID_X540T1: |
Don Skidmore | df8c26f | 2015-06-09 16:00:17 -0700 | [diff] [blame] | 9063 | case IXGBE_DEV_ID_X550T: |
Mark Rustad | a711ad8 | 2016-03-21 11:21:31 -0700 | [diff] [blame] | 9064 | case IXGBE_DEV_ID_X550T1: |
Don Skidmore | df8c26f | 2015-06-09 16:00:17 -0700 | [diff] [blame] | 9065 | case IXGBE_DEV_ID_X550EM_X_KX4: |
| 9066 | case IXGBE_DEV_ID_X550EM_X_KR: |
| 9067 | case IXGBE_DEV_ID_X550EM_X_10G_T: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9068 | /* check eeprom to see if enabled wol */ |
| 9069 | if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) || |
| 9070 | ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) && |
| 9071 | (hw->bus.func == 0))) { |
| 9072 | is_wol_supported = 1; |
| 9073 | } |
| 9074 | break; |
| 9075 | } |
| 9076 | |
| 9077 | return is_wol_supported; |
| 9078 | } |
| 9079 | |
| 9080 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9081 | * ixgbe_probe - Device Initialization Routine |
| 9082 | * @pdev: PCI device information struct |
| 9083 | * @ent: entry in ixgbe_pci_tbl |
| 9084 | * |
| 9085 | * Returns 0 on success, negative on failure |
| 9086 | * |
| 9087 | * ixgbe_probe initializes an adapter identified by a pci_dev structure. |
| 9088 | * The OS initialization, configuring of the adapter private structure, |
| 9089 | * and a hardware reset occur. |
| 9090 | **/ |
Greg Kroah-Hartman | 1dd06ae | 2012-12-06 14:30:56 +0000 | [diff] [blame] | 9091 | 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] | 9092 | { |
| 9093 | struct net_device *netdev; |
| 9094 | struct ixgbe_adapter *adapter = NULL; |
| 9095 | struct ixgbe_hw *hw; |
| 9096 | const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data]; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 9097 | int i, err, pci_using_dac, expected_gts; |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 9098 | unsigned int indices = MAX_TX_QUEUES; |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 9099 | u8 part_str[IXGBE_PBANUM_LENGTH]; |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 9100 | bool disable_dev = false; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 9101 | #ifdef IXGBE_FCOE |
| 9102 | u16 device_caps; |
| 9103 | #endif |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 9104 | u32 eec; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9105 | |
Andy Gospodarek | bded64a | 2010-07-21 06:40:31 +0000 | [diff] [blame] | 9106 | /* Catch broken hardware that put the wrong VF device ID in |
| 9107 | * the PCIe SR-IOV capability. |
| 9108 | */ |
| 9109 | if (pdev->is_virtfn) { |
| 9110 | WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n", |
| 9111 | pci_name(pdev), pdev->vendor, pdev->device); |
| 9112 | return -EINVAL; |
| 9113 | } |
| 9114 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 9115 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9116 | if (err) |
| 9117 | return err; |
| 9118 | |
Russell King | f5f2eda | 2013-06-10 12:47:42 +0100 | [diff] [blame] | 9119 | if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9120 | pci_using_dac = 1; |
| 9121 | } else { |
Russell King | f5f2eda | 2013-06-10 12:47:42 +0100 | [diff] [blame] | 9122 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9123 | if (err) { |
Russell King | f5f2eda | 2013-06-10 12:47:42 +0100 | [diff] [blame] | 9124 | dev_err(&pdev->dev, |
| 9125 | "No usable DMA configuration, aborting\n"); |
| 9126 | goto err_dma; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9127 | } |
| 9128 | pci_using_dac = 0; |
| 9129 | } |
| 9130 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 9131 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 9132 | IORESOURCE_MEM), ixgbe_driver_name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9133 | if (err) { |
Dan Carpenter | b8bc042 | 2010-07-27 00:05:56 +0000 | [diff] [blame] | 9134 | dev_err(&pdev->dev, |
| 9135 | "pci_request_selected_regions failed 0x%x\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9136 | goto err_pci_reg; |
| 9137 | } |
| 9138 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 9139 | pci_enable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9140 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9141 | pci_set_master(pdev); |
Wendy Xiong | fb3b27b | 2008-04-23 11:09:24 -0700 | [diff] [blame] | 9142 | pci_save_state(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9143 | |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 9144 | if (ii->mac == ixgbe_mac_82598EB) { |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 9145 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 9146 | /* 8 TC w/ 4 queues per TC */ |
| 9147 | indices = 4 * MAX_TRAFFIC_CLASS; |
| 9148 | #else |
| 9149 | indices = IXGBE_MAX_RSS_INDICES; |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 9150 | #endif |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 9151 | } |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 9152 | |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 9153 | netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9154 | if (!netdev) { |
| 9155 | err = -ENOMEM; |
| 9156 | goto err_alloc_etherdev; |
| 9157 | } |
| 9158 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9159 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 9160 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9161 | adapter = netdev_priv(netdev); |
| 9162 | |
| 9163 | adapter->netdev = netdev; |
| 9164 | adapter->pdev = pdev; |
| 9165 | hw = &adapter->hw; |
| 9166 | hw->back = adapter; |
stephen hemminger | b3f4d59 | 2012-03-13 06:04:20 +0000 | [diff] [blame] | 9167 | adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9168 | |
Jeff Kirsher | 0585798 | 2008-09-11 19:57:00 -0700 | [diff] [blame] | 9169 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 9170 | pci_resource_len(pdev, 0)); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 9171 | adapter->io_addr = hw->hw_addr; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9172 | if (!hw->hw_addr) { |
| 9173 | err = -EIO; |
| 9174 | goto err_ioremap; |
| 9175 | } |
| 9176 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 9177 | netdev->netdev_ops = &ixgbe_netdev_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9178 | ixgbe_set_ethtool_ops(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9179 | netdev->watchdog_timeo = 5 * HZ; |
Mark Rustad | 339de30 | 2014-06-06 01:57:06 +0000 | [diff] [blame] | 9180 | strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9181 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9182 | /* Setup hw api */ |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 9183 | hw->mac.ops = *ii->mac_ops; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 9184 | hw->mac.type = ii->mac; |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 9185 | hw->mvals = ii->mvals; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9186 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9187 | /* EEPROM */ |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 9188 | hw->eeprom.ops = *ii->eeprom_ops; |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 9189 | eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw)); |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 9190 | if (ixgbe_removed(hw->hw_addr)) { |
| 9191 | err = -EIO; |
| 9192 | goto err_ioremap; |
| 9193 | } |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9194 | /* 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^] | 9195 | if (!(eec & BIT(8))) |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9196 | hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic; |
| 9197 | |
| 9198 | /* PHY */ |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 9199 | hw->phy.ops = *ii->phy_ops; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 9200 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 9201 | /* ixgbe_identify_phy_generic will set prtad and mmds properly */ |
| 9202 | hw->phy.mdio.prtad = MDIO_PRTAD_NONE; |
| 9203 | hw->phy.mdio.mmds = 0; |
| 9204 | hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 9205 | hw->phy.mdio.dev = netdev; |
| 9206 | hw->phy.mdio.mdio_read = ixgbe_mdio_read; |
| 9207 | hw->phy.mdio.mdio_write = ixgbe_mdio_write; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 9208 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 9209 | ii->get_invariants(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9210 | |
| 9211 | /* setup the private structure */ |
| 9212 | err = ixgbe_sw_init(adapter); |
| 9213 | if (err) |
| 9214 | goto err_sw_init; |
| 9215 | |
Don Skidmore | dbd15b8 | 2016-03-09 16:45:00 -0500 | [diff] [blame] | 9216 | /* Make sure the SWFW semaphore is in a valid state */ |
| 9217 | if (hw->mac.ops.init_swfw_sync) |
| 9218 | hw->mac.ops.init_swfw_sync(hw); |
| 9219 | |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 9220 | /* Make it possible the adapter to be woken up via WOL */ |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 9221 | switch (adapter->hw.mac.type) { |
| 9222 | case ixgbe_mac_82599EB: |
| 9223 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 9224 | case ixgbe_mac_X550: |
| 9225 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 9226 | case ixgbe_mac_x550em_a: |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 9227 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 9228 | break; |
| 9229 | default: |
| 9230 | break; |
| 9231 | } |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 9232 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 9233 | /* |
| 9234 | * If there is a fan on this device and it has failed log the |
| 9235 | * failure. |
| 9236 | */ |
| 9237 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 9238 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 9239 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 9240 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 9241 | } |
| 9242 | |
Peter P Waskiewicz Jr | 8ef78ad | 2012-02-01 09:19:21 +0000 | [diff] [blame] | 9243 | if (allow_unsupported_sfp) |
| 9244 | hw->allow_unsupported_sfp = allow_unsupported_sfp; |
| 9245 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9246 | /* reset_hw fills in the perm_addr as well */ |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 9247 | hw->phy.reset_if_overtemp = true; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9248 | err = hw->mac.ops.reset_hw(hw); |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 9249 | hw->phy.reset_if_overtemp = false; |
Mark Rustad | 29a8dca | 2015-08-08 16:17:46 -0700 | [diff] [blame] | 9250 | if (err == IXGBE_ERR_SFP_NOT_PRESENT) { |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 9251 | err = 0; |
| 9252 | } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 1b1bf31 | 2013-07-31 05:27:04 +0000 | [diff] [blame] | 9253 | e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n"); |
| 9254 | e_dev_err("Reload the driver after installing a supported module.\n"); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 9255 | goto err_sw_init; |
| 9256 | } else if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 9257 | e_dev_err("HW Init failed: %d\n", err); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9258 | goto err_sw_init; |
| 9259 | } |
| 9260 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 9261 | #ifdef CONFIG_PCI_IOV |
Greg Rose | 60a1a68 | 2012-12-11 08:26:33 +0000 | [diff] [blame] | 9262 | /* SR-IOV not supported on the 82598 */ |
| 9263 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 9264 | goto skip_sriov; |
| 9265 | /* Mailbox */ |
| 9266 | ixgbe_init_mbx_params_pf(hw); |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 9267 | hw->mbx.ops = ii->mbx_ops; |
ethan.zhao | dcc23e3 | 2014-01-16 19:41:04 -0800 | [diff] [blame] | 9268 | pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT); |
ethan.zhao | 31ac910 | 2014-01-16 19:41:05 -0800 | [diff] [blame] | 9269 | ixgbe_enable_sriov(adapter); |
Greg Rose | 60a1a68 | 2012-12-11 08:26:33 +0000 | [diff] [blame] | 9270 | skip_sriov: |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 9271 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 9272 | #endif |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 9273 | netdev->features = NETIF_F_SG | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9274 | NETIF_F_TSO | |
| 9275 | NETIF_F_TSO6 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9276 | NETIF_F_RXHASH | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 9277 | NETIF_F_RXCSUM | |
| 9278 | NETIF_F_HW_CSUM | |
| 9279 | NETIF_F_HW_VLAN_CTAG_TX | |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 9280 | NETIF_F_HW_VLAN_CTAG_RX | |
| 9281 | NETIF_F_HW_VLAN_CTAG_FILTER; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9282 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 9283 | if (hw->mac.type >= ixgbe_mac_82599EB) |
Tom Herbert | 53692b1 | 2015-12-14 11:19:41 -0800 | [diff] [blame] | 9284 | netdev->features |= NETIF_F_SCTP_CRC; |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 9285 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 9286 | /* copy netdev features into list of user selectable features */ |
| 9287 | netdev->hw_features |= netdev->features; |
| 9288 | netdev->hw_features |= NETIF_F_RXALL | |
| 9289 | NETIF_F_HW_L2FW_DOFFLOAD; |
| 9290 | |
| 9291 | if (hw->mac.type >= ixgbe_mac_82599EB) |
| 9292 | netdev->hw_features |= NETIF_F_NTUPLE | |
| 9293 | NETIF_F_HW_TC; |
| 9294 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 9295 | netdev->vlan_features |= NETIF_F_SG | |
| 9296 | NETIF_F_TSO | |
| 9297 | NETIF_F_TSO6 | |
| 9298 | NETIF_F_HW_CSUM | |
| 9299 | NETIF_F_SCTP_CRC; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 9300 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 9301 | netdev->mpls_features |= NETIF_F_HW_CSUM; |
| 9302 | netdev->hw_enc_features |= NETIF_F_HW_CSUM; |
Mark Rustad | f467bc0 | 2015-06-15 11:33:20 -0700 | [diff] [blame] | 9303 | |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 9304 | netdev->priv_flags |= IFF_UNICAST_FLT; |
Ben Greear | f43f313 | 2012-03-06 09:42:04 +0000 | [diff] [blame] | 9305 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 9306 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 9307 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 9308 | netdev->dcbnl_ops = &dcbnl_ops; |
| 9309 | #endif |
| 9310 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 9311 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 9312 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 9313 | unsigned int fcoe_l; |
| 9314 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 9315 | if (hw->mac.ops.get_device_caps) { |
| 9316 | hw->mac.ops.get_device_caps(hw, &device_caps); |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 9317 | if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS) |
| 9318 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 9319 | } |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 9320 | |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 9321 | |
| 9322 | fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus()); |
| 9323 | adapter->ring_feature[RING_F_FCOE].limit = fcoe_l; |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 9324 | |
Alexander Duyck | a58915c | 2012-05-25 06:38:18 +0000 | [diff] [blame] | 9325 | netdev->features |= NETIF_F_FSO | |
| 9326 | NETIF_F_FCOE_CRC; |
| 9327 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 9328 | netdev->vlan_features |= NETIF_F_FSO | |
| 9329 | NETIF_F_FCOE_CRC | |
| 9330 | NETIF_F_FCOE_MTU; |
Yi Zou | 5e09d7f | 2010-07-19 13:59:52 +0000 | [diff] [blame] | 9331 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 9332 | #endif /* IXGBE_FCOE */ |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 9333 | if (pci_using_dac) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9334 | netdev->features |= NETIF_F_HIGHDMA; |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 9335 | netdev->vlan_features |= NETIF_F_HIGHDMA; |
| 9336 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9337 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9338 | if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) |
| 9339 | netdev->hw_features |= NETIF_F_LRO; |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 9340 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 9341 | netdev->features |= NETIF_F_LRO; |
| 9342 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9343 | /* make sure the EEPROM is good */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 9344 | if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 9345 | e_dev_err("The EEPROM Checksum Is Not Valid\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9346 | err = -EIO; |
Alexander Duyck | 35937c0 | 2012-02-08 07:51:37 +0000 | [diff] [blame] | 9347 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9348 | } |
| 9349 | |
Sowmini Varadhan | c7374b5 | 2016-01-12 19:32:30 -0800 | [diff] [blame] | 9350 | eth_platform_get_mac_address(&adapter->pdev->dev, |
| 9351 | adapter->hw.mac.perm_addr); |
Martin K Petersen | c762dff | 2014-11-15 14:24:51 +0000 | [diff] [blame] | 9352 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9353 | memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9354 | |
Jiri Pirko | aaeb6cd | 2013-01-08 01:38:26 +0000 | [diff] [blame] | 9355 | if (!is_valid_ether_addr(netdev->dev_addr)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 9356 | e_dev_err("invalid MAC address\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9357 | err = -EIO; |
Alexander Duyck | 35937c0 | 2012-02-08 07:51:37 +0000 | [diff] [blame] | 9358 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9359 | } |
| 9360 | |
Tushar Dave | 5676804 | 2016-01-07 14:17:03 -0800 | [diff] [blame] | 9361 | /* Set hw->mac.addr to permanent MAC address */ |
| 9362 | ether_addr_copy(hw->mac.addr, hw->mac.perm_addr); |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 9363 | ixgbe_mac_set_default_filter(adapter); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 9364 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 9365 | setup_timer(&adapter->service_timer, &ixgbe_service_timer, |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 9366 | (unsigned long) adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9367 | |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 9368 | if (ixgbe_removed(hw->hw_addr)) { |
| 9369 | err = -EIO; |
| 9370 | goto err_sw_init; |
| 9371 | } |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 9372 | INIT_WORK(&adapter->service_task, ixgbe_service_task); |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 9373 | set_bit(__IXGBE_SERVICE_INITED, &adapter->state); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 9374 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9375 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 9376 | err = ixgbe_init_interrupt_scheme(adapter); |
| 9377 | if (err) |
| 9378 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9379 | |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9380 | /* WOL not supported for all devices */ |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 9381 | adapter->wol = 0; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9382 | hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap); |
Jacob Keller | 6b92b0b | 2013-04-13 05:40:37 +0000 | [diff] [blame] | 9383 | hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device, |
Don Skidmore | b8f8363 | 2013-02-28 08:08:44 +0000 | [diff] [blame] | 9384 | pdev->subsystem_device); |
Jacob Keller | 6b92b0b | 2013-04-13 05:40:37 +0000 | [diff] [blame] | 9385 | if (hw->wol_enabled) |
Andy Gospodarek | 9417c46 | 2011-07-16 07:31:33 +0000 | [diff] [blame] | 9386 | adapter->wol = IXGBE_WUFC_MAG; |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 9387 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 9388 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 9389 | |
Emil Tantilov | 15e5209 | 2011-09-29 05:01:29 +0000 | [diff] [blame] | 9390 | /* save off EEPROM version number */ |
| 9391 | hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh); |
| 9392 | hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl); |
| 9393 | |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 9394 | /* pick up the PCI bus settings for reporting later */ |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 9395 | if (ixgbe_pcie_from_parent(hw)) |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 9396 | ixgbe_get_parent_bus_info(adapter); |
Don Skidmore | f9328bc | 2015-06-18 13:24:06 -0400 | [diff] [blame] | 9397 | else |
| 9398 | hw->mac.ops.get_bus_info(hw); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 9399 | |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 9400 | /* calculate the expected PCIe bandwidth required for optimal |
| 9401 | * performance. Note that some older parts will never have enough |
| 9402 | * bandwidth due to being older generation PCIe parts. We clamp these |
| 9403 | * parts to ensure no warning is displayed if it can't be fixed. |
| 9404 | */ |
| 9405 | switch (hw->mac.type) { |
| 9406 | case ixgbe_mac_82598EB: |
| 9407 | expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16); |
| 9408 | break; |
| 9409 | default: |
| 9410 | expected_gts = ixgbe_enumerate_functions(adapter) * 10; |
| 9411 | break; |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 9412 | } |
Jacob Keller | caafb95 | 2014-07-19 07:17:17 +0000 | [diff] [blame] | 9413 | |
| 9414 | /* don't check link if we failed to enumerate functions */ |
| 9415 | if (expected_gts > 0) |
| 9416 | ixgbe_check_minimum_link(adapter, expected_gts); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 9417 | |
Mark Rustad | 339de30 | 2014-06-06 01:57:06 +0000 | [diff] [blame] | 9418 | err = ixgbe_read_pba_string_generic(hw, part_str, sizeof(part_str)); |
Jacob Keller | 6a2aae5 | 2013-10-18 05:09:24 +0000 | [diff] [blame] | 9419 | if (err) |
Mark Rustad | 339de30 | 2014-06-06 01:57:06 +0000 | [diff] [blame] | 9420 | strlcpy(part_str, "Unknown", sizeof(part_str)); |
Jacob Keller | 6a2aae5 | 2013-10-18 05:09:24 +0000 | [diff] [blame] | 9421 | if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present) |
| 9422 | e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n", |
| 9423 | hw->mac.type, hw->phy.type, hw->phy.sfp_type, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 9424 | part_str); |
Jacob Keller | 6a2aae5 | 2013-10-18 05:09:24 +0000 | [diff] [blame] | 9425 | else |
| 9426 | e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n", |
| 9427 | hw->mac.type, hw->phy.type, part_str); |
| 9428 | |
| 9429 | e_dev_info("%pM\n", netdev->dev_addr); |
| 9430 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9431 | /* reset the hardware with the new settings */ |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 9432 | err = hw->mac.ops.start_hw(hw); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 9433 | if (err == IXGBE_ERR_EEPROM_VERSION) { |
| 9434 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 9435 | e_dev_warn("This device is a pre-production adapter/LOM. " |
| 9436 | "Please be aware there may be issues associated " |
| 9437 | "with your hardware. If you are experiencing " |
| 9438 | "problems please contact your Intel or hardware " |
| 9439 | "representative who provided you with this " |
| 9440 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 9441 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9442 | strcpy(netdev->name, "eth%d"); |
| 9443 | err = register_netdev(netdev); |
| 9444 | if (err) |
| 9445 | goto err_register; |
| 9446 | |
Emil Tantilov | 0fb6a55 | 2014-12-04 03:03:38 +0000 | [diff] [blame] | 9447 | pci_set_drvdata(pdev, adapter); |
| 9448 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 9449 | /* power down the optics for 82599 SFP+ fiber */ |
| 9450 | if (hw->mac.ops.disable_tx_laser) |
Emil Tantilov | 93d3ce8 | 2011-10-19 07:59:55 +0000 | [diff] [blame] | 9451 | hw->mac.ops.disable_tx_laser(hw); |
| 9452 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 9453 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 9454 | netif_carrier_off(netdev); |
| 9455 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 9456 | #ifdef CONFIG_IXGBE_DCA |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 9457 | if (dca_add_requester(&pdev->dev) == 0) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9458 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9459 | ixgbe_setup_dca(adapter); |
| 9460 | } |
| 9461 | #endif |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 9462 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 9463 | 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] | 9464 | for (i = 0; i < adapter->num_vfs; i++) |
| 9465 | ixgbe_vf_configuration(pdev, (i | 0x10000000)); |
| 9466 | } |
| 9467 | |
Jacob Keller | 2466dd9 | 2011-09-08 03:50:54 +0000 | [diff] [blame] | 9468 | /* firmware requires driver version to be 0xFFFFFFFF |
| 9469 | * since os does not support feature |
| 9470 | */ |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 9471 | if (hw->mac.ops.set_fw_drv_ver) |
Jacob Keller | 2466dd9 | 2011-09-08 03:50:54 +0000 | [diff] [blame] | 9472 | hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, |
| 9473 | 0xFF); |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 9474 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 9475 | /* add san mac addr to netdev */ |
| 9476 | ixgbe_add_sanmac_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9477 | |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 9478 | e_dev_info("%s\n", ixgbe_default_device_descr); |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 9479 | |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 9480 | #ifdef CONFIG_IXGBE_HWMON |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 9481 | if (ixgbe_sysfs_init(adapter)) |
| 9482 | e_err(probe, "failed to allocate sysfs resources\n"); |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 9483 | #endif /* CONFIG_IXGBE_HWMON */ |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 9484 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 9485 | ixgbe_dbg_adapter_init(adapter); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 9486 | |
Emil Tantilov | d1a35ee | 2014-05-13 08:24:00 +0000 | [diff] [blame] | 9487 | /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */ |
| 9488 | 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] | 9489 | hw->mac.ops.setup_link(hw, |
| 9490 | IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL, |
| 9491 | true); |
| 9492 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9493 | return 0; |
| 9494 | |
| 9495 | err_register: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 9496 | ixgbe_release_hw_control(adapter); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 9497 | ixgbe_clear_interrupt_scheme(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9498 | err_sw_init: |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 9499 | ixgbe_disable_sriov(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 9500 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 9501 | iounmap(adapter->io_addr); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 9502 | kfree(adapter->mac_table); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9503 | err_ioremap: |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 9504 | disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9505 | free_netdev(netdev); |
| 9506 | err_alloc_etherdev: |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 9507 | pci_release_selected_regions(pdev, |
| 9508 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9509 | err_pci_reg: |
| 9510 | err_dma: |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 9511 | if (!adapter || disable_dev) |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 9512 | pci_disable_device(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9513 | return err; |
| 9514 | } |
| 9515 | |
| 9516 | /** |
| 9517 | * ixgbe_remove - Device Removal Routine |
| 9518 | * @pdev: PCI device information struct |
| 9519 | * |
| 9520 | * ixgbe_remove is called by the PCI subsystem to alert the driver |
| 9521 | * that it should release a PCI device. The could be caused by a |
| 9522 | * Hot-Plug event, or because the driver is going to be removed from |
| 9523 | * memory. |
| 9524 | **/ |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 9525 | static void ixgbe_remove(struct pci_dev *pdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9526 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 9527 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
Emil Tantilov | 0fb6a55 | 2014-12-04 03:03:38 +0000 | [diff] [blame] | 9528 | struct net_device *netdev; |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 9529 | bool disable_dev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9530 | |
Emil Tantilov | 0fb6a55 | 2014-12-04 03:03:38 +0000 | [diff] [blame] | 9531 | /* if !adapter then we already cleaned up in probe */ |
| 9532 | if (!adapter) |
| 9533 | return; |
| 9534 | |
| 9535 | netdev = adapter->netdev; |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 9536 | ixgbe_dbg_adapter_exit(adapter); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 9537 | |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 9538 | set_bit(__IXGBE_REMOVING, &adapter->state); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 9539 | cancel_work_sync(&adapter->service_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9540 | |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 9541 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 9542 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9543 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 9544 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 9545 | dca_remove_requester(&pdev->dev); |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 9546 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 9547 | IXGBE_DCA_CTRL_DCA_DISABLE); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9548 | } |
| 9549 | |
| 9550 | #endif |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 9551 | #ifdef CONFIG_IXGBE_HWMON |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 9552 | ixgbe_sysfs_exit(adapter); |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 9553 | #endif /* CONFIG_IXGBE_HWMON */ |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 9554 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 9555 | /* remove the added san mac */ |
| 9556 | ixgbe_del_sanmac_netdev(netdev); |
| 9557 | |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 9558 | #ifdef CONFIG_PCI_IOV |
Alex Williamson | 7837e28 | 2015-07-10 15:31:34 -0600 | [diff] [blame] | 9559 | ixgbe_disable_sriov(adapter); |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 9560 | #endif |
Alex Williamson | 6b010e9 | 2015-07-29 14:38:21 -0600 | [diff] [blame] | 9561 | if (netdev->reg_state == NETREG_REGISTERED) |
| 9562 | unregister_netdev(netdev); |
| 9563 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 9564 | ixgbe_clear_interrupt_scheme(adapter); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 9565 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 9566 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9567 | |
Alexander Duyck | 2b1588c | 2012-03-17 02:39:16 +0000 | [diff] [blame] | 9568 | #ifdef CONFIG_DCB |
| 9569 | kfree(adapter->ixgbe_ieee_pfc); |
| 9570 | kfree(adapter->ixgbe_ieee_ets); |
| 9571 | |
| 9572 | #endif |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 9573 | iounmap(adapter->io_addr); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 9574 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 9575 | IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9576 | |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 9577 | e_dev_info("complete\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 9578 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 9579 | kfree(adapter->mac_table); |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 9580 | disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9581 | free_netdev(netdev); |
| 9582 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 9583 | pci_disable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9584 | |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 9585 | if (disable_dev) |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 9586 | pci_disable_device(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9587 | } |
| 9588 | |
| 9589 | /** |
| 9590 | * ixgbe_io_error_detected - called when PCI error is detected |
| 9591 | * @pdev: Pointer to PCI device |
| 9592 | * @state: The current pci connection state |
| 9593 | * |
| 9594 | * This function is called after a PCI bus error affecting |
| 9595 | * this device has been detected. |
| 9596 | */ |
| 9597 | 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] | 9598 | pci_channel_state_t state) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9599 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 9600 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 9601 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9602 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 9603 | #ifdef CONFIG_PCI_IOV |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 9604 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 9605 | struct pci_dev *bdev, *vfdev; |
| 9606 | u32 dw0, dw1, dw2, dw3; |
| 9607 | int vf, pos; |
| 9608 | u16 req_id, pf_func; |
| 9609 | |
| 9610 | if (adapter->hw.mac.type == ixgbe_mac_82598EB || |
| 9611 | adapter->num_vfs == 0) |
| 9612 | goto skip_bad_vf_detection; |
| 9613 | |
| 9614 | bdev = pdev->bus->self; |
Yijing Wang | 62f87c0 | 2012-07-24 17:20:03 +0800 | [diff] [blame] | 9615 | while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT)) |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 9616 | bdev = bdev->bus->self; |
| 9617 | |
| 9618 | if (!bdev) |
| 9619 | goto skip_bad_vf_detection; |
| 9620 | |
| 9621 | pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR); |
| 9622 | if (!pos) |
| 9623 | goto skip_bad_vf_detection; |
| 9624 | |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 9625 | dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG); |
| 9626 | dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4); |
| 9627 | dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8); |
| 9628 | dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12); |
| 9629 | if (ixgbe_removed(hw->hw_addr)) |
| 9630 | goto skip_bad_vf_detection; |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 9631 | |
| 9632 | req_id = dw1 >> 16; |
| 9633 | /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */ |
| 9634 | if (!(req_id & 0x0080)) |
| 9635 | goto skip_bad_vf_detection; |
| 9636 | |
| 9637 | pf_func = req_id & 0x01; |
| 9638 | if ((pf_func & 1) == (pdev->devfn & 1)) { |
| 9639 | unsigned int device_id; |
| 9640 | |
| 9641 | vf = (req_id & 0x7F) >> 1; |
| 9642 | e_dev_err("VF %d has caused a PCIe error\n", vf); |
| 9643 | e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: " |
| 9644 | "%8.8x\tdw3: %8.8x\n", |
| 9645 | dw0, dw1, dw2, dw3); |
| 9646 | switch (adapter->hw.mac.type) { |
| 9647 | case ixgbe_mac_82599EB: |
| 9648 | device_id = IXGBE_82599_VF_DEVICE_ID; |
| 9649 | break; |
| 9650 | case ixgbe_mac_X540: |
| 9651 | device_id = IXGBE_X540_VF_DEVICE_ID; |
| 9652 | break; |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 9653 | case ixgbe_mac_X550: |
| 9654 | device_id = IXGBE_DEV_ID_X550_VF; |
| 9655 | break; |
| 9656 | case ixgbe_mac_X550EM_x: |
| 9657 | device_id = IXGBE_DEV_ID_X550EM_X_VF; |
| 9658 | break; |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 9659 | case ixgbe_mac_x550em_a: |
| 9660 | device_id = IXGBE_DEV_ID_X550EM_A_VF; |
| 9661 | break; |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 9662 | default: |
| 9663 | device_id = 0; |
| 9664 | break; |
| 9665 | } |
| 9666 | |
| 9667 | /* Find the pci device of the offending VF */ |
Jon Mason | 36e9031 | 2012-07-19 21:02:09 +0000 | [diff] [blame] | 9668 | vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL); |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 9669 | while (vfdev) { |
| 9670 | if (vfdev->devfn == (req_id & 0xFF)) |
| 9671 | break; |
Jon Mason | 36e9031 | 2012-07-19 21:02:09 +0000 | [diff] [blame] | 9672 | vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 9673 | device_id, vfdev); |
| 9674 | } |
| 9675 | /* |
| 9676 | * There's a slim chance the VF could have been hot plugged, |
| 9677 | * so if it is no longer present we don't need to issue the |
| 9678 | * VFLR. Just clean up the AER in that case. |
| 9679 | */ |
| 9680 | if (vfdev) { |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 9681 | ixgbe_issue_vf_flr(adapter, vfdev); |
Greg Rose | b4fafbe | 2012-12-13 01:14:06 +0000 | [diff] [blame] | 9682 | /* Free device reference count */ |
| 9683 | pci_dev_put(vfdev); |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 9684 | } |
| 9685 | |
| 9686 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 9687 | } |
| 9688 | |
| 9689 | /* |
| 9690 | * Even though the error may have occurred on the other port |
| 9691 | * we still need to increment the vf error reference count for |
| 9692 | * both ports because the I/O resume function will be called |
| 9693 | * for both of them. |
| 9694 | */ |
| 9695 | adapter->vferr_refcount++; |
| 9696 | |
| 9697 | return PCI_ERS_RESULT_RECOVERED; |
| 9698 | |
| 9699 | skip_bad_vf_detection: |
| 9700 | #endif /* CONFIG_PCI_IOV */ |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 9701 | if (!test_bit(__IXGBE_SERVICE_INITED, &adapter->state)) |
| 9702 | return PCI_ERS_RESULT_DISCONNECT; |
| 9703 | |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 9704 | rtnl_lock(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9705 | netif_device_detach(netdev); |
| 9706 | |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 9707 | if (state == pci_channel_io_perm_failure) { |
| 9708 | rtnl_unlock(); |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 9709 | return PCI_ERS_RESULT_DISCONNECT; |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 9710 | } |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 9711 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9712 | if (netif_running(netdev)) |
| 9713 | ixgbe_down(adapter); |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 9714 | |
| 9715 | if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state)) |
| 9716 | pci_disable_device(pdev); |
| 9717 | rtnl_unlock(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9718 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 9719 | /* Request a slot reset. */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9720 | return PCI_ERS_RESULT_NEED_RESET; |
| 9721 | } |
| 9722 | |
| 9723 | /** |
| 9724 | * ixgbe_io_slot_reset - called after the pci bus has been reset. |
| 9725 | * @pdev: Pointer to PCI device |
| 9726 | * |
| 9727 | * Restart the card from scratch, as if from a cold-boot. |
| 9728 | */ |
| 9729 | static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev) |
| 9730 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 9731 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9732 | pci_ers_result_t result; |
| 9733 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9734 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 9735 | if (pci_enable_device_mem(pdev)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 9736 | 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] | 9737 | result = PCI_ERS_RESULT_DISCONNECT; |
| 9738 | } else { |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 9739 | smp_mb__before_atomic(); |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 9740 | clear_bit(__IXGBE_DISABLED, &adapter->state); |
Mark Rustad | 0391bbe | 2014-02-28 15:48:55 -0800 | [diff] [blame] | 9741 | adapter->hw.hw_addr = adapter->io_addr; |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9742 | pci_set_master(pdev); |
| 9743 | pci_restore_state(pdev); |
Breno Leitao | c0e1f68 | 2009-11-10 08:37:47 +0000 | [diff] [blame] | 9744 | pci_save_state(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9745 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 9746 | pci_wake_from_d3(pdev, false); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9747 | |
| 9748 | ixgbe_reset(adapter); |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 9749 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9750 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9751 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9752 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9753 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 9754 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 9755 | e_dev_err("pci_cleanup_aer_uncorrect_error_status " |
| 9756 | "failed 0x%0x\n", err); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9757 | /* non-fatal, continue */ |
| 9758 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9759 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 9760 | return result; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9761 | } |
| 9762 | |
| 9763 | /** |
| 9764 | * ixgbe_io_resume - called when traffic can start flowing again. |
| 9765 | * @pdev: Pointer to PCI device |
| 9766 | * |
| 9767 | * This callback is called when the error recovery driver tells us that |
| 9768 | * its OK to resume normal operation. |
| 9769 | */ |
| 9770 | static void ixgbe_io_resume(struct pci_dev *pdev) |
| 9771 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 9772 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 9773 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9774 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 9775 | #ifdef CONFIG_PCI_IOV |
| 9776 | if (adapter->vferr_refcount) { |
| 9777 | e_info(drv, "Resuming after VF err\n"); |
| 9778 | adapter->vferr_refcount--; |
| 9779 | return; |
| 9780 | } |
| 9781 | |
| 9782 | #endif |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 9783 | if (netif_running(netdev)) |
| 9784 | ixgbe_up(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9785 | |
| 9786 | netif_device_attach(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9787 | } |
| 9788 | |
Stephen Hemminger | 3646f0e | 2012-09-07 09:33:15 -0700 | [diff] [blame] | 9789 | static const struct pci_error_handlers ixgbe_err_handler = { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9790 | .error_detected = ixgbe_io_error_detected, |
| 9791 | .slot_reset = ixgbe_io_slot_reset, |
| 9792 | .resume = ixgbe_io_resume, |
| 9793 | }; |
| 9794 | |
| 9795 | static struct pci_driver ixgbe_driver = { |
| 9796 | .name = ixgbe_driver_name, |
| 9797 | .id_table = ixgbe_pci_tbl, |
| 9798 | .probe = ixgbe_probe, |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 9799 | .remove = ixgbe_remove, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9800 | #ifdef CONFIG_PM |
| 9801 | .suspend = ixgbe_suspend, |
| 9802 | .resume = ixgbe_resume, |
| 9803 | #endif |
| 9804 | .shutdown = ixgbe_shutdown, |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 9805 | .sriov_configure = ixgbe_pci_sriov_configure, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9806 | .err_handler = &ixgbe_err_handler |
| 9807 | }; |
| 9808 | |
| 9809 | /** |
| 9810 | * ixgbe_init_module - Driver Registration Routine |
| 9811 | * |
| 9812 | * ixgbe_init_module is the first routine called when the driver is |
| 9813 | * loaded. All it does is register with the PCI subsystem. |
| 9814 | **/ |
| 9815 | static int __init ixgbe_init_module(void) |
| 9816 | { |
| 9817 | int ret; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 9818 | pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version); |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 9819 | pr_info("%s\n", ixgbe_copyright); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9820 | |
Mark Rustad | 780484d | 2015-10-21 17:21:10 -0700 | [diff] [blame] | 9821 | ixgbe_wq = create_singlethread_workqueue(ixgbe_driver_name); |
| 9822 | if (!ixgbe_wq) { |
| 9823 | pr_err("%s: Failed to create workqueue\n", ixgbe_driver_name); |
| 9824 | return -ENOMEM; |
| 9825 | } |
| 9826 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 9827 | ixgbe_dbg_init(); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 9828 | |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 9829 | ret = pci_register_driver(&ixgbe_driver); |
| 9830 | if (ret) { |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 9831 | ixgbe_dbg_exit(); |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 9832 | return ret; |
| 9833 | } |
| 9834 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 9835 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9836 | dca_register_notify(&dca_notifier); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9837 | #endif |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 9838 | |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 9839 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9840 | } |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 9841 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9842 | module_init(ixgbe_init_module); |
| 9843 | |
| 9844 | /** |
| 9845 | * ixgbe_exit_module - Driver Exit Cleanup Routine |
| 9846 | * |
| 9847 | * ixgbe_exit_module is called just before the driver is removed |
| 9848 | * from memory. |
| 9849 | **/ |
| 9850 | static void __exit ixgbe_exit_module(void) |
| 9851 | { |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 9852 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9853 | dca_unregister_notify(&dca_notifier); |
| 9854 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9855 | pci_unregister_driver(&ixgbe_driver); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 9856 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 9857 | ixgbe_dbg_exit(); |
Mark Rustad | 780484d | 2015-10-21 17:21:10 -0700 | [diff] [blame] | 9858 | if (ixgbe_wq) { |
| 9859 | destroy_workqueue(ixgbe_wq); |
| 9860 | ixgbe_wq = NULL; |
| 9861 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9862 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9863 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 9864 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9865 | static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 9866 | void *p) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9867 | { |
| 9868 | int ret_val; |
| 9869 | |
| 9870 | ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 9871 | __ixgbe_notify_dca); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9872 | |
| 9873 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; |
| 9874 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 9875 | |
Alexander Duyck | b453368 | 2009-03-31 21:32:42 +0000 | [diff] [blame] | 9876 | #endif /* CONFIG_IXGBE_DCA */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 9877 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 9878 | module_exit(ixgbe_exit_module); |
| 9879 | |
| 9880 | /* ixgbe_main.c */ |